Java Code Examples for com.sun.tools.javac.code.Symbol.PackageSymbol#exists()

The following examples show how to use com.sun.tools.javac.code.Symbol.PackageSymbol#exists() . 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: 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 2
Source File: TypeEnter.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private void resolveImports(JCCompilationUnit tree, Env<AttrContext> env) {
    if (tree.starImportScope.isFilled()) {
        // we must have already processed this toplevel
        return;
    }

    ImportFilter prevStaticImportFilter = staticImportFilter;
    ImportFilter prevTypeImportFilter = typeImportFilter;
    DiagnosticPosition prevLintPos = deferredLintHandler.immediate();
    Lint prevLint = chk.setLint(lint);
    Env<AttrContext> prevEnv = this.env;
    try {
        this.env = env;
        final PackageSymbol packge = env.toplevel.packge;
        this.staticImportFilter =
                (origin, sym) -> sym.isStatic() &&
                                 chk.importAccessible(sym, packge) &&
                                 sym.isMemberOf((TypeSymbol) origin.owner, types);
        this.typeImportFilter =
                (origin, sym) -> sym.kind == TYP &&
                                 chk.importAccessible(sym, packge);

        // Import-on-demand java.lang.
        PackageSymbol javaLang = syms.enterPackage(syms.java_base, names.java_lang);
        if (javaLang.members().isEmpty() && !javaLang.exists())
            throw new FatalError(diags.fragment(Fragments.FatalErrNoJavaLang));
        importAll(make.at(tree.pos()).Import(make.QualIdent(javaLang), false), javaLang, env);

        JCModuleDecl decl = tree.getModuleDecl();

        // Process the package def and all import clauses.
        if (tree.getPackage() != null && decl == null)
            checkClassPackageClash(tree.getPackage());

        for (JCImport imp : tree.getImports()) {
            doImport(imp);
        }

        if (decl != null) {
            //check @Deprecated:
            markDeprecated(decl.sym, decl.mods.annotations, env);
            // process module annotations
            annotate.annotateLater(decl.mods.annotations, env, env.toplevel.modle, null);
        }
    } finally {
        this.env = prevEnv;
        chk.setLint(prevLint);
        deferredLintHandler.setPos(prevLintPos);
        this.staticImportFilter = prevStaticImportFilter;
        this.typeImportFilter = prevTypeImportFilter;
    }
}
 
Example 3
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);
}