Java Code Examples for com.sun.tools.javac.code.Symbol.ModuleSymbol#complete()

The following examples show how to use com.sun.tools.javac.code.Symbol.ModuleSymbol#complete() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Modules.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public Completer getUsesProvidesCompleter() {
    return sym -> {
        ModuleSymbol msym = (ModuleSymbol) sym;

        msym.complete();

        Env<AttrContext> env = typeEnvs.get(msym);
        UsesProvidesVisitor v = new UsesProvidesVisitor(msym, env);
        JavaFileObject prev = log.useSource(env.toplevel.sourcefile);
        JCModuleDecl decl = env.toplevel.getModuleDecl();
        DiagnosticPosition prevLintPos = deferredLintHandler.setPos(decl.pos());

        try {
            decl.accept(v);
        } finally {
            log.useSource(prev);
            deferredLintHandler.setPos(prevLintPos);
        }
    };
}
 
Example 2
Source File: Modules.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private Completer getUnnamedModuleCompleter() {
    moduleFinder.findAllModules();
    return new Symbol.Completer() {
        @Override
        public void complete(Symbol sym) throws CompletionFailure {
            if (inInitModules) {
                sym.completer = this;
                return ;
            }
            ModuleSymbol msym = (ModuleSymbol) sym;
            Set<ModuleSymbol> allModules = new HashSet<>(allModules());
            allModules.remove(syms.unnamedModule);
            for (ModuleSymbol m : allModules) {
                m.complete();
            }
            initVisiblePackages(msym, allModules);
        }

        @Override
        public String toString() {
            return "unnamedModule Completer";
        }
    };
}
 
Example 3
Source File: Modules.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public Completer getUsesProvidesCompleter() {
    return sym -> {
        ModuleSymbol msym = (ModuleSymbol) sym;

        msym.complete();

        Env<AttrContext> env = typeEnvs.get(msym);
        UsesProvidesVisitor v = new UsesProvidesVisitor(msym, env);
        JavaFileObject prev = log.useSource(env.toplevel.sourcefile);
        JCModuleDecl decl = env.toplevel.getModuleDecl();
        DiagnosticPosition prevLintPos = deferredLintHandler.setPos(decl.pos());

        try {
            decl.accept(v);
        } finally {
            log.useSource(prev);
            deferredLintHandler.setPos(prevLintPos);
        }
    };
}
 
Example 4
Source File: Modules.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private Completer getUnnamedModuleCompleter() {
    moduleFinder.findAllModules();
    return new Symbol.Completer() {
        @Override
        public void complete(Symbol sym) throws CompletionFailure {
            if (inInitModules) {
                sym.completer = this;
                return ;
            }
            ModuleSymbol msym = (ModuleSymbol) sym;
            Set<ModuleSymbol> allModules = new HashSet<>(allModules());
            allModules.remove(syms.unnamedModule);
            for (ModuleSymbol m : allModules) {
                m.complete();
            }
            initVisiblePackages(msym, allModules);
        }

        @Override
        public String toString() {
            return "unnamedModule Completer";
        }
    };
}
 
Example 5
Source File: ClassFinder.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/** Load directory of package into members scope.
 */
private void fillIn(PackageSymbol p) throws IOException {
    if (p.members_field == null)
        p.members_field = WriteableScope.create(p);

    ModuleSymbol msym = p.modle;

    Assert.checkNonNull(msym, p::toString);

    msym.complete();

    if (msym == syms.noModule) {
        preferCurrent = false;
        if (userPathsFirst) {
            scanUserPaths(p, true);
            preferCurrent = true;
            scanPlatformPath(p);
        } else {
            scanPlatformPath(p);
            scanUserPaths(p, true);
        }
    } else if (msym.classLocation == StandardLocation.CLASS_PATH) {
        scanUserPaths(p, msym.sourceLocation == StandardLocation.SOURCE_PATH);
    } else {
        scanModulePaths(p, msym);
    }
}
 
Example 6
Source File: Modules.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private boolean enter(List<JCCompilationUnit> trees, Consumer<Set<ModuleSymbol>> init, ClassSymbol c) {
    if (!allowModules) {
        for (JCCompilationUnit tree: trees) {
            tree.modle = syms.noModule;
        }
        defaultModule = syms.noModule;
        return true;
    }

    int startErrors = log.nerrors;

    depth++;
    try {
        // scan trees for module defs
        Set<ModuleSymbol> roots = enterModules(trees, c);

        setCompilationUnitModules(trees, roots, c);

        init.accept(roots);

        for (ModuleSymbol msym: roots) {
            msym.complete();
        }
    } catch (CompletionFailure ex) {
        chk.completionError(null, ex);
    } finally {
        depth--;
    }

    return (log.nerrors == startErrors);
}
 
