Example usage for org.eclipse.jdt.core.search IJavaSearchScope SYSTEM_LIBRARIES

List of usage examples for org.eclipse.jdt.core.search IJavaSearchScope SYSTEM_LIBRARIES

Introduction

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

Prototype

int SYSTEM_LIBRARIES

To view the source code for org.eclipse.jdt.core.search IJavaSearchScope SYSTEM_LIBRARIES.

Click Source Link

Document

Include type constant (bit mask) indicating that system libraries should be considered in the search scope.

Usage

From source file:edu.brown.cs.bubbles.bedrock.BedrockJava.java

License:Open Source License

/********************************************************************************/

void handleFindAll(String proj, String file, int start, int end, boolean defs, boolean refs, boolean impls,
        boolean equiv, boolean exact, boolean system, boolean typeof, boolean ronly, boolean wonly,
        IvyXmlWriter xw) throws BedrockException {
    IJavaProject ijp = getJavaProject(proj);
    IPath fp = new Path(file);

    int limit = 0;
    if (defs && refs)
        limit = IJavaSearchConstants.ALL_OCCURRENCES;
    else if (defs)
        limit = IJavaSearchConstants.DECLARATIONS;
    else if (refs)
        limit = IJavaSearchConstants.REFERENCES;
    int flimit = limit;
    if (ronly)/*from ww w  .  j  av a2s . c  o  m*/
        flimit = IJavaSearchConstants.READ_ACCESSES;
    else if (wonly)
        flimit = IJavaSearchConstants.WRITE_ACCESSES;

    int mrule = -1;
    if (equiv)
        mrule = SearchPattern.R_EQUIVALENT_MATCH;
    else if (exact)
        mrule = SearchPattern.R_EXACT_MATCH;

    SearchPattern pat = null;
    IJavaSearchScope scp = null;

    ICompilationUnit icu = our_plugin.getProjectManager().getCompilationUnit(proj, file);
    if (icu == null)
        throw new BedrockException("Compilation unit not found for " + fp);
    icu = getCompilationElement(icu);

    ICompilationUnit[] working = null;
    FindFilter filter = null;

    IJavaElement cls = null;
    char[] packagename = null;
    char[] typename = null;

    try {
        BedrockPlugin.logD("Getting search scopes");
        IJavaElement[] pelt;
        if (ijp != null)
            pelt = new IJavaElement[] { ijp };
        else
            pelt = getAllProjects();
        working = getWorkingElements(pelt);
        int fg = IJavaSearchScope.SOURCES | IJavaSearchScope.REFERENCED_PROJECTS;
        if (system)
            fg |= IJavaSearchScope.SYSTEM_LIBRARIES | IJavaSearchScope.APPLICATION_LIBRARIES;
        scp = SearchEngine.createJavaSearchScope(pelt, fg);

        BedrockPlugin.logD("Locating item to search for");
        IJavaElement[] elts = icu.codeSelect(start, end - start);

        if (typeof) {
            Set<IJavaElement> nelt = new LinkedHashSet<IJavaElement>();
            for (int i = 0; i < elts.length; ++i) {
                IType typ = null;
                String tnm = null;
                switch (elts[i].getElementType()) {
                case IJavaElement.FIELD:
                    tnm = ((IField) elts[i]).getTypeSignature();
                    break;
                case IJavaElement.LOCAL_VARIABLE:
                    tnm = ((ILocalVariable) elts[i]).getTypeSignature();
                    break;
                case IJavaElement.METHOD:
                    typ = ((IMethod) elts[i]).getDeclaringType();
                    break;
                default:
                    nelt.add(elts[i]);
                    break;
                }
                if (typ != null)
                    nelt.add(typ);
                else if (tnm != null && ijp != null) {
                    IJavaElement elt = ijp.findElement(tnm, null);
                    if (elt != null) {
                        nelt.add(elt);
                        typ = null;
                    } else {
                        while (tnm.startsWith("[")) {
                            String xtnm = tnm.substring(1);
                            if (xtnm == null)
                                break;
                            tnm = xtnm;
                        }
                        int ln = tnm.length();
                        String xtnm = tnm;
                        if (tnm.startsWith("L") && tnm.endsWith(";")) {
                            xtnm = tnm.substring(1, ln - 1);
                        } else if (tnm.startsWith("Q") && tnm.endsWith(";")) {
                            xtnm = tnm.substring(1, ln - 1);
                        }
                        if (xtnm != null)
                            tnm = xtnm;
                        int idx1 = tnm.lastIndexOf(".");
                        if (idx1 > 0) {
                            String pkgnm = tnm.substring(0, idx1);
                            xtnm = tnm.substring(idx1 + 1);
                            if (xtnm != null)
                                tnm = xtnm;
                            pkgnm = pkgnm.replace('$', '.');
                            packagename = pkgnm.toCharArray();
                        }
                        tnm = tnm.replace('$', '.');
                        typename = tnm.toCharArray();
                    }

                    if (typename != null) {
                        BedrockPlugin.logD("Handling type names");
                        FindTypeHandler fth = new FindTypeHandler(ijp);
                        SearchEngine se = new SearchEngine(working);
                        se.searchAllTypeNames(packagename, SearchPattern.R_EXACT_MATCH, typename,
                                SearchPattern.R_EXACT_MATCH, IJavaSearchConstants.TYPE, scp, fth,
                                IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, null);
                        nelt.addAll(fth.getFoundItems());
                    }
                }
            }
            IJavaElement[] nelts = new IJavaElement[nelt.size()];
            elts = nelt.toArray(nelts);
        }

        if (elts.length == 1 && !typeof) {
            xw.begin("SEARCHFOR");
            switch (elts[0].getElementType()) {
            case IJavaElement.FIELD:
                xw.field("TYPE", "Field");
                break;
            case IJavaElement.LOCAL_VARIABLE:
                xw.field("TYPE", "Local");
                break;
            case IJavaElement.METHOD:
                xw.field("TYPE", "Function");
                break;
            case IJavaElement.TYPE:
            case IJavaElement.TYPE_PARAMETER:
                xw.field("TYPE", "Class");
                cls = elts[0];
                break;
            }
            xw.text(elts[0].getElementName());
            xw.end("SEARCHFOR");
        }
        int etyp = -1;
        for (int i = 0; i < elts.length; ++i) {
            SearchPattern sp;
            int xlimit = limit;
            switch (elts[i].getElementType()) {
            case IJavaElement.FIELD:
            case IJavaElement.LOCAL_VARIABLE:
                xlimit = flimit;
                break;
            case IJavaElement.TYPE:
                if (impls)
                    xlimit = IJavaSearchConstants.IMPLEMENTORS;
                break;
            case IJavaElement.METHOD:
                if (impls)
                    xlimit |= IJavaSearchConstants.IGNORE_DECLARING_TYPE;
                break;
            }
            if (mrule < 0)
                sp = SearchPattern.createPattern(elts[i], xlimit);
            else
                sp = SearchPattern.createPattern(elts[i], xlimit, mrule);
            if (pat == null)
                pat = sp;
            else
                pat = SearchPattern.createOrPattern(pat, sp);
            if (etyp < 0)
                etyp = elts[i].getElementType();
        }

        if (etyp == IJavaElement.METHOD) {
            if (impls) {
                if (defs)
                    filter = new ImplementFilter(elts);
            } else if (defs && !refs)
                filter = new ClassFilter(elts);
        }

    } catch (JavaModelException e) {
        BedrockPlugin.logE("SEARCH PROBLEM: " + e);
        e.printStackTrace();
        throw new BedrockException("Can't find anything to search for", e);
    }

    if (pat == null) {
        BedrockPlugin.logW("Nothing to search for");
        return;
    }

    BedrockPlugin.logD("Setting up search");
    SearchEngine se = new SearchEngine(working);
    SearchParticipant[] parts = new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() };
    FindHandler fh = new FindHandler(xw, filter, false);

    BedrockPlugin.logD(
            "BEGIN SEARCH " + pat + " " + parts.length + " " + " " + scp + " :: COPIES: " + working.length);

    try {
        se.search(pat, parts, scp, fh, null);
    } catch (Throwable e) {
        throw new BedrockException("Problem doing find all search for " + pat + ": " + e, e);
    }

    if (cls != null && defs) { // need to add the actual class definition
        BedrockUtil.outputJavaElement(cls, false, xw);
    }
}

