< prev index next >

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

Print this page




  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package com.sun.tools.javac.tree;
  27 
  28 import java.io.IOException;
  29 import java.io.StringWriter;
  30 import java.util.*;
  31 
  32 import javax.lang.model.element.Modifier;
  33 import javax.lang.model.type.TypeKind;
  34 import javax.tools.JavaFileObject;
  35 
  36 import com.sun.source.tree.*;
  37 import com.sun.tools.javac.code.*;
  38 import com.sun.tools.javac.code.Directive.RequiresDirective;
  39 import com.sun.tools.javac.code.Scope.*;
  40 import com.sun.tools.javac.code.Symbol.*;

  41 import com.sun.tools.javac.util.*;
  42 import com.sun.tools.javac.util.DefinedBy.Api;
  43 import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
  44 import com.sun.tools.javac.util.List;
  45 
  46 import static com.sun.tools.javac.tree.JCTree.Tag.*;
  47 
  48 import javax.tools.JavaFileManager.Location;
  49 
  50 import com.sun.source.tree.CaseTree.CaseKind;
  51 import com.sun.source.tree.ModuleTree.ModuleKind;
  52 import com.sun.tools.javac.code.Directive.ExportsDirective;
  53 import com.sun.tools.javac.code.Directive.OpensDirective;
  54 import com.sun.tools.javac.code.Type.ModuleType;
  55 import com.sun.tools.javac.tree.JCTree.JCPolyExpression.PolyKind;
  56 
  57 /**
  58  * Root class for abstract syntax tree nodes. It provides definitions
  59  * for specific tree nodes as subclasses nested inside.
  60  *


 222         /** Lambda expression, of type Lambda.
 223          */
 224         LAMBDA,
 225 
 226         /** Parenthesized subexpressions, of type Parens.
 227          */
 228         PARENS,
 229 
 230         /** Assignment expressions, of type Assign.
 231          */
 232         ASSIGN,
 233 
 234         /** Type cast expressions, of type TypeCast.
 235          */
 236         TYPECAST,
 237 
 238         /** Type test expressions, of type TypeTest.
 239          */
 240         TYPETEST,
 241 




 242         /** Indexed array expressions, of type Indexed.
 243          */
 244         INDEXED,
 245 
 246         /** Selections, of type Select.
 247          */
 248         SELECT,
 249 
 250         /** Member references, of type Reference.
 251          */
 252         REFERENCE,
 253 
 254         /** Simple identifiers, of type Ident.
 255          */
 256         IDENT,
 257 
 258         /** Literals, of type Literal.
 259          */
 260         LITERAL,
 261 