Example 7
Source File: Modules.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private Set<ModuleSymbol> retrieveRequiresTransitive(ModuleSymbol msym) {
    Set<ModuleSymbol> requiresTransitive = requiresTransitiveCache.get(msym);

    if (requiresTransitive == null) {
        //the module graph may contain cycles involving automatic modules or --add-reads edges
        requiresTransitive = new HashSet<>();

        Set<ModuleSymbol> seen = new HashSet<>();
        List<ModuleSymbol> todo = List.of(msym);

        while (todo.nonEmpty()) {
            ModuleSymbol current = todo.head;
            todo = todo.tail;
            if (!seen.add(current))
                continue;
            requiresTransitive.add(current);
            current.complete();
            Iterable<? extends RequiresDirective> requires;
            if (current != syms.unnamedModule) {
                Assert.checkNonNull(current.requires, () -> current + ".requires == null; " + msym);
                requires = current.requires;
                for (RequiresDirective rd : requires) {
                    if (rd.isTransitive())
                        todo = todo.prepend(rd.module);
                }
            } else {
                for (ModuleSymbol mod : allModules()) {
                    todo = todo.prepend(mod);
                }
            }
        }

        requiresTransitive.remove(msym);
    }

    return requiresTransitive;
}
 
Example 8
Source File: Modules.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void checkCyclicDependencies(JCModuleDecl mod) {
    for (JCDirective d : mod.directives) {
        JCRequires rd;
        if (!d.hasTag(Tag.REQUIRES) || (rd = (JCRequires) d).directive == null)
            continue;
        Set<ModuleSymbol> nonSyntheticDeps = new HashSet<>();
        List<ModuleSymbol> queue = List.of(rd.directive.module);
        while (queue.nonEmpty()) {
            ModuleSymbol current = queue.head;
            queue = queue.tail;
            if (!nonSyntheticDeps.add(current))
                continue;
            current.complete();
            if ((current.flags() & Flags.ACYCLIC) != 0)
                continue;
            Assert.checkNonNull(current.requires, current::toString);
            for (RequiresDirective dep : current.requires) {
                if (!dep.flags.contains(RequiresFlag.EXTRA))
                    queue = queue.prepend(dep.module);
            }
        }
        if (nonSyntheticDeps.contains(mod.sym)) {
            log.error(rd.moduleName.pos(), Errors.CyclicRequires(rd.directive.module));
        }
        mod.sym.flags_field |= Flags.ACYCLIC;
    }
}
 
Example 9
Source File: ClassFinder.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/** Load directory of package into members scope.
 */
private void fillIn(PackageSymbol p) throws IOException {
    if (p.members_field == null)
        p.members_field = WriteableScope.create(p);

    ModuleSymbol msym = p.modle;

    Assert.checkNonNull(msym, p::toString);

    msym.complete();

    if (msym == syms.noModule) {
        preferCurrent = false;
        if (userPathsFirst) {
            scanUserPaths(p, true);
            preferCurrent = true;
            scanPlatformPath(p);
        } else {
            scanPlatformPath(p);
            scanUserPaths(p, true);
        }
    } else if (msym.classLocation == StandardLocation.CLASS_PATH) {
        scanUserPaths(p, msym.sourceLocation == StandardLocation.SOURCE_PATH);
    } else {
        scanModulePaths(p, msym);
    }
}
 
Example 10
Source File: Modules.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private boolean enter(List<JCCompilationUnit> trees, Consumer<Set<ModuleSymbol>> init, ClassSymbol c) {
    if (!allowModules) {
        for (JCCompilationUnit tree: trees) {
            tree.modle = syms.noModule;
        }
        defaultModule = syms.noModule;
        return true;
    }

    int startErrors = log.nerrors;

    depth++;
    try {
        // scan trees for module defs
        Set<ModuleSymbol> roots = enterModules(trees, c);

        setCompilationUnitModules(trees, roots, c);

        init.accept(roots);

        for (ModuleSymbol msym: roots) {
            msym.complete();
        }
    } catch (CompletionFailure ex) {
        log.error(JCDiagnostic.DiagnosticFlag.NON_DEFERRABLE, Position.NOPOS, "cant.access", ex.sym, ex.getDetailValue());
        if (ex instanceof ClassFinder.BadClassFile) throw new Abort();
    } finally {
        depth--;
    }

    return (log.nerrors == startErrors);
}
 