From source file:edu.brown.cs.bubbles.bedrock.BedrockJava.java

License:Open Source License

/********************************************************************************/

void handleJavaSearch(String proj, String bid, String patstr, String foritems, boolean defs, boolean refs,
        boolean impls, boolean equiv, boolean exact, boolean system, IvyXmlWriter xw) throws BedrockException {
    IJavaProject ijp = getJavaProject(proj);

    our_plugin.waitForEdits();/*from  w w w .j  a  v  a2 s. co m*/

    int forflags = 0;
    if (foritems == null)
        forflags = IJavaSearchConstants.TYPE;
    else if (foritems.equalsIgnoreCase("CLASS"))
        forflags = IJavaSearchConstants.CLASS;
    else if (foritems.equalsIgnoreCase("INTERFACE"))
        forflags = IJavaSearchConstants.INTERFACE;
    else if (foritems.equalsIgnoreCase("ENUM"))
        forflags = IJavaSearchConstants.ENUM;
    else if (foritems.equalsIgnoreCase("ANNOTATION"))
        forflags = IJavaSearchConstants.ANNOTATION_TYPE;
    else if (foritems.equalsIgnoreCase("CLASS&ENUM"))
        forflags = IJavaSearchConstants.CLASS_AND_ENUM;
    else if (foritems.equalsIgnoreCase("CLASS&INTERFACE"))
        forflags = IJavaSearchConstants.CLASS_AND_INTERFACE;
    else if (foritems.equalsIgnoreCase("TYPE"))
        forflags = IJavaSearchConstants.TYPE;
    else if (foritems.equalsIgnoreCase("FIELD"))
        forflags = IJavaSearchConstants.FIELD;
    else if (foritems.equalsIgnoreCase("METHOD"))
        forflags = IJavaSearchConstants.METHOD;
    else if (foritems.equalsIgnoreCase("CONSTRUCTOR"))
        forflags = IJavaSearchConstants.CONSTRUCTOR;
    else if (foritems.equalsIgnoreCase("PACKAGE"))
        forflags = IJavaSearchConstants.PACKAGE;
    else if (foritems.equalsIgnoreCase("FIELDWRITE"))
        forflags = IJavaSearchConstants.FIELD | IJavaSearchConstants.WRITE_ACCESSES;
    else if (foritems.equalsIgnoreCase("FIELDREAD"))
        forflags = IJavaSearchConstants.FIELD | IJavaSearchConstants.READ_ACCESSES;
    else
        forflags = IJavaSearchConstants.TYPE;

    int limit = 0;
    if (defs && refs)
        limit = IJavaSearchConstants.ALL_OCCURRENCES;
    else if (defs)
        limit = IJavaSearchConstants.DECLARATIONS;
    else if (refs)
        limit = IJavaSearchConstants.REFERENCES;
    else if (impls)
        limit = IJavaSearchConstants.IMPLEMENTORS;

    int mrule = SearchPattern.R_PATTERN_MATCH;
    if (equiv)
        mrule = SearchPattern.R_EQUIVALENT_MATCH;
    else if (exact)
        mrule = SearchPattern.R_EXACT_MATCH;

    SearchPattern pat = SearchPattern.createPattern(patstr, forflags, limit, mrule);
    if (pat == null) {
        throw new BedrockException(
                "Invalid java search pattern `" + patstr + "' " + forflags + " " + limit + " " + mrule);
    }

    FindFilter filter = null;
    if (forflags == IJavaSearchConstants.METHOD) {
        String p = patstr;
        int idx = p.indexOf("(");
        if (idx > 0)
            p = p.substring(0, idx);
        idx = p.lastIndexOf(".");
        if (idx > 0) {
            if (defs)
                filter = new ClassFilter(p.substring(0, idx));
        }
    }

    // TODO: create scope for only user's items
    IJavaElement[] pelt;
    if (ijp != null)
        pelt = new IJavaElement[] { ijp };
    else
        pelt = getAllProjects();

    ICompilationUnit[] working = getWorkingElements(pelt);
    for (ICompilationUnit xcu : working) {
        try {
            BedrockPlugin.logD("WORK WITH " + xcu.isWorkingCopy() + " " + xcu.getPath() + xcu.getSourceRange());
        } catch (JavaModelException e) {
            BedrockPlugin.logD("WORK WITH ERROR: " + e);
        }
    }

    IJavaSearchScope scp = null;
    int fg = IJavaSearchScope.SOURCES | IJavaSearchScope.REFERENCED_PROJECTS;
    if (system) {
        fg |= IJavaSearchScope.SYSTEM_LIBRARIES | IJavaSearchScope.APPLICATION_LIBRARIES;
        scp = SearchEngine.createWorkspaceScope();
    } else {
        scp = SearchEngine.createJavaSearchScope(pelt, fg);
    }

    SearchEngine se = new SearchEngine(working);
    SearchParticipant[] parts = new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() };
    FindHandler fh = new FindHandler(xw, filter, system);

    BedrockPlugin.logD("BEGIN SEARCH " + pat);
    BedrockPlugin.logD("SEARCH SCOPE " + system + " " + fg + " " + scp);

    try {
        se.search(pat, parts, scp, fh, null);
    } catch (Throwable e) {
        throw new BedrockException("Problem doing Java search: " + e, e);
    }
}

