< prev index next >

src/jdk.compiler/share/classes/com/sun/tools/javac/comp/TypeEnter.java

Print this page

  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:

1200                 (types.supertype(tree.sym.type).tsym.flags() & Flags.ENUM) == 0) {
1201                 addEnumMembers(tree, env);
1202             }
1203             boolean isRecord = (tree.sym.flags_field & RECORD) != 0;
1204             List<JCTree> alreadyEntered = null;
1205             if (isRecord) {
1206                 alreadyEntered = List.convert(JCTree.class, TreeInfo.recordFields(tree));
1207                 alreadyEntered = alreadyEntered.prependList(tree.defs.stream()
1208                         .filter(t -> TreeInfo.isConstructor(t) && t != defaultConstructor).collect(List.collector()));
1209             }
1210             List<JCTree> defsToEnter = isRecord ?
1211                     tree.defs.diff(alreadyEntered) : tree.defs;
1212             memberEnter.memberEnter(defsToEnter, env);
1213             if (isRecord) {
1214                 addRecordMembersIfNeeded(tree, env);
1215             }
1216             if (tree.sym.isAnnotationType()) {
1217                 Assert.check(tree.sym.isCompleted());
1218                 tree.sym.setAnnotationTypeMetadata(new AnnotationTypeMetadata(tree.sym, annotate.annotationTypeSourceCompleter()));
1219             }




1220         }
1221 
1222         private void addAccessor(JCVariableDecl tree, Env<AttrContext> env) {
1223             MethodSymbol implSym = lookupMethod(env.enclClass.sym, tree.sym.name, List.nil());
1224             RecordComponent rec = ((ClassSymbol) tree.sym.owner).getRecordComponent(tree.sym);
1225             if (implSym == null || (implSym.flags_field & GENERATED_MEMBER) != 0) {
1226                 /* here we are pushing the annotations present in the corresponding field down to the accessor
1227                  * it could be that some of those annotations are not applicable to the accessor, they will be striped
1228                  * away later at Check::validateAnnotation
1229                  */
1230                 TreeCopier<JCTree> tc = new TreeCopier<JCTree>(make.at(tree.pos));
1231                 List<JCAnnotation> originalAnnos = rec.getOriginalAnnos().isEmpty() ?
1232                         rec.getOriginalAnnos() :
1233                         tc.copy(rec.getOriginalAnnos());
1234                 JCVariableDecl recordField = TreeInfo.recordFields((JCClassDecl) env.tree).stream().filter(rf -> rf.name == tree.name).findAny().get();
1235                 JCMethodDecl getter = make.at(tree.pos).
1236                         MethodDef(
1237                                 make.Modifiers(PUBLIC | Flags.GENERATED_MEMBER, originalAnnos),
1238                           tree.sym.name,
1239                           /* 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:

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             if ((tree.sym.flags() & (INTERFACE | VALUE_CLASS)) == 0) {
1223                 tree.sym.flags_field |= IDENTITY_TYPE;
1224             }
1225         }
1226 
1227         private void addAccessor(JCVariableDecl tree, Env<AttrContext> env) {
1228             MethodSymbol implSym = lookupMethod(env.enclClass.sym, tree.sym.name, List.nil());
1229             RecordComponent rec = ((ClassSymbol) tree.sym.owner).getRecordComponent(tree.sym);
1230             if (implSym == null || (implSym.flags_field & GENERATED_MEMBER) != 0) {
1231                 /* here we are pushing the annotations present in the corresponding field down to the accessor
1232                  * it could be that some of those annotations are not applicable to the accessor, they will be striped
1233                  * away later at Check::validateAnnotation
1234                  */
1235                 TreeCopier<JCTree> tc = new TreeCopier<JCTree>(make.at(tree.pos));
1236                 List<JCAnnotation> originalAnnos = rec.getOriginalAnnos().isEmpty() ?
1237                         rec.getOriginalAnnos() :
1238                         tc.copy(rec.getOriginalAnnos());
1239                 JCVariableDecl recordField = TreeInfo.recordFields((JCClassDecl) env.tree).stream().filter(rf -> rf.name == tree.name).findAny().get();
1240                 JCMethodDecl getter = make.at(tree.pos).
1241                         MethodDef(
1242                                 make.Modifiers(PUBLIC | Flags.GENERATED_MEMBER, originalAnnos),
1243                           tree.sym.name,
1244                           /* we need to special case for the case when the user declared the type as an ident
< prev index next >