Java Code Examples for javax.lang.model.element.ModuleElement#RequiresDirective
The following examples show how to use
javax.lang.model.element.ModuleElement#RequiresDirective .
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: ModuleClassPaths.java From netbeans with Apache License 2.0 | 6 votes |
private static boolean dependsOnUnnamed( @NonNull final ModuleElement module, final boolean transitive, final boolean topLevel, final Set<ModuleElement> seen) { if (module.isUnnamed()) { return true; } if (seen.add(module)) { for (ModuleElement.Directive d : module.getDirectives()) { if (d.getKind() == ModuleElement.DirectiveKind.REQUIRES) { final ModuleElement.RequiresDirective rd = (ModuleElement.RequiresDirective) d; if (topLevel || (transitive && rd.isTransitive())) { if (dependsOnUnnamed(rd.getDependency(), transitive, false, seen)) { return true; } } } } } return false; }
Example 2
Source File: ModuleClassPathsTest.java From netbeans with Apache License 2.0 | 6 votes |
private static void collectDeps( @NullAllowed final ModuleElement me, @NonNull final Collection<? super String> modNames) { if (me != null) { final String mn = me.getQualifiedName().toString(); if (!modNames.contains(mn)) { modNames.add(mn); for (ModuleElement.Directive d : me.getDirectives()) { if (d.getKind() == ModuleElement.DirectiveKind.REQUIRES) { final ModuleElement.RequiresDirective rd = (ModuleElement.RequiresDirective)d; if (rd.isTransitive()|| isMandated(rd)) { collectDeps(rd.getDependency(), modNames); } } } } } }
Example 3
Source File: ElementScanningTask.java From netbeans with Apache License 2.0 | 6 votes |
/** * Tests if the directive is important (neither synthetic nor mandated). * Hack of missing javac API for testing synthetic directives */ private static boolean isImportant(@NonNull final ModuleElement.Directive directive) { if (directive instanceof ModuleElement.RequiresDirective) { try { final Set<?> flags = (Set) directive.getClass().getField("flags").get(directive); //NOI18N int expectedSize = 0; if (((ModuleElement.RequiresDirective)directive).isStatic()) expectedSize++; if (((ModuleElement.RequiresDirective)directive).isTransitive()) expectedSize++; return flags.size() == expectedSize; } catch (ReflectiveOperationException e) { throw new IllegalStateException(e); } } else { return true; } }
Example 4
Source File: CodeGenerator.java From netbeans with Apache License 2.0 | 5 votes |
@Override public Tree visitModule(ModuleElement e, Void p) { ModifiersTree mods = make.Modifiers(e.getModifiers()); ModuleTree.ModuleKind kind = wc.getElementUtilities().isOpen(e) ? ModuleTree.ModuleKind.OPEN : ModuleTree.ModuleKind.STRONG; List<DirectiveTree> directives = new LinkedList<>(); for (ModuleElement.Directive directive : e.getDirectives()) { switch(directive.getKind()) { case EXPORTS: ModuleElement.ExportsDirective expDirective = (ModuleElement.ExportsDirective)directive; directives.add(make.Exports(make.QualIdent(expDirective.getPackage()), constructModuleList(expDirective.getTargetModules()))); break; case OPENS: ModuleElement.OpensDirective opensDirective = (ModuleElement.OpensDirective)directive; directives.add(make.Opens(make.QualIdent(opensDirective.getPackage()), constructModuleList(opensDirective.getTargetModules()))); break; case PROVIDES: ModuleElement.ProvidesDirective provDirective = (ModuleElement.ProvidesDirective)directive; directives.add(make.Provides(make.QualIdent(provDirective.getService()), constructTypeList(provDirective.getImplementations()))); break; case REQUIRES: ModuleElement.RequiresDirective reqDirective = (ModuleElement.RequiresDirective)directive; directives.add(make.Requires(reqDirective.isTransitive(), reqDirective.isStatic(), make.QualIdent(reqDirective.getDependency().getQualifiedName().toString()))); break; case USES: ModuleElement.UsesDirective usesDirective = (ModuleElement.UsesDirective)directive; directives.add(make.Uses(make.QualIdent(usesDirective.getService()))); break; } } return addDeprecated(e, make.Module(mods, kind, make.QualIdent(e.getQualifiedName().toString()), directives)); }
Example 5
Source File: TraverseProc.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
Set<ModuleElement> findModules0(ModuleElement m, Set<ModuleElement> set, int nesting) { set.add(m); for (ModuleElement.Directive dir : m.getDirectives()) { if (dir.getKind() == ModuleElement.DirectiveKind.REQUIRES) { ModuleElement.RequiresDirective req = (ModuleElement.RequiresDirective)dir; findModules0(req.getDependency(), set, nesting + 1); } } return set; }
Example 6
Source File: ModuleClassPaths.java From netbeans with Apache License 2.0 | 4 votes |
private static boolean isMandated(@NonNull final ModuleElement.RequiresDirective rd) { return Optional.ofNullable(rd.getDependency()) .map((me) -> MOD_JAVA_BASE.equals(me.getQualifiedName().toString())) .orElse(Boolean.FALSE); }
Example 7
Source File: ModuleClassPathsTest.java From netbeans with Apache License 2.0 | 4 votes |
private static boolean isMandated(ModuleElement.RequiresDirective rd) { return Optional.ofNullable(rd.getDependency()) .map((me) -> me.getQualifiedName().toString()) .map((mn) -> "java.base".equals(mn)) .orElse(Boolean.FALSE); }
Example 8
Source File: DependencyCalculator.java From netbeans with Apache License 2.0 | 4 votes |
public Dependency(ModuleNode node, ModuleElement.RequiresDirective reqD, boolean unseen) { this.node = node; this.unseen = unseen; this.reqD = reqD; }