From source file:net.harawata.mybatipse.mybatis.TypeAliasCache.java

License:Open Source License

private void collectTypesInPackages(final IJavaProject project, Set<String> packages,
        final TypeAliasMap aliasMap, Set<String> superTypes, IReporter reporter) {
    final Set<IType> superTypeSet = new HashSet<IType>();
    try {/*from   w w w.  j a v a2s.c o m*/
        for (String supType : superTypes) {
            superTypeSet.add(project.findType(supType));
        }
    } catch (JavaModelException e) {
        Activator.log(Status.ERROR, e.getMessage(), e);
    }

    int includeMask = IJavaSearchScope.SOURCES | IJavaSearchScope.REFERENCED_PROJECTS
            | IJavaSearchScope.APPLICATION_LIBRARIES | IJavaSearchScope.SYSTEM_LIBRARIES;
    IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaProject[] { project }, includeMask);
    TypeNameRequestor requestor = new TypeNameRequestor() {
        @Override
        public void acceptType(int modifiers, char[] packageName, char[] simpleTypeName,
                char[][] enclosingTypeNames, String path) {
            // Ignore abstract classes.
            if (Flags.isAbstract(modifiers))
                return;

            String qualifiedName = NameUtil.buildQualifiedName(packageName, simpleTypeName, enclosingTypeNames,
                    false);
            try {
                IType foundType = project.findType(qualifiedName);
                if (superTypeSet.isEmpty() || isSuperTypeMatched(foundType, superTypeSet)) {
                    String alias = getAliasAnnotationValue(foundType);
                    if (alias == null) {
                        alias = new String(simpleTypeName);
                    }
                    aliasMap.put(alias, qualifiedName);
                }
            } catch (JavaModelException e) {
                Activator.log(Status.WARNING, "Error occurred while searching type alias.", e);
            }
        }

        private boolean isSuperTypeMatched(IType foundType, Set<IType> superTypeSet) throws JavaModelException {
            for (IType superType : superTypeSet) {
                if (isAssignable(foundType, superType)) {
                    return true;
                }
            }
            return false;
        }
    };

    SearchEngine searchEngine = new SearchEngine();
    for (String pkg : packages) {
        if (reporter != null && reporter.isCancelled()) {
            throw new OperationCanceledException();
        }
        try {
            searchEngine.searchAllTypeNames(pkg.toCharArray(), SearchPattern.R_EXACT_MATCH, null,
                    SearchPattern.R_CAMELCASE_MATCH, IJavaSearchConstants.CLASS, scope, requestor,
                    IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, null);
        } catch (JavaModelException e) {
            Activator.log(Status.ERROR, e.getMessage(), e);
        }
    }
}

