public Kind getKind() { switch (el.getKind()) { case PACKAGE: return Kind.COMPILATION_UNIT;
private TreeDelegate(Position position, KindPath kindPath, FileObject file, ElementHandle element, ElementHandle correspondingEl) { this.kindPath = kindPath; this.position = position; this.file = file; this.enclosingElement = element; this.correspondingEl = correspondingEl; if (kindPath != null) { this.kind = kindPath.kindPath.get(0); } else { if (correspondingEl != null) { ElementKind k = correspondingEl.getKind(); switch (k) { case ANNOTATION_TYPE: kind = Tree.Kind.ANNOTATION_TYPE; break; case CLASS: kind = Tree.Kind.CLASS; break; case ENUM: kind = Tree.Kind.ENUM; break; case INTERFACE: kind = Tree.Kind.INTERFACE; break; case ENUM_CONSTANT: case FIELD: kind = Tree.Kind.VARIABLE; break; case METHOD: case CONSTRUCTOR: kind = Tree.Kind.METHOD; break; default: kind = null; break; } } else { kind = null; } } }
/** * Returns an estimate of a number of classes on given source path (source root) which are * using given type. * @param type the type type to find the usage frequency for. * @return number of classes using the type. */ public int getTypeReferenceCount(@NonNull final ElementHandle<? extends TypeElement> type) { Parameters.notNull("binaryName", type); //NOI18N if (!type.getKind().isClass() && !type.getKind().isInterface() && type.getKind() != ElementKind.OTHER) { throw new IllegalArgumentException(type.toString()); } try { init(); final Integer count = typeFreqs.get(SourceUtils.getJVMSignature(type)[0]); return count == null ? 0 : count; } catch (InterruptedException ie) { return 0; } }
/** * Returns an estimate of a number of classes on given source path (source root) which are * using given package. * @param pkg the package to find the usage frequency for. * @return number of classes using types from given package. */ public int getPackageReferenceCount(@NonNull final ElementHandle<? extends PackageElement> pkg) { Parameters.notNull("pkgName", pkg); //NOI18N if (pkg.getKind() != ElementKind.PACKAGE) { throw new IllegalArgumentException(pkg.toString()); } try { init(); final Integer count = pkgFreqs.get(SourceUtils.getJVMSignature(pkg)[0]); return count == null ? 0 : count; } catch (InterruptedException ie) { return 0; } }
ElementKind kind = cl.getKind(); switch (tag) { case CLASS: {
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; }
/** * Tests if the handle has this same signature as the parameter. * The handles has the same signatures if it is resolved into the same * element in the same {@link javax.tools.JavaCompiler} task, but may be resolved into * the different {@link Element} in the different {@link javax.tools.JavaCompiler} task. * @param element to be checked * @return true if this handle resolves into the same {@link Element} * in the same {@link javax.tools.JavaCompiler} task. */ public boolean signatureEquals (@NonNull final T element) { final ElementKind ek = element.getKind(); final ElementKind thisKind = getKind(); if ((ek != thisKind) && !(thisKind == ElementKind.OTHER && (ek.isClass() || ek.isInterface()))) { return false; } final ElementHandle<T> handle = create (element); return signatureEquals (handle); }
continue; if (!kinds.contains(name.getKind()) && !doNotRemove.contains(name.getQualifiedName())) { removed.put(name.getQualifiedName(), name); continue;
Parameters.notNull("convertor", convertor); //NOI18N final Set<T> result = new HashSet<T> (); final Set<ClassIndexImpl.UsageType> ut = encodeSearchKind(element.getKind(),searchKind); if (!ut.isEmpty()) { try {
return; if (eh.getKind() == ElementKind.CLASS) { LazyTypeCompletionItem item = LazyTypeCompletionItem.create(substitutionOffset, eh, js); addCacheItem(item);
Parameters.notNull("cpInfo", cpInfo); try { boolean pkg = handle.getKind() == ElementKind.PACKAGE; String[] signature = handle.getSignature(); assert signature.length >= 1;
try { final String binaryName = SourceUtils.getJVMSignature(element)[0]; final ElementKind kind = element.getKind(); if (kind == ElementKind.PACKAGE) { IndexManager.priorityAccess(new IndexManager.Action<Void> () {