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

The following examples show how to use javax.lang.model.util.ElementFilter#requiresIn() . 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: ElementsTable.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns the "requires" modules for the target module.
 * @param mdle the target module element
 * @param onlyTransitive true gets all the requires transitive, otherwise
 *                 gets all the non-transitive requires
 *
 * @return a set of modules
 */
private Set<ModuleElement> getModuleRequires(ModuleElement mdle, boolean onlyTransitive) throws ToolException {
    Set<ModuleElement> result = new HashSet<>();
    for (RequiresDirective rd : ElementFilter.requiresIn(mdle.getDirectives())) {
        ModuleElement dep = rd.getDependency();
        if (result.contains(dep))
            continue;
        if (!isMandated(mdle, rd) && onlyTransitive == rd.isTransitive()) {
            if (!haveModuleSources(dep)) {
                messager.printWarning(dep, "main.module_not_found", dep.getSimpleName());
            }
            result.add(dep);
        } else if (isMandated(mdle, rd) && haveModuleSources(dep)) {
            result.add(dep);
        }
    }
    return result;
}
 
Example 2
Source File: AddReadsTest.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) {
    ModuleElement m2Module = processingEnv.getElementUtils().getModuleElement("m2x");
    if (m2Module == null) {
        throw new AssertionError("Cannot find the m2x module!");
    }
    boolean foundM1 = false;
    for (RequiresDirective rd : ElementFilter.requiresIn(m2Module.getDirectives())) {
        foundM1 |= rd.getDependency().getSimpleName().contentEquals("m1x");
    }
    if (!foundM1) {
        throw new AssertionError("Cannot find the dependency on m1x module!");
    }
    return false;
}
 
Example 3
Source File: MutliReleaseModuleInfoTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean process(Set<? extends TypeElement> u, RoundEnvironment r) {
    ModuleElement sm = processingEnv.getElementUtils().getModuleElement("service");
    if (sm == null) {
        throw new AssertionError("Cannot find the service module!");
    }
    boolean foundjd = false;
    for (RequiresDirective rd : ElementFilter.requiresIn(sm.getDirectives())) {
        foundjd |= rd.getDependency().getQualifiedName().contentEquals("java.desktop");
    }
    if (!foundjd) {
        throw new AssertionError("Missing dependency on java desktop module!");
    }
    return false;
}