2128         public Kind getKind() { return Kind.TYPE_CAST; }
2129         @DefinedBy(Api.COMPILER_TREE)
2130         public JCTree getType() { return clazz; }
2131         @DefinedBy(Api.COMPILER_TREE)
2132         public JCExpression getExpression() { return expr; }
2133         @Override @DefinedBy(Api.COMPILER_TREE)
2134         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
2135             return v.visitTypeCast(this, d);
2136         }
2137         @Override
2138         public Tag getTag() {
2139             return TYPECAST;
2140         }
2141     }
2142 
2143     /**
2144      * A type test.
2145      */
2146     public static class JCInstanceOf extends JCExpression implements InstanceOfTree {
2147         public JCExpression expr;
2148         public JCTree clazz;
2149         protected JCInstanceOf(JCExpression expr, JCTree clazz) {
2150             this.expr = expr;
2151             this.clazz = clazz;
2152         }
2153         @Override
2154         public void accept(Visitor v) { v.visitTypeTest(this); }
2155 
2156         @DefinedBy(Api.COMPILER_TREE)
2157         public Kind getKind() { return Kind.INSTANCE_OF; }
2158         @DefinedBy(Api.COMPILER_TREE)
2159         public JCTree getType() { return clazz; }






2160         @DefinedBy(Api.COMPILER_TREE)
2161         public JCExpression getExpression() { return expr; }
2162         @Override @DefinedBy(Api.COMPILER_TREE)
2163         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
2164             return v.visitInstanceOf(this, d);
2165         }
2166         @Override
2167         public Tag getTag() {
2168             return TYPETEST;
2169         }
2170     }
2171 
2172     /**






















































2173      * An array selection
2174      */
2175     public static class JCArrayAccess extends JCExpression implements ArrayAccessTree {
2176         public JCExpression indexed;
2177         public JCExpression index;
2178         protected JCArrayAccess(JCExpression indexed, JCExpression index) {
2179             this.indexed = indexed;
2180             this.index = index;
2181         }
2182         @Override
2183         public void accept(Visitor v) { v.visitIndexed(this); }
2184 
2185         @DefinedBy(Api.COMPILER_TREE)
2186         public Kind getKind() { return Kind.ARRAY_ACCESS; }
2187         @DefinedBy(Api.COMPILER_TREE)
2188         public JCExpression getExpression() { return indexed; }
2189         @DefinedBy(Api.COMPILER_TREE)
2190         public JCExpression getIndex() { return index; }
2191         @Override @DefinedBy(Api.COMPILER_TREE)
2192         public <R,D> R accept(TreeVisitor<R,D> v, D d) {


3126         JCThrow Throw(JCExpression expr);
3127         JCAssert Assert(JCExpression cond, JCExpression detail);
3128         JCMethodInvocation Apply(List<JCExpression> typeargs,
3129                     JCExpression fn,
3130                     List<JCExpression> args);
3131         JCNewClass NewClass(JCExpression encl,
3132                           List<JCExpression> typeargs,
3133                           JCExpression clazz,
3134                           List<JCExpression> args,
3135                           JCClassDecl def);
3136         JCNewArray NewArray(JCExpression elemtype,
3137                           List<JCExpression> dims,
3138                           List<JCExpression> elems);
3139         JCParens Parens(JCExpression expr);
3140         JCAssign Assign(JCExpression lhs, JCExpression rhs);
3141         JCAssignOp Assignop(Tag opcode, JCTree lhs, JCTree rhs);
3142         JCUnary Unary(Tag opcode, JCExpression arg);
3143         JCBinary Binary(Tag opcode, JCExpression lhs, JCExpression rhs);
3144         JCTypeCast TypeCast(JCTree expr, JCExpression type);
3145         JCInstanceOf TypeTest(JCExpression expr, JCTree clazz);

3146         JCArrayAccess Indexed(JCExpression indexed, JCExpression index);
3147         JCFieldAccess Select(JCExpression selected, Name selector);
3148         JCIdent Ident(Name idname);
3149         JCLiteral Literal(TypeTag tag, Object value);
3150         JCPrimitiveTypeTree TypeIdent(TypeTag typetag);
3151         JCArrayTypeTree TypeArray(JCExpression elemtype);
3152         JCTypeApply TypeApply(JCExpression clazz, List<JCExpression> arguments);
3153         JCTypeParameter TypeParameter(Name name, List<JCExpression> bounds);
3154         JCWildcard Wildcard(TypeBoundKind kind, JCTree type);
3155         TypeBoundKind TypeBoundKind(BoundKind kind);
3156         JCAnnotation Annotation(JCTree annotationType, List<JCExpression> args);
3157         JCModifiers Modifiers(long flags, List<JCAnnotation> annotations);
3158         JCErroneous Erroneous(List<? extends JCTree> errs);
3159         JCModuleDecl ModuleDef(JCModifiers mods, ModuleKind kind, JCExpression qualId, List<JCDirective> directives);
3160         JCExports Exports(JCExpression qualId, List<JCExpression> moduleNames);
3161         JCOpens Opens(JCExpression qualId, List<JCExpression> moduleNames);
3162         JCProvides Provides(JCExpression serviceName, List<JCExpression> implNames);
3163         JCRequires Requires(boolean isTransitive, boolean isStaticPhase, JCExpression qualId);
3164         JCUses Uses(JCExpression qualId);
3165         LetExpr LetExpr(List<JCStatement> defs, JCExpression expr);


3190         public void visitConditional(JCConditional that)     { visitTree(that); }
3191         public void visitIf(JCIf that)                       { visitTree(that); }
3192         public void visitExec(JCExpressionStatement that)    { visitTree(that); }
3193         public void visitBreak(JCBreak that)                 { visitTree(that); }
3194         public void visitYield(JCYield that)                 { visitTree(that); }
3195         public void visitContinue(JCContinue that)           { visitTree(that); }
3196         public void visitReturn(JCReturn that)               { visitTree(that); }
3197         public void visitThrow(JCThrow that)                 { visitTree(that); }
3198         public void visitAssert(JCAssert that)               { visitTree(that); }
3199         public void visitApply(JCMethodInvocation that)      { visitTree(that); }
3200         public void visitNewClass(JCNewClass that)           { visitTree(that); }
3201         public void visitNewArray(JCNewArray that)           { visitTree(that); }
3202         public void visitLambda(JCLambda that)               { visitTree(that); }
3203         public void visitParens(JCParens that)               { visitTree(that); }
3204         public void visitAssign(JCAssign that)               { visitTree(that); }
3205         public void visitAssignop(JCAssignOp that)           { visitTree(that); }
3206         public void visitUnary(JCUnary that)                 { visitTree(that); }
3207         public void visitBinary(JCBinary that)               { visitTree(that); }
3208         public void visitTypeCast(JCTypeCast that)           { visitTree(that); }
3209         public void visitTypeTest(JCInstanceOf that)         { visitTree(that); }

3210         public void visitIndexed(JCArrayAccess that)         { visitTree(that); }
3211         public void visitSelect(JCFieldAccess that)          { visitTree(that); }
3212         public void visitReference(JCMemberReference that)   { visitTree(that); }
3213         public void visitIdent(JCIdent that)                 { visitTree(that); }
3214         public void visitLiteral(JCLiteral that)             { visitTree(that); }
3215         public void visitTypeIdent(JCPrimitiveTypeTree that) { visitTree(that); }
3216         public void visitTypeArray(JCArrayTypeTree that)     { visitTree(that); }
3217         public void visitTypeApply(JCTypeApply that)         { visitTree(that); }
3218         public void visitTypeUnion(JCTypeUnion that)         { visitTree(that); }
3219         public void visitTypeIntersection(JCTypeIntersection that)  { visitTree(that); }
3220         public void visitTypeParameter(JCTypeParameter that) { visitTree(that); }
3221         public void visitWildcard(JCWildcard that)           { visitTree(that); }
3222         public void visitTypeBoundKind(TypeBoundKind that)   { visitTree(that); }
3223         public void visitAnnotation(JCAnnotation that)       { visitTree(that); }
3224         public void visitModifiers(JCModifiers that)         { visitTree(that); }
3225         public void visitAnnotatedType(JCAnnotatedType that) { visitTree(that); }
3226         public void visitErroneous(JCErroneous that)         { visitTree(that); }
3227         public void visitModuleDef(JCModuleDecl that)        { visitTree(that); }
3228         public void visitExports(JCExports that)             { visitTree(that); }
3229         public void visitOpens(JCOpens that)                 { visitTree(that); }


  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package com.sun.tools.javac.tree;
  27 
  28 import java.io.IOException;
  29 import java.io.StringWriter;
  30 import java.util.*;
  31 
  32 import javax.lang.model.element.Modifier;
  33 import javax.lang.model.type.TypeKind;
  34 import javax.tools.JavaFileObject;
  35 
  36 import com.sun.source.tree.*;
  37 import com.sun.tools.javac.code.*;
  38 import com.sun.tools.javac.code.Directive.RequiresDirective;
  39 import com.sun.tools.javac.code.Scope.*;
  40 import com.sun.tools.javac.code.Symbol.*;
  41 import com.sun.tools.javac.comp.MatchBindingsComputer.BindingSymbol;
  42 import com.sun.tools.javac.util.*;
  43 import com.sun.tools.javac.util.DefinedBy.Api;
  44 import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
  45 import com.sun.tools.javac.util.List;
  46 
  47 import static com.sun.tools.javac.tree.JCTree.Tag.*;
  48 
  49 import javax.tools.JavaFileManager.Location;
  50 
  51 import com.sun.source.tree.CaseTree.CaseKind;
  52 import com.sun.source.tree.ModuleTree.ModuleKind;
  53 import com.sun.tools.javac.code.Directive.ExportsDirective;
  54 import com.sun.tools.javac.code.Directive.OpensDirective;
  55 import com.sun.tools.javac.code.Type.ModuleType;
  56 import com.sun.tools.javac.tree.JCTree.JCPolyExpression.PolyKind;
  57 
  58 /**
  59  * Root class for abstract syntax tree nodes. It provides definitions
  60  * for specific tree nodes as subclasses nested inside.
  61  *


 223         /** Lambda expression, of type Lambda.
 224          */
 225         LAMBDA,
 226 
 227         /** Parenthesized subexpressions, of type Parens.
 228          */
 229         PARENS,
 230 
 231         /** Assignment expressions, of type Assign.
 232          */
 233         ASSIGN,
 234 
 235         /** Type cast expressions, of type TypeCast.
 236          */
 237         TYPECAST,
 238 
 239         /** Type test expressions, of type TypeTest.
 240          */
 241         TYPETEST,
 242 
 243         /** Patterns.
 244          */
 245         BINDINGPATTERN,
 246 
 247         /** Indexed array expressions, of type Indexed.
 248          */
 249         INDEXED,
 250 
 251         /** Selections, of type Select.
 252          */
 253         SELECT,
 254 
 255         /** Member references, of type Reference.
 256          */
 257         REFERENCE,
 258 
 259         /** Simple identifiers, of type Ident.
 260          */
 261         IDENT,
 262 
 263         /** Literals, of type Literal.
 264          */
 265         LITERAL,
 266 


2133         public Kind getKind() { return Kind.TYPE_CAST; }
2134         @DefinedBy(Api.COMPILER_TREE)
2135         public JCTree getType() { return clazz; }
2136         @DefinedBy(Api.COMPILER_TREE)
2137         public JCExpression getExpression() { return expr; }
2138         @Override @DefinedBy(Api.COMPILER_TREE)
2139         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
2140             return v.visitTypeCast(this, d);
2141         }
2142         @Override
2143         public Tag getTag() {
2144             return TYPECAST;
2145         }
2146     }
2147 
2148     /**
2149      * A type test.
2150      */
2151     public static class JCInstanceOf extends JCExpression implements InstanceOfTree {
2152         public JCExpression expr;
2153         public JCTree pattern;
2154         protected JCInstanceOf(JCExpression expr, JCTree pattern) {
2155             this.expr = expr;
2156             this.pattern = pattern;
2157         }
2158         @Override
2159         public void accept(Visitor v) { v.visitTypeTest(this); }
2160 
2161         @DefinedBy(Api.COMPILER_TREE)
2162         public Kind getKind() { return Kind.INSTANCE_OF; }
2163         @DefinedBy(Api.COMPILER_TREE)
2164         public JCTree getType() { return pattern instanceof JCPattern ? pattern.hasTag(BINDINGPATTERN) ? ((JCBindingPattern) pattern).vartype : null : pattern; }
2165 
2166         @Override @DefinedBy(Api.COMPILER_TREE)
2167         public JCPattern getPattern() {
2168             return pattern instanceof JCPattern ? (JCPattern) pattern : null;
2169         }
2170 
2171         @DefinedBy(Api.COMPILER_TREE)
2172         public JCExpression getExpression() { return expr; }
2173         @Override @DefinedBy(Api.COMPILER_TREE)
2174         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
2175             return v.visitInstanceOf(this, d);
2176         }
2177         @Override
2178         public Tag getTag() {
2179             return TYPETEST;
2180         }
2181     }
2182 
2183     /**
2184      * Pattern matching forms.
2185      */
2186     public static abstract class JCPattern extends JCTree
2187             implements PatternTree {
2188         public JCExpression constExpression() {
2189             return null;
2190         }
2191     }
2192 
2193     public static class JCBindingPattern extends JCPattern
2194             implements BindingPatternTree {
2195         public Name name;
2196         public BindingSymbol symbol;
2197         public JCTree vartype;
2198 
2199         protected JCBindingPattern(Name name, BindingSymbol symbol, JCTree vartype) {
2200             this.name = name;
2201             this.symbol = symbol;
2202             this.vartype = vartype;
2203         }
2204 
2205         @DefinedBy(Api.COMPILER_TREE)
2206         public Name getBinding() {
2207             return name;
2208         }
2209 
2210         @Override @DefinedBy(Api.COMPILER_TREE)
2211         public Tree getType() {
2212             return vartype;
2213         }
2214 
2215         @Override
2216         public void accept(Visitor v) {
2217             v.visitBindingPattern(this);
2218         }
2219 
2220         @DefinedBy(Api.COMPILER_TREE)
2221         public Kind getKind() {
2222             return Kind.BINDING_PATTERN;
2223         }
2224 
2225         @Override
2226         @DefinedBy(Api.COMPILER_TREE)
2227         public <R, D> R accept(TreeVisitor<R, D> v, D d) {
2228             return v.visitBindingPattern(this, d);
2229         }
2230 
2231         @Override
2232         public Tag getTag() {
2233             return BINDINGPATTERN;
2234         }
2235     }
2236 
2237     /**
2238      * An array selection
2239      */
2240     public static class JCArrayAccess extends JCExpression implements ArrayAccessTree {
2241         public JCExpression indexed;
2242         public JCExpression index;
2243         protected JCArrayAccess(JCExpression indexed, JCExpression index) {
2244             this.indexed = indexed;
2245             this.index = index;
2246         }
2247         @Override
2248         public void accept(Visitor v) { v.visitIndexed(this); }
2249 
2250         @DefinedBy(Api.COMPILER_TREE)
2251         public Kind getKind() { return Kind.ARRAY_ACCESS; }
2252         @DefinedBy(Api.COMPILER_TREE)
2253         public JCExpression getExpression() { return indexed; }
2254         @DefinedBy(Api.COMPILER_TREE)
2255         public JCExpression getIndex() { return index; }
2256         @Override @DefinedBy(Api.COMPILER_TREE)
2257         public <R,D> R accept(TreeVisitor<R,D> v, D d) {


3191         JCThrow Throw(JCExpression expr);
3192         JCAssert Assert(JCExpression cond, JCExpression detail);
3193         JCMethodInvocation Apply(List<JCExpression> typeargs,
3194                     JCExpression fn,
3195                     List<JCExpression> args);
3196         JCNewClass NewClass(JCExpression encl,
3197                           List<JCExpression> typeargs,
3198                           JCExpression clazz,
3199                           List<JCExpression> args,
3200                           JCClassDecl def);
3201         JCNewArray NewArray(JCExpression elemtype,
3202                           List<JCExpression> dims,
3203                           List<JCExpression> elems);
3204         JCParens Parens(JCExpression expr);
3205         JCAssign Assign(JCExpression lhs, JCExpression rhs);
3206         JCAssignOp Assignop(Tag opcode, JCTree lhs, JCTree rhs);
3207         JCUnary Unary(Tag opcode, JCExpression arg);
3208         JCBinary Binary(Tag opcode, JCExpression lhs, JCExpression rhs);
3209         JCTypeCast TypeCast(JCTree expr, JCExpression type);
3210         JCInstanceOf TypeTest(JCExpression expr, JCTree clazz);
3211         JCBindingPattern BindingPattern(Name name, JCTree vartype);
3212         JCArrayAccess Indexed(JCExpression indexed, JCExpression index);
3213         JCFieldAccess Select(JCExpression selected, Name selector);
3214         JCIdent Ident(Name idname);
3215         JCLiteral Literal(TypeTag tag, Object value);
3216         JCPrimitiveTypeTree TypeIdent(TypeTag typetag);
3217         JCArrayTypeTree TypeArray(JCExpression elemtype);
3218         JCTypeApply TypeApply(JCExpression clazz, List<JCExpression> arguments);
3219         JCTypeParameter TypeParameter(Name name, List<JCExpression> bounds);
3220         JCWildcard Wildcard(TypeBoundKind kind, JCTree type);
3221         TypeBoundKind TypeBoundKind(BoundKind kind);
3222         JCAnnotation Annotation(JCTree annotationType, List<JCExpression> args);
3223         JCModifiers Modifiers(long flags, List<JCAnnotation> annotations);
3224         JCErroneous Erroneous(List<? extends JCTree> errs);
3225         JCModuleDecl ModuleDef(JCModifiers mods, ModuleKind kind, JCExpression qualId, List<JCDirective> directives);
3226         JCExports Exports(JCExpression qualId, List<JCExpression> moduleNames);
3227         JCOpens Opens(JCExpression qualId, List<JCExpression> moduleNames);
3228         JCProvides Provides(JCExpression serviceName, List<JCExpression> implNames);
3229         JCRequires Requires(boolean isTransitive, boolean isStaticPhase, JCExpression qualId);
3230         JCUses Uses(JCExpression qualId);
3231         LetExpr LetExpr(List<JCStatement> defs, JCExpression expr);


3256         public void visitConditional(JCConditional that)     { visitTree(that); }
3257         public void visitIf(JCIf that)                       { visitTree(that); }
3258         public void visitExec(JCExpressionStatement that)    { visitTree(that); }
3259         public void visitBreak(JCBreak that)                 { visitTree(that); }
3260         public void visitYield(JCYield that)                 { visitTree(that); }
3261         public void visitContinue(JCContinue that)           { visitTree(that); }
3262         public void visitReturn(JCReturn that)               { visitTree(that); }
3263         public void visitThrow(JCThrow that)                 { visitTree(that); }
3264         public void visitAssert(JCAssert that)               { visitTree(that); }
3265         public void visitApply(JCMethodInvocation that)      { visitTree(that); }
3266         public void visitNewClass(JCNewClass that)           { visitTree(that); }
3267         public void visitNewArray(JCNewArray that)           { visitTree(that); }
3268         public void visitLambda(JCLambda that)               { visitTree(that); }
3269         public void visitParens(JCParens that)               { visitTree(that); }
3270         public void visitAssign(JCAssign that)               { visitTree(that); }
3271         public void visitAssignop(JCAssignOp that)           { visitTree(that); }
3272         public void visitUnary(JCUnary that)                 { visitTree(that); }
3273         public void visitBinary(JCBinary that)               { visitTree(that); }
3274         public void visitTypeCast(JCTypeCast that)           { visitTree(that); }
3275         public void visitTypeTest(JCInstanceOf that)         { visitTree(that); }
3276         public void visitBindingPattern(JCBindingPattern that) { visitTree(that); }
3277         public void visitIndexed(JCArrayAccess that)         { visitTree(that); }
3278         public void visitSelect(JCFieldAccess that)          { visitTree(that); }
3279         public void visitReference(JCMemberReference that)   { visitTree(that); }
3280         public void visitIdent(JCIdent that)                 { visitTree(that); }
3281         public void visitLiteral(JCLiteral that)             { visitTree(that); }
3282         public void visitTypeIdent(JCPrimitiveTypeTree that) { visitTree(that); }
3283         public void visitTypeArray(JCArrayTypeTree that)     { visitTree(that); }
3284         public void visitTypeApply(JCTypeApply that)         { visitTree(that); }
3285         public void visitTypeUnion(JCTypeUnion that)         { visitTree(that); }
3286         public void visitTypeIntersection(JCTypeIntersection that)  { visitTree(that); }
3287         public void visitTypeParameter(JCTypeParameter that) { visitTree(that); }
3288         public void visitWildcard(JCWildcard that)           { visitTree(that); }
3289         public void visitTypeBoundKind(TypeBoundKind that)   { visitTree(that); }
3290         public void visitAnnotation(JCAnnotation that)       { visitTree(that); }
3291         public void visitModifiers(JCModifiers that)         { visitTree(that); }
3292         public void visitAnnotatedType(JCAnnotatedType that) { visitTree(that); }
3293         public void visitErroneous(JCErroneous that)         { visitTree(that); }
3294         public void visitModuleDef(JCModuleDecl that)        { visitTree(that); }
3295         public void visitExports(JCExports that)             { visitTree(that); }
3296         public void visitOpens(JCOpens that)                 { visitTree(that); }
< prev index next >