diff -r 475eb15dfdad -r f91144b7da75 src/share/classes/com/sun/tools/javac/tree/JCTree.java --- a/src/share/classes/com/sun/tools/javac/tree/JCTree.java Mon Jan 21 01:27:42 2013 -0500 +++ b/src/share/classes/com/sun/tools/javac/tree/JCTree.java Mon Feb 04 18:08:53 2013 -0500 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -250,11 +250,11 @@ */ TYPEAPPLY, - /** Union types, of type TypeUnion + /** Union types, of type TypeUnion. */ TYPEUNION, - /** Intersection types, of type TypeIntersection + /** Intersection types, of type TypeIntersection. */ TYPEINTERSECTION, @@ -274,10 +274,16 @@ */ ANNOTATION, + /** metadata: Type annotation. + */ + TYPE_ANNOTATION, + /** metadata: Modifiers */ MODIFIERS, + /** An annotated type tree. + */ ANNOTATED_TYPE, /** Error trees, of type Erroneous. @@ -607,6 +613,42 @@ } /** + * Common supertype for all poly expression trees (lambda, method references, + * conditionals, method and constructor calls) + */ + public static abstract class JCPolyExpression extends JCExpression { + + /** + * A poly expression can only be truly 'poly' in certain contexts + */ + public enum PolyKind { + /** poly expression to be treated as a standalone expression */ + STANDALONE, + /** true poly expression */ + POLY; + } + + /** is this poly expression a 'true' poly expression? */ + public PolyKind polyKind; + } + + /** + * Common supertype for all functional expression trees (lambda and method references) + */ + public static abstract class JCFunctionalExpression extends JCPolyExpression { + + public JCFunctionalExpression() { + //a functional expression is always a 'true' poly + polyKind = PolyKind.POLY; + } + + /** target descriptor inferred for this functional expression. */ + public Type descriptorType; + /** list of target types inferred for this functional expression. */ + public List targets; + } + + /** * A class definition. */ public static class JCClassDecl extends JCStatement implements ClassTree { @@ -689,6 +731,8 @@ public JCExpression restype; /** type parameters */ public List typarams; + /** receiver parameter */ + public JCVariableDecl recvparam; /** value parameters */ public List params; /** exceptions thrown by this method */ @@ -703,6 +747,7 @@ Name name, JCExpression restype, List typarams, + JCVariableDecl recvparam, List params, List thrown, JCBlock body, @@ -714,6 +759,9 @@ this.restype = restype; this.typarams = typarams; this.params = params; + this.recvparam = recvparam; + // TODO: do something special if the given type is null? + // receiver != null ? receiver : List.nil()); this.thrown = thrown; this.body = body; this.defaultValue = defaultValue; @@ -732,6 +780,7 @@ public List getParameters() { return params; } + public JCVariableDecl getReceiverParameter() { return recvparam; } public List getThrows() { return thrown; } @@ -1147,7 +1196,7 @@ /** * A ( ) ? ( ) : ( ) conditional expression */ - public static class JCConditional extends JCExpression implements ConditionalExpressionTree { + public static class JCConditional extends JCPolyExpression implements ConditionalExpressionTree { public JCExpression cond; public JCExpression truepart; public JCExpression falsepart; @@ -1373,7 +1422,7 @@ /** * A method invocation */ - public static class JCMethodInvocation extends JCExpression implements MethodInvocationTree { + public static class JCMethodInvocation extends JCPolyExpression implements MethodInvocationTree { public List typeargs; public JCExpression meth; public List args; @@ -1416,7 +1465,7 @@ /** * A new(...) operation. */ - public static class JCNewClass extends JCExpression implements NewClassTree { + public static class JCNewClass extends JCPolyExpression implements NewClassTree { public JCExpression encl; public List typeargs; public JCExpression clazz; @@ -1469,6 +1518,10 @@ public static class JCNewArray extends JCExpression implements NewArrayTree { public JCExpression elemtype; public List dims; + // type annotations on inner-most component + public List annotations; + // type annotations on dimensions + public List> dimAnnotations; public List elems; protected JCNewArray(JCExpression elemtype, List dims, @@ -1476,6 +1529,8 @@ { this.elemtype = elemtype; this.dims = dims; + this.annotations = List.nil(); + this.dimAnnotations = List.nil(); this.elems = elems; } @Override @@ -1502,18 +1557,29 @@ /** * A lambda expression. */ - public static class JCLambda extends JCExpression implements LambdaExpressionTree { + public static class JCLambda extends JCFunctionalExpression implements LambdaExpressionTree { + + public enum ParameterKind { + IMPLICIT, + EXPLICIT; + } public List params; public JCTree body; - public Type targetType; public boolean canCompleteNormally = true; public List inferredThrownTypes; + public ParameterKind paramKind; public JCLambda(List params, JCTree body) { this.params = params; this.body = body; + if (params.isEmpty() || + params.head.vartype != null) { + paramKind = ParameterKind.EXPLICIT; + } else { + paramKind = ParameterKind.IMPLICIT; + } } @Override public Tag getTag() { @@ -1812,15 +1878,15 @@ /** * Selects a member expression. */ - public static class JCMemberReference extends JCExpression implements MemberReferenceTree { + public static class JCMemberReference extends JCFunctionalExpression implements MemberReferenceTree { public ReferenceMode mode; public ReferenceKind kind; public Name name; public JCExpression expr; public List typeargs; - public Type targetType; public Symbol sym; public Type varargsElement; + public PolyKind refPolyKind; /** * Javac-dependent classification for member references, based @@ -1838,7 +1904,9 @@ /** Inner # new */ IMPLICIT_INNER(ReferenceMode.NEW, false), /** Toplevel # new */ - TOPLEVEL(ReferenceMode.NEW, false); + TOPLEVEL(ReferenceMode.NEW, false), + /** ArrayType # new */ + ARRAY_CTOR(ReferenceMode.NEW, false); final ReferenceMode mode; final boolean unbound; @@ -2103,9 +2171,12 @@ public Name name; /** bounds */ public List bounds; - protected JCTypeParameter(Name name, List bounds) { + /** type annotations on type parameter */ + public List annotations; + protected JCTypeParameter(Name name, List bounds, List annotations) { this.name = name; this.bounds = bounds; + this.annotations = annotations; } @Override public void accept(Visitor v) { v.visitTypeParameter(this); } @@ -2115,6 +2186,9 @@ public List getBounds() { return bounds; } + public List getAnnotations() { + return annotations; + } @Override public R accept(TreeVisitor v, D d) { return v.visitTypeParameter(this, d); @@ -2181,16 +2255,27 @@ } public static class JCAnnotation extends JCExpression implements AnnotationTree { + // Either Tag.ANNOTATION or Tag.TYPE_ANNOTATION + private Tag tag; + public JCTree annotationType; public List args; - protected JCAnnotation(JCTree annotationType, List args) { + + // Attribute.Compound if tag is ANNOTATION + // Attribute.TypeCompound if tag is TYPE_ANNOTATION + public Attribute.Compound attribute; + + protected JCAnnotation(Tag tag, JCTree annotationType, List args) { + this.tag = tag; this.annotationType = annotationType; this.args = args; } + @Override public void accept(Visitor v) { v.visitAnnotation(this); } - public Kind getKind() { return Kind.ANNOTATION; } + public Kind getKind() { return TreeInfo.tagToKind(getTag()); } + public JCTree getAnnotationType() { return annotationType; } public List getArguments() { return args; @@ -2201,7 +2286,7 @@ } @Override public Tag getTag() { - return ANNOTATION; + return tag; } } @@ -2232,6 +2317,35 @@ } } + public static class JCAnnotatedType extends JCExpression implements com.sun.source.tree.AnnotatedTypeTree { + // type annotations + public List annotations; + public JCExpression underlyingType; + + protected JCAnnotatedType(List annotations, JCExpression underlyingType) { + this.annotations = annotations; + this.underlyingType = underlyingType; + } + @Override + public void accept(Visitor v) { v.visitAnnotatedType(this); } + + public Kind getKind() { return Kind.ANNOTATED_TYPE; } + public List getAnnotations() { + return annotations; + } + public JCExpression getUnderlyingType() { + return underlyingType; + } + @Override + public R accept(TreeVisitor v, D d) { + return v.visitAnnotatedType(this, d); + } + @Override + public Tag getTag() { + return ANNOTATED_TYPE; + } + } + public static class JCErroneous extends JCExpression implements com.sun.source.tree.ErroneousTree { public List errs; @@ -2298,6 +2412,7 @@ Name name, JCExpression restype, List typarams, + JCVariableDecl recvparam, List params, List thrown, JCBlock body, @@ -2423,6 +2538,7 @@ public void visitTypeBoundKind(TypeBoundKind that) { visitTree(that); } public void visitAnnotation(JCAnnotation that) { visitTree(that); } public void visitModifiers(JCModifiers that) { visitTree(that); } + public void visitAnnotatedType(JCAnnotatedType that) { visitTree(that); } public void visitErroneous(JCErroneous that) { visitTree(that); } public void visitLetExpr(LetExpr that) { visitTree(that); }