From source file:net.harawata.mybatipse.mybatis.XmlCompletionProposalComputer.java

License:Open Source License

private void proposePackage(final ContentAssistRequest contentAssistRequest, IJavaProject project,
        String matchString, final int start, final int length) throws CoreException {
    final List<ICompletionProposal> results = new ArrayList<ICompletionProposal>();
    final Set<String> foundPkgs = new HashSet<String>();
    int includeMask = IJavaSearchScope.SOURCES | IJavaSearchScope.REFERENCED_PROJECTS;
    // Include application libraries only when package is specified (for better performance).
    boolean pkgSpecified = matchString != null && matchString.indexOf('.') > 0;
    if (pkgSpecified)
        includeMask |= IJavaSearchScope.APPLICATION_LIBRARIES | IJavaSearchScope.SYSTEM_LIBRARIES;
    IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaProject[] { project }, includeMask);
    SearchRequestor requestor = new SearchRequestor() {
        @Override/*from  w  w w.  j av a 2  s  .c  om*/
        public void acceptSearchMatch(SearchMatch match) throws CoreException {
            PackageFragment element = (PackageFragment) match.getElement();
            String pkg = element.getElementName();
            if (pkg != null && pkg.length() > 0 && !foundPkgs.contains(pkg)) {
                foundPkgs.add(pkg);
                results.add(new CompletionProposal(pkg, start, length, pkg.length(), Activator.getIcon(), pkg,
                        null, null));
            }
        }
    };
    searchPackage(matchString, scope, requestor);
    addProposals(contentAssistRequest, results);
}