Example 11
Source File: Modules.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private Set<ModuleSymbol> retrieveRequiresTransitive(ModuleSymbol msym) {
    Set<ModuleSymbol> requiresTransitive = requiresTransitiveCache.get(msym);

    if (requiresTransitive == null) {
        //the module graph may contain cycles involving automatic modules or --add-reads edges
        requiresTransitive = new HashSet<>();

        Set<ModuleSymbol> seen = new HashSet<>();
        List<ModuleSymbol> todo = List.of(msym);

        while (todo.nonEmpty()) {
            ModuleSymbol current = todo.head;
            todo = todo.tail;
            if (!seen.add(current))
                continue;
            requiresTransitive.add(current);
            current.complete();
            Iterable<? extends RequiresDirective> requires;
            if (current != syms.unnamedModule) {
                Assert.checkNonNull(current.requires, () -> current + ".requires == null; " + msym);
                requires = current.requires;
                for (RequiresDirective rd : requires) {
                    if (rd.isTransitive())
                        todo = todo.prepend(rd.module);
                }
            } else {
                for (ModuleSymbol mod : allModules()) {
                    todo = todo.prepend(mod);
                }
            }
        }

        requiresTransitive.remove(msym);
    }

    return requiresTransitive;
}
 
Example 12
Source File: Modules.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private void checkCyclicDependencies(JCModuleDecl mod) {
    for (JCDirective d : mod.directives) {
        JCRequires rd;
        if (!d.hasTag(Tag.REQUIRES) || (rd = (JCRequires) d).directive == null)
            continue;
        Set<ModuleSymbol> nonSyntheticDeps = new HashSet<>();
        List<ModuleSymbol> queue = List.of(rd.directive.module);
        while (queue.nonEmpty()) {
            ModuleSymbol current = queue.head;
            queue = queue.tail;
            if (!nonSyntheticDeps.add(current))
                continue;
            current.complete();
            if ((current.flags() & Flags.ACYCLIC) != 0)
                continue;
            Assert.checkNonNull(current.requires, current::toString);
            for (RequiresDirective dep : current.requires) {
                if (!dep.flags.contains(RequiresFlag.EXTRA))
                    queue = queue.prepend(dep.module);
            }
        }
        if (nonSyntheticDeps.contains(mod.sym)) {
            log.error(rd.moduleName.pos(), Errors.CyclicRequires(rd.directive.module));
        }
        mod.sym.flags_field |= Flags.ACYCLIC;
    }
}
 
Example 13
Source File: Symtab.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public PackageSymbol lookupPackage(ModuleSymbol msym, Name flatName) {
    Assert.checkNonNull(msym);

    if (flatName.isEmpty()) {
        //unnamed packages only from the current module - visiblePackages contains *root* package, not unnamed package!
        return msym.unnamedPackage;
    }

    if (msym == noModule) {
        return enterPackage(msym, flatName);
    }

    msym.complete();

    PackageSymbol pack;

    pack = msym.visiblePackages.get(flatName);

    if (pack != null)
        return pack;

    pack = getPackage(msym, flatName);

    if (pack != null && pack.exists())
        return pack;

    boolean dependsOnUnnamed = msym.requires != null &&
                               StreamSupport.stream(msym.requires)
                                            .map(rd -> rd.module)
                                            .anyMatch(mod -> mod == unnamedModule);

    if (dependsOnUnnamed) {
        //msyms depends on the unnamed module, for which we generally don't know
        //the list of packages it "exports" ahead of time. So try to lookup the package in the
        //current module, and in the unnamed module and see if it exists in one of them
        PackageSymbol unnamedPack = getPackage(unnamedModule, flatName);

        if (unnamedPack != null && unnamedPack.exists()) {
            msym.visiblePackages.put(unnamedPack.fullname, unnamedPack);
            return unnamedPack;
        }

        pack = enterPackage(msym, flatName);
        pack.complete();
        if (pack.exists())
            return pack;

        unnamedPack = enterPackage(unnamedModule, flatName);
        unnamedPack.complete();
        if (unnamedPack.exists()) {
            msym.visiblePackages.put(unnamedPack.fullname, unnamedPack);
            return unnamedPack;
        }

        return pack;
    }

    return enterPackage(msym, flatName);
}
 
