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.ModuleTree.ModuleKind;
51 import com.sun.tools.javac.code.Directive.ExportsDirective;
52 import com.sun.tools.javac.code.Directive.OpensDirective;
53 import com.sun.tools.javac.code.Type.ModuleType;
54
55 /**
56 * Root class for abstract syntax tree nodes. It provides definitions
57 * for specific tree nodes as subclasses nested inside.
58 *
59 * <p>Each subclass is highly standardized. It generally contains
60 * only tree fields for the syntactic subcomponents of the node. Some
736 /**
737 * A poly expression can only be truly 'poly' in certain contexts
738 */
739 public enum PolyKind {
740 /** poly expression to be treated as a standalone expression */
741 STANDALONE,
742 /** true poly expression */
743 POLY
744 }
745
746 /** is this poly expression a 'true' poly expression? */
747 public PolyKind polyKind;
748
749 @Override public boolean isPoly() { return polyKind == PolyKind.POLY; }
750 @Override public boolean isStandalone() { return polyKind == PolyKind.STANDALONE; }
751 }
752
753 /**
754 * Common supertype for all functional expression trees (lambda and method references)
755 */
756 public abstract static class JCFunctionalExpression extends JCPolyExpression {
757
758 public JCFunctionalExpression() {
759 //a functional expression is always a 'true' poly
760 polyKind = PolyKind.POLY;
761 }
762
763 /** list of target types inferred for this functional expression. */
764 public Type target;
765
766 public Type getDescriptorType(Types types) {
767 return target != null ? types.findDescriptorType(target) : types.createErrorType(null);
768 }
769 }
770
771 /**
772 * A class definition.
773 */
774 public static class JCClassDecl extends JCStatement implements ClassTree {
775 /** the modifiers */
776 public JCModifiers mods;
777 /** the name of the class */
778 public Name name;
779 /** formal class parameters */
780 public List<JCTypeParameter> typarams;
781 /** the classes this class extends */
782 public JCExpression extending;
783 /** the interfaces implemented by this class */
784 public List<JCExpression> implementing;
785 /** the subclasses allowed to extend this class, if sealed */
786 public List<JCExpression> permitting;
787 /** all variables and methods defined in this class */
788 public List<JCTree> defs;
1940 }
1941 @Override
1942 public Tag getTag() {
1943 return NEWARRAY;
1944 }
1945
1946 @Override @DefinedBy(Api.COMPILER_TREE)
1947 public List<JCAnnotation> getAnnotations() {
1948 return annotations;
1949 }
1950
1951 @Override @DefinedBy(Api.COMPILER_TREE)
1952 public List<List<JCAnnotation>> getDimAnnotations() {
1953 return dimAnnotations;
1954 }
1955 }
1956
1957 /**
1958 * A lambda expression.
1959 */
1960 public static class JCLambda extends JCFunctionalExpression implements LambdaExpressionTree {
1961
1962 public enum ParameterKind {
1963 IMPLICIT,
1964 EXPLICIT
1965 }
1966
1967 public List<JCVariableDecl> params;
1968 public JCTree body;
1969 public boolean canCompleteNormally = true;
1970 public ParameterKind paramKind;
1971
1972 public JCLambda(List<JCVariableDecl> params,
1973 JCTree body) {
1974 this.params = params;
1975 this.body = body;
1976 if (params.isEmpty() ||
1977 params.head.vartype != null) {
1978 paramKind = ParameterKind.EXPLICIT;
1979 } else {
1980 paramKind = ParameterKind.IMPLICIT;
2526
2527 @DefinedBy(Api.COMPILER_TREE)
2528 public Kind getKind() { return Kind.MEMBER_SELECT; }
2529 @DefinedBy(Api.COMPILER_TREE)
2530 public JCExpression getExpression() { return selected; }
2531 @Override @DefinedBy(Api.COMPILER_TREE)
2532 public <R,D> R accept(TreeVisitor<R,D> v, D d) {
2533 return v.visitMemberSelect(this, d);
2534 }
2535 @DefinedBy(Api.COMPILER_TREE)
2536 public Name getIdentifier() { return name; }
2537 @Override
2538 public Tag getTag() {
2539 return SELECT;
2540 }
2541 }
2542
2543 /**
2544 * Selects a member expression.
2545 */
2546 public static class JCMemberReference extends JCFunctionalExpression implements MemberReferenceTree {
2547
2548 public ReferenceMode mode;
2549 public ReferenceKind kind;
2550 public Name name;
2551 public JCExpression expr;
2552 public List<JCExpression> typeargs;
2553 public Symbol sym;
2554 public Type varargsElement;
2555 public PolyKind refPolyKind;
2556 public boolean ownerAccessible;
2557 private OverloadKind overloadKind;
2558 public Type referentType;
2559
2560 public enum OverloadKind {
2561 OVERLOADED,
2562 UNOVERLOADED,
2563 ERROR
2564 }
2565
2566 /**
|
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.code.Type.MethodType;
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.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
56 /**
57 * Root class for abstract syntax tree nodes. It provides definitions
58 * for specific tree nodes as subclasses nested inside.
59 *
60 * <p>Each subclass is highly standardized. It generally contains
61 * only tree fields for the syntactic subcomponents of the node. Some
737 /**
738 * A poly expression can only be truly 'poly' in certain contexts
739 */
740 public enum PolyKind {
741 /** poly expression to be treated as a standalone expression */
742 STANDALONE,
743 /** true poly expression */
744 POLY
745 }
746
747 /** is this poly expression a 'true' poly expression? */
748 public PolyKind polyKind;
749
750 @Override public boolean isPoly() { return polyKind == PolyKind.POLY; }
751 @Override public boolean isStandalone() { return polyKind == PolyKind.STANDALONE; }
752 }
753
754 /**
755 * Common supertype for all functional expression trees (lambda and method references)
756 */
757 public abstract static sealed class JCFunctionalExpression extends JCPolyExpression
758 permits JCLambda, JCMemberReference {
759
760 public JCFunctionalExpression() {
761 //a functional expression is always a 'true' poly
762 polyKind = PolyKind.POLY;
763 }
764
765 /** list of target types inferred for this functional expression. */
766 public Type target;
767 /** code reflection specific metadata. */
768 public CodeReflectionInfo codeReflectionInfo;
769
770 public Type getDescriptorType(Types types) {
771 if (target == null) {
772 return types.createErrorType(null);
773 } else if (target.hasTag(TypeTag.METHOD)) {
774 // this is a quoted expression
775 return target;
776 } else {
777 return types.findDescriptorType(target);
778 }
779 }
780
781 public record CodeReflectionInfo(Symbol quotedField, List<JCExpression> capturedArgs) { }
782 }
783
784 /**
785 * A class definition.
786 */
787 public static class JCClassDecl extends JCStatement implements ClassTree {
788 /** the modifiers */
789 public JCModifiers mods;
790 /** the name of the class */
791 public Name name;
792 /** formal class parameters */
793 public List<JCTypeParameter> typarams;
794 /** the classes this class extends */
795 public JCExpression extending;
796 /** the interfaces implemented by this class */
797 public List<JCExpression> implementing;
798 /** the subclasses allowed to extend this class, if sealed */
799 public List<JCExpression> permitting;
800 /** all variables and methods defined in this class */
801 public List<JCTree> defs;
1953 }
1954 @Override
1955 public Tag getTag() {
1956 return NEWARRAY;
1957 }
1958
1959 @Override @DefinedBy(Api.COMPILER_TREE)
1960 public List<JCAnnotation> getAnnotations() {
1961 return annotations;
1962 }
1963
1964 @Override @DefinedBy(Api.COMPILER_TREE)
1965 public List<List<JCAnnotation>> getDimAnnotations() {
1966 return dimAnnotations;
1967 }
1968 }
1969
1970 /**
1971 * A lambda expression.
1972 */
1973 public static final class JCLambda extends JCFunctionalExpression implements LambdaExpressionTree {
1974
1975 public enum ParameterKind {
1976 IMPLICIT,
1977 EXPLICIT
1978 }
1979
1980 public List<JCVariableDecl> params;
1981 public JCTree body;
1982 public boolean canCompleteNormally = true;
1983 public ParameterKind paramKind;
1984
1985 public JCLambda(List<JCVariableDecl> params,
1986 JCTree body) {
1987 this.params = params;
1988 this.body = body;
1989 if (params.isEmpty() ||
1990 params.head.vartype != null) {
1991 paramKind = ParameterKind.EXPLICIT;
1992 } else {
1993 paramKind = ParameterKind.IMPLICIT;
2539
2540 @DefinedBy(Api.COMPILER_TREE)
2541 public Kind getKind() { return Kind.MEMBER_SELECT; }
2542 @DefinedBy(Api.COMPILER_TREE)
2543 public JCExpression getExpression() { return selected; }
2544 @Override @DefinedBy(Api.COMPILER_TREE)
2545 public <R,D> R accept(TreeVisitor<R,D> v, D d) {
2546 return v.visitMemberSelect(this, d);
2547 }
2548 @DefinedBy(Api.COMPILER_TREE)
2549 public Name getIdentifier() { return name; }
2550 @Override
2551 public Tag getTag() {
2552 return SELECT;
2553 }
2554 }
2555
2556 /**
2557 * Selects a member expression.
2558 */
2559 public static non-sealed class JCMemberReference extends JCFunctionalExpression implements MemberReferenceTree {
2560
2561 public ReferenceMode mode;
2562 public ReferenceKind kind;
2563 public Name name;
2564 public JCExpression expr;
2565 public List<JCExpression> typeargs;
2566 public Symbol sym;
2567 public Type varargsElement;
2568 public PolyKind refPolyKind;
2569 public boolean ownerAccessible;
2570 private OverloadKind overloadKind;
2571 public Type referentType;
2572
2573 public enum OverloadKind {
2574 OVERLOADED,
2575 UNOVERLOADED,
2576 ERROR
2577 }
2578
2579 /**
|