From source file:org.eclipse.ajdt.internal.launching.AspectJMainTab.java

License:Open Source License

/**
 * Show a dialog that lists all main types
 *//*  w ww  . j  a v a 2  s .  co m*/
protected void handleSearchButtonSelected() {
    IJavaProject project = getJavaProject();
    IJavaElement[] elements = null;
    if ((project == null) || !project.exists()) {
        IJavaModel model = JavaCore.create(ResourcesPlugin.getWorkspace().getRoot());
        if (model != null) {
            try {
                elements = model.getJavaProjects();
            } //end try 
            catch (JavaModelException e) {
                JDIDebugUIPlugin.log(e);
            }
        } //end if
    } //end if 
    else {
        elements = new IJavaElement[] { project };
    } //end else      
    if (elements == null) {
        elements = new IJavaElement[] {};
    } //end if
    int constraints = IJavaSearchScope.SOURCES;
    if (fSearchExternalJarsCheckButton.getSelection()) {
        constraints |= IJavaSearchScope.APPLICATION_LIBRARIES;
        constraints |= IJavaSearchScope.SYSTEM_LIBRARIES;
    } //end if   
    IJavaSearchScope searchScope = SearchEngine.createJavaSearchScope(elements, constraints);
    // AspectJ Change Begin
    AJMainMethodSearchEngine engine = new AJMainMethodSearchEngine();
    // AspectJ Change End
    IType[] types = null;
    try {
        // AspectJ Change Begin
        types = engine.searchMainMethodsIncludingAspects(getLaunchConfigurationDialog(), searchScope,
                fConsiderInheritedMainButton.getSelection());
        // AspectJ Change End
    } //end try 
    catch (InvocationTargetException e) {
        setErrorMessage(e.getMessage());
        return;
    } //end catch 
    catch (InterruptedException e) {
        setErrorMessage(e.getMessage());
        return;
    } //end catch
    SelectionDialog dialog = null;
    // AspectJ Change Begin
    dialog = new AJMainTypeSelectionDialog(getShell(), types);
    // AspectJ Change End
    dialog.setTitle(LauncherMessages.JavaMainTab_Choose_Main_Type_11);
    dialog.setMessage(LauncherMessages.JavaMainTab_Choose_a_main__type_to_launch__12);
    if (dialog.open() == Window.CANCEL) {
        return;
    } //end if
    Object[] results = dialog.getResult();
    IType type = (IType) results[0];
    if (type != null) {
        fMainText.setText(type.getFullyQualifiedName());
        fProjText.setText(type.getJavaProject().getElementName());
    } //end if
}

