langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/TypeEnter.java
changeset 29149 3fa94aad0264
parent 27857 7e913a535736
child 29842 826ac2519523
equal deleted inserted replaced
29148:57ca99b88ddb 29149:3fa94aad0264
   158      */
   158      */
   159     protected void ensureImportsChecked(List<JCCompilationUnit> trees) {
   159     protected void ensureImportsChecked(List<JCCompilationUnit> trees) {
   160         // if there remain any unimported toplevels (these must have
   160         // if there remain any unimported toplevels (these must have
   161         // no classes at all), process their import statements as well.
   161         // no classes at all), process their import statements as well.
   162         for (JCCompilationUnit tree : trees) {
   162         for (JCCompilationUnit tree : trees) {
   163             if (tree.starImportScope.isEmpty()) {
   163             if (!tree.starImportScope.isFilled()) {
   164                 Env<AttrContext> topEnv = enter.topLevelEnv(tree);
   164                 Env<AttrContext> topEnv = enter.topLevelEnv(tree);
   165                 finishImports(tree, () -> { completeClass.resolveImports(tree, topEnv); });
   165                 finishImports(tree, () -> { completeClass.resolveImports(tree, topEnv); });
   166             }
   166             }
   167        }
   167        }
   168     }
   168     }
   278             super(CompletionCause.IMPORTS_PHASE, new HierarchyPhase());
   278             super(CompletionCause.IMPORTS_PHASE, new HierarchyPhase());
   279         }
   279         }
   280 
   280 
   281         Env<AttrContext> env;
   281         Env<AttrContext> env;
   282         ImportFilter staticImportFilter;
   282         ImportFilter staticImportFilter;
   283         ImportFilter typeImportFilter = new ImportFilter() {
   283         ImportFilter typeImportFilter;
   284             @Override
       
   285             public boolean accepts(Scope origin, Symbol t) {
       
   286                 return t.kind == TYP;
       
   287             }
       
   288         };
       
   289 
   284 
   290         @Override
   285         @Override
   291         protected void doRunPhase(Env<AttrContext> env) {
   286         protected void doRunPhase(Env<AttrContext> env) {
   292             JCClassDecl tree = env.enclClass;
   287             JCClassDecl tree = env.enclClass;
   293             ClassSymbol sym = tree.sym;
   288             ClassSymbol sym = tree.sym;
   302             if (sym.owner.kind == TYP)
   297             if (sym.owner.kind == TYP)
   303                 sym.owner.complete();
   298                 sym.owner.complete();
   304         }
   299         }
   305 
   300 
   306         private void resolveImports(JCCompilationUnit tree, Env<AttrContext> env) {
   301         private void resolveImports(JCCompilationUnit tree, Env<AttrContext> env) {
   307             if (!tree.starImportScope.isEmpty()) {
   302             if (tree.starImportScope.isFilled()) {
   308                 // we must have already processed this toplevel
   303                 // we must have already processed this toplevel
   309                 return;
   304                 return;
   310             }
   305             }
   311 
   306 
   312             ImportFilter prevStaticImportFilter = staticImportFilter;
   307             ImportFilter prevStaticImportFilter = staticImportFilter;
       
   308             ImportFilter prevTypeImportFilter = typeImportFilter;
   313             DiagnosticPosition prevLintPos = deferredLintHandler.immediate();
   309             DiagnosticPosition prevLintPos = deferredLintHandler.immediate();
   314             Lint prevLint = chk.setLint(lint);
   310             Lint prevLint = chk.setLint(lint);
   315             Env<AttrContext> prevEnv = this.env;
   311             Env<AttrContext> prevEnv = this.env;
   316             try {
   312             try {
   317                 this.env = env;
   313                 this.env = env;
   318                 final PackageSymbol packge = env.toplevel.packge;
   314                 final PackageSymbol packge = env.toplevel.packge;
   319                 this.staticImportFilter = new ImportFilter() {
   315                 this.staticImportFilter =
   320                     @Override
   316                         (origin, sym) -> sym.isStatic() &&
   321                     public boolean accepts(Scope origin, Symbol sym) {
   317                                          chk.importAccessible(sym, packge) &&
   322                         return sym.isStatic() &&
   318                                          sym.isMemberOf((TypeSymbol) origin.owner, types);
   323                                chk.staticImportAccessible(sym, packge) &&
   319                 this.typeImportFilter =
   324                                sym.isMemberOf((TypeSymbol) origin.owner, types);
   320                         (origin, sym) -> sym.kind == TYP &&
   325                     }
   321                                          chk.importAccessible(sym, packge);
   326                 };
       
   327 
   322 
   328                 // Import-on-demand java.lang.
   323                 // Import-on-demand java.lang.
   329                 importAll(tree.pos, syms.enterPackage(names.java_lang), env);
   324                 importAll(tree.pos, syms.enterPackage(names.java_lang), env);
   330 
   325 
   331                 // Process the package def and all import clauses.
   326                 // Process the package def and all import clauses.
   338             } finally {
   333             } finally {
   339                 this.env = prevEnv;
   334                 this.env = prevEnv;
   340                 chk.setLint(prevLint);
   335                 chk.setLint(prevLint);
   341                 deferredLintHandler.setPos(prevLintPos);
   336                 deferredLintHandler.setPos(prevLintPos);
   342                 this.staticImportFilter = prevStaticImportFilter;
   337                 this.staticImportFilter = prevStaticImportFilter;
       
   338                 this.typeImportFilter = prevTypeImportFilter;
   343             }
   339             }
   344         }
   340         }
   345 
   341 
   346         private void checkClassPackageClash(JCPackageDecl tree) {
   342         private void checkClassPackageClash(JCPackageDecl tree) {
   347             // check that no class exists with same fully qualified name as
   343             // check that no class exists with same fully qualified name as