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.Lint.LintCategory;
38 import com.sun.tools.javac.code.Scope.ImportFilter;
39 import com.sun.tools.javac.code.Scope.NamedImportScope;
40 import com.sun.tools.javac.code.Scope.StarImportScope;
41 import com.sun.tools.javac.code.Scope.WriteableScope;
42 import com.sun.tools.javac.code.Source.Feature;
43 import com.sun.tools.javac.comp.Annotate.AnnotationTypeMetadata;
44 import com.sun.tools.javac.tree.*;
45 import com.sun.tools.javac.util.*;
46 import com.sun.tools.javac.util.DefinedBy.Api;
47
48 import com.sun.tools.javac.code.Symbol.*;
49 import com.sun.tools.javac.code.Type.*;
50 import com.sun.tools.javac.resources.CompilerProperties.Errors;
51 import com.sun.tools.javac.tree.JCTree.*;
52
53 import static com.sun.tools.javac.code.Flags.*;
54 import static com.sun.tools.javac.code.Flags.ANNOTATION;
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:
1201 (types.supertype(tree.sym.type).tsym.flags() & Flags.ENUM) == 0) {
1202 addEnumMembers(tree, env);
1203 }
1204 boolean isRecord = (tree.sym.flags_field & RECORD) != 0;
1205 List<JCTree> alreadyEntered = null;
1206 if (isRecord) {
1207 alreadyEntered = List.convert(JCTree.class, TreeInfo.recordFields(tree));
1208 alreadyEntered = alreadyEntered.prependList(tree.defs.stream()
1209 .filter(t -> TreeInfo.isConstructor(t) && t != defaultConstructor).collect(List.collector()));
1210 }
1211 List<JCTree> defsToEnter = isRecord ?
1212 tree.defs.diff(alreadyEntered) : tree.defs;
1213 memberEnter.memberEnter(defsToEnter, env);
1214 if (isRecord) {
1215 addRecordMembersIfNeeded(tree, env);
1216 }
1217 if (tree.sym.isAnnotationType()) {
1218 Assert.check(tree.sym.isCompleted());
1219 tree.sym.setAnnotationTypeMetadata(new AnnotationTypeMetadata(tree.sym, annotate.annotationTypeSourceCompleter()));
1220 }
1221 }
1222
1223 private void addAccessor(JCVariableDecl tree, Env<AttrContext> env) {
1224 MethodSymbol implSym = lookupMethod(env.enclClass.sym, tree.sym.name, List.nil());
1225 RecordComponent rec = ((ClassSymbol) tree.sym.owner).getRecordComponent(tree.sym);
1226 if (implSym == null || (implSym.flags_field & GENERATED_MEMBER) != 0) {
1227 /* here we are pushing the annotations present in the corresponding field down to the accessor
1228 * it could be that some of those annotations are not applicable to the accessor, they will be striped
1229 * away later at Check::validateAnnotation
1230 */
1231 TreeCopier<JCTree> tc = new TreeCopier<JCTree>(make.at(tree.pos));
1232 List<JCAnnotation> originalAnnos = rec.getOriginalAnnos().isEmpty() ?
1233 rec.getOriginalAnnos() :
1234 tc.copy(rec.getOriginalAnnos());
1235 JCVariableDecl recordField = TreeInfo.recordFields((JCClassDecl) env.tree).stream().filter(rf -> rf.name == tree.name).findAny().get();
1236 JCMethodDecl getter = make.at(tree.pos).
1237 MethodDef(
1238 make.Modifiers(PUBLIC | Flags.GENERATED_MEMBER, originalAnnos),
1239 tree.sym.name,
1240 /* we need to special case for the case when the user declared the type as an ident
|
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.Lint.LintCategory;
38 import com.sun.tools.javac.code.Scope.ImportFilter;
39 import com.sun.tools.javac.code.Scope.NamedImportScope;
40 import com.sun.tools.javac.code.Scope.StarImportScope;
41 import com.sun.tools.javac.code.Scope.WriteableScope;
42 import com.sun.tools.javac.code.Source.Feature;
43 import com.sun.tools.javac.comp.Annotate.AnnotationTypeMetadata;
44 import com.sun.tools.javac.tree.*;
45 import com.sun.tools.javac.util.*;
46 import com.sun.tools.javac.util.DefinedBy.Api;
47
48 import com.sun.tools.javac.code.Symbol.*;
49 import com.sun.tools.javac.code.Type.*;
50 import com.sun.tools.javac.resources.CompilerProperties.Errors;
51 import com.sun.tools.javac.tree.JCTree.*;
52
53 import static com.sun.tools.javac.code.Flags.*;
54 import static com.sun.tools.javac.code.Flags.ANNOTATION;
55 import static com.sun.tools.javac.code.Flags.SYNCHRONIZED;
56 import static com.sun.tools.javac.code.Scope.LookupKind.NON_RECURSIVE;
57 import static com.sun.tools.javac.code.Kinds.Kind.*;
58 import static com.sun.tools.javac.code.TypeTag.CLASS;
59 import static com.sun.tools.javac.code.TypeTag.ERROR;
60
61 import static com.sun.tools.javac.code.TypeTag.*;
62 import static com.sun.tools.javac.tree.JCTree.Tag.*;
63
64 import com.sun.tools.javac.util.Dependencies.CompletionCause;
65 import com.sun.tools.javac.util.JCDiagnostic.DiagnosticFlag;
66 import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
67
68 /** This is the second phase of Enter, in which classes are completed
69 * by resolving their headers and entering their members in the into
70 * the class scope. See Enter for an overall overview.
71 *
72 * This class uses internal phases to process the classes. When a phase
73 * processes classes, the lower phases are not invoked until all classes
74 * pass through the current phase. Note that it is possible that upper phases
75 * are run due to recursive completion. The internal phases are:
1202 (types.supertype(tree.sym.type).tsym.flags() & Flags.ENUM) == 0) {
1203 addEnumMembers(tree, env);
1204 }
1205 boolean isRecord = (tree.sym.flags_field & RECORD) != 0;
1206 List<JCTree> alreadyEntered = null;
1207 if (isRecord) {
1208 alreadyEntered = List.convert(JCTree.class, TreeInfo.recordFields(tree));
1209 alreadyEntered = alreadyEntered.prependList(tree.defs.stream()
1210 .filter(t -> TreeInfo.isConstructor(t) && t != defaultConstructor).collect(List.collector()));
1211 }
1212 List<JCTree> defsToEnter = isRecord ?
1213 tree.defs.diff(alreadyEntered) : tree.defs;
1214 memberEnter.memberEnter(defsToEnter, env);
1215 if (isRecord) {
1216 addRecordMembersIfNeeded(tree, env);
1217 }
1218 if (tree.sym.isAnnotationType()) {
1219 Assert.check(tree.sym.isCompleted());
1220 tree.sym.setAnnotationTypeMetadata(new AnnotationTypeMetadata(tree.sym, annotate.annotationTypeSourceCompleter()));
1221 }
1222
1223 if ((tree.sym.flags() & (INTERFACE | VALUE_CLASS)) == 0) {
1224 tree.sym.flags_field |= IDENTITY_TYPE;
1225 }
1226 }
1227
1228 private void addAccessor(JCVariableDecl tree, Env<AttrContext> env) {
1229 MethodSymbol implSym = lookupMethod(env.enclClass.sym, tree.sym.name, List.nil());
1230 RecordComponent rec = ((ClassSymbol) tree.sym.owner).getRecordComponent(tree.sym);
1231 if (implSym == null || (implSym.flags_field & GENERATED_MEMBER) != 0) {
1232 /* here we are pushing the annotations present in the corresponding field down to the accessor
1233 * it could be that some of those annotations are not applicable to the accessor, they will be striped
1234 * away later at Check::validateAnnotation
1235 */
1236 TreeCopier<JCTree> tc = new TreeCopier<JCTree>(make.at(tree.pos));
1237 List<JCAnnotation> originalAnnos = rec.getOriginalAnnos().isEmpty() ?
1238 rec.getOriginalAnnos() :
1239 tc.copy(rec.getOriginalAnnos());
1240 JCVariableDecl recordField = TreeInfo.recordFields((JCClassDecl) env.tree).stream().filter(rf -> rf.name == tree.name).findAny().get();
1241 JCMethodDecl getter = make.at(tree.pos).
1242 MethodDef(
1243 make.Modifiers(PUBLIC | Flags.GENERATED_MEMBER, originalAnnos),
1244 tree.sym.name,
1245 /* we need to special case for the case when the user declared the type as an ident
|