com.sun.tools.javac.code.Symbol.ModuleSymbol Java Examples

The following examples show how to use com.sun.tools.javac.code.Symbol.ModuleSymbol. 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: ElementUtils.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public static TypeElement getTypeElementByBinaryName(JavacTask task, ModuleElement mod, String name) {
    Context ctx = ((JavacTaskImpl) task).getContext();
    Names names = Names.instance(ctx);
    Symtab syms = Symtab.instance(ctx);
    Check chk = Check.instance(ctx);
    final Name wrappedName = names.fromString(name);
    ClassSymbol clazz = chk.getCompiled((ModuleSymbol) mod, wrappedName);
    if (clazz != null) {
        return clazz;
    }
    clazz = syms.enterClass((ModuleSymbol) mod, wrappedName);
    
    try {
        clazz.complete();
        
        if (clazz.kind == Kind.TYP &&
            clazz.flatName() == wrappedName) {
            return clazz;
        }
    } catch (CompletionFailure cf) {
    }

    return null;
}
 
Example #2
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 #3
Source File: Modules.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void visitRequires(JCRequires tree) {
    ModuleSymbol msym = lookupModule(tree.moduleName);
    if (msym.kind != MDL) {
        log.error(tree.moduleName.pos(), Errors.ModuleNotFound(msym));
        warnedMissing.add(msym);
    } else if (allRequires.contains(msym)) {
        log.error(tree.moduleName.pos(), Errors.DuplicateRequires(msym));
    } else {
        allRequires.add(msym);
        Set<RequiresFlag> flags = EnumSet.noneOf(RequiresFlag.class);
        if (tree.isTransitive)
            flags.add(RequiresFlag.TRANSITIVE);
        if (tree.isStaticPhase)
            flags.add(RequiresFlag.STATIC_PHASE);
        RequiresDirective d = new RequiresDirective(msym, flags);
        tree.directive = d;
        sym.requires = sym.requires.prepend(d);
    }
}
 
Example #4
Source File: Symtab.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public ModuleSymbol inferModule(Name packageName) {
    if (packageName.isEmpty())
        return java_base == noModule ? noModule : unnamedModule;//!

    ModuleSymbol msym = null;
    Map<ModuleSymbol,PackageSymbol> map = packages.get(packageName);
    if (map == null)
        return null;
    for (Map.Entry<ModuleSymbol,PackageSymbol> e: map.entrySet()) {
        if (!e.getValue().members().isEmpty()) {
            if (msym == null) {
                msym = e.getKey();
            } else {
                return null;
            }
        }
    }
    return msym;
}
 
Example #5
Source File: JavaCompiler.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/** Resolve an identifier.
 * @param msym      The module in which the search should be performed
 * @param name      The identifier to resolve
 */
public Symbol resolveIdent(ModuleSymbol msym, String name) {
    if (name.equals(""))
        return syms.errSymbol;
    JavaFileObject prev = log.useSource(null);
    try {
        JCExpression tree = null;
        for (String s : name.split("\\.", -1)) {
            if (!SourceVersion.isIdentifier(s)) // TODO: check for keywords
                return syms.errSymbol;
            tree = (tree == null) ? make.Ident(names.fromString(s))
                                  : make.Select(tree, names.fromString(s));
        }
        JCCompilationUnit toplevel =
            make.TopLevel(List.nil());
        toplevel.modle = msym;
        toplevel.packge = msym.unnamedPackage;
        return attr.attribIdent(tree, toplevel);
    } finally {
        log.useSource(prev);
    }
}
 
Example #6
Source File: ElementsTable.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private Set<PackageElement> getAllModulePackages(ModuleElement mdle) throws ToolException {
    Set<PackageElement> result = new HashSet<>();
    ModuleSymbol msym = (ModuleSymbol) mdle;
    List<Location> msymlocs = getModuleLocation(locations, msym.name.toString());
    for (Location msymloc : msymlocs) {
        for (JavaFileObject fo : fmList(msymloc, "", sourceKinds, true)) {
            if (fo.getName().endsWith("module-info.java")) {
                continue;
            }
            String binaryName = fm.inferBinaryName(msymloc, fo);
            String pn = getPackageName(binaryName);
            PackageSymbol psym = syms.enterPackage(msym, names.fromString(pn));
            result.add((PackageElement) psym);
        }
    }
    return result;
}
 
