< prev index next >

src/jdk.compiler/share/classes/com/sun/tools/javac/tree/JCTree.java

Print this page

        

*** 36,45 **** --- 36,46 ---- import com.sun.source.tree.*; import com.sun.tools.javac.code.*; import com.sun.tools.javac.code.Directive.RequiresDirective; import com.sun.tools.javac.code.Scope.*; import com.sun.tools.javac.code.Symbol.*; + import com.sun.tools.javac.comp.MatchBindingsComputer.BindingSymbol; import com.sun.tools.javac.util.*; import com.sun.tools.javac.util.DefinedBy.Api; import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition; import com.sun.tools.javac.util.List;
*** 237,246 **** --- 238,251 ---- /** Type test expressions, of type TypeTest. */ TYPETEST, + /** Patterns. + */ + BINDINGPATTERN, + /** Indexed array expressions, of type Indexed. */ INDEXED, /** Selections, of type Select.
*** 2143,2164 **** /** * A type test. */ public static class JCInstanceOf extends JCExpression implements InstanceOfTree { public JCExpression expr; ! public JCTree clazz; ! protected JCInstanceOf(JCExpression expr, JCTree clazz) { this.expr = expr; ! this.clazz = clazz; } @Override public void accept(Visitor v) { v.visitTypeTest(this); } @DefinedBy(Api.COMPILER_TREE) public Kind getKind() { return Kind.INSTANCE_OF; } @DefinedBy(Api.COMPILER_TREE) ! public JCTree getType() { return clazz; } @DefinedBy(Api.COMPILER_TREE) public JCExpression getExpression() { return expr; } @Override @DefinedBy(Api.COMPILER_TREE) public <R,D> R accept(TreeVisitor<R,D> v, D d) { return v.visitInstanceOf(this, d); --- 2148,2175 ---- /** * A type test. */ public static class JCInstanceOf extends JCExpression implements InstanceOfTree { public JCExpression expr; ! public JCTree pattern; ! protected JCInstanceOf(JCExpression expr, JCTree pattern) { this.expr = expr; ! this.pattern = pattern; } @Override public void accept(Visitor v) { v.visitTypeTest(this); } @DefinedBy(Api.COMPILER_TREE) public Kind getKind() { return Kind.INSTANCE_OF; } @DefinedBy(Api.COMPILER_TREE) ! public JCTree getType() { return pattern instanceof JCPattern ? pattern.hasTag(BINDINGPATTERN) ? ((JCBindingPattern) pattern).vartype : null : pattern; } ! ! @Override @DefinedBy(Api.COMPILER_TREE) ! public JCPattern getPattern() { ! return pattern instanceof JCPattern ? (JCPattern) pattern : null; ! } ! @DefinedBy(Api.COMPILER_TREE) public JCExpression getExpression() { return expr; } @Override @DefinedBy(Api.COMPILER_TREE) public <R,D> R accept(TreeVisitor<R,D> v, D d) { return v.visitInstanceOf(this, d);
*** 2168,2177 **** --- 2179,2242 ---- return TYPETEST; } } /** + * Pattern matching forms. + */ + public static abstract class JCPattern extends JCTree + implements PatternTree { + public JCExpression constExpression() { + return null; + } + } + + public static class JCBindingPattern extends JCPattern + implements BindingPatternTree { + public Name name; + public BindingSymbol symbol; + public JCTree vartype; + + protected JCBindingPattern(Name name, BindingSymbol symbol, JCTree vartype) { + this.name = name; + this.symbol = symbol; + this.vartype = vartype; + } + + @DefinedBy(Api.COMPILER_TREE) + public Name getBinding() { + return name; + } + + @Override @DefinedBy(Api.COMPILER_TREE) + public Tree getType() { + return vartype; + } + + @Override + public void accept(Visitor v) { + v.visitBindingPattern(this); + } + + @DefinedBy(Api.COMPILER_TREE) + public Kind getKind() { + return Kind.BINDING_PATTERN; + } + + @Override + @DefinedBy(Api.COMPILER_TREE) + public <R, D> R accept(TreeVisitor<R, D> v, D d) { + return v.visitBindingPattern(this, d); + } + + @Override + public Tag getTag() { + return BINDINGPATTERN; + } + } + + /** * An array selection */ public static class JCArrayAccess extends JCExpression implements ArrayAccessTree { public JCExpression indexed; public JCExpression index;
*** 3141,3150 **** --- 3206,3216 ---- JCAssignOp Assignop(Tag opcode, JCTree lhs, JCTree rhs); JCUnary Unary(Tag opcode, JCExpression arg); JCBinary Binary(Tag opcode, JCExpression lhs, JCExpression rhs); JCTypeCast TypeCast(JCTree expr, JCExpression type); JCInstanceOf TypeTest(JCExpression expr, JCTree clazz); + JCBindingPattern BindingPattern(Name name, JCTree vartype); JCArrayAccess Indexed(JCExpression indexed, JCExpression index); JCFieldAccess Select(JCExpression selected, Name selector); JCIdent Ident(Name idname); JCLiteral Literal(TypeTag tag, Object value); JCPrimitiveTypeTree TypeIdent(TypeTag typetag);
*** 3205,3214 **** --- 3271,3281 ---- public void visitAssignop(JCAssignOp that) { visitTree(that); } public void visitUnary(JCUnary that) { visitTree(that); } public void visitBinary(JCBinary that) { visitTree(that); } public void visitTypeCast(JCTypeCast that) { visitTree(that); } public void visitTypeTest(JCInstanceOf that) { visitTree(that); } + public void visitBindingPattern(JCBindingPattern that) { visitTree(that); } public void visitIndexed(JCArrayAccess that) { visitTree(that); } public void visitSelect(JCFieldAccess that) { visitTree(that); } public void visitReference(JCMemberReference that) { visitTree(that); } public void visitIdent(JCIdent that) { visitTree(that); } public void visitLiteral(JCLiteral that) { visitTree(that); }
< prev index next >