Example 14
Source File: Modules.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private Set<ModuleSymbol> computeTransitiveClosure(Set<? extends ModuleSymbol> base,
                                                   Set<? extends ModuleSymbol> rootModules,
                                                   Set<ModuleSymbol> observable) {
    List<ModuleSymbol> primaryTodo = List.nil();
    List<ModuleSymbol> secondaryTodo = List.nil();

    for (ModuleSymbol ms : base) {
        if (rootModules.contains(ms)) {
            primaryTodo = primaryTodo.prepend(ms);
        } else {
            secondaryTodo = secondaryTodo.prepend(ms);
        }
    }

    Set<ModuleSymbol> result = new LinkedHashSet<>();
    result.add(syms.java_base);

    while (primaryTodo.nonEmpty() || secondaryTodo.nonEmpty()) {
        try {
            ModuleSymbol current;
            boolean isPrimaryTodo;
            if (primaryTodo.nonEmpty()) {
                current = primaryTodo.head;
                primaryTodo = primaryTodo.tail;
                isPrimaryTodo = true;
            } else {
                current = secondaryTodo.head;
                secondaryTodo = secondaryTodo.tail;
                isPrimaryTodo = false;
            }
            if (observable != null && !observable.contains(current))
                continue;
            if (!result.add(current) || current == syms.unnamedModule || ((current.flags_field & Flags.AUTOMATIC_MODULE) != 0))
                continue;
            current.complete();
            if (current.kind == ERR && (isPrimaryTodo || base.contains(current)) && warnedMissing.add(current)) {
                log.error(Errors.ModuleNotFound(current));
            }
            for (RequiresDirective rd : current.requires) {
                if (rd.module == syms.java_base) continue;
                if ((rd.isTransitive() && isPrimaryTodo) || rootModules.contains(current)) {
                    primaryTodo = primaryTodo.prepend(rd.module);
                } else {
                    secondaryTodo = secondaryTodo.prepend(rd.module);
                }
            }
        } catch (CompletionFailure ex) {
            chk.completionError(null, ex);
        }
    }

    return result;
}
 
Example 15
Source File: Symtab.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public PackageSymbol lookupPackage(ModuleSymbol msym, Name flatName) {
    Assert.checkNonNull(msym);

    if (flatName.isEmpty()) {
        //unnamed packages only from the current module - visiblePackages contains *root* package, not unnamed package!
        return msym.unnamedPackage;
    }

    if (msym == noModule) {
        return enterPackage(msym, flatName);
    }

    msym.complete();

    PackageSymbol pack;

    pack = msym.visiblePackages.get(flatName);

    if (pack != null)
        return pack;

    pack = getPackage(msym, flatName);

    if (pack != null && pack.exists())
        return pack;

    boolean dependsOnUnnamed = msym.requires != null &&
                               msym.requires.stream()
                                            .map(rd -> rd.module)
                                            .anyMatch(mod -> mod == unnamedModule);

    if (dependsOnUnnamed) {
        //msyms depends on the unnamed module, for which we generally don't know
        //the list of packages it "exports" ahead of time. So try to lookup the package in the
        //current module, and in the unnamed module and see if it exists in one of them
        PackageSymbol unnamedPack = getPackage(unnamedModule, flatName);

        if (unnamedPack != null && unnamedPack.exists()) {
            msym.visiblePackages.put(unnamedPack.fullname, unnamedPack);
            return unnamedPack;
        }

        pack = enterPackage(msym, flatName);
        pack.complete();
        if (pack.exists())
            return pack;

        unnamedPack = enterPackage(unnamedModule, flatName);
        unnamedPack.complete();
        if (unnamedPack.exists()) {
            msym.visiblePackages.put(unnamedPack.fullname, unnamedPack);
            return unnamedPack;
        }

        return pack;
    }

    return enterPackage(msym, flatName);
}
 
Example 16
Source File: Modules.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
private Set<ModuleSymbol> computeTransitiveClosure(Set<? extends ModuleSymbol> base,
                                                   Set<? extends ModuleSymbol> rootModules,
                                                   Set<ModuleSymbol> observable) {
    List<ModuleSymbol> primaryTodo = List.nil();
    List<ModuleSymbol> secondaryTodo = List.nil();

    for (ModuleSymbol ms : base) {
        if (rootModules.contains(ms)) {
            primaryTodo = primaryTodo.prepend(ms);
        } else {
            secondaryTodo = secondaryTodo.prepend(ms);
        }
    }

    Set<ModuleSymbol> result = new LinkedHashSet<>();
    result.add(syms.java_base);

    while (primaryTodo.nonEmpty() || secondaryTodo.nonEmpty()) {
        ModuleSymbol current;
        boolean isPrimaryTodo;
        if (primaryTodo.nonEmpty()) {
            current = primaryTodo.head;
            primaryTodo = primaryTodo.tail;
            isPrimaryTodo = true;
        } else {
            current = secondaryTodo.head;
            secondaryTodo = secondaryTodo.tail;
            isPrimaryTodo = false;
        }
        if (observable != null && !observable.contains(current))
            continue;
        if (!result.add(current) || current == syms.unnamedModule || ((current.flags_field & Flags.AUTOMATIC_MODULE) != 0))
            continue;
        current.complete();
        if (current.kind == ERR && (isPrimaryTodo || base.contains(current)) && warnedMissing.add(current)) {
            log.error(Errors.ModuleNotFound(current));
        }
        for (RequiresDirective rd : current.requires) {
            if (rd.module == syms.java_base) continue;
            if ((rd.isTransitive() && isPrimaryTodo) || rootModules.contains(current)) {
                primaryTodo = primaryTodo.prepend(rd.module);
            } else {
                secondaryTodo = secondaryTodo.prepend(rd.module);
            }
        }
    }

    return result;
}