From source file:org.eclipse.ajdt.internal.ui.refactoring.RippleMethodFinder2.java

License:Open Source License

private void findAllDeclarations(IProgressMonitor monitor, WorkingCopyOwner owner) throws CoreException {
    fDeclarations = new ArrayList();

    class MethodRequestor extends SearchRequestor {
        public void acceptSearchMatch(SearchMatch match) throws CoreException {
            IMethod method = (IMethod) match.getElement();
            boolean isBinary = method.isBinary();
            if (fBinaryRefs != null || !(fExcludeBinaries && isBinary)) {
                fDeclarations.add(method);
            }/*from   ww  w  .j  a  v a2  s .co  m*/
            if (isBinary && fBinaryRefs != null) {
                fDeclarationToMatch.put(method, match);
            }
        }
    }

    int limitTo = IJavaSearchConstants.DECLARATIONS | IJavaSearchConstants.IGNORE_DECLARING_TYPE
            | IJavaSearchConstants.IGNORE_RETURN_TYPE;
    int matchRule = SearchPattern.R_ERASURE_MATCH | SearchPattern.R_CASE_SENSITIVE;
    SearchPattern pattern = SearchPattern.createPattern(fMethod, limitTo, matchRule);
    SearchParticipant[] participants = SearchUtils.getDefaultSearchParticipants();
    IJavaSearchScope scope = RefactoringScopeFactory.createRelatedProjectsScope(fMethod.getJavaProject(),
            IJavaSearchScope.SOURCES | IJavaSearchScope.APPLICATION_LIBRARIES
                    | IJavaSearchScope.SYSTEM_LIBRARIES);
    MethodRequestor requestor = new MethodRequestor();
    SearchEngine searchEngine = owner != null ? new SearchEngine(owner) : new SearchEngine();

    searchEngine.search(pattern, participants, scope, requestor, monitor);
}

From source file:org.eclipse.mylyn.internal.java.ui.search.AbstractJavaRelationProvider.java

License:Open Source License

