Java Code Examples for javax.lang.model.element.PackageElement#getEnclosedElements()
The following examples show how to use
javax.lang.model.element.PackageElement#getEnclosedElements() .
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: JavadocCompletionQuery.java From netbeans with Apache License 2.0 | 6 votes |
private void addPackageContent(PackageElement pe, EnumSet<ElementKind> kinds, DeclaredType baseType, Set<? extends Element> toExclude, String prefix, int substitutionOffset, JavadocContext jdctx) { CompilationInfo controller = jdctx.javac; Element srcEl = jdctx.handle.resolve(controller); Elements elements = controller.getElements(); Types types = controller.getTypes(); Trees trees = controller.getTrees(); TreeUtilities tu = controller.getTreeUtilities(); ElementUtilities eu = controller.getElementUtilities(); TreePath docpath = srcEl != null ? trees.getPath(srcEl) : null; Scope scope = docpath != null ? trees.getScope(docpath) : tu.scopeFor(caretOffset); for(Element e : pe.getEnclosedElements()) { if ((e.getKind().isClass() || e.getKind().isInterface()) && (toExclude == null || !toExclude.contains(e))) { String name = e.getSimpleName().toString(); if (Utilities.startsWith(name, prefix) && (Utilities.isShowDeprecatedMembers() || !elements.isDeprecated(e)) && trees.isAccessible(scope, (TypeElement)e) && isOfKindAndType(e.asType(), e, kinds, baseType, scope, trees, types) && !Utilities.isExcluded(eu.getElementName(e, true))) { items.add(JavadocCompletionItem.createTypeItem(jdctx.javac, (TypeElement) e, substitutionOffset, null, elements.isDeprecated(e)/*, isOfSmartType(env, e.asType(), smartTypes)*/)); } } } }
Example 2
Source File: JPAEditorUtil.java From netbeans with Apache License 2.0 | 5 votes |
@Override public TypeElement visitPackage(PackageElement packElem, String binaryName) { for (Element e : packElem.getEnclosedElements()) { if (e.getKind().isClass()) { TypeElement ret = e.accept(this, binaryName); if (ret != null) { return ret; } } } return null; }
Example 3
Source File: JavaUtils.java From netbeans with Apache License 2.0 | 5 votes |
@Override public TypeElement visitPackage(PackageElement packElem, String binaryName) { for(Element e : packElem.getEnclosedElements()) { if(e.getKind().isClass()) { TypeElement ret = e.accept(this, binaryName); if(ret != null) { return ret; } } } return null; }
Example 4
Source File: ImportCompleter.java From netbeans with Apache License 2.0 | 5 votes |
@Override public List<CompletionItem> complete() { if (ctx.getType() == CompletionContext.Type.INSTRUCTION_TARGET || ctx.getType() == CompletionContext.Type.ROOT) { CompletionItem item = completeTarget(); return item != null ? Collections.singletonList(completeTarget()) : null; } results = new ArrayList<CompletionItem>(); Set<String> packages = ctx.getClasspathInfo().getClassIndex().getPackageNames(ctx.getPrefix(), true, EnumSet.of(ClassIndex.SearchScope.SOURCE, ClassIndex.SearchScope.DEPENDENCIES)); if (!"".equals(ctx.getPrefix())) { if (ctx.getPrefix().endsWith("*")) { return null; } if (ctx.getPrefix().endsWith(".")) { PackageElement pel = ctx.getCompilationInfo().getElements().getPackageElement(ctx.getPrefix().substring(0, ctx.getPrefix().length() - 1)); if (pel != null) { List<?> els = pel.getEnclosedElements(); if (!els.isEmpty()) { results.add(new PackageItem(ctx, ctx.getPrefix() + "*")); } } } } for (String s : packages) { // results.add(JavaCompletionItem.createPackageItem(s, ctx.getStartOffset(), true)); results.add(new PackageItem(ctx, s)); } return results; }
Example 5
Source File: ClassCompleter.java From netbeans with Apache License 2.0 | 5 votes |
/** * Loads classes imported by explicit or star import. */ private Set<ElementHandle<TypeElement>> loadImportedClasses() { Set<ElementHandle<TypeElement>> handles = new HashSet<ElementHandle<TypeElement>>(); Collection<ImportDecl> imports = ctx.getModel().getImports(); for (ImportDecl decl : imports) { if (decl.isWildcard()) { if (packagePrefix != null && !CompletionUtils.startsWith(decl.getImportedName(), namePrefix)) { continue; } // import all relevant classes from the package PackageElement pel = ctx.getCompilationInfo().getElements().getPackageElement(decl.getImportedName()); for (Element e : pel.getEnclosedElements()) { TypeElement tel = (TypeElement)e; if (acceptsName(tel.getSimpleName()) && acceptsType(tel)) { handles.add(ElementHandle.create((TypeElement)e)); } } } else if (CompletionUtils.startsWithCamelCase(decl.getImportedName(), namePrefix)) { TypeElement el = ctx.getCompilationInfo().getElements().getTypeElement(decl.getImportedName()); if (el != null && acceptsType(el)) { handles.add(ElementHandle.create(el)); } } } return handles; }
Example 6
Source File: TraverseProc.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
Map<PackageElement, List<TypeElement>> findPublicTypes(Collection<PackageElement> pkgs) { Map<PackageElement, List<TypeElement>> map = new HashMap<>(); for (PackageElement pkg : pkgs) { List<TypeElement> enclosed = new ArrayList<>(); for (Element e : pkg.getEnclosedElements()) { addPublicTypes(enclosed, e); } map.put(pkg, enclosed); } return map; }
Example 7
Source File: ElementStructureTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
@Override public Void visitPackage(PackageElement e, Void p) { List<Element> types = new ArrayList<>(e.getEnclosedElements()); Collections.sort(types, (e1, e2) -> e1.getSimpleName().toString().compareTo(e2.getSimpleName().toString())); for (Element encl : types) { visit(encl, p); } return null; }
Example 8
Source File: APIIsSelfContainedTest.java From netbeans with Apache License 2.0 | 4 votes |
private void verifySelfContainedAPI(PackageElement pel) { for (Element e : pel.getEnclosedElements()) { verifySelfContainedAPI(e, null); } }