Java Code Examples for javax.lang.model.element.ModuleElement#Directive
The following examples show how to use
javax.lang.model.element.ModuleElement#Directive .
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: OpenAction.java From netbeans with Apache License 2.0 | 6 votes |
@NonNull public static Openable openable( @NonNull final ModuleElement module, @NonNull final ModuleElement.Directive directive, @NonNull final ClasspathInfo cpInfo) { final String displayName = module.getQualifiedName().toString(); final ElementHandle<ModuleElement> moduleHandle = ElementHandle.create(module); final Object[] directiveHandle = createDirectiveHandle(directive); return () -> { final FileObject source = SourceUtils.getFile(moduleHandle, cpInfo); if (source == null) { noSource(displayName); } TreePathHandle path = resolveDirectiveHandle(source, directiveHandle); if (path == null) { noSource(displayName); } if (!ElementOpen.open(source, path)) { noSource(displayName); } }; }
Example 4
Source File: OpenAction.java From netbeans with Apache License 2.0 | 6 votes |
@NonNull private static Object[] createDirectiveHandle(@NonNull ModuleElement.Directive dir) { switch (dir.getKind()) { case EXPORTS: return new Object[] {dir.getKind(), ((ModuleElement.ExportsDirective)dir).getPackage().getQualifiedName().toString()}; case OPENS: return new Object[] {dir.getKind(), ((ModuleElement.OpensDirective)dir).getPackage().getQualifiedName().toString()}; case REQUIRES: return new Object[] {dir.getKind(), ((ModuleElement.RequiresDirective)dir).getDependency().getQualifiedName().toString()}; case USES: return new Object[] {dir.getKind(), ((ModuleElement.UsesDirective)dir).getService().getQualifiedName().toString()}; case PROVIDES: return new Object[] {dir.getKind(), ((ModuleElement.ProvidesDirective)dir).getService().getQualifiedName().toString()}; default: throw new IllegalArgumentException(String.valueOf(dir)); } }
Example 5
Source File: ElementScanningTask.java From netbeans with Apache License 2.0 | 6 votes |
@Override public Context visitModule(ModuleTree node, Void p) { final ModuleElement module = (ModuleElement) trees.getElement(getCurrentPath()); if (module != null) { ctx.pos.put(module, this.sourcePositions.getStartPosition(cu, node)); final List<? extends ModuleElement.Directive> de = module.getDirectives(); final List<? extends DirectiveTree> dt = node.getDirectives(); for (int i = 0, j = 0; i < de.size() ; i++) { if (isImportant(de.get(i))) { ctx.directives.put(de.get(i), dt.get(j)); ctx.pos.put(de.get(i), this.sourcePositions.getStartPosition(cu, dt.get(j))); j += 1; } } } return super.visitModule(node, p); }
Example 6
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 7
Source File: JavacElements.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override @DefinedBy(Api.LANGUAGE_MODEL) public Origin getOrigin(ModuleElement m, ModuleElement.Directive directive) { switch (directive.getKind()) { case REQUIRES: RequiresDirective rd = cast(RequiresDirective.class, directive); if (rd.flags.contains(RequiresFlag.MANDATED)) return Origin.MANDATED; if (rd.flags.contains(RequiresFlag.SYNTHETIC)) return Origin.SYNTHETIC; return Origin.EXPLICIT; case EXPORTS: ExportsDirective ed = cast(ExportsDirective.class, directive); if (ed.flags.contains(ExportsFlag.MANDATED)) return Origin.MANDATED; if (ed.flags.contains(ExportsFlag.SYNTHETIC)) return Origin.SYNTHETIC; return Origin.EXPLICIT; case OPENS: OpensDirective od = cast(OpensDirective.class, directive); if (od.flags.contains(OpensFlag.MANDATED)) return Origin.MANDATED; if (od.flags.contains(OpensFlag.SYNTHETIC)) return Origin.SYNTHETIC; return Origin.EXPLICIT; } return Origin.EXPLICIT; }
Example 8
Source File: ElementScanningTask.java From netbeans with Apache License 2.0 | 5 votes |
private void addModuleDirectives( @NonNull final ModuleElement module, @NonNull final Description target, @NonNull final Context ctx, @NonNull final CompilationInfo info, final boolean fqn) { target.subs = new HashSet<>(); for (ModuleElement.Directive dir : module.getDirectives()) { if (isImportant(dir)) { final ClasspathInfo cpInfo = info.getClasspathInfo(); final Description dirDesc; if (ctx.isSource) { final DirectiveTree dt = ctx.getDirectiveTree(dir); final TreePathHandle treePathHandle = TreePathHandle.create(TreePath.getPath(info.getCompilationUnit(), dt), info); final String name = getDirectiveName(dir, fqn); dirDesc = Description.directive( ui, name, treePathHandle, dir.getKind(), cpInfo, ctx.getStartPosition(dir), OpenAction.openable(treePathHandle, ctx.getFileObject(), name)); } else { dirDesc = Description.directive( ui, getDirectiveName(dir, fqn), dir.getKind(), cpInfo, OpenAction.openable(module, dir, cpInfo)); } dirDesc.htmlHeader = createHtmlHeader(info, dir, fqn); target.subs.add(dirDesc); } } }
Example 9
Source File: ElementScanningTask.java From netbeans with Apache License 2.0 | 5 votes |
@NonNull private static String getDirectiveName( @NonNull final ModuleElement.Directive directive, final boolean fqn) { final StringBuilder sb = new StringBuilder(); switch (directive.getKind()) { case EXPORTS: sb.append(((ModuleElement.ExportsDirective)directive).getPackage().getQualifiedName()); break; case OPENS: sb.append(((ModuleElement.OpensDirective)directive).getPackage().getQualifiedName()); break; case REQUIRES: sb.append(((ModuleElement.RequiresDirective)directive).getDependency().getQualifiedName()); break; case USES: final TypeElement service = ((ModuleElement.UsesDirective)directive).getService(); sb.append(fqn ? service.getQualifiedName() : service.getSimpleName()); break; case PROVIDES: final TypeElement impl = ((ModuleElement.ProvidesDirective)directive).getService(); sb.append(fqn ? impl.getQualifiedName() : impl.getSimpleName()); break; default: throw new IllegalArgumentException(directive.toString()); } return sb.toString(); }
Example 10
Source File: ElementScanningTask.java From netbeans with Apache License 2.0 | 5 votes |
@NonNull private String createHtmlHeader( @NonNull final CompilationInfo info, @NonNull final ModuleElement.Directive directive, final boolean fqn) { final StringBuilder sb = new StringBuilder(); switch (directive.getKind()) { case REQUIRES: sb.append(((ModuleElement.RequiresDirective)directive).getDependency().getQualifiedName()); break; case EXPORTS: sb.append(((ModuleElement.ExportsDirective)directive).getPackage().getQualifiedName()); break; case OPENS: sb.append(((ModuleElement.OpensDirective)directive).getPackage().getQualifiedName()); break; case USES: final TypeElement service = ((ModuleElement.UsesDirective)directive).getService(); sb.append((fqn ? service.getQualifiedName() : service.getSimpleName())); break; case PROVIDES: final TypeElement intf = ((ModuleElement.ProvidesDirective)directive).getService(); sb.append(fqn ? intf.getQualifiedName() : intf.getSimpleName()); break; default: throw new IllegalArgumentException(directive.toString()); } return sb.toString(); }
Example 11
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 12
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 13
Source File: TraverseProc.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
Set<PackageElement> findPackages(Collection<ModuleElement> mods) { Set<PackageElement> set = new HashSet<>(); for (ModuleElement m : mods) { for (ModuleElement.Directive dir : m.getDirectives()) { if (dir.getKind() == ModuleElement.DirectiveKind.EXPORTS) { //XXX ModuleElement.ExportsDirective exp = (ModuleElement.ExportsDirective)dir; if (exp.getTargetModules() == null) { set.add(exp.getPackage()); } } } } return set; }
Example 14
Source File: ElementScanningTask.java From netbeans with Apache License 2.0 | 4 votes |
long getStartPosition(@NonNull final ModuleElement.Directive directive) { final Long res = pos.get(directive); return res == null ? -1: res; }
Example 15
Source File: ElementScanningTask.java From netbeans with Apache License 2.0 | 4 votes |
@CheckForNull DirectiveTree getDirectiveTree(@NonNull final ModuleElement.Directive directive) { return directives.get(directive); }