private IJavaSearchScope createJavaSearchScope(IJavaElement element, int degreeOfSeparation) {
    Set<IInteractionElement> landmarks = ContextCore.getContextManager().getActiveLandmarks();
    List<IInteractionElement> interestingElements = ContextCore.getContextManager().getActiveContext()
            .getInteresting();/* ww w  .j a  v  a 2 s.  co m*/

    Set<IJavaElement> searchElements = new HashSet<IJavaElement>();
    int includeMask = IJavaSearchScope.SOURCES;
    if (degreeOfSeparation == 1) {
        for (IInteractionElement landmark : landmarks) {
            AbstractContextStructureBridge bridge = ContextCore.getStructureBridge(landmark.getContentType());
            if (includeNodeInScope(landmark, bridge)) {
                Object o = bridge.getObjectForHandle(landmark.getHandleIdentifier());
                if (o instanceof IJavaElement) {
                    IJavaElement landmarkElement = (IJavaElement) o;
                    if (landmarkElement.exists()) {
                        if (landmarkElement instanceof IMember && !landmark.getInterest().isPropagated()) {
                            searchElements.add(((IMember) landmarkElement).getCompilationUnit());
                        } else if (landmarkElement instanceof ICompilationUnit) {
                            searchElements.add(landmarkElement);
                        }
                    }
                }
            }
        }
    } else if (degreeOfSeparation == 2) {
        for (IInteractionElement interesting : interestingElements) {
            AbstractContextStructureBridge bridge = ContextCore
                    .getStructureBridge(interesting.getContentType());
            if (includeNodeInScope(interesting, bridge)) {
                Object object = bridge.getObjectForHandle(interesting.getHandleIdentifier());
                if (object instanceof IJavaElement) {
                    IJavaElement interestingElement = (IJavaElement) object;
                    if (interestingElement.exists()) {
                        if (interestingElement instanceof IMember
                                && !interesting.getInterest().isPropagated()) {
                            searchElements.add(((IMember) interestingElement).getCompilationUnit());
                        } else if (interestingElement instanceof ICompilationUnit) {
                            searchElements.add(interestingElement);
                        }
                    }
                }
            }
        }
    } else if (degreeOfSeparation == 3 || degreeOfSeparation == 4) {
        for (IInteractionElement interesting : interestingElements) {
            AbstractContextStructureBridge bridge = ContextCore
                    .getStructureBridge(interesting.getContentType());
            if (includeNodeInScope(interesting, bridge)) {
                // TODO what to do when the element is not a java element,
                // how determine if a javaProject?
                IResource resource = ResourcesUiBridgePlugin.getDefault().getResourceForElement(interesting,
                        true);
                if (resource != null) {
                    IProject project = resource.getProject();
                    if (project != null && JavaProject.hasJavaNature(project) && project.exists()) {
                        IJavaProject javaProject = JavaCore.create(project);// ((IJavaElement)o).getJavaProject();
                        if (javaProject != null && javaProject.exists()) {
                            searchElements.add(javaProject);
                        }
                    }
                }
            }
        }
        if (degreeOfSeparation == 4) {

            includeMask = IJavaSearchScope.SOURCES | IJavaSearchScope.APPLICATION_LIBRARIES
                    | IJavaSearchScope.SYSTEM_LIBRARIES;
        }
    } else if (degreeOfSeparation == 5) {
        return SearchEngine.createWorkspaceScope();
    }

    if (searchElements.size() == 0) {
        return null;
    } else {
        IJavaElement[] elements = new IJavaElement[searchElements.size()];
        int j = 0;
        for (IJavaElement searchElement : searchElements) {
            elements[j] = searchElement;
            j++;
        }
        return SearchEngine.createJavaSearchScope(elements, includeMask);
    }
}

From source file:org.jboss.ide.eclipse.as.ui.xpl.JavaMainTabClone.java

License:Open Source License

/**
 * Show a dialog that lists all main types
 *//*from ww  w  .  j  a va 2 s  .c  om*/
protected void handleSearchButtonSelected() {
    IJavaProject project = getJavaProject();
    IJavaElement[] elements = null;
    if ((project == null) || !project.exists()) {
        IJavaModel model = JavaCore.create(ResourcesPlugin.getWorkspace().getRoot());
        if (model != null) {
            try {
                elements = model.getJavaProjects();
            } catch (JavaModelException e) {
                JDIDebugUIPlugin.log(e);
            }
        }
    } else {
        elements = new IJavaElement[] { project };
    }
    if (elements == null) {
        elements = new IJavaElement[] {};
    }
    int constraints = IJavaSearchScope.SOURCES;
    constraints |= IJavaSearchScope.APPLICATION_LIBRARIES;
    if (fSearchExternalJarsCheckButton.getSelection()) {
        constraints |= IJavaSearchScope.SYSTEM_LIBRARIES;
    }
    IJavaSearchScope searchScope = SearchEngine.createJavaSearchScope(elements, constraints);
    MainMethodSearchEngine engine = new MainMethodSearchEngine();
    IType[] types = null;
    try {
        types = engine.searchMainMethods(getLaunchConfigurationDialog(), searchScope,
                fConsiderInheritedMainButton.getSelection());
    } catch (InvocationTargetException e) {
        setErrorMessage(e.getMessage());
        return;
    } catch (InterruptedException e) {
        setErrorMessage(e.getMessage());
        return;
    }
    DebugTypeSelectionDialog mmsd = new DebugTypeSelectionDialog(getShell(), types,
            LauncherMessages.JavaMainTab_Choose_Main_Type_11);
    if (mmsd.open() == Window.CANCEL) {
        return;
    }
    Object[] results = mmsd.getResult();
    IType type = (IType) results[0];
    if (type != null) {
        fMainText.setText(type.getFullyQualifiedName());
        fProjText.setText(type.getJavaProject().getElementName());
    }
}

