36 import com.sun.source.tree.*; |
36 import com.sun.source.tree.*; |
37 import com.sun.tools.javac.code.*; |
37 import com.sun.tools.javac.code.*; |
38 import com.sun.tools.javac.code.Directive.RequiresDirective; |
38 import com.sun.tools.javac.code.Directive.RequiresDirective; |
39 import com.sun.tools.javac.code.Scope.*; |
39 import com.sun.tools.javac.code.Scope.*; |
40 import com.sun.tools.javac.code.Symbol.*; |
40 import com.sun.tools.javac.code.Symbol.*; |
|
41 import com.sun.tools.javac.comp.MatchBindingsComputer.BindingSymbol; |
41 import com.sun.tools.javac.util.*; |
42 import com.sun.tools.javac.util.*; |
42 import com.sun.tools.javac.util.DefinedBy.Api; |
43 import com.sun.tools.javac.util.DefinedBy.Api; |
43 import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition; |
44 import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition; |
44 import com.sun.tools.javac.util.List; |
45 import com.sun.tools.javac.util.List; |
45 |
46 |
2133 /** |
2138 /** |
2134 * A type test. |
2139 * A type test. |
2135 */ |
2140 */ |
2136 public static class JCInstanceOf extends JCExpression implements InstanceOfTree { |
2141 public static class JCInstanceOf extends JCExpression implements InstanceOfTree { |
2137 public JCExpression expr; |
2142 public JCExpression expr; |
2138 public JCTree clazz; |
2143 public JCTree pattern; |
2139 protected JCInstanceOf(JCExpression expr, JCTree clazz) { |
2144 protected JCInstanceOf(JCExpression expr, JCTree pattern) { |
2140 this.expr = expr; |
2145 this.expr = expr; |
2141 this.clazz = clazz; |
2146 this.pattern = pattern; |
2142 } |
2147 } |
2143 @Override |
2148 @Override |
2144 public void accept(Visitor v) { v.visitTypeTest(this); } |
2149 public void accept(Visitor v) { v.visitTypeTest(this); } |
2145 |
2150 |
2146 @DefinedBy(Api.COMPILER_TREE) |
2151 @DefinedBy(Api.COMPILER_TREE) |
2147 public Kind getKind() { return Kind.INSTANCE_OF; } |
2152 public Kind getKind() { return Kind.INSTANCE_OF; } |
2148 @DefinedBy(Api.COMPILER_TREE) |
2153 @DefinedBy(Api.COMPILER_TREE) |
2149 public JCTree getType() { return clazz; } |
2154 public JCTree getType() { return pattern instanceof JCPattern ? pattern.hasTag(BINDINGPATTERN) ? ((JCBindingPattern) pattern).vartype : null : pattern; } |
|
2155 |
|
2156 @Override @DefinedBy(Api.COMPILER_TREE) |
|
2157 public JCPattern getPattern() { |
|
2158 return pattern instanceof JCPattern ? (JCPattern) pattern : null; |
|
2159 } |
|
2160 |
2150 @DefinedBy(Api.COMPILER_TREE) |
2161 @DefinedBy(Api.COMPILER_TREE) |
2151 public JCExpression getExpression() { return expr; } |
2162 public JCExpression getExpression() { return expr; } |
2152 @Override @DefinedBy(Api.COMPILER_TREE) |
2163 @Override @DefinedBy(Api.COMPILER_TREE) |
2153 public <R,D> R accept(TreeVisitor<R,D> v, D d) { |
2164 public <R,D> R accept(TreeVisitor<R,D> v, D d) { |
2154 return v.visitInstanceOf(this, d); |
2165 return v.visitInstanceOf(this, d); |
2155 } |
2166 } |
2156 @Override |
2167 @Override |
2157 public Tag getTag() { |
2168 public Tag getTag() { |
2158 return TYPETEST; |
2169 return TYPETEST; |
|
2170 } |
|
2171 } |
|
2172 |
|
2173 /** |
|
2174 * Pattern matching forms. |
|
2175 */ |
|
2176 public static abstract class JCPattern extends JCTree |
|
2177 implements PatternTree { |
|
2178 public JCExpression constExpression() { |
|
2179 return null; |
|
2180 } |
|
2181 } |
|
2182 |
|
2183 public static class JCBindingPattern extends JCPattern |
|
2184 implements BindingPatternTree { |
|
2185 public Name name; |
|
2186 public BindingSymbol symbol; |
|
2187 public JCTree vartype; |
|
2188 |
|
2189 protected JCBindingPattern(Name name, BindingSymbol symbol, JCTree vartype) { |
|
2190 this.name = name; |
|
2191 this.symbol = symbol; |
|
2192 this.vartype = vartype; |
|
2193 } |
|
2194 |
|
2195 @DefinedBy(Api.COMPILER_TREE) |
|
2196 public Name getBinding() { |
|
2197 return name; |
|
2198 } |
|
2199 |
|
2200 @Override @DefinedBy(Api.COMPILER_TREE) |
|
2201 public Tree getType() { |
|
2202 return vartype; |
|
2203 } |
|
2204 |
|
2205 @Override |
|
2206 public void accept(Visitor v) { |
|
2207 v.visitBindingPattern(this); |
|
2208 } |
|
2209 |
|
2210 @DefinedBy(Api.COMPILER_TREE) |
|
2211 public Kind getKind() { |
|
2212 return Kind.BINDING_PATTERN; |
|
2213 } |
|
2214 |
|
2215 @Override |
|
2216 @DefinedBy(Api.COMPILER_TREE) |
|
2217 public <R, D> R accept(TreeVisitor<R, D> v, D d) { |
|
2218 return v.visitBindingPattern(this, d); |
|
2219 } |
|
2220 |
|
2221 @Override |
|
2222 public Tag getTag() { |
|
2223 return BINDINGPATTERN; |
2159 } |
2224 } |
2160 } |
2225 } |
2161 |
2226 |
2162 /** |
2227 /** |
2163 * An array selection |
2228 * An array selection |
3131 JCAssignOp Assignop(Tag opcode, JCTree lhs, JCTree rhs); |
3196 JCAssignOp Assignop(Tag opcode, JCTree lhs, JCTree rhs); |
3132 JCUnary Unary(Tag opcode, JCExpression arg); |
3197 JCUnary Unary(Tag opcode, JCExpression arg); |
3133 JCBinary Binary(Tag opcode, JCExpression lhs, JCExpression rhs); |
3198 JCBinary Binary(Tag opcode, JCExpression lhs, JCExpression rhs); |
3134 JCTypeCast TypeCast(JCTree expr, JCExpression type); |
3199 JCTypeCast TypeCast(JCTree expr, JCExpression type); |
3135 JCInstanceOf TypeTest(JCExpression expr, JCTree clazz); |
3200 JCInstanceOf TypeTest(JCExpression expr, JCTree clazz); |
|
3201 JCBindingPattern BindingPattern(Name name, JCTree vartype); |
3136 JCArrayAccess Indexed(JCExpression indexed, JCExpression index); |
3202 JCArrayAccess Indexed(JCExpression indexed, JCExpression index); |
3137 JCFieldAccess Select(JCExpression selected, Name selector); |
3203 JCFieldAccess Select(JCExpression selected, Name selector); |
3138 JCIdent Ident(Name idname); |
3204 JCIdent Ident(Name idname); |
3139 JCLiteral Literal(TypeTag tag, Object value); |
3205 JCLiteral Literal(TypeTag tag, Object value); |
3140 JCPrimitiveTypeTree TypeIdent(TypeTag typetag); |
3206 JCPrimitiveTypeTree TypeIdent(TypeTag typetag); |
3195 public void visitAssignop(JCAssignOp that) { visitTree(that); } |
3261 public void visitAssignop(JCAssignOp that) { visitTree(that); } |
3196 public void visitUnary(JCUnary that) { visitTree(that); } |
3262 public void visitUnary(JCUnary that) { visitTree(that); } |
3197 public void visitBinary(JCBinary that) { visitTree(that); } |
3263 public void visitBinary(JCBinary that) { visitTree(that); } |
3198 public void visitTypeCast(JCTypeCast that) { visitTree(that); } |
3264 public void visitTypeCast(JCTypeCast that) { visitTree(that); } |
3199 public void visitTypeTest(JCInstanceOf that) { visitTree(that); } |
3265 public void visitTypeTest(JCInstanceOf that) { visitTree(that); } |
|
3266 public void visitBindingPattern(JCBindingPattern that) { visitTree(that); } |
3200 public void visitIndexed(JCArrayAccess that) { visitTree(that); } |
3267 public void visitIndexed(JCArrayAccess that) { visitTree(that); } |
3201 public void visitSelect(JCFieldAccess that) { visitTree(that); } |
3268 public void visitSelect(JCFieldAccess that) { visitTree(that); } |
3202 public void visitReference(JCMemberReference that) { visitTree(that); } |
3269 public void visitReference(JCMemberReference that) { visitTree(that); } |
3203 public void visitIdent(JCIdent that) { visitTree(that); } |
3270 public void visitIdent(JCIdent that) { visitTree(that); } |
3204 public void visitLiteral(JCLiteral that) { visitTree(that); } |
3271 public void visitLiteral(JCLiteral that) { visitTree(that); } |