Example usage for org.eclipse.jdt.core.search SearchEngine searchAllTypeNames

List of usage examples for org.eclipse.jdt.core.search SearchEngine searchAllTypeNames

Introduction

In this page you can find the example usage for org.eclipse.jdt.core.search SearchEngine searchAllTypeNames.

Prototype

public void searchAllTypeNames(final char[][] qualifications, final char[][] typeNames, IJavaSearchScope scope,
        final TypeNameMatchRequestor nameMatchRequestor, int waitingPolicy, IProgressMonitor progressMonitor)
        throws JavaModelException 

Source Link

Document

Searches for all top-level types and member types in the given scope matching any of the given qualifications and type names in a case sensitive way.

Usage

From source file:de.jcup.egradle.eclipse.gradleeditor.jdt.JDTDataAccess.java

License:Apache License

/**
 * Scan for package names/*from  w  w w . ja va  2  s. c  o  m*/
 * 
 * @param type
 * @param scope
 * @param packageNames
 *            - can be <code>null</code>
 * @return list with java types
 */
public List<String> scanForJavaType(String type, IJavaSearchScope scope, String... packageNames) {
    SearchEngine engine = new SearchEngine();
    List<String> foundList = new ArrayList<>();
    try {
        // int packageFlags=0;
        // String packPattern = "org.gradle.api";
        // String typePattern = "Project";
        // int matchRule;
        // int elementKind;
        // IJavaSearchScope searchScope;
        // TypeNameRequestor requestor;
        // IProgressMonitor progressMonitor;
        // engine.searchAllTypeNames((packPattern == null) ? null :
        // packPattern.toCharArray(),
        // packageFlags,
        // typePattern.toCharArray(), matchRule,
        // IJavaElement.TYPE, searchScope, requestor, 3,
        // progressMonitor);

        List<char[]> groovyAutomaticImports = new ArrayList<>();
        if ("BigDecimal".equals(type) || "BigInteger".equals(type)) {
            addImport(groovyAutomaticImports, "java.math");
        } else {
            addImport(groovyAutomaticImports, "java.lang");
            addImport(groovyAutomaticImports, "java.util");
            addImport(groovyAutomaticImports, "java.net");
            addImport(groovyAutomaticImports, "java.io");
            if (packageNames != null && packageNames.length > 0) {
                for (String packageName : packageNames) {
                    if (packageName != null && !packageName.isEmpty()) {
                        addImport(groovyAutomaticImports, packageName);
                    }
                }
            }
        }
        char[][] qualifications = new char[groovyAutomaticImports.size()][];
        for (int i = 0; i < groovyAutomaticImports.size(); i++) {
            qualifications[i] = groovyAutomaticImports.get(i);
        }

        char[][] typeNames = new char[1][];
        typeNames[0] = type.toCharArray();
        TypeNameRequestor nameRequestor = new TypeNameRequestor() {

            @Override
            public void acceptType(int modifiers, char[] packageName, char[] simpleTypeName,
                    char[][] enclosingTypeNames, String path) {
                String simpleName = new String(simpleTypeName);
                String simplePackageName = new String(packageName);
                foundList.add(simplePackageName + "." + simpleName);
            }
        };

        int policiy = IJavaSearchConstants.FORCE_IMMEDIATE_SEARCH;
        IProgressMonitor progressMonitor = new NullProgressMonitor();

        engine.searchAllTypeNames(qualifications, typeNames, scope, nameRequestor, policiy, progressMonitor);

    } catch (JavaModelException e) {
        EGradleUtil.log(e);
        ;
    }
    return foundList;

}

From source file:org.eclipse.che.plugin.jdb.server.utils.JavaDebuggerUtils.java

License:Open Source License

private List<IType> findTypeByFqn(char[][] packages, char[][] names, IJavaSearchScope scope)
        throws JavaModelException {
    List<IType> result = new ArrayList<>();

    SearchEngine searchEngine = new SearchEngine();
    searchEngine.searchAllTypeNames(packages, names, scope, new TypeNameMatchRequestor() {
        @Override/*  w w  w.j  a  v a2 s .  co  m*/
        public void acceptTypeNameMatch(TypeNameMatch typeNameMatch) {
            result.add(typeNameMatch.getType());
        }
    }, IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, new NullProgressMonitor());
    return result;
}

From source file:org.emftext.commons.jdt.resolve.JDTClassifierResolver.java

License:Open Source License

/**
 * Returns a list of all Java classifiers that are available in the
 * classpath of the given project within the given package. If
 * <code>packageName</code> is null, all classifiers in the project are
 * returned./*  w  w w  . j a va  2s.com*/
 */
public List<JDTJavaClassifier> getAllClassifiersForPackageInClassPath(String packageName,
        IJavaProject project) {

    List<JDTJavaClassifier> classes = new ArrayList<JDTJavaClassifier>();
    try {
        SearchEngine searchEngine = new SearchEngine();
        ClassifierVisitor visitor = new ClassifierVisitor(project);

        // prepare search parameters
        char[][] packages = null;
        if (packageName != null) {
            packages = new char[][] { packageName.toCharArray() };
        }
        char[][] typeNames = null;
        IJavaProject[] projects = new IJavaProject[] { project };
        IJavaSearchScope searchScope = SearchEngine.createJavaSearchScope(projects);
        int waitingPolicy = IJavaSearchConstants.FORCE_IMMEDIATE_SEARCH;
        IProgressMonitor progessMonitor = null;

        // perform search
        searchEngine.searchAllTypeNames(packages, typeNames, searchScope, visitor, waitingPolicy,
                progessMonitor);

        classes = visitor.getClassifiersInClasspath();
    } catch (JavaModelException e) {
        logWarning("Search for Java classifiers failed.", e);
    }
    return classes;
}