Example #7
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 #8
Source File: JavacFiler.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private ModuleSymbol inferModule(String pkg) {
    if (modules.getDefaultModule() == syms.noModule)
        return modules.getDefaultModule();

    Set<ModuleSymbol> rootModules = modules.getRootModules();

    if (rootModules.size() == 1) {
        return rootModules.iterator().next();
    }

    PackageSymbol pack = elementUtils.getPackageElement(pkg);

    if (pack != null && pack.modle != syms.unnamedModule) {
        return pack.modle;
    }

    return null;
}
 
Example #9
Source File: JavaCompiler.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/** Resolve an identifier.
 * @param msym      The module in which the search should be performed
 * @param name      The identifier to resolve
 */
public Symbol resolveIdent(ModuleSymbol msym, String name) {
    if (name.equals(""))
        return syms.errSymbol;
    JavaFileObject prev = log.useSource(null);
    try {
        JCExpression tree = null;
        for (String s : name.split("\\.", -1)) {
            if (!SourceVersion.isIdentifier(s)) // TODO: check for keywords
                return syms.errSymbol;
            tree = (tree == null) ? make.Ident(names.fromString(s))
                                  : make.Select(tree, names.fromString(s));
        }
        JCCompilationUnit toplevel =
            make.TopLevel(List.nil());
        toplevel.modle = msym;
        toplevel.packge = msym.unnamedPackage;
        return attr.attribIdent(tree, toplevel);
    } finally {
        log.useSource(prev);
    }
}
 
Example #10
Source File: Modules.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void initVisiblePackages(ModuleSymbol msym, Collection<ModuleSymbol> readable) {
    initAddExports();

    msym.visiblePackages = new LinkedHashMap<>();
    msym.readModules = new HashSet<>(readable);

    Map<Name, ModuleSymbol> seen = new HashMap<>();

    for (ModuleSymbol rm : readable) {
        if (rm == syms.unnamedModule)
            continue;
        addVisiblePackages(msym, seen, rm, rm.exports);
    }

    Maps.forEach(addExports,(exportsFrom, exports) -> {
        addVisiblePackages(msym, seen, exportsFrom, exports);
    });
}
 
Example #11
Source File: Modules.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private void checkSourceLocation(JCCompilationUnit tree, ModuleSymbol msym) {
    try {
        JavaFileObject fo = tree.sourcefile;
        if (fileManager.contains(msym.sourceLocation, fo)) {
            return;
        }
        if (msym.patchLocation != null && fileManager.contains(msym.patchLocation, fo)) {
            return;
        }
        if (fileManager.hasLocation(StandardLocation.SOURCE_OUTPUT)) {
            if (fileManager.contains(StandardLocation.SOURCE_OUTPUT, fo)) {
                return;
            }
        } else {
            if (fileManager.contains(StandardLocation.CLASS_OUTPUT, fo)) {
                return;
            }
        }
    } catch (IOException e) {
        throw new Error(e);
    }

    JavaFileObject prev = log.useSource(tree.sourcefile);
    try {
        log.error(tree.pos(), "file.sb.on.source.or.patch.path.for.module");
    } finally {
        log.useSource(prev);
    }
}
 
Example #12
Source File: JavaCompiler.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/** Resolve an identifier which may be the binary name of a class or
 * the Java name of a class or package.
 * @param msym      The module in which the search should be performed
 * @param name      The name to resolve
 */
public Symbol resolveBinaryNameOrIdent(ModuleSymbol msym, String name) {
    try {
        Name flatname = names.fromString(name.replace("/", "."));
        return finder.loadClass(msym, flatname);
    } catch (CompletionFailure ignore) {
        return resolveIdent(msym, name);
    }
}
 
Example #13
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 #14
Source File: NPEGetDirectivesTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
    for (Element e: roundEnv.getRootElements()) {
        Element m = e.getEnclosingElement();
        while (!(m instanceof ModuleElement)) {
            m = m.getEnclosingElement();
        }
        ((ModuleSymbol)m).getDirectives();
        RequiresDirective requiresDirective = ((ModuleSymbol)m).requires.head;
        Assert.check(requiresDirective.getDependency().getQualifiedName().toString().equals("java.base"));
        Assert.check(requiresDirective.flags.contains(MANDATED));
    }
    return false;
}
 
Example #15
Source File: ModuleFinder.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public List<ModuleSymbol> findAllModules() {
    List<ModuleSymbol> list = scanModulePath(null);
    for (ModuleSymbol msym: list) {
        if (msym.kind != ERR && msym.module_info.sourcefile == null && msym.module_info.classfile == null) {
            // fill in module-info
            findModuleInfo(msym);
        }
    }
    return list;
}
 
Example #16
Source File: ModuleFinder.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public ModuleSymbol findModule(ModuleSymbol msym) {
    if (msym.kind != ERR && msym.sourceLocation == null && msym.classLocation == null) {
        // fill in location
        List<ModuleSymbol> list = scanModulePath(msym);
        if (list.isEmpty()) {
            msym.kind = ERR;
        }
    }
    if (msym.kind != ERR && msym.module_info.sourcefile == null && msym.module_info.classfile == null) {
        // fill in module-info
        findModuleInfo(msym);
    }
    return msym;
}
 
Example #17
Source File: ModuleFinder.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private void findModuleInfo(ModuleSymbol msym) {
    try {
        JavaFileObject fo;

        fo = getModuleInfoFromLocation(msym.patchOutputLocation, Kind.CLASS);
        fo = preferredFileObject(getModuleInfoFromLocation(msym.patchLocation, Kind.CLASS), fo);
        fo = preferredFileObject(getModuleInfoFromLocation(msym.patchLocation, Kind.SOURCE), fo);

        if (fo == null) {
            fo = getModuleInfoFromLocation(msym.classLocation, Kind.CLASS);
            fo = preferredFileObject(getModuleInfoFromLocation(msym.sourceLocation, Kind.SOURCE), fo);
        }

        if (fo == null) {
            String moduleName = msym.sourceLocation == null && msym.classLocation != null ?
                fileManager.inferModuleName(msym.classLocation) : null;
            if (moduleName != null) {
                msym.module_info.classfile = null;
                msym.flags_field |= Flags.AUTOMATIC_MODULE;
            } else {
                msym.kind = ERR;
            }
        } else {
            msym.module_info.classfile = fo;
            msym.module_info.completer = new Symbol.Completer() {
                @Override
                public void complete(Symbol sym) throws CompletionFailure {
                    classFinder.fillIn(msym.module_info);
                }
                @Override
                public String toString() {
                    return "ModuleInfoCompleter";
                }
            };
        }
    } catch (IOException e) {
        msym.kind = ERR;
    }
}
 
Example #18
Source File: JNIWriter.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/** Emit a class file for a given class.
 *  @param c      The class from which a class file is generated.
 */
public FileObject write(ClassSymbol c) throws IOException {
    String className = c.flatName().toString();
    Location outLocn;
    if (multiModuleMode) {
        ModuleSymbol msym = c.owner.kind == MDL ? (ModuleSymbol) c.owner : c.packge().modle;
        outLocn = fileManager.getLocationForModule(StandardLocation.NATIVE_HEADER_OUTPUT, msym.name.toString());
    } else {
        outLocn = StandardLocation.NATIVE_HEADER_OUTPUT;
    }
    FileObject outFile
        = fileManager.getFileForOutput(outLocn,
            "", className.replaceAll("[.$]", "_") + ".h", null);
    PrintWriter out = new PrintWriter(outFile.openWriter());
    try {
        write(out, c);
        if (verbose)
            log.printVerbose("wrote.file", outFile);
        out.close();
        out = null;
    } finally {
        if (out != null) {
            // if we are propogating an exception, delete the file
            out.close();
            outFile.delete();
            outFile = null;
        }
    }
    return outFile; // may be null if write failed
}
 
Example #19
Source File: JavacElements.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private <S extends Symbol> S doGetElement(ModuleElement module, String methodName,
                                          CharSequence name, Class<S> clazz) {
    String strName = name.toString();
    if (!SourceVersion.isName(strName) && (!strName.isEmpty() || clazz == ClassSymbol.class)) {
        return null;
    }
    if (module == null) {
        return unboundNameToSymbol(methodName, strName, clazz);
    } else {
        return nameToSymbol((ModuleSymbol) module, strName, clazz);
    }
}
 
Example #20
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 #21
Source File: JNIWriter.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/** Emit a class file for a given class.
 *  @param c      The class from which a class file is generated.
 */
public FileObject write(ClassSymbol c) throws IOException {
    String className = c.flatName().toString();
    Location outLocn;
    if (multiModuleMode) {
        ModuleSymbol msym = c.owner.kind == MDL ? (ModuleSymbol) c.owner : c.packge().modle;
        outLocn = fileManager.getLocationForModule(StandardLocation.NATIVE_HEADER_OUTPUT, msym.name.toString());
    } else {
        outLocn = StandardLocation.NATIVE_HEADER_OUTPUT;
    }
    FileObject outFile
        = fileManager.getFileForOutput(outLocn,
            "", className.replaceAll("[.$]", "_") + ".h", null);
    PrintWriter out = new PrintWriter(outFile.openWriter());
    try {
        write(out, c);
        if (verbose)
            log.printVerbose("wrote.file", outFile);
        out.close();
        out = null;
    } finally {
        if (out != null) {
            // if we are propogating an exception, delete the file
            out.close();
            outFile.delete();
            outFile = null;
        }
    }
    return outFile; // may be null if write failed
}
 
Example #22
Source File: Modules.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private void setupAutomaticModule(ModuleSymbol msym) throws CompletionFailure {
    try {
        ListBuffer<Directive> directives = new ListBuffer<>();
        ListBuffer<ExportsDirective> exports = new ListBuffer<>();
        Set<String> seenPackages = new HashSet<>();

        for (JavaFileObject clazz : fileManager.list(msym.classLocation, "", EnumSet.of(Kind.CLASS), true)) {
            String binName = fileManager.inferBinaryName(msym.classLocation, clazz);
            String pack = binName.lastIndexOf('.') != (-1) ? binName.substring(0, binName.lastIndexOf('.')) : ""; //unnamed package????
            if (seenPackages.add(pack)) {
                ExportsDirective d = new ExportsDirective(syms.enterPackage(msym, names.fromString(pack)), null);
                //TODO: opens?
                directives.add(d);
                exports.add(d);
            }
        }

        msym.exports = exports.toList();
        msym.provides = List.nil();
        msym.requires = List.nil();
        msym.uses = List.nil();
        msym.directives = directives.toList();
        msym.flags_field |= Flags.ACYCLIC;
    } catch (IOException ex) {
        throw new IllegalStateException(ex);
    }
}
 
Example #23
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 #24
Source File: ElementsTable.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private List<Location> getLocation(ModulePackage modpkg) throws ToolException {
    if (locations.size() == 1 && !locations.contains(StandardLocation.MODULE_SOURCE_PATH)) {
        return Collections.singletonList(locations.get(0));
    }

    if (modpkg.hasModule()) {
        return getModuleLocation(locations, modpkg.moduleName);
    }
    // TODO: handle invalid results better.
    ModuleSymbol msym = findModuleOfPackageName(modpkg.packageName);
    if (msym == null) {
        return Collections.emptyList();
    }
    return getModuleLocation(locations, msym.name.toString());
}
 
Example #25
Source File: JavacFiler.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private JavaFileObject createSourceOrClassFile(ModuleSymbol mod, boolean isSourceFile, String name) throws IOException {
    Assert.checkNonNull(mod);

    if (lint) {
        int periodIndex = name.lastIndexOf(".");
        if (periodIndex != -1) {
            String base = name.substring(periodIndex);
            String extn = (isSourceFile ? ".java" : ".class");
            if (base.equals(extn))
                log.warning("proc.suspicious.class.name", name, extn);
        }
    }
    checkNameAndExistence(mod, name, isSourceFile);
    Location loc = (isSourceFile ? SOURCE_OUTPUT : CLASS_OUTPUT);

    if (modules.multiModuleMode) {
        loc = this.fileManager.getLocationForModule(loc, mod.name.toString());
    }
    JavaFileObject.Kind kind = (isSourceFile ?
                                JavaFileObject.Kind.SOURCE :
                                JavaFileObject.Kind.CLASS);

    JavaFileObject fileObject =
        fileManager.getJavaFileForOutput(loc, name, kind, null);
    checkFileReopening(fileObject, true);

    if (lastRound)
        log.warning("proc.file.create.last.round", name);

    if (isSourceFile)
        aggregateGeneratedSourceNames.add(Pair.of(mod, name));
    else
        aggregateGeneratedClassNames.add(Pair.of(mod, name));
    openTypeNames.add(name);

    return new FilerOutputJavaFileObject(mod, name, fileObject);
}
 
Example #26
Source File: Check.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
void checkModuleExists(final DiagnosticPosition pos, ModuleSymbol msym) {
    if (msym.kind != MDL) {
        deferredLintHandler.report(() -> {
            if (lint.isEnabled(LintCategory.MODULE))
                log.warning(LintCategory.MODULE, pos, Warnings.ModuleNotFound(msym));
        });
    }
}
 
Example #27
Source File: Lower.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void visitModuleDef(JCModuleDecl tree) {
    ModuleSymbol msym = tree.sym;
    ClassSymbol c = msym.module_info;
    c.setAttributes(msym);
    c.flags_field |= Flags.MODULE;
    createInfoClass(List.nil(), tree.sym.module_info);
}
 
Example #28
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> enterModules(List<JCCompilationUnit> trees, ClassSymbol c) {
    Set<ModuleSymbol> modules = new LinkedHashSet<>();
    for (JCCompilationUnit tree : trees) {
        JavaFileObject prev = log.useSource(tree.sourcefile);
        try {
            enterModule(tree, c, modules);
        } finally {
            log.useSource(prev);
        }
    }
    return modules;
}
 
Example #29
Source File: Modules.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void checkSourceLocation(JCCompilationUnit tree, ModuleSymbol msym) {
    try {
        JavaFileObject fo = tree.sourcefile;
        if (fileManager.contains(msym.sourceLocation, fo)) {
            return;
        }
        if (msym.patchLocation != null && fileManager.contains(msym.patchLocation, fo)) {
            return;
        }
        if (fileManager.hasLocation(StandardLocation.SOURCE_OUTPUT)) {
            if (fileManager.contains(StandardLocation.SOURCE_OUTPUT, fo)) {
                return;
            }
        } else {
            if (fileManager.contains(StandardLocation.CLASS_OUTPUT, fo)) {
                return;
            }
        }
    } catch (IOException e) {
        throw new Error(e);
    }

    JavaFileObject prev = log.useSource(tree.sourcefile);
    try {
        log.error(tree.pos(), Errors.FileSbOnSourceOrPatchPathForModule);
    } finally {
        log.useSource(prev);
    }
}
 
Example #30
Source File: Modules.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void complete(Symbol sym) throws CompletionFailure {
    ModuleSymbol msym = moduleFinder.findModule((ModuleSymbol) sym);

    if (msym.kind == ERR) {
        //make sure the module is initialized:
        msym.directives = List.nil();
        msym.exports = List.nil();
        msym.provides = List.nil();
        msym.requires = List.nil();
        msym.uses = List.nil();
    } else if ((msym.flags_field & Flags.AUTOMATIC_MODULE) != 0) {
        setupAutomaticModule(msym);
    } else {
        msym.module_info.complete();
    }

    // If module-info comes from a .java file, the underlying
    // call of classFinder.fillIn will have called through the
    // source completer, to Enter, and then to Modules.enter,
    // which will call completeModule.
    // But, if module-info comes from a .class file, the underlying
    // call of classFinder.fillIn will just call ClassReader to read
    // the .class file, and so we call completeModule here.
    if (msym.module_info.classfile == null || msym.module_info.classfile.getKind() == Kind.CLASS) {
        completeModule(msym);
    }
}