Search in sources :

Example 1 with TypeNameMatchCollector

use of org.eclipse.jdt.internal.corext.util.TypeNameMatchCollector in project che by eclipse.

the class AddImportsOperation method findAllTypes.

/*
	 * Finds a type by the simple name.
	 */
private TypeNameMatch[] findAllTypes(String simpleTypeName, IJavaSearchScope searchScope, SimpleName nameNode, IProgressMonitor monitor) throws JavaModelException {
    boolean is50OrHigher = JavaModelUtil.is50OrHigher(fCompilationUnit.getJavaProject());
    int typeKinds = SimilarElementsRequestor.ALL_TYPES;
    if (nameNode != null) {
        typeKinds = ASTResolving.getPossibleTypeKinds(nameNode, is50OrHigher);
    }
    ArrayList<TypeNameMatch> typeInfos = new ArrayList<TypeNameMatch>();
    TypeNameMatchCollector requestor = new TypeNameMatchCollector(typeInfos);
    int matchMode = SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE;
    new SearchEngine().searchAllTypeNames(null, matchMode, simpleTypeName.toCharArray(), matchMode, getSearchForConstant(typeKinds), searchScope, requestor, IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, monitor);
    ArrayList<TypeNameMatch> typeRefsFound = new ArrayList<TypeNameMatch>(typeInfos.size());
    for (int i = 0, len = typeInfos.size(); i < len; i++) {
        TypeNameMatch curr = typeInfos.get(i);
        if (curr.getPackageName().length() > 0) {
            // do not suggest imports from the default package
            if (isOfKind(curr, typeKinds, is50OrHigher) && isVisible(curr)) {
                typeRefsFound.add(curr);
            }
        }
    }
    return typeRefsFound.toArray(new TypeNameMatch[typeRefsFound.size()]);
}
Also used : SearchEngine(org.eclipse.jdt.core.search.SearchEngine) TypeNameMatch(org.eclipse.jdt.core.search.TypeNameMatch) ArrayList(java.util.ArrayList) TypeNameMatchCollector(org.eclipse.jdt.internal.corext.util.TypeNameMatchCollector)

Example 2 with TypeNameMatchCollector

use of org.eclipse.jdt.internal.corext.util.TypeNameMatchCollector in project che by eclipse.

the class JavaContext method findAllTypes.

/*
	 * Finds a type by the simple name. From AddImportsOperation
	 */
private TypeNameMatch[] findAllTypes(String simpleTypeName, IJavaSearchScope searchScope, SimpleName nameNode, IProgressMonitor monitor, ICompilationUnit cu) throws JavaModelException {
    boolean is50OrHigher = JavaModelUtil.is50OrHigher(cu.getJavaProject());
    int typeKinds = SimilarElementsRequestor.ALL_TYPES;
    if (nameNode != null) {
        typeKinds = ASTResolving.getPossibleTypeKinds(nameNode, is50OrHigher);
    }
    ArrayList<TypeNameMatch> typeInfos = new ArrayList<TypeNameMatch>();
    TypeNameMatchCollector requestor = new TypeNameMatchCollector(typeInfos);
    new SearchEngine().searchAllTypeNames(null, 0, simpleTypeName.toCharArray(), SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE, getSearchForConstant(typeKinds), searchScope, requestor, IJavaSearchConstants.FORCE_IMMEDIATE_SEARCH, monitor);
    ArrayList<TypeNameMatch> typeRefsFound = new ArrayList<TypeNameMatch>(typeInfos.size());
    for (int i = 0, len = typeInfos.size(); i < len; i++) {
        TypeNameMatch curr = typeInfos.get(i);
        if (curr.getPackageName().length() > 0) {
            // do not suggest imports from the default package
            if (isOfKind(curr, typeKinds, is50OrHigher) && isVisible(curr, cu)) {
                typeRefsFound.add(curr);
            }
        }
    }
    return typeRefsFound.toArray(new TypeNameMatch[typeRefsFound.size()]);
}
Also used : SearchEngine(org.eclipse.jdt.core.search.SearchEngine) TypeNameMatch(org.eclipse.jdt.core.search.TypeNameMatch) ArrayList(java.util.ArrayList) TypeNameMatchCollector(org.eclipse.jdt.internal.corext.util.TypeNameMatchCollector)

Aggregations

ArrayList (java.util.ArrayList)2 SearchEngine (org.eclipse.jdt.core.search.SearchEngine)2 TypeNameMatch (org.eclipse.jdt.core.search.TypeNameMatch)2 TypeNameMatchCollector (org.eclipse.jdt.internal.corext.util.TypeNameMatchCollector)2