Java Code Examples for javax.lang.model.util.ElementFilter#packagesIn()

The following examples show how to use javax.lang.model.util.ElementFilter#packagesIn() . 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: ModuleFrameWriter.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Add class listing for all the classes in this module. Divide class
 * listing as per the class kind and generate separate listing for
 * Classes, Interfaces, Exceptions and Errors.
 *
 * @param contentTree the content tree to which the listing will be added
 */
protected void addClassListing(HtmlTree contentTree) {
    List<PackageElement> packagesIn = ElementFilter.packagesIn(mdle.getEnclosedElements());
    SortedSet<TypeElement> interfaces = new TreeSet<>(utils.makeGeneralPurposeComparator());
    SortedSet<TypeElement> classes = new TreeSet<>(utils.makeGeneralPurposeComparator());
    SortedSet<TypeElement> enums = new TreeSet<>(utils.makeGeneralPurposeComparator());
    SortedSet<TypeElement> exceptions = new TreeSet<>(utils.makeGeneralPurposeComparator());
    SortedSet<TypeElement> errors = new TreeSet<>(utils.makeGeneralPurposeComparator());
    SortedSet<TypeElement> annotationTypes = new TreeSet<>(utils.makeGeneralPurposeComparator());
    for (PackageElement pkg : packagesIn) {
        if (utils.isIncluded(pkg)) {
            interfaces.addAll(utils.getInterfaces(pkg));
            classes.addAll(utils.getOrdinaryClasses(pkg));
            enums.addAll(utils.getEnums(pkg));
            exceptions.addAll(utils.getExceptions(pkg));
            errors.addAll(utils.getErrors(pkg));
            annotationTypes.addAll(utils.getAnnotationTypes(pkg));
        }
    }
    addClassKindListing(interfaces, contents.interfaces, contentTree);
    addClassKindListing(classes, contents.classes, contentTree);
    addClassKindListing(enums, contents.enums, contentTree);
    addClassKindListing(exceptions, contents.exceptions, contentTree);
    addClassKindListing(errors, contents.errors, contentTree);
    addClassKindListing(annotationTypes, contents.annotationTypes, contentTree);
}
 
Example 2
Source File: ModuleTestBase.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
Set<Element> getAllSelectedElements(DocletEnvironment docenv) {
    Set<Element> result = new TreeSet<Element>((Element e1, Element e2) -> {
        // some grouping by kind preferred
        int rc = e1.getKind().compareTo(e2.getKind());
        if (rc != 0) return rc;
        rc = e1.toString().compareTo(e2.toString());
        if (rc != 0) return rc;
        return Integer.compare(e1.hashCode(), e2.hashCode());
    });
    Set<? extends Element> elements = docenv.getIncludedElements();
    for (ModuleElement me : ElementFilter.modulesIn(elements)) {
        addEnclosedElements(docenv, result, me);
    }
    for (PackageElement pe : ElementFilter.packagesIn(elements)) {
        ModuleElement mdle = docenv.getElementUtils().getModuleOf(pe);
        if (mdle != null)
            addEnclosedElements(docenv, result, mdle);
        addEnclosedElements(docenv, result, pe);
    }
    for (TypeElement te : ElementFilter.typesIn(elements)) {
        addEnclosedElements(docenv, result, te);
    }
    return result;
}
 
Example 3
Source File: ElementsTable.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private Set<PackageElement> computeModulePackages() throws ToolException {
    AccessKind accessValue = accessFilter.getAccessValue(ElementKind.PACKAGE);
    final boolean documentAllModulePackages = (accessValue == AccessKind.PACKAGE ||
            accessValue == AccessKind.PRIVATE);

    accessValue = accessFilter.getAccessValue(ElementKind.MODULE);
    final boolean moduleDetailedMode = (accessValue == AccessKind.PACKAGE ||
            accessValue == AccessKind.PRIVATE);
    Set<PackageElement> expandedModulePackages = new LinkedHashSet<>();

    for (ModuleElement mdle : specifiedModuleElements) {
        if (documentAllModulePackages) { // include all packages
            List<PackageElement> packages = ElementFilter.packagesIn(mdle.getEnclosedElements());
            expandedModulePackages.addAll(packages);
            expandedModulePackages.addAll(getAllModulePackages(mdle));
        } else { // selectively include required packages
            List<ExportsDirective> exports = ElementFilter.exportsIn(mdle.getDirectives());
            for (ExportsDirective export : exports) {
                // add if fully exported or add qualified exports only if desired
                if (export.getTargetModules() == null
                        || documentAllModulePackages || moduleDetailedMode) {
                    expandedModulePackages.add(export.getPackage());
                }
            }
        }

        // add all packages specified on the command line
        // belonging to this module
        if (!cmdLinePackages.isEmpty()) {
            for (ModulePackage modpkg : cmdLinePackages) {
                PackageElement pkg = toolEnv.elements.getPackageElement(mdle,
                        modpkg.packageName);
                if (pkg != null) {
                    expandedModulePackages.add(pkg);
                }
            }
        }
    }
    return expandedModulePackages;
}