Refine search
public Set<ElementHandle<TypeElement>> query(ClasspathInfo classpathInfo, String textForQuery, NameKind nameKind, Set<SearchScope> searchScopes) { return classpathInfo.getClassIndex().getDeclaredTypes(textForQuery, nameKind, searchScopes); }
@Override public void run(CompilationController controller) throws Exception { Elements elems = controller.getElements(); TypeElement fxAppElement = elems.getTypeElement(classType); ElementHandle<TypeElement> appHandle = ElementHandle.create(fxAppElement); Set<ElementHandle<TypeElement>> appHandles = classIndex.getElements(appHandle, kinds, scopes); for (ElementHandle<TypeElement> elemHandle : appHandles) { appClassNames.add(elemHandle.getQualifiedName()); } } @Override
protected final boolean isValidPackage(ClasspathInfo pathInfo, String pkg) { assert pathInfo != null : "ClasspathInfo can not be null"; // the following statement gives us all the packages *starting* with the // first parameter. We have to check for exact matches ourselves. See # 142372 Set<String> pkgSet = pathInfo.getClassIndex().getPackageNames(pkg, true, EnumSet.allOf(ClassIndex.SearchScope.class)); if (pkgSet.size() > 0) { LOG.log(Level.FINEST, "Packages with prefix : {0}", pkg); LOG.log(Level.FINEST, " found : {0}", pkgSet); for (String singlePkg : pkgSet) { if (singlePkg.equals(pkg)){ LOG.log(Level.FINEST, "Exact match found."); return true; } } return false; } else { return false; } }
private static boolean containsAnnotatedJsfResource(CompilationController parameter) { if (jsfResourcesElementHandles == null) { loadJsfResourcesElementsHandles(parameter); } ClassIndex classIndex = parameter.getClasspathInfo().getClassIndex(); for (ElementHandle jsfResourceElementHandle : jsfResourcesElementHandles) { Set<ElementHandle<TypeElement>> elements = classIndex.getElements( jsfResourceElementHandle, EnumSet.of(ClassIndex.SearchKind.TYPE_REFERENCES), EnumSet.of(ClassIndex.SearchScope.SOURCE)); for (ElementHandle<TypeElement> handle : elements) { TypeElement element = handle.resolve(parameter); if (element != null) { List<? extends AnnotationMirror> annotationMirrors = element.getAnnotationMirrors(); for (AnnotationMirror annotationMirror : annotationMirrors) { if (ElementHandle.create(annotationMirror.getAnnotationType().asElement()) .equals(jsfResourceElementHandle)) { return true; } } } } } return false; }
: subwordsPattern != null ? ClassIndex.NameKind.REGEXP : Utilities.isCaseSensitive() ? ClassIndex.NameKind.PREFIX : ClassIndex.NameKind.CASE_INSENSITIVE_PREFIX; for (ElementHandle<TypeElement> handle : controller.getClasspathInfo().getClassIndex().getDeclaredTypes(subwordsPattern != null ? subwordsPattern : prefix, kind, EnumSet.allOf(ClassIndex.SearchScope.class))) { TypeElement te = handle.resolve(controller); if (te != null && trees.isAccessible(scope, te) && types.isSubtype(types.getDeclaredType(te), baseType)) { subtypes.add(types.getDeclaredType(te)); LinkedList<DeclaredType> bases = new LinkedList<>(); bases.add(baseType); ClassIndex index = controller.getClasspathInfo().getClassIndex(); while (!bases.isEmpty()) { DeclaredType head = bases.remove(); boolean isRaw = !tas.iterator().hasNext(); subtypes: for (ElementHandle<TypeElement> eh : index.getElements(ElementHandle.create(elem), EnumSet.of(ClassIndex.SearchKind.IMPLEMENTORS), EnumSet.allOf(ClassIndex.SearchScope.class))) { TypeElement e = eh.resolve(controller); if (e != null) { if (trees.isAccessible(scope, e)) { Logger.getLogger("global").log(Level.FINE, String.format("Cannot resolve: %s on bootpath: %s classpath: %s sourcepath: %s\n", eh.toString(), controller.getClasspathInfo().getClassPath(ClasspathInfo.PathKind.BOOT), controller.getClasspathInfo().getClassPath(ClasspathInfo.PathKind.COMPILE), controller.getClasspathInfo().getClassPath(ClasspathInfo.PathKind.SOURCE)));
case EXTENDS: case SUPER: addTypes(env, EnumSet.of(CLASS, INTERFACE, ENUM, ANNOTATION_TYPE, TYPE_PARAMETER), null); break; boolean insideNew = false; if (TreeUtilities.CLASS_TREE_KINDS.contains(parent.getKind()) && ((ClassTree) parent).getExtendsClause() == fa) { kinds = EnumSet.of(CLASS); env.afterExtends(); } else if (TreeUtilities.CLASS_TREE_KINDS.contains(parent.getKind()) && ((ClassTree) parent).getImplementsClause().contains(fa)) { kinds = EnumSet.of(INTERFACE); } else if (parent.getKind() == Tree.Kind.IMPORT) { inImport = true; if (results.isEmpty() && ((PackageElement) el).getQualifiedName() == el.getSimpleName()) { ClassIndex ci = controller.getClasspathInfo().getClassIndex(); if (el.getEnclosedElements().isEmpty() && ci.getPackageNames(el.getSimpleName() + ".", true, EnumSet.allOf(ClassIndex.SearchScope.class)).isEmpty()) { Trees trees = controller.getTrees(); Scope scope = env.getScope(); for (ElementHandle<TypeElement> teHandle : ci.getDeclaredTypes(el.getSimpleName().toString(), ClassIndex.NameKind.SIMPLE_NAME, EnumSet.allOf(ClassIndex.SearchScope.class))) { TypeElement te = teHandle.resolve(controller); if (te != null && trees.isAccessible(scope, te)) { addMembers(env, te.asType(), te, kinds, baseType, inImport, insideNew, true);
excludeHandles = new HashSet<>(excludes.size()); for (Element el : excludes) { excludeHandles.add(ElementHandle.create(el)); if (!kinds.contains(ElementKind.CLASS) && !kinds.contains(ElementKind.INTERFACE)) { Set<ElementHandle<TypeElement>> declaredTypes = controller.getClasspathInfo().getClassIndex().getDeclaredTypes(EMPTY, ClassIndex.NameKind.PREFIX, EnumSet.allOf(ClassIndex.SearchScope.class)); Map<String, ElementHandle<TypeElement>> removed = new HashMap<>(declaredTypes.size()); Set<String> doNotRemove = new HashSet<>(); continue; if (!kinds.contains(name.getKind()) && !doNotRemove.contains(name.getQualifiedName())) { removed.put(name.getQualifiedName(), name); continue; : subwordsPattern != null ? ClassIndex.NameKind.REGEXP : Utilities.isCaseSensitive() ? ClassIndex.NameKind.PREFIX : ClassIndex.NameKind.CASE_INSENSITIVE_PREFIX; Set<ElementHandle<TypeElement>> declaredTypes = controller.getClasspathInfo().getClassIndex().getDeclaredTypes(subwordsPattern != null ? subwordsPattern : prefix != null ? prefix : EMPTY, kind, EnumSet.allOf(ClassIndex.SearchScope.class)); results.ensureCapacity(results.size() + declaredTypes.size()); for (ElementHandle<TypeElement> name : declaredTypes) {
if (ANONYMOUS.matcher(i.next().getBinaryName()).find()) { i.remove(); final ClassIndexImpl ciImpl = ClassIndexManager.getDefault().getUsagesQuery(depRoot, true); if (ciImpl != null) { final ClassIndex index = ClasspathInfo.create(EMPTY, EMPTY, ClassPathSupport.createClassPath(depRoot)).getClassIndex(); final Collection<Map<URL,List<URL>>> depMaps = new ArrayList<Map<URL,List<URL>>>(2); if (sourceDeps != null) { final ElementHandle<TypeElement> e = queue.poll(); if (toHandle.add(e)) queue.addAll(index.getElements(e, EnumSet.of(ClassIndex.SearchKind.IMPLEMENTORS), EnumSet.of(ClassIndex.SearchScope.SOURCE))); files.addAll(index.getResources(e, EnumSet.complementOf(EnumSet.of(ClassIndex.SearchKind.IMPLEMENTORS)), EnumSet.of(ClassIndex.SearchScope.SOURCE)));
return Collections.emptyMap (); final SourceGroup sourceGroup = MidpProjectSupport.getSourceGroup (project); final Set<ElementHandle<TypeElement>> allHandles = info.getClassIndex ().getDeclaredTypes ("", ClassIndex.NameKind.PREFIX, EnumSet.of (ClassIndex.SearchScope.SOURCE, ClassIndex.SearchScope.DEPENDENCIES)); // NOI18N final Map<String, ComponentDescriptor> registry = resolveRegistryMap (project); final HashMap<String, Item> result = new HashMap<String, Item> ();
private static Set<ImportCandidate> findJavaImportCandidates(FileObject fo, String packageName, String missingClass) { final Set<ImportCandidate> candidates = new HashSet<>(); final ClasspathInfo pathInfo = createClasspathInfo(fo); Set<ElementHandle<TypeElement>> typeNames = pathInfo.getClassIndex().getDeclaredTypes( missingClass, NameKind.SIMPLE_NAME, EnumSet.allOf(ClassIndex.SearchScope.class)); for (ElementHandle<TypeElement> typeName : typeNames) { ElementKind kind = typeName.getKind(); // Skip classes within the same package String pkgName = GroovyUtils.stripClassName(typeName.getQualifiedName()); if (packageName == null && pkgName == null) { // Probably both in default package continue; } if (packageName != null && packageName.equals(pkgName)) { continue; } if (kind == ElementKind.CLASS || kind == ElementKind.INTERFACE || kind == ElementKind.ANNOTATION_TYPE) { candidates.add(createImportCandidate(missingClass, typeName.getQualifiedName(), kind)); } } return candidates; }
TypeElement te = (TypeElement) ((DeclaredType) err).asElement(); if (te.getQualifiedName() == te.getSimpleName()) { ClassIndex ci = controller.getClasspathInfo().getClassIndex(); for (ElementHandle<TypeElement> eh : ci.getDeclaredTypes(te.getSimpleName().toString(), ClassIndex.NameKind.SIMPLE_NAME, EnumSet.allOf(ClassIndex.SearchScope.class))) { te = eh.resolve(controller); if (te != null) { st.add(types.erasure(te.asType()));
public synchronized @NonNull ClassIndex getClassIndex () { if ( usagesQuery == null ) { usagesQuery = new ClassIndex ( this.bootClassPath, this.compileClassPath, this.cachedSrcClassPath); } return usagesQuery; }
private static FileObject getFileObjectFromClassName(Project p, String qualifiedClassName) throws IOException { FileObject root = MiscUtilities.findSourceRoot(p); ClasspathInfo cpInfo = ClasspathInfo.create(root); ClassIndex ci = cpInfo.getClassIndex(); int beginIndex = qualifiedClassName.lastIndexOf('.')+1; String simple = qualifiedClassName.substring(beginIndex); Set<ElementHandle<TypeElement>> handles = ci.getDeclaredTypes( simple, ClassIndex.NameKind.SIMPLE_NAME, Collections.singleton(ClassIndex.SearchScope.SOURCE)); if ( handles == null ){ return null; } for (ElementHandle<TypeElement> handle : handles) { if (qualifiedClassName.equals(handle.getQualifiedName())) { return SourceUtils.getFile(handle, cpInfo); } } return null; }
cc.toPhase(Phase.ELEMENTS_RESOLVED); Set<ElementHandle<TypeElement>> declaredTypes = null; declaredTypes = cc.getClasspathInfo().getClassIndex().getDeclaredTypes(typedPrefix, ClassIndex.NameKind.PREFIX, Collections.singleton(ClassIndex.SearchScope.SOURCE));//to have dependencies: EnumSet.allOf(ClassIndex.SearchScope.class) ElementKind kind = cl.getKind(); switch (tag) { case CLASS: { TypeElement te = cl.resolve(cc); if (isAlternative(te)) { BeansCompletionItem item = BeansCompletionItem.createBeansTagValueItem(substitutionOffset-typedPrefix.length(), cl.getQualifiedName(), te.getSimpleName().toString()); results.add(item);
ClassIndex ci = cc.getClasspathInfo().getClassIndex(); matchingTypes = ci.getDeclaredTypes(typedPrefix, NameKind.CASE_INSENSITIVE_PREFIX, ALL); } else { matchingTypes = ci.getDeclaredTypes(typedPrefix, NameKind.CASE_INSENSITIVE_PREFIX, LOCAL); setAdditionalItems(true); return; if (eh.getKind() == ElementKind.CLASS) { LazyTypeCompletionItem item = LazyTypeCompletionItem.create(substitutionOffset, eh, js); addCacheItem(item);
@Override protected List<PackageNode> getContainedPackages() { ClassIndex index = cpInfo.getClassIndex(); List<PackageNode> nodes = new ArrayList<PackageNode>(); for (String pkgName : index.getPackageNames(getNodeName() + ".", true, scope)) { // NOI18N nodes.add(new JavaPackageNode(cpInfo, pkgName, this, scope)); } return nodes; }
private void addIndexListener() { isIndexListenerAdded = true; helper.getClasspathInfo().getClassIndex().addClassIndexListener( new ClassIndexListener() { @Override public void typesAdded(final TypesEvent event) { setDirty(); } @Override public void typesRemoved(final TypesEvent event) { setDirty(); } @Override public void typesChanged(final TypesEvent event) { setDirty(); } @Override public void rootsAdded(RootsEvent event) { setDirty(); } @Override public void rootsRemoved(RootsEvent event) { setDirty(); } private void setDirty() { isDirty.set(true); } }); }
private void addPackages(ClassIndex ci, String typedPrefix, int substitutionOffset, int queryType) { Set<SearchScope> scope = (queryType == CompletionProvider.COMPLETION_ALL_QUERY_TYPE) ? ALL : LOCAL; Set<String> packages = ci.getPackageNames(typedPrefix, true, scope); for (String pkg : packages) { if (pkg.length() > 0) { SpringXMLConfigCompletionItem item = SpringXMLConfigCompletionItem.createPackageItem(substitutionOffset, pkg, false); addCacheItem(item); } } }
@Override public ClassIndex createClassIndex(ClassPath bootPath, ClassPath classPath, ClassPath sourcePath, boolean supportsChanges) { return new ClassIndex(bootPath, classPath, sourcePath, supportsChanges); } }
.create((TypeElement) typeElement); final Set<ElementHandle<TypeElement>> handles = modelImpl .getHelper().getClasspathInfo().getClassIndex() .getElements( handle, EnumSet.of(SearchKind.IMPLEMENTORS), EnumSet.of(SearchScope.SOURCE, SearchScope.DEPENDENCIES)); if (handles == null) { elementHandle.getQualifiedName()); // NOI18N TypeElement derivedElement = elementHandle.resolve(modelImpl .getHelper().getCompilationController()); if (derivedElement == null) {