34 import com.sun.tools.javac.code.*;
35 import com.sun.tools.javac.code.Directive.ExportsDirective;
36 import com.sun.tools.javac.code.Directive.RequiresDirective;
37 import com.sun.tools.javac.code.Scope.ImportFilter;
38 import com.sun.tools.javac.code.Scope.NamedImportScope;
39 import com.sun.tools.javac.code.Scope.StarImportScope;
40 import com.sun.tools.javac.code.Scope.WriteableScope;
41 import com.sun.tools.javac.code.Source.Feature;
42 import com.sun.tools.javac.comp.Annotate.AnnotationTypeMetadata;
43 import com.sun.tools.javac.tree.*;
44 import com.sun.tools.javac.util.*;
45 import com.sun.tools.javac.util.DefinedBy.Api;
46
47 import com.sun.tools.javac.code.Symbol.*;
48 import com.sun.tools.javac.code.Type.*;
49 import com.sun.tools.javac.resources.CompilerProperties.Errors;
50 import com.sun.tools.javac.tree.JCTree.*;
51
52 import static com.sun.tools.javac.code.Flags.*;
53 import static com.sun.tools.javac.code.Flags.ANNOTATION;
54 import static com.sun.tools.javac.code.Scope.LookupKind.NON_RECURSIVE;
55 import static com.sun.tools.javac.code.Kinds.Kind.*;
56 import static com.sun.tools.javac.code.TypeTag.CLASS;
57 import static com.sun.tools.javac.code.TypeTag.ERROR;
58
59 import static com.sun.tools.javac.code.TypeTag.*;
60 import static com.sun.tools.javac.tree.JCTree.Tag.*;
61
62 import com.sun.tools.javac.util.Dependencies.CompletionCause;
63 import com.sun.tools.javac.util.JCDiagnostic.DiagnosticFlag;
64 import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
65
66 /** This is the second phase of Enter, in which classes are completed
67 * by resolving their headers and entering their members in the into
68 * the class scope. See Enter for an overall overview.
69 *
70 * This class uses internal phases to process the classes. When a phase
71 * processes classes, the lower phases are not invoked until all classes
72 * pass through the current phase. Note that it is possible that upper phases
73 * are run due to recursive completion. The internal phases are:
1170 (types.supertype(tree.sym.type).tsym.flags() & Flags.ENUM) == 0) {
1171 addEnumMembers(tree, env);
1172 }
1173 boolean isRecord = (tree.sym.flags_field & RECORD) != 0;
1174 List<JCTree> alreadyEntered = null;
1175 if (isRecord) {
1176 alreadyEntered = List.convert(JCTree.class, TreeInfo.recordFields(tree));
1177 alreadyEntered = alreadyEntered.prependList(tree.defs.stream()
1178 .filter(t -> TreeInfo.isConstructor(t) && t != defaultConstructor).collect(List.collector()));
1179 }
1180 List<JCTree> defsToEnter = isRecord ?
1181 tree.defs.diff(alreadyEntered) : tree.defs;
1182 memberEnter.memberEnter(defsToEnter, env);
1183 if (isRecord) {
1184 addRecordMembersIfNeeded(tree, env);
1185 }
1186 if (tree.sym.isAnnotationType()) {
1187 Assert.check(tree.sym.isCompleted());
1188 tree.sym.setAnnotationTypeMetadata(new AnnotationTypeMetadata(tree.sym, annotate.annotationTypeSourceCompleter()));
1189 }
1190 }
1191
1192 private void addAccessor(JCVariableDecl tree, Env<AttrContext> env) {
1193 MethodSymbol implSym = lookupMethod(env.enclClass.sym, tree.sym.name, List.nil());
1194 RecordComponent rec = ((ClassSymbol) tree.sym.owner).getRecordComponent(tree.sym);
1195 if (implSym == null || (implSym.flags_field & GENERATED_MEMBER) != 0) {
1196 /* here we are pushing the annotations present in the corresponding field down to the accessor
1197 * it could be that some of those annotations are not applicable to the accessor, they will be striped
1198 * away later at Check::validateAnnotation
1199 */
1200 TreeCopier<JCTree> tc = new TreeCopier<JCTree>(make.at(tree.pos));
1201 List<JCAnnotation> originalAnnos = rec.getOriginalAnnos().isEmpty() ?
1202 rec.getOriginalAnnos() :
1203 tc.copy(rec.getOriginalAnnos());
1204 JCVariableDecl recordField = TreeInfo.recordFields((JCClassDecl) env.tree).stream().filter(rf -> rf.name == tree.name).findAny().get();
1205 JCMethodDecl getter = make.at(tree.pos).
1206 MethodDef(
1207 make.Modifiers(PUBLIC | Flags.GENERATED_MEMBER, originalAnnos),
1208 tree.sym.name,
1209 /* we need to special case for the case when the user declared the type as an ident
|
34 import com.sun.tools.javac.code.*;
35 import com.sun.tools.javac.code.Directive.ExportsDirective;
36 import com.sun.tools.javac.code.Directive.RequiresDirective;
37 import com.sun.tools.javac.code.Scope.ImportFilter;
38 import com.sun.tools.javac.code.Scope.NamedImportScope;
39 import com.sun.tools.javac.code.Scope.StarImportScope;
40 import com.sun.tools.javac.code.Scope.WriteableScope;
41 import com.sun.tools.javac.code.Source.Feature;
42 import com.sun.tools.javac.comp.Annotate.AnnotationTypeMetadata;
43 import com.sun.tools.javac.tree.*;
44 import com.sun.tools.javac.util.*;
45 import com.sun.tools.javac.util.DefinedBy.Api;
46
47 import com.sun.tools.javac.code.Symbol.*;
48 import com.sun.tools.javac.code.Type.*;
49 import com.sun.tools.javac.resources.CompilerProperties.Errors;
50 import com.sun.tools.javac.tree.JCTree.*;
51
52 import static com.sun.tools.javac.code.Flags.*;
53 import static com.sun.tools.javac.code.Flags.ANNOTATION;
54 import static com.sun.tools.javac.code.Flags.SYNCHRONIZED;
55 import static com.sun.tools.javac.code.Scope.LookupKind.NON_RECURSIVE;
56 import static com.sun.tools.javac.code.Kinds.Kind.*;
57 import static com.sun.tools.javac.code.TypeTag.CLASS;
58 import static com.sun.tools.javac.code.TypeTag.ERROR;
59
60 import static com.sun.tools.javac.code.TypeTag.*;
61 import static com.sun.tools.javac.tree.JCTree.Tag.*;
62
63 import com.sun.tools.javac.util.Dependencies.CompletionCause;
64 import com.sun.tools.javac.util.JCDiagnostic.DiagnosticFlag;
65 import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
66
67 /** This is the second phase of Enter, in which classes are completed
68 * by resolving their headers and entering their members in the into
69 * the class scope. See Enter for an overall overview.
70 *
71 * This class uses internal phases to process the classes. When a phase
72 * processes classes, the lower phases are not invoked until all classes
73 * pass through the current phase. Note that it is possible that upper phases
74 * are run due to recursive completion. The internal phases are:
1171 (types.supertype(tree.sym.type).tsym.flags() & Flags.ENUM) == 0) {
1172 addEnumMembers(tree, env);
1173 }
1174 boolean isRecord = (tree.sym.flags_field & RECORD) != 0;
1175 List<JCTree> alreadyEntered = null;
1176 if (isRecord) {
1177 alreadyEntered = List.convert(JCTree.class, TreeInfo.recordFields(tree));
1178 alreadyEntered = alreadyEntered.prependList(tree.defs.stream()
1179 .filter(t -> TreeInfo.isConstructor(t) && t != defaultConstructor).collect(List.collector()));
1180 }
1181 List<JCTree> defsToEnter = isRecord ?
1182 tree.defs.diff(alreadyEntered) : tree.defs;
1183 memberEnter.memberEnter(defsToEnter, env);
1184 if (isRecord) {
1185 addRecordMembersIfNeeded(tree, env);
1186 }
1187 if (tree.sym.isAnnotationType()) {
1188 Assert.check(tree.sym.isCompleted());
1189 tree.sym.setAnnotationTypeMetadata(new AnnotationTypeMetadata(tree.sym, annotate.annotationTypeSourceCompleter()));
1190 }
1191
1192 if ((tree.sym.flags() & (INTERFACE | VALUE_CLASS)) == 0) {
1193 tree.sym.flags_field |= IDENTITY_TYPE;
1194 }
1195 }
1196
1197 private void addAccessor(JCVariableDecl tree, Env<AttrContext> env) {
1198 MethodSymbol implSym = lookupMethod(env.enclClass.sym, tree.sym.name, List.nil());
1199 RecordComponent rec = ((ClassSymbol) tree.sym.owner).getRecordComponent(tree.sym);
1200 if (implSym == null || (implSym.flags_field & GENERATED_MEMBER) != 0) {
1201 /* here we are pushing the annotations present in the corresponding field down to the accessor
1202 * it could be that some of those annotations are not applicable to the accessor, they will be striped
1203 * away later at Check::validateAnnotation
1204 */
1205 TreeCopier<JCTree> tc = new TreeCopier<JCTree>(make.at(tree.pos));
1206 List<JCAnnotation> originalAnnos = rec.getOriginalAnnos().isEmpty() ?
1207 rec.getOriginalAnnos() :
1208 tc.copy(rec.getOriginalAnnos());
1209 JCVariableDecl recordField = TreeInfo.recordFields((JCClassDecl) env.tree).stream().filter(rf -> rf.name == tree.name).findAny().get();
1210 JCMethodDecl getter = make.at(tree.pos).
1211 MethodDef(
1212 make.Modifiers(PUBLIC | Flags.GENERATED_MEMBER, originalAnnos),
1213 tree.sym.name,
1214 /* we need to special case for the case when the user declared the type as an ident
|