From source file:org.raspinloop.fmi.plugin.launcher.RilMainTab.java

License:Open Source License

/**
 * Show a dialog that lists all main types
 *///w w  w  .j av  a  2  s .c  om
@Override
protected void handleSearchButtonSelected() {
    IJavaProject project = getJavaProject();
    IJavaElement[] elements = null;
    if ((project == null) || !project.exists()) {
        IJavaModel model = JavaCore.create(ResourcesPlugin.getWorkspace().getRoot());
        if (model != null) {
            try {
                elements = model.getJavaProjects();
            } catch (JavaModelException e) {
                Activator.getDefault().log("", e);
                ;
            }
        }
    } else {
        elements = new IJavaElement[] { project };
    }
    if (elements == null) {
        elements = new IJavaElement[] {};
    }
    int constraints = IJavaSearchScope.SOURCES;
    constraints |= IJavaSearchScope.APPLICATION_LIBRARIES;
    if (fSearchExternalJarsCheckButton.getSelection()) {
        constraints |= IJavaSearchScope.SYSTEM_LIBRARIES;
    }
    IJavaSearchScope searchScope = SearchEngine.createJavaSearchScope(elements, constraints);
    MainMethodSearchEngine engine = new MainMethodSearchEngine();
    IType[] types = null;
    try {
        types = engine.searchMainMethods(getLaunchConfigurationDialog(), searchScope,
                fConsiderInheritedMainButton.getSelection());
    } catch (InvocationTargetException e) {
        setErrorMessage(e.getMessage());
        return;
    } catch (InterruptedException e) {
        setErrorMessage(e.getMessage());
        return;
    }
    DebugTypeSelectionDialog mmsd = new DebugTypeSelectionDialog(getShell(), types,
            LauncherMessages.JavaMainTab_Choose_Main_Type_11);
    if (mmsd.open() == Window.CANCEL) {
        return;
    }
    Object[] results = mmsd.getResult();
    IType type = (IType) results[0];
    if (type != null) {
        fMainText.setText(type.getFullyQualifiedName());
        fProjText.setText(type.getJavaProject().getElementName());
    }
}

From source file:org.springframework.tooling.jdt.ls.commons.java.FluxJdtSearch.java

License:Open Source License

/**
 * Create a search scope that includes a given project and its dependencies.
 *//*w  w  w.  ja  va2  s.co  m*/
public static IJavaSearchScope searchScope(IJavaProject javaProject, boolean includeBinaries,
        boolean includeSystemLibs) throws JavaModelException {
    int includeMask = IJavaSearchScope.REFERENCED_PROJECTS | IJavaSearchScope.SOURCES;
    if (includeBinaries) {
        includeMask = includeMask | IJavaSearchScope.APPLICATION_LIBRARIES;
    }
    if (includeSystemLibs) {
        includeMask = includeMask | IJavaSearchScope.SYSTEM_LIBRARIES;
    }
    return SearchEngine.createJavaSearchScope(new IJavaElement[] { javaProject }, includeMask);
}