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

changeset 1570
f91144b7da75
parent 1521
71f35e4b93a5
child 1615
12202e6ab78a
     1.1 --- a/src/share/classes/com/sun/tools/javac/tree/JCTree.java	Mon Jan 21 01:27:42 2013 -0500
     1.2 +++ b/src/share/classes/com/sun/tools/javac/tree/JCTree.java	Mon Feb 04 18:08:53 2013 -0500
     1.3 @@ -1,5 +1,5 @@
     1.4  /*
     1.5 - * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved.
     1.6 + * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.
     1.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.8   *
     1.9   * This code is free software; you can redistribute it and/or modify it
    1.10 @@ -250,11 +250,11 @@
    1.11           */
    1.12          TYPEAPPLY,
    1.13  
    1.14 -        /** Union types, of type TypeUnion
    1.15 +        /** Union types, of type TypeUnion.
    1.16           */
    1.17          TYPEUNION,
    1.18  
    1.19 -        /** Intersection types, of type TypeIntersection
    1.20 +        /** Intersection types, of type TypeIntersection.
    1.21           */
    1.22          TYPEINTERSECTION,
    1.23  
    1.24 @@ -274,10 +274,16 @@
    1.25           */
    1.26          ANNOTATION,
    1.27  
    1.28 +        /** metadata: Type annotation.
    1.29 +         */
    1.30 +        TYPE_ANNOTATION,
    1.31 +
    1.32          /** metadata: Modifiers
    1.33           */
    1.34          MODIFIERS,
    1.35  
    1.36 +        /** An annotated type tree.
    1.37 +         */
    1.38          ANNOTATED_TYPE,
    1.39  
    1.40          /** Error trees, of type Erroneous.
    1.41 @@ -607,6 +613,42 @@
    1.42      }
    1.43  
    1.44      /**
    1.45 +     * Common supertype for all poly expression trees (lambda, method references,
    1.46 +     * conditionals, method and constructor calls)
    1.47 +     */
    1.48 +    public static abstract class JCPolyExpression extends JCExpression {
    1.49 +
    1.50 +        /**
    1.51 +         * A poly expression can only be truly 'poly' in certain contexts
    1.52 +         */
    1.53 +        public enum PolyKind {
    1.54 +            /** poly expression to be treated as a standalone expression */
    1.55 +            STANDALONE,
    1.56 +            /** true poly expression */
    1.57 +            POLY;
    1.58 +        }
    1.59 +
    1.60 +        /** is this poly expression a 'true' poly expression? */
    1.61 +        public PolyKind polyKind;
    1.62 +    }
    1.63 +
    1.64 +    /**
    1.65 +     * Common supertype for all functional expression trees (lambda and method references)
    1.66 +     */
    1.67 +    public static abstract class JCFunctionalExpression extends JCPolyExpression {
    1.68 +
    1.69 +        public JCFunctionalExpression() {
    1.70 +            //a functional expression is always a 'true' poly
    1.71 +            polyKind = PolyKind.POLY;
    1.72 +        }
    1.73 +
    1.74 +        /** target descriptor inferred for this functional expression. */
    1.75 +        public Type descriptorType;
    1.76 +        /** list of target types inferred for this functional expression. */
    1.77 +        public List<TypeSymbol> targets;
    1.78 +    }
    1.79 +
    1.80 +    /**
    1.81       * A class definition.
    1.82       */
    1.83      public static class JCClassDecl extends JCStatement implements ClassTree {
    1.84 @@ -689,6 +731,8 @@
    1.85          public JCExpression restype;
    1.86          /** type parameters */
    1.87          public List<JCTypeParameter> typarams;
    1.88 +        /** receiver parameter */
    1.89 +        public JCVariableDecl recvparam;
    1.90          /** value parameters */
    1.91          public List<JCVariableDecl> params;
    1.92          /** exceptions thrown by this method */
    1.93 @@ -703,6 +747,7 @@
    1.94                              Name name,
    1.95                              JCExpression restype,
    1.96                              List<JCTypeParameter> typarams,
    1.97 +                            JCVariableDecl recvparam,
    1.98                              List<JCVariableDecl> params,
    1.99                              List<JCExpression> thrown,
   1.100                              JCBlock body,
   1.101 @@ -714,6 +759,9 @@
   1.102              this.restype = restype;
   1.103              this.typarams = typarams;
   1.104              this.params = params;
   1.105 +            this.recvparam = recvparam;
   1.106 +            // TODO: do something special if the given type is null?
   1.107 +            // receiver != null ? receiver : List.<JCTypeAnnotation>nil());
   1.108              this.thrown = thrown;
   1.109              this.body = body;
   1.110              this.defaultValue = defaultValue;
   1.111 @@ -732,6 +780,7 @@
   1.112          public List<JCVariableDecl> getParameters() {
   1.113              return params;
   1.114          }
   1.115 +        public JCVariableDecl getReceiverParameter() { return recvparam; }
   1.116          public List<JCExpression> getThrows() {
   1.117              return thrown;
   1.118          }
   1.119 @@ -1147,7 +1196,7 @@
   1.120      /**
   1.121       * A ( ) ? ( ) : ( ) conditional expression
   1.122       */
   1.123 -    public static class JCConditional extends JCExpression implements ConditionalExpressionTree {
   1.124 +    public static class JCConditional extends JCPolyExpression implements ConditionalExpressionTree {
   1.125          public JCExpression cond;
   1.126          public JCExpression truepart;
   1.127          public JCExpression falsepart;
   1.128 @@ -1373,7 +1422,7 @@
   1.129      /**
   1.130       * A method invocation
   1.131       */
   1.132 -    public static class JCMethodInvocation extends JCExpression implements MethodInvocationTree {
   1.133 +    public static class JCMethodInvocation extends JCPolyExpression implements MethodInvocationTree {
   1.134          public List<JCExpression> typeargs;
   1.135          public JCExpression meth;
   1.136          public List<JCExpression> args;
   1.137 @@ -1416,7 +1465,7 @@
   1.138      /**
   1.139       * A new(...) operation.
   1.140       */
   1.141 -    public static class JCNewClass extends JCExpression implements NewClassTree {
   1.142 +    public static class JCNewClass extends JCPolyExpression implements NewClassTree {
   1.143          public JCExpression encl;
   1.144          public List<JCExpression> typeargs;
   1.145          public JCExpression clazz;
   1.146 @@ -1469,6 +1518,10 @@
   1.147      public static class JCNewArray extends JCExpression implements NewArrayTree {
   1.148          public JCExpression elemtype;
   1.149          public List<JCExpression> dims;
   1.150 +        // type annotations on inner-most component
   1.151 +        public List<JCAnnotation> annotations;
   1.152 +        // type annotations on dimensions
   1.153 +        public List<List<JCAnnotation>> dimAnnotations;
   1.154          public List<JCExpression> elems;
   1.155          protected JCNewArray(JCExpression elemtype,
   1.156                             List<JCExpression> dims,
   1.157 @@ -1476,6 +1529,8 @@
   1.158          {
   1.159              this.elemtype = elemtype;
   1.160              this.dims = dims;
   1.161 +            this.annotations = List.nil();
   1.162 +            this.dimAnnotations = List.nil();
   1.163              this.elems = elems;
   1.164          }
   1.165          @Override
   1.166 @@ -1502,18 +1557,29 @@
   1.167      /**
   1.168       * A lambda expression.
   1.169       */
   1.170 -    public static class JCLambda extends JCExpression implements LambdaExpressionTree {
   1.171 +    public static class JCLambda extends JCFunctionalExpression implements LambdaExpressionTree {
   1.172 +
   1.173 +        public enum ParameterKind {
   1.174 +            IMPLICIT,
   1.175 +            EXPLICIT;
   1.176 +        }
   1.177  
   1.178          public List<JCVariableDecl> params;
   1.179          public JCTree body;
   1.180 -        public Type targetType;
   1.181          public boolean canCompleteNormally = true;
   1.182          public List<Type> inferredThrownTypes;
   1.183 +        public ParameterKind paramKind;
   1.184  
   1.185          public JCLambda(List<JCVariableDecl> params,
   1.186                          JCTree body) {
   1.187              this.params = params;
   1.188              this.body = body;
   1.189 +            if (params.isEmpty() ||
   1.190 +                params.head.vartype != null) {
   1.191 +                paramKind = ParameterKind.EXPLICIT;
   1.192 +            } else {
   1.193 +                paramKind = ParameterKind.IMPLICIT;
   1.194 +            }
   1.195          }
   1.196          @Override
   1.197          public Tag getTag() {
   1.198 @@ -1812,15 +1878,15 @@
   1.199      /**
   1.200       * Selects a member expression.
   1.201       */
   1.202 -    public static class JCMemberReference extends JCExpression implements MemberReferenceTree {
   1.203 +    public static class JCMemberReference extends JCFunctionalExpression implements MemberReferenceTree {
   1.204          public ReferenceMode mode;
   1.205          public ReferenceKind kind;
   1.206          public Name name;
   1.207          public JCExpression expr;
   1.208          public List<JCExpression> typeargs;
   1.209 -        public Type targetType;
   1.210          public Symbol sym;
   1.211          public Type varargsElement;
   1.212 +        public PolyKind refPolyKind;
   1.213  
   1.214          /**
   1.215           * Javac-dependent classification for member references, based
   1.216 @@ -1838,7 +1904,9 @@
   1.217              /** Inner # new */
   1.218              IMPLICIT_INNER(ReferenceMode.NEW, false),
   1.219              /** Toplevel # new */
   1.220 -            TOPLEVEL(ReferenceMode.NEW, false);
   1.221 +            TOPLEVEL(ReferenceMode.NEW, false),
   1.222 +            /** ArrayType # new */
   1.223 +            ARRAY_CTOR(ReferenceMode.NEW, false);
   1.224  
   1.225              final ReferenceMode mode;
   1.226              final boolean unbound;
   1.227 @@ -2103,9 +2171,12 @@
   1.228          public Name name;
   1.229          /** bounds */
   1.230          public List<JCExpression> bounds;
   1.231 -        protected JCTypeParameter(Name name, List<JCExpression> bounds) {
   1.232 +        /** type annotations on type parameter */
   1.233 +        public List<JCAnnotation> annotations;
   1.234 +        protected JCTypeParameter(Name name, List<JCExpression> bounds, List<JCAnnotation> annotations) {
   1.235              this.name = name;
   1.236              this.bounds = bounds;
   1.237 +            this.annotations = annotations;
   1.238          }
   1.239          @Override
   1.240          public void accept(Visitor v) { v.visitTypeParameter(this); }
   1.241 @@ -2115,6 +2186,9 @@
   1.242          public List<JCExpression> getBounds() {
   1.243              return bounds;
   1.244          }
   1.245 +        public List<JCAnnotation> getAnnotations() {
   1.246 +            return annotations;
   1.247 +        }
   1.248          @Override
   1.249          public <R,D> R accept(TreeVisitor<R,D> v, D d) {
   1.250              return v.visitTypeParameter(this, d);
   1.251 @@ -2181,16 +2255,27 @@
   1.252      }
   1.253  
   1.254      public static class JCAnnotation extends JCExpression implements AnnotationTree {
   1.255 +        // Either Tag.ANNOTATION or Tag.TYPE_ANNOTATION
   1.256 +        private Tag tag;
   1.257 +
   1.258          public JCTree annotationType;
   1.259          public List<JCExpression> args;
   1.260 -        protected JCAnnotation(JCTree annotationType, List<JCExpression> args) {
   1.261 +
   1.262 +        // Attribute.Compound if tag is ANNOTATION
   1.263 +        // Attribute.TypeCompound if tag is TYPE_ANNOTATION
   1.264 +        public Attribute.Compound attribute;
   1.265 +
   1.266 +        protected JCAnnotation(Tag tag, JCTree annotationType, List<JCExpression> args) {
   1.267 +            this.tag = tag;
   1.268              this.annotationType = annotationType;
   1.269              this.args = args;
   1.270          }
   1.271 +
   1.272          @Override
   1.273          public void accept(Visitor v) { v.visitAnnotation(this); }
   1.274  
   1.275 -        public Kind getKind() { return Kind.ANNOTATION; }
   1.276 +        public Kind getKind() { return TreeInfo.tagToKind(getTag()); }
   1.277 +
   1.278          public JCTree getAnnotationType() { return annotationType; }
   1.279          public List<JCExpression> getArguments() {
   1.280              return args;
   1.281 @@ -2201,7 +2286,7 @@
   1.282          }
   1.283          @Override
   1.284          public Tag getTag() {
   1.285 -            return ANNOTATION;
   1.286 +            return tag;
   1.287          }
   1.288      }
   1.289  
   1.290 @@ -2232,6 +2317,35 @@
   1.291          }
   1.292      }
   1.293  
   1.294 +    public static class JCAnnotatedType extends JCExpression implements com.sun.source.tree.AnnotatedTypeTree {
   1.295 +        // type annotations
   1.296 +        public List<JCAnnotation> annotations;
   1.297 +        public JCExpression underlyingType;
   1.298 +
   1.299 +        protected JCAnnotatedType(List<JCAnnotation> annotations, JCExpression underlyingType) {
   1.300 +            this.annotations = annotations;
   1.301 +            this.underlyingType = underlyingType;
   1.302 +        }
   1.303 +        @Override
   1.304 +        public void accept(Visitor v) { v.visitAnnotatedType(this); }
   1.305 +
   1.306 +        public Kind getKind() { return Kind.ANNOTATED_TYPE; }
   1.307 +        public List<JCAnnotation> getAnnotations() {
   1.308 +            return annotations;
   1.309 +        }
   1.310 +        public JCExpression getUnderlyingType() {
   1.311 +            return underlyingType;
   1.312 +        }
   1.313 +        @Override
   1.314 +        public <R,D> R accept(TreeVisitor<R,D> v, D d) {
   1.315 +            return v.visitAnnotatedType(this, d);
   1.316 +        }
   1.317 +        @Override
   1.318 +        public Tag getTag() {
   1.319 +            return ANNOTATED_TYPE;
   1.320 +        }
   1.321 +    }
   1.322 +
   1.323      public static class JCErroneous extends JCExpression
   1.324              implements com.sun.source.tree.ErroneousTree {
   1.325          public List<? extends JCTree> errs;
   1.326 @@ -2298,6 +2412,7 @@
   1.327                              Name name,
   1.328                              JCExpression restype,
   1.329                              List<JCTypeParameter> typarams,
   1.330 +                            JCVariableDecl recvparam,
   1.331                              List<JCVariableDecl> params,
   1.332                              List<JCExpression> thrown,
   1.333                              JCBlock body,
   1.334 @@ -2423,6 +2538,7 @@
   1.335          public void visitTypeBoundKind(TypeBoundKind that)   { visitTree(that); }
   1.336          public void visitAnnotation(JCAnnotation that)       { visitTree(that); }
   1.337          public void visitModifiers(JCModifiers that)         { visitTree(that); }
   1.338 +        public void visitAnnotatedType(JCAnnotatedType that) { visitTree(that); }
   1.339          public void visitErroneous(JCErroneous that)         { visitTree(that); }
   1.340          public void visitLetExpr(LetExpr that)               { visitTree(that); }
   1.341  

mercurial