Java Code Examples for com.sun.tools.javac.code.Symbol.ClassSymbol#packge()

The following examples show how to use com.sun.tools.javac.code.Symbol.ClassSymbol#packge() . 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: PubAPIs.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Convert the map from class names to their pubapi to a map
 * from package names to their pubapi.
 */
public Map<String, PubApi> getPubapis(Collection<JavaFileObject> explicitJFOs, boolean explicits) {

    // Maps ":java.lang" to a package level pub api (with only types on top level)
    Map<String, PubApi> result = new HashMap<>();
    for (ClassSymbol cs : publicApiPerClass.keySet()) {

        boolean amongExplicits = explicitJFOs.contains(cs.sourcefile);
        if (explicits != amongExplicits)
            continue;

        String pkg = ":" + cs.packge().fullname;
        PubApi currentPubApi = result.getOrDefault(pkg, new PubApi());
        result.put(pkg, PubApi.mergeTypes(currentPubApi, publicApiPerClass.get(cs)));
    }

    return result;
}
 
Example 2
Source File: ClassWriter.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 JavaFileObject writeClass(ClassSymbol c)
    throws IOException, PoolOverflow, StringOverflow
{
    String name = (c.owner.kind == MDL ? c.name : c.flatname).toString();
    Location outLocn;
    if (multiModuleMode) {
        ModuleSymbol msym = c.owner.kind == MDL ? (ModuleSymbol) c.owner : c.packge().modle;
        outLocn = fileManager.getLocationForModule(CLASS_OUTPUT, msym.name.toString());
    } else {
        outLocn = CLASS_OUTPUT;
    }
    JavaFileObject outFile
        = fileManager.getJavaFileForOutput(outLocn,
                                           name,
                                           JavaFileObject.Kind.CLASS,
                                           c.sourcefile);
    OutputStream out = outFile.openOutputStream();
    try {
        writeClassFile(out, c);
        if (verbose)
            log.printVerbose("wrote.file", outFile);
        out.close();
        out = null;
    } finally {
        if (out != null) {
            // if we are propagating an exception, delete the file
            out.close();
            outFile.delete();
            outFile = null;
        }
    }
    return outFile; // may be null if write failed
}
 
Example 3
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 4
Source File: Lower.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/** Return an anonymous class nested in this toplevel class.
 */
ClassSymbol accessConstructorTag() {
    ClassSymbol topClass = currentClass.outermostClass();
    ModuleSymbol topModle = topClass.packge().modle;
    Name flatname = names.fromString("" + topClass.getQualifiedName() +
                                     target.syntheticNameChar() +
                                     "1");
    ClassSymbol ctag = chk.getCompiled(topModle, flatname);
    if (ctag == null)
        ctag = makeEmptyClass(STATIC | SYNTHETIC, topClass).sym;
    // keep a record of all tags, to verify that all are generated as required
    accessConstrTags = accessConstrTags.prepend(ctag);
    return ctag;
}
 
Example 5
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 6
Source File: JavacProcessingEnvironment.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private boolean isPkgInfo(ClassSymbol sym) {
    return isPkgInfo(sym.classfile, JavaFileObject.Kind.CLASS) && (sym.packge().package_info == sym);
}
 
Example 7
Source File: Modules.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private void checkForCorrectness() {
    for (Directive.ProvidesDirective provides : msym.provides) {
        JCProvides tree = directiveToTreeMap.get(provides);
        for (ClassSymbol impl : provides.impls) {
            /* The implementation must be defined in the same module as the provides directive
             * (else, error)
             */
            PackageSymbol implementationDefiningPackage = impl.packge();
            if (implementationDefiningPackage.modle != msym) {
                // TODO: should use tree for the implentation name, not the entire provides tree
                // TODO: should improve error message to identify the implementation type
                log.error(tree.pos(), Errors.ServiceImplementationNotInRightModule(implementationDefiningPackage.modle));
            }

            /* There is no inherent requirement that module that provides a service should actually
             * use it itself. However, it is a pointless declaration if the service package is not
             * exported and there is no uses for the service.
             */
            PackageSymbol interfaceDeclaringPackage = provides.service.packge();
            boolean isInterfaceDeclaredInCurrentModule = interfaceDeclaringPackage.modle == msym;
            boolean isInterfaceExportedFromAReadableModule =
                    msym.visiblePackages.get(interfaceDeclaringPackage.fullname) == interfaceDeclaringPackage;
            if (isInterfaceDeclaredInCurrentModule && !isInterfaceExportedFromAReadableModule) {
                // ok the interface is declared in this module. Let's check if it's exported
                boolean warn = true;
                for (ExportsDirective export : msym.exports) {
                    if (interfaceDeclaringPackage == export.packge) {
                        warn = false;
                        break;
                    }
                }
                if (warn) {
                    for (UsesDirective uses : msym.uses) {
                        if (provides.service == uses.service) {
                            warn = false;
                            break;
                        }
                    }
                }
                if (warn) {
                    log.warning(tree.pos(), Warnings.ServiceProvidedButNotExportedOrUsed(provides.service));
                }
            }
        }
    }
}
 
Example 8
Source File: Modules.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
private void checkForCorrectness() {
    for (Directive.ProvidesDirective provides : msym.provides) {
        JCProvides tree = directiveToTreeMap.get(provides);
        for (ClassSymbol impl : provides.impls) {
            /* The implementation must be defined in the same module as the provides directive
             * (else, error)
             */
            PackageSymbol implementationDefiningPackage = impl.packge();
            if (implementationDefiningPackage.modle != msym) {
                // TODO: should use tree for the implentation name, not the entire provides tree
                // TODO: should improve error message to identify the implementation type
                log.error(tree.pos(), Errors.ServiceImplementationNotInRightModule(implementationDefiningPackage.modle));
            }

            /* There is no inherent requirement that module that provides a service should actually
             * use it itself. However, it is a pointless declaration if the service package is not
             * exported and there is no uses for the service.
             */
            PackageSymbol interfaceDeclaringPackage = provides.service.packge();
            boolean isInterfaceDeclaredInCurrentModule = interfaceDeclaringPackage.modle == msym;
            boolean isInterfaceExportedFromAReadableModule =
                    msym.visiblePackages.get(interfaceDeclaringPackage.fullname) == interfaceDeclaringPackage;
            if (isInterfaceDeclaredInCurrentModule && !isInterfaceExportedFromAReadableModule) {
                // ok the interface is declared in this module. Let's check if it's exported
                boolean warn = true;
                for (ExportsDirective export : msym.exports) {
                    if (interfaceDeclaringPackage == export.packge) {
                        warn = false;
                        break;
                    }
                }
                if (warn) {
                    for (UsesDirective uses : msym.uses) {
                        if (provides.service == uses.service) {
                            warn = false;
                            break;
                        }
                    }
                }
                if (warn) {
                    log.warning(tree.pos(), Warnings.ServiceProvidedButNotExportedOrUsed(provides.service));
                }
            }
        }
    }
}