1 /* |
1 /* |
2 * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. Oracle designates this |
7 * published by the Free Software Foundation. Oracle designates this |
248 |
248 |
249 /** Parameterized types, of type TypeApply. |
249 /** Parameterized types, of type TypeApply. |
250 */ |
250 */ |
251 TYPEAPPLY, |
251 TYPEAPPLY, |
252 |
252 |
253 /** Union types, of type TypeUnion |
253 /** Union types, of type TypeUnion. |
254 */ |
254 */ |
255 TYPEUNION, |
255 TYPEUNION, |
256 |
256 |
257 /** Intersection types, of type TypeIntersection |
257 /** Intersection types, of type TypeIntersection. |
258 */ |
258 */ |
259 TYPEINTERSECTION, |
259 TYPEINTERSECTION, |
260 |
260 |
261 /** Formal type parameters, of type TypeParameter. |
261 /** Formal type parameters, of type TypeParameter. |
262 */ |
262 */ |
605 return this; |
611 return this; |
606 } |
612 } |
607 } |
613 } |
608 |
614 |
609 /** |
615 /** |
|
616 * Common supertype for all poly expression trees (lambda, method references, |
|
617 * conditionals, method and constructor calls) |
|
618 */ |
|
619 public static abstract class JCPolyExpression extends JCExpression { |
|
620 |
|
621 /** |
|
622 * A poly expression can only be truly 'poly' in certain contexts |
|
623 */ |
|
624 public enum PolyKind { |
|
625 /** poly expression to be treated as a standalone expression */ |
|
626 STANDALONE, |
|
627 /** true poly expression */ |
|
628 POLY; |
|
629 } |
|
630 |
|
631 /** is this poly expression a 'true' poly expression? */ |
|
632 public PolyKind polyKind; |
|
633 } |
|
634 |
|
635 /** |
|
636 * Common supertype for all functional expression trees (lambda and method references) |
|
637 */ |
|
638 public static abstract class JCFunctionalExpression extends JCPolyExpression { |
|
639 |
|
640 public JCFunctionalExpression() { |
|
641 //a functional expression is always a 'true' poly |
|
642 polyKind = PolyKind.POLY; |
|
643 } |
|
644 |
|
645 /** target descriptor inferred for this functional expression. */ |
|
646 public Type descriptorType; |
|
647 /** list of target types inferred for this functional expression. */ |
|
648 public List<TypeSymbol> targets; |
|
649 } |
|
650 |
|
651 /** |
610 * A class definition. |
652 * A class definition. |
611 */ |
653 */ |
612 public static class JCClassDecl extends JCStatement implements ClassTree { |
654 public static class JCClassDecl extends JCStatement implements ClassTree { |
613 /** the modifiers */ |
655 /** the modifiers */ |
614 public JCModifiers mods; |
656 public JCModifiers mods; |
687 public Name name; |
729 public Name name; |
688 /** type of method return value */ |
730 /** type of method return value */ |
689 public JCExpression restype; |
731 public JCExpression restype; |
690 /** type parameters */ |
732 /** type parameters */ |
691 public List<JCTypeParameter> typarams; |
733 public List<JCTypeParameter> typarams; |
|
734 /** receiver parameter */ |
|
735 public JCVariableDecl recvparam; |
692 /** value parameters */ |
736 /** value parameters */ |
693 public List<JCVariableDecl> params; |
737 public List<JCVariableDecl> params; |
694 /** exceptions thrown by this method */ |
738 /** exceptions thrown by this method */ |
695 public List<JCExpression> thrown; |
739 public List<JCExpression> thrown; |
696 /** statements in the method */ |
740 /** statements in the method */ |
701 public MethodSymbol sym; |
745 public MethodSymbol sym; |
702 protected JCMethodDecl(JCModifiers mods, |
746 protected JCMethodDecl(JCModifiers mods, |
703 Name name, |
747 Name name, |
704 JCExpression restype, |
748 JCExpression restype, |
705 List<JCTypeParameter> typarams, |
749 List<JCTypeParameter> typarams, |
|
750 JCVariableDecl recvparam, |
706 List<JCVariableDecl> params, |
751 List<JCVariableDecl> params, |
707 List<JCExpression> thrown, |
752 List<JCExpression> thrown, |
708 JCBlock body, |
753 JCBlock body, |
709 JCExpression defaultValue, |
754 JCExpression defaultValue, |
710 MethodSymbol sym) |
755 MethodSymbol sym) |
712 this.mods = mods; |
757 this.mods = mods; |
713 this.name = name; |
758 this.name = name; |
714 this.restype = restype; |
759 this.restype = restype; |
715 this.typarams = typarams; |
760 this.typarams = typarams; |
716 this.params = params; |
761 this.params = params; |
|
762 this.recvparam = recvparam; |
|
763 // TODO: do something special if the given type is null? |
|
764 // receiver != null ? receiver : List.<JCTypeAnnotation>nil()); |
717 this.thrown = thrown; |
765 this.thrown = thrown; |
718 this.body = body; |
766 this.body = body; |
719 this.defaultValue = defaultValue; |
767 this.defaultValue = defaultValue; |
720 this.sym = sym; |
768 this.sym = sym; |
721 } |
769 } |
730 return typarams; |
778 return typarams; |
731 } |
779 } |
732 public List<JCVariableDecl> getParameters() { |
780 public List<JCVariableDecl> getParameters() { |
733 return params; |
781 return params; |
734 } |
782 } |
|
783 public JCVariableDecl getReceiverParameter() { return recvparam; } |
735 public List<JCExpression> getThrows() { |
784 public List<JCExpression> getThrows() { |
736 return thrown; |
785 return thrown; |
737 } |
786 } |
738 public JCBlock getBody() { return body; } |
787 public JCBlock getBody() { return body; } |
739 public JCTree getDefaultValue() { // for annotation types |
788 public JCTree getDefaultValue() { // for annotation types |
1145 } |
1194 } |
1146 |
1195 |
1147 /** |
1196 /** |
1148 * A ( ) ? ( ) : ( ) conditional expression |
1197 * A ( ) ? ( ) : ( ) conditional expression |
1149 */ |
1198 */ |
1150 public static class JCConditional extends JCExpression implements ConditionalExpressionTree { |
1199 public static class JCConditional extends JCPolyExpression implements ConditionalExpressionTree { |
1151 public JCExpression cond; |
1200 public JCExpression cond; |
1152 public JCExpression truepart; |
1201 public JCExpression truepart; |
1153 public JCExpression falsepart; |
1202 public JCExpression falsepart; |
1154 protected JCConditional(JCExpression cond, |
1203 protected JCConditional(JCExpression cond, |
1155 JCExpression truepart, |
1204 JCExpression truepart, |
1371 } |
1420 } |
1372 |
1421 |
1373 /** |
1422 /** |
1374 * A method invocation |
1423 * A method invocation |
1375 */ |
1424 */ |
1376 public static class JCMethodInvocation extends JCExpression implements MethodInvocationTree { |
1425 public static class JCMethodInvocation extends JCPolyExpression implements MethodInvocationTree { |
1377 public List<JCExpression> typeargs; |
1426 public List<JCExpression> typeargs; |
1378 public JCExpression meth; |
1427 public JCExpression meth; |
1379 public List<JCExpression> args; |
1428 public List<JCExpression> args; |
1380 public Type varargsElement; |
1429 public Type varargsElement; |
1381 protected JCMethodInvocation(List<JCExpression> typeargs, |
1430 protected JCMethodInvocation(List<JCExpression> typeargs, |
1414 } |
1463 } |
1415 |
1464 |
1416 /** |
1465 /** |
1417 * A new(...) operation. |
1466 * A new(...) operation. |
1418 */ |
1467 */ |
1419 public static class JCNewClass extends JCExpression implements NewClassTree { |
1468 public static class JCNewClass extends JCPolyExpression implements NewClassTree { |
1420 public JCExpression encl; |
1469 public JCExpression encl; |
1421 public List<JCExpression> typeargs; |
1470 public List<JCExpression> typeargs; |
1422 public JCExpression clazz; |
1471 public JCExpression clazz; |
1423 public List<JCExpression> args; |
1472 public List<JCExpression> args; |
1424 public JCClassDecl def; |
1473 public JCClassDecl def; |
1467 * A new[...] operation. |
1516 * A new[...] operation. |
1468 */ |
1517 */ |
1469 public static class JCNewArray extends JCExpression implements NewArrayTree { |
1518 public static class JCNewArray extends JCExpression implements NewArrayTree { |
1470 public JCExpression elemtype; |
1519 public JCExpression elemtype; |
1471 public List<JCExpression> dims; |
1520 public List<JCExpression> dims; |
|
1521 // type annotations on inner-most component |
|
1522 public List<JCAnnotation> annotations; |
|
1523 // type annotations on dimensions |
|
1524 public List<List<JCAnnotation>> dimAnnotations; |
1472 public List<JCExpression> elems; |
1525 public List<JCExpression> elems; |
1473 protected JCNewArray(JCExpression elemtype, |
1526 protected JCNewArray(JCExpression elemtype, |
1474 List<JCExpression> dims, |
1527 List<JCExpression> dims, |
1475 List<JCExpression> elems) |
1528 List<JCExpression> elems) |
1476 { |
1529 { |
1477 this.elemtype = elemtype; |
1530 this.elemtype = elemtype; |
1478 this.dims = dims; |
1531 this.dims = dims; |
|
1532 this.annotations = List.nil(); |
|
1533 this.dimAnnotations = List.nil(); |
1479 this.elems = elems; |
1534 this.elems = elems; |
1480 } |
1535 } |
1481 @Override |
1536 @Override |
1482 public void accept(Visitor v) { v.visitNewArray(this); } |
1537 public void accept(Visitor v) { v.visitNewArray(this); } |
1483 |
1538 |
1500 } |
1555 } |
1501 |
1556 |
1502 /** |
1557 /** |
1503 * A lambda expression. |
1558 * A lambda expression. |
1504 */ |
1559 */ |
1505 public static class JCLambda extends JCExpression implements LambdaExpressionTree { |
1560 public static class JCLambda extends JCFunctionalExpression implements LambdaExpressionTree { |
|
1561 |
|
1562 public enum ParameterKind { |
|
1563 IMPLICIT, |
|
1564 EXPLICIT; |
|
1565 } |
1506 |
1566 |
1507 public List<JCVariableDecl> params; |
1567 public List<JCVariableDecl> params; |
1508 public JCTree body; |
1568 public JCTree body; |
1509 public Type targetType; |
|
1510 public boolean canCompleteNormally = true; |
1569 public boolean canCompleteNormally = true; |
1511 public List<Type> inferredThrownTypes; |
1570 public List<Type> inferredThrownTypes; |
|
1571 public ParameterKind paramKind; |
1512 |
1572 |
1513 public JCLambda(List<JCVariableDecl> params, |
1573 public JCLambda(List<JCVariableDecl> params, |
1514 JCTree body) { |
1574 JCTree body) { |
1515 this.params = params; |
1575 this.params = params; |
1516 this.body = body; |
1576 this.body = body; |
|
1577 if (params.isEmpty() || |
|
1578 params.head.vartype != null) { |
|
1579 paramKind = ParameterKind.EXPLICIT; |
|
1580 } else { |
|
1581 paramKind = ParameterKind.IMPLICIT; |
|
1582 } |
1517 } |
1583 } |
1518 @Override |
1584 @Override |
1519 public Tag getTag() { |
1585 public Tag getTag() { |
1520 return LAMBDA; |
1586 return LAMBDA; |
1521 } |
1587 } |
1810 } |
1876 } |
1811 |
1877 |
1812 /** |
1878 /** |
1813 * Selects a member expression. |
1879 * Selects a member expression. |
1814 */ |
1880 */ |
1815 public static class JCMemberReference extends JCExpression implements MemberReferenceTree { |
1881 public static class JCMemberReference extends JCFunctionalExpression implements MemberReferenceTree { |
1816 public ReferenceMode mode; |
1882 public ReferenceMode mode; |
1817 public ReferenceKind kind; |
1883 public ReferenceKind kind; |
1818 public Name name; |
1884 public Name name; |
1819 public JCExpression expr; |
1885 public JCExpression expr; |
1820 public List<JCExpression> typeargs; |
1886 public List<JCExpression> typeargs; |
1821 public Type targetType; |
|
1822 public Symbol sym; |
1887 public Symbol sym; |
1823 public Type varargsElement; |
1888 public Type varargsElement; |
|
1889 public PolyKind refPolyKind; |
1824 |
1890 |
1825 /** |
1891 /** |
1826 * Javac-dependent classification for member references, based |
1892 * Javac-dependent classification for member references, based |
1827 * on relevant properties w.r.t. code-generation |
1893 * on relevant properties w.r.t. code-generation |
1828 */ |
1894 */ |
1836 /** Expr # instMethod */ |
1902 /** Expr # instMethod */ |
1837 BOUND(ReferenceMode.INVOKE, false), |
1903 BOUND(ReferenceMode.INVOKE, false), |
1838 /** Inner # new */ |
1904 /** Inner # new */ |
1839 IMPLICIT_INNER(ReferenceMode.NEW, false), |
1905 IMPLICIT_INNER(ReferenceMode.NEW, false), |
1840 /** Toplevel # new */ |
1906 /** Toplevel # new */ |
1841 TOPLEVEL(ReferenceMode.NEW, false); |
1907 TOPLEVEL(ReferenceMode.NEW, false), |
|
1908 /** ArrayType # new */ |
|
1909 ARRAY_CTOR(ReferenceMode.NEW, false); |
1842 |
1910 |
1843 final ReferenceMode mode; |
1911 final ReferenceMode mode; |
1844 final boolean unbound; |
1912 final boolean unbound; |
1845 |
1913 |
1846 private ReferenceKind(ReferenceMode mode, boolean unbound) { |
1914 private ReferenceKind(ReferenceMode mode, boolean unbound) { |
2101 public static class JCTypeParameter extends JCTree implements TypeParameterTree { |
2169 public static class JCTypeParameter extends JCTree implements TypeParameterTree { |
2102 /** name */ |
2170 /** name */ |
2103 public Name name; |
2171 public Name name; |
2104 /** bounds */ |
2172 /** bounds */ |
2105 public List<JCExpression> bounds; |
2173 public List<JCExpression> bounds; |
2106 protected JCTypeParameter(Name name, List<JCExpression> bounds) { |
2174 /** type annotations on type parameter */ |
|
2175 public List<JCAnnotation> annotations; |
|
2176 protected JCTypeParameter(Name name, List<JCExpression> bounds, List<JCAnnotation> annotations) { |
2107 this.name = name; |
2177 this.name = name; |
2108 this.bounds = bounds; |
2178 this.bounds = bounds; |
|
2179 this.annotations = annotations; |
2109 } |
2180 } |
2110 @Override |
2181 @Override |
2111 public void accept(Visitor v) { v.visitTypeParameter(this); } |
2182 public void accept(Visitor v) { v.visitTypeParameter(this); } |
2112 |
2183 |
2113 public Kind getKind() { return Kind.TYPE_PARAMETER; } |
2184 public Kind getKind() { return Kind.TYPE_PARAMETER; } |
2114 public Name getName() { return name; } |
2185 public Name getName() { return name; } |
2115 public List<JCExpression> getBounds() { |
2186 public List<JCExpression> getBounds() { |
2116 return bounds; |
2187 return bounds; |
|
2188 } |
|
2189 public List<JCAnnotation> getAnnotations() { |
|
2190 return annotations; |
2117 } |
2191 } |
2118 @Override |
2192 @Override |
2119 public <R,D> R accept(TreeVisitor<R,D> v, D d) { |
2193 public <R,D> R accept(TreeVisitor<R,D> v, D d) { |
2120 return v.visitTypeParameter(this, d); |
2194 return v.visitTypeParameter(this, d); |
2121 } |
2195 } |
2179 return TYPEBOUNDKIND; |
2253 return TYPEBOUNDKIND; |
2180 } |
2254 } |
2181 } |
2255 } |
2182 |
2256 |
2183 public static class JCAnnotation extends JCExpression implements AnnotationTree { |
2257 public static class JCAnnotation extends JCExpression implements AnnotationTree { |
|
2258 // Either Tag.ANNOTATION or Tag.TYPE_ANNOTATION |
|
2259 private Tag tag; |
|
2260 |
2184 public JCTree annotationType; |
2261 public JCTree annotationType; |
2185 public List<JCExpression> args; |
2262 public List<JCExpression> args; |
2186 protected JCAnnotation(JCTree annotationType, List<JCExpression> args) { |
2263 |
|
2264 // Attribute.Compound if tag is ANNOTATION |
|
2265 // Attribute.TypeCompound if tag is TYPE_ANNOTATION |
|
2266 public Attribute.Compound attribute; |
|
2267 |
|
2268 protected JCAnnotation(Tag tag, JCTree annotationType, List<JCExpression> args) { |
|
2269 this.tag = tag; |
2187 this.annotationType = annotationType; |
2270 this.annotationType = annotationType; |
2188 this.args = args; |
2271 this.args = args; |
2189 } |
2272 } |
|
2273 |
2190 @Override |
2274 @Override |
2191 public void accept(Visitor v) { v.visitAnnotation(this); } |
2275 public void accept(Visitor v) { v.visitAnnotation(this); } |
2192 |
2276 |
2193 public Kind getKind() { return Kind.ANNOTATION; } |
2277 public Kind getKind() { return TreeInfo.tagToKind(getTag()); } |
|
2278 |
2194 public JCTree getAnnotationType() { return annotationType; } |
2279 public JCTree getAnnotationType() { return annotationType; } |
2195 public List<JCExpression> getArguments() { |
2280 public List<JCExpression> getArguments() { |
2196 return args; |
2281 return args; |
2197 } |
2282 } |
2198 @Override |
2283 @Override |
2199 public <R,D> R accept(TreeVisitor<R,D> v, D d) { |
2284 public <R,D> R accept(TreeVisitor<R,D> v, D d) { |
2200 return v.visitAnnotation(this, d); |
2285 return v.visitAnnotation(this, d); |
2201 } |
2286 } |
2202 @Override |
2287 @Override |
2203 public Tag getTag() { |
2288 public Tag getTag() { |
2204 return ANNOTATION; |
2289 return tag; |
2205 } |
2290 } |
2206 } |
2291 } |
2207 |
2292 |
2208 public static class JCModifiers extends JCTree implements com.sun.source.tree.ModifiersTree { |
2293 public static class JCModifiers extends JCTree implements com.sun.source.tree.ModifiersTree { |
2209 public long flags; |
2294 public long flags; |
2227 return v.visitModifiers(this, d); |
2312 return v.visitModifiers(this, d); |
2228 } |
2313 } |
2229 @Override |
2314 @Override |
2230 public Tag getTag() { |
2315 public Tag getTag() { |
2231 return MODIFIERS; |
2316 return MODIFIERS; |
|
2317 } |
|
2318 } |
|
2319 |
|
2320 public static class JCAnnotatedType extends JCExpression implements com.sun.source.tree.AnnotatedTypeTree { |
|
2321 // type annotations |
|
2322 public List<JCAnnotation> annotations; |
|
2323 public JCExpression underlyingType; |
|
2324 |
|
2325 protected JCAnnotatedType(List<JCAnnotation> annotations, JCExpression underlyingType) { |
|
2326 this.annotations = annotations; |
|
2327 this.underlyingType = underlyingType; |
|
2328 } |
|
2329 @Override |
|
2330 public void accept(Visitor v) { v.visitAnnotatedType(this); } |
|
2331 |
|
2332 public Kind getKind() { return Kind.ANNOTATED_TYPE; } |
|
2333 public List<JCAnnotation> getAnnotations() { |
|
2334 return annotations; |
|
2335 } |
|
2336 public JCExpression getUnderlyingType() { |
|
2337 return underlyingType; |
|
2338 } |
|
2339 @Override |
|
2340 public <R,D> R accept(TreeVisitor<R,D> v, D d) { |
|
2341 return v.visitAnnotatedType(this, d); |
|
2342 } |
|
2343 @Override |
|
2344 public Tag getTag() { |
|
2345 return ANNOTATED_TYPE; |
2232 } |
2346 } |
2233 } |
2347 } |
2234 |
2348 |
2235 public static class JCErroneous extends JCExpression |
2349 public static class JCErroneous extends JCExpression |
2236 implements com.sun.source.tree.ErroneousTree { |
2350 implements com.sun.source.tree.ErroneousTree { |
2296 List<JCTree> defs); |
2410 List<JCTree> defs); |
2297 JCMethodDecl MethodDef(JCModifiers mods, |
2411 JCMethodDecl MethodDef(JCModifiers mods, |
2298 Name name, |
2412 Name name, |
2299 JCExpression restype, |
2413 JCExpression restype, |
2300 List<JCTypeParameter> typarams, |
2414 List<JCTypeParameter> typarams, |
|
2415 JCVariableDecl recvparam, |
2301 List<JCVariableDecl> params, |
2416 List<JCVariableDecl> params, |
2302 List<JCExpression> thrown, |
2417 List<JCExpression> thrown, |
2303 JCBlock body, |
2418 JCBlock body, |
2304 JCExpression defaultValue); |
2419 JCExpression defaultValue); |
2305 JCVariableDecl VarDef(JCModifiers mods, |
2420 JCVariableDecl VarDef(JCModifiers mods, |
2421 public void visitTypeParameter(JCTypeParameter that) { visitTree(that); } |
2536 public void visitTypeParameter(JCTypeParameter that) { visitTree(that); } |
2422 public void visitWildcard(JCWildcard that) { visitTree(that); } |
2537 public void visitWildcard(JCWildcard that) { visitTree(that); } |
2423 public void visitTypeBoundKind(TypeBoundKind that) { visitTree(that); } |
2538 public void visitTypeBoundKind(TypeBoundKind that) { visitTree(that); } |
2424 public void visitAnnotation(JCAnnotation that) { visitTree(that); } |
2539 public void visitAnnotation(JCAnnotation that) { visitTree(that); } |
2425 public void visitModifiers(JCModifiers that) { visitTree(that); } |
2540 public void visitModifiers(JCModifiers that) { visitTree(that); } |
|
2541 public void visitAnnotatedType(JCAnnotatedType that) { visitTree(that); } |
2426 public void visitErroneous(JCErroneous that) { visitTree(that); } |
2542 public void visitErroneous(JCErroneous that) { visitTree(that); } |
2427 public void visitLetExpr(LetExpr that) { visitTree(that); } |
2543 public void visitLetExpr(LetExpr that) { visitTree(that); } |
2428 |
2544 |
2429 public void visitTree(JCTree that) { Assert.error(); } |
2545 public void visitTree(JCTree that) { Assert.error(); } |
2430 } |
2546 } |