Java Code Examples for org.netbeans.api.java.source.ClassIndex#NameKind

The following examples show how to use org.netbeans.api.java.source.ClassIndex#NameKind . 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 vote down vote up
private void addAllTypes(JavadocContext env, EnumSet<ElementKind> kinds, Set<? extends Element> toExclude, String prefix, int substitutionOffset) {
//        String prefix = env.getPrefix();
        CompilationInfo controller = env.javac;
        boolean isCaseSensitive = false;
        ClassIndex.NameKind kind = 
            isCaseSensitive? ClassIndex.NameKind.PREFIX : ClassIndex.NameKind.CASE_INSENSITIVE_PREFIX;
//        ClassIndex.NameKind kind = env.isCamelCasePrefix() ?
//            Utilities.isCaseSensitive() ? ClassIndex.NameKind.CAMEL_CASE : ClassIndex.NameKind.CAMEL_CASE_INSENSITIVE :
//            Utilities.isCaseSensitive() ? ClassIndex.NameKind.PREFIX : ClassIndex.NameKind.CASE_INSENSITIVE_PREFIX;
        Set<ElementHandle<Element>> excludeHandles = null;
        if (toExclude != null) {
            excludeHandles = new HashSet<ElementHandle<Element>>(toExclude.size());
            for (Element el : toExclude) {
                excludeHandles.add(ElementHandle.create(el));
            }
        }
        for(ElementHandle<TypeElement> name : controller.getClasspathInfo().getClassIndex().getDeclaredTypes(prefix, kind, EnumSet.allOf(ClassIndex.SearchScope.class))) {
            if ((excludeHandles == null || !excludeHandles.contains(name)) && !isAnnonInner(name)) {
                items.add(LazyJavaCompletionItem.createTypeItem(name, kinds, substitutionOffset, env.getReferencesCount(), controller.getSnapshot().getSource(), false, false, false, null));
            }
        }
    }
 
Example 2
Source File: ExceptionCompletionProvider.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private List<DeclaredType> fillSubTypes(CompilationController cc, DeclaredType dType) {
    List<DeclaredType> subtypes = new ArrayList<>();
    //Set<? extends SearchScopeType> scope = Collections.singleton(new ClassSearchScopeType(prefix));
    Types types = cc.getTypes();
    if (prefix != null && prefix.length() > 2 && lastPrefixDot < 0) {
        //Trees trees = cc.getTrees();
        ClassIndex.NameKind kind = ClassIndex.NameKind.CASE_INSENSITIVE_PREFIX;
        for (ElementHandle<TypeElement> handle : cpi.getClassIndex().getDeclaredTypes(prefix, kind, EnumSet.allOf(ClassIndex.SearchScope.class))) {
            TypeElement te = handle.resolve(cc);
            if (te != null && /*trees.isAccessible(scope, te) &&*/ types.isSubtype(types.getDeclaredType(te), dType)) {
                subtypes.add(types.getDeclaredType(te));
            }
        }
    } else {
        HashSet<TypeElement> elems = new HashSet<>();
        LinkedList<DeclaredType> bases = new LinkedList<>();
        bases.add(dType);
        ClassIndex index = cpi.getClassIndex();
        while (!bases.isEmpty()) {
            DeclaredType head = bases.remove();
            TypeElement elem = (TypeElement) head.asElement();
            if (!elems.add(elem)) {
                continue;
            }
            if (accept(elem)) {
                subtypes.add(head);
            }
            //List<? extends TypeMirror> tas = head.getTypeArguments();
            //boolean isRaw = !tas.iterator().hasNext();
            for (ElementHandle<TypeElement> eh : index.getElements(ElementHandle.create(elem), EnumSet.of(ClassIndex.SearchKind.IMPLEMENTORS), EnumSet.allOf(ClassIndex.SearchScope.class))) {
                TypeElement e = eh.resolve(cc);
                if (e != null) {
                    DeclaredType dt = types.getDeclaredType(e);
                    bases.add(dt);
                }
            }
        }
    }
    return subtypes;
}
 
Example 3
Source File: DocumentUtil.java    From netbeans with Apache License 2.0 5 votes vote down vote up
static Queries.QueryKind translateQueryKind(final ClassIndex.NameKind kind) {
    switch (kind) {
        case SIMPLE_NAME: return Queries.QueryKind.EXACT;
        case PREFIX: return Queries.QueryKind.PREFIX;
        case CASE_INSENSITIVE_PREFIX: return Queries.QueryKind.CASE_INSENSITIVE_PREFIX;
        case CAMEL_CASE: return Queries.QueryKind.CAMEL_CASE;
        case CAMEL_CASE_INSENSITIVE: return Queries.QueryKind.CASE_INSENSITIVE_CAMEL_CASE;
        case REGEXP: return Queries.QueryKind.REGEXP;
        case CASE_INSENSITIVE_REGEXP: return Queries.QueryKind.CASE_INSENSITIVE_REGEXP;
        default: throw new IllegalArgumentException();
    }
}
 
Example 4
Source File: ClassIndexImpl.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public abstract <T> void getDeclaredElements (
@NonNull String name,
@NonNull ClassIndex.NameKind kind,
@NonNull Set<? extends ClassIndex.SearchScopeType> scope,
@NonNull FieldSelector selector,
@NonNull Convertor<? super Document, T> convertor,
@NonNull Collection<? super T> result) throws IOException, InterruptedException;
 
Example 5
Source File: ClassIndexImpl.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public abstract <T> void getDeclaredElements (
String ident,
ClassIndex.NameKind kind,
Convertor<? super Document, T> convertor,
Map<T,Set<String>> result) throws IOException, InterruptedException;
 
Example 6
Source File: ClassNameList.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public Set<ElementHandle<TypeElement>> query(ClasspathInfo classpathInfo, String textForQuery, ClassIndex.NameKind nameKind, Set<ClassIndex.SearchScope> searchScopes) {
    return classpathInfo.getClassIndex().getDeclaredTypes(textForQuery, nameKind, searchScopes);
}
 
Example 7
Source File: TypeElementFinder.java    From netbeans with Apache License 2.0 2 votes vote down vote up
/**
 * Set the scope of the search on particular classpath. Too expensive queries
 * will affect performance of dialog, consider also using in combination
 * with {@link #query}
 */
Set<ElementHandle<TypeElement>> query(ClasspathInfo classpathInfo, String textForQuery, ClassIndex.NameKind nameKind, Set<ClassIndex.SearchScope> searchScopes);