Example usage for org.eclipse.jdt.core.search IJavaSearchConstants FORCE_IMMEDIATE_SEARCH

List of usage examples for org.eclipse.jdt.core.search IJavaSearchConstants FORCE_IMMEDIATE_SEARCH

Introduction

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

Prototype

int FORCE_IMMEDIATE_SEARCH

To view the source code for org.eclipse.jdt.core.search IJavaSearchConstants FORCE_IMMEDIATE_SEARCH.

Click Source Link

Document

The search operation starts immediately, even if the underlying indexer has not finished indexing the workspace.

Usage

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

License:Apache License

/**
 * Scan for package names//w w  w. j a  v  a 2s  .co 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.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./*from  w ww  .  ja v  a  2 s . c  o m*/
 */
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;
}

From source file:org.jboss.tools.batch.ui.internal.contentassist.BatchJobCompletionProposalComputer.java

License:Open Source License

private void addClassValueProposals(final ContentAssistRequest contentAssistRequest,
        CompletionProposalInvocationContext context, Element current, String matchString, final int begin,
        final int length) throws JavaModelException {
    if (matchString.length() > 0) {
        int lastDot = matchString.lastIndexOf('.');
        String packageNameString = null;
        String classNameString = matchString;
        int packagePatern = SearchPattern.R_PREFIX_MATCH;
        if (lastDot > 0) {
            if (matchString.length() > lastDot + 1 && Character.isUpperCase(matchString.charAt(lastDot + 1))) {
                classNameString = matchString.substring(lastDot + 1);
                packageNameString = matchString.substring(0, lastDot);
                packagePatern = SearchPattern.R_EXACT_MATCH;
            } else {
                classNameString = null;/*from  www  .j  ava2s. co  m*/
                packageNameString = matchString;
            }
        }
        char[] packageName = packageNameString != null ? packageNameString.toCharArray() : null;
        char[] className = classNameString != null ? classNameString.toCharArray() : null;

        IProject project = bp.getProject();
        IJavaProject jp = JavaCore.create(project);
        IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] { jp });
        SearchEngine engine = new SearchEngine();
        engine.searchAllTypeNames(packageName, packagePatern, className, SearchPattern.R_PREFIX_MATCH,
                IJavaSearchConstants.CLASS, scope, new TypeNameRequestor() {
                    @Override
                    public void acceptType(int modifiers, char[] packageName, char[] simpleTypeName,
                            char[][] enclosingTypeNames, String path) {

                        StringBuffer fullName = new StringBuffer();
                        fullName.append(packageName).append('.').append(simpleTypeName);
                        String fn = fullName.toString();
                        CustomCompletionProposal proposal = new CustomCompletionProposal(fn, begin, length,
                                fn.length(), CommonUIImages.getImage(JavaPluginImages.DESC_OBJS_CLASS),
                                new String(simpleTypeName), fn, null, fn, TextProposal.R_XML_ATTRIBUTE_VALUE,
                                true);
                        contentAssistRequest.addProposal(proposal);
                    }
                }, IJavaSearchConstants.FORCE_IMMEDIATE_SEARCH, monitor);
    }
}

From source file:org.springsource.ide.eclipse.commons.frameworks.core.async.FluxConstructorSearch.java

License:Open Source License

public Flux<JavaConstructorHint> search() {
    validate();/*from  w w  w. j  a  v  a2s. c  o m*/
    if (scope == null) {
        return Flux.empty();
    }
    final FluxSearchRequestor requestor = new FluxSearchRequestor();
    Job job = new Job("Search for " + pattern) {
        @Override
        protected IStatus run(IProgressMonitor monitor) {
            long start = System.currentTimeMillis();
            debug("Starting search for '" + pattern + "'");
            try {
                engine.searchAllConstructorDeclarations(null, pattern.toCharArray(), patternRule, scope,
                        new IRestrictedAccessConstructorRequestor() {

                            @Override
                            public void acceptConstructor(int modifiers, char[] simpleTypeName,
                                    int parameterCount, char[] signature, char[][] parameterTypes,
                                    char[][] parameterNames, int typeModifiers, char[] packageName,
                                    int extraFlags, String path, AccessRestriction access) {
                                requestor.acceptSearchMatch(JavaConstructorHint.asHint(modifiers,
                                        simpleTypeName, parameterCount, signature, parameterTypes,
                                        parameterNames, typeModifiers, packageName, extraFlags, path, access));
                            }

                        }, IJavaSearchConstants.FORCE_IMMEDIATE_SEARCH, monitor);
                requestor.done();
            } catch (Exception e) {
                debug("Canceled search for: " + pattern);
                debug("          exception: " + ExceptionUtil.getMessage(e));
                long duration = System.currentTimeMillis() - start;
                debug("          duration: " + duration + " ms");
                requestor.cancel();
            }
            return Status.OK_STATUS;
        }
    };
    job.setSystem(useSystemJob);
    job.setPriority(jobPriority);
    job.schedule();
    return requestor.asFlux();
}