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

The following examples show how to use com.sun.tools.javac.code.Symbol.ModuleSymbol#isUnnamed() . 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: JavacFiler.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void checkNameAndExistence(ModuleSymbol mod, String typename, boolean allowUnnamedPackageInfo) throws FilerException {
    // TODO: Check if type already exists on source or class path?
    // If so, use warning message key proc.type.already.exists
    checkName(typename, allowUnnamedPackageInfo);
    ClassSymbol existing;
    boolean alreadySeen = aggregateGeneratedSourceNames.contains(Pair.of(mod, typename)) ||
                          aggregateGeneratedClassNames.contains(Pair.of(mod, typename)) ||
                          initialClassNames.contains(typename) ||
                          ((existing = elementUtils.getTypeElement(typename)) != null &&
                           initialInputs.contains(existing.sourcefile));
    if (alreadySeen) {
        if (lint)
            log.warning(Warnings.ProcTypeRecreate(typename));
        throw new FilerException("Attempt to recreate a file for type " + typename);
    }
    if (!mod.isUnnamed() && !typename.contains(".")) {
        throw new FilerException("Attempt to create a type in unnamed package of a named module: " + typename);
    }
}
 
Example 2
Source File: JavacFiler.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private void checkNameAndExistence(ModuleSymbol mod, String typename, boolean allowUnnamedPackageInfo) throws FilerException {
    // TODO: Check if type already exists on source or class path?
    // If so, use warning message key proc.type.already.exists
    checkName(typename, allowUnnamedPackageInfo);
    ClassSymbol existing;
    boolean alreadySeen = aggregateGeneratedSourceNames.contains(Pair.of(mod, typename)) ||
                          aggregateGeneratedClassNames.contains(Pair.of(mod, typename)) ||
                          initialClassNames.contains(typename) ||
                          ((existing = elementUtils.getTypeElement(typename)) != null &&
                           initialInputs.contains(existing.sourcefile));
    if (alreadySeen) {
        if (lint)
            log.warning("proc.type.recreate", typename);
        throw new FilerException("Attempt to recreate a file for type " + typename);
    }
    if (!mod.isUnnamed() && !typename.contains(".")) {
        throw new FilerException("Attempt to create a type in unnamed package of a named module: " + typename);
    }
}
 
Example 3
Source File: ElementsTable.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private void addPackagesFromLocations(Location packageLocn, ModulePackage modpkg) throws ToolException {
    for (JavaFileObject fo : fmList(packageLocn, modpkg.packageName, sourceKinds, true)) {
        String binaryName = fm.inferBinaryName(packageLocn, fo);
        String pn = getPackageName(binaryName);
        String simpleName = getSimpleName(binaryName);
        Entry e = getEntry(pn);
        if (!e.isExcluded() && isValidClassName(simpleName)) {
            ModuleSymbol msym = (modpkg.hasModule())
                    ? syms.getModule(names.fromString(modpkg.moduleName))
                    : findModuleOfPackageName(modpkg.packageName);

            if (msym != null && !msym.isUnnamed()) {
                syms.enterPackage(msym, names.fromString(pn));
                ModulePackage npkg = new ModulePackage(msym.toString(), pn);
                cmdLinePackages.add(npkg);
            } else {
                cmdLinePackages.add(e.modpkg);
            }
            e.files = (e.files == null
                    ? com.sun.tools.javac.util.List.of(fo)
                    : e.files.prepend(fo));
        }
    }
}
 
Example 4
Source File: Modules.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void addVisiblePackages(ModuleSymbol msym,
                                Map<Name, ModuleSymbol> seenPackages,
                                ModuleSymbol exportsFrom,
                                Collection<ExportsDirective> exports) {
    for (ExportsDirective d : exports) {
        if (d.modules == null || d.modules.contains(msym)) {
            Name packageName = d.packge.fullname;
            ModuleSymbol previousModule = seenPackages.get(packageName);

            if (previousModule != null && previousModule != exportsFrom) {
                Env<AttrContext> env = typeEnvs.get(msym);
                JavaFileObject origSource = env != null ? log.useSource(env.toplevel.sourcefile)
                                                        : null;
                DiagnosticPosition pos = env != null ? env.tree.pos() : null;
                try {
                    if (msym.isUnnamed()) {
                        log.error(pos, Errors.PackageClashFromRequiresInUnnamed(packageName,
                                                                                previousModule, exportsFrom));
                    } else {
                        log.error(pos, Errors.PackageClashFromRequires(msym, packageName,
                                                                       previousModule, exportsFrom));
                    }
                } finally {
                    if (env != null)
                        log.useSource(origSource);
                }
                continue;
            }

            seenPackages.put(packageName, exportsFrom);
            msym.visiblePackages.put(d.packge.fullname, d.packge);
        }
    }
}
 
Example 5
Source File: Modules.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private void addVisiblePackages(ModuleSymbol msym,
                                Map<Name, ModuleSymbol> seenPackages,
                                ModuleSymbol exportsFrom,
                                Collection<ExportsDirective> exports) {
    for (ExportsDirective d : exports) {
        if (d.modules == null || d.modules.contains(msym)) {
            Name packageName = d.packge.fullname;
            ModuleSymbol previousModule = seenPackages.get(packageName);

            if (previousModule != null && previousModule != exportsFrom) {
                Env<AttrContext> env = typeEnvs.get(msym);
                JavaFileObject origSource = env != null ? log.useSource(env.toplevel.sourcefile)
                                                        : null;
                DiagnosticPosition pos = env != null ? env.tree.pos() : null;
                try {
                    if (msym.isUnnamed()) {
                        log.error(pos, Errors.PackageClashFromRequiresInUnnamed(packageName,
                                                                                previousModule, exportsFrom));
                    } else {
                        log.error(pos, Errors.PackageClashFromRequires(msym, packageName,
                                                                       previousModule, exportsFrom));
                    }
                } finally {
                    if (env != null)
                        log.useSource(origSource);
                }
                continue;
            }

            seenPackages.put(packageName, exportsFrom);
            msym.visiblePackages.put(d.packge.fullname, d.packge);
        }
    }
}