List of usage examples for org.eclipse.jdt.core.search IJavaSearchScope APPLICATION_LIBRARIES
int APPLICATION_LIBRARIES
To view the source code for org.eclipse.jdt.core.search IJavaSearchScope APPLICATION_LIBRARIES.
Click Source Link
From source file:at.bestsolution.efxclipse.tooling.jdt.ui.internal.editors.JFXBuildConfigurationEditor.java
License:Open Source License
private String handleRootclassSelection(Shell parent) { IFileEditorInput i = (IFileEditorInput) getEditorInput(); IJavaProject project = JavaCore.create(i.getFile().getProject()); if (project == null) { return null; }/* www .ja v a 2 s. c o m*/ IJavaElement[] elements = new IJavaElement[] { project }; int constraints = IJavaSearchScope.SOURCES; constraints |= IJavaSearchScope.APPLICATION_LIBRARIES; IJavaSearchScope searchScope = SearchEngine.createJavaSearchScope(elements, constraints); BusyIndicatorRunnableContext context = new BusyIndicatorRunnableContext(); MainTypeSelectionDialog dialog = new MainTypeSelectionDialog(parent, context, searchScope, 0); dialog.setTitle("Find class"); dialog.setMessage("Find the class used to launch the application"); if (dialog.open() == Window.CANCEL) { return null; } Object[] results = dialog.getResult(); IType type = (IType) results[0]; if (type != null) { return type.getFullyQualifiedName(); } return null; }
From source file:com.aliyun.odps.eclipse.launch.configuration.udf.UDFClassTab.java
License:Apache License
/** * Show a dialog that lists all main types *///from www .jav a 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; // constraints |= IJavaSearchScope.SYSTEM_LIBRARIES; IJavaSearchScope searchScope = SearchEngine.createJavaSearchScope(elements, constraints); UDFSearchEngine engine = new UDFSearchEngine(); IType[] types = null; try { types = engine.searchUDFClass(getLaunchConfigurationDialog(), searchScope, false); } 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:com.aliyun.odps.eclipse.launch.shortcut.udf.UDFLaunchShortcuts2.java
License:Apache License
protected IType[] findTypes(Object[] elements, IRunnableContext context) throws InterruptedException, CoreException { try {/*from w w w.ja v a 2s .c o m*/ if (elements.length == 1) { IType type = isUDF(elements[0]); if (type != null) { return new IType[] { type }; } } IJavaElement[] javaElements = getJavaElements(elements); UDFSearchEngine engine = new UDFSearchEngine(); int constraints = IJavaSearchScope.SOURCES; constraints |= IJavaSearchScope.APPLICATION_LIBRARIES; IJavaSearchScope scope = SearchEngine.createJavaSearchScope(javaElements, constraints); return engine.searchUDFClass(context, scope, true); } catch (InvocationTargetException e) { throw (CoreException) e.getTargetException(); } }
From source file:com.ebmwebsourcing.petals.common.extensions.internal.wizards.JavaToWSDLWizardPage.java
License:Open Source License
/** * Open a dialog to select a class./*from w ww. j a v a2 s .c o m*/ */ private void openClassSelectionDialog() { if (this.javaProject == null) return; Shell shell = this.classText.getShell(); IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] { this.javaProject }, IJavaSearchScope.SOURCES | IJavaSearchScope.APPLICATION_LIBRARIES | IJavaSearchScope.REFERENCED_PROJECTS); String filter = this.classText.getText().trim(); filter = filter.length() == 0 ? "?" : filter; try { SelectionDialog dlg = JavaUI.createTypeDialog(shell, new ProgressMonitorDialog(shell), scope, IJavaElementSearchConstants.CONSIDER_INTERFACES, true, filter); if (dlg.open() == Window.OK) { IType type = (IType) dlg.getResult()[0]; String selection = type.getFullyQualifiedName(); this.classText.setText(selection); this.classText.setSelection(selection.length()); } } catch (JavaModelException e) { PetalsCommonWsdlExtPlugin.log(e, IStatus.ERROR); } }
From source file:com.redhat.ceylon.eclipse.core.launch.CeylonMainTab.java
License:Open Source License
/** * Show a dialog that lists all main types *//*from w ww .j a va 2 s . c o 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(); } 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; IJavaSearchScope searchScope = SearchEngine.createJavaSearchScope(elements, constraints); MainMethodSearchEngine engine = new MainMethodSearchEngine(); IType[] types = null; try { types = engine.searchMainMethods(getLaunchConfigurationDialog(), searchScope, false); } 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:com.sureassert.uc.builder.SaUCApplicationLaunchShortcutBak.java
License:Open Source License
/** * @see org.eclipse.jdt.internal.debug.ui.launcher.JavaLaunchShortcut#findTypes(java.lang.Object[], org.eclipse.jface.operation.IRunnableContext) */// w w w.java2s . c o m @Override protected IType[] findTypes(Object[] elements, IRunnableContext context) throws InterruptedException, CoreException { try { if(elements.length == 1) { IType type = isMainMethod(elements[0]); if(type != null) { return new IType[] {type}; } } IJavaElement[] javaElements = getJavaElements(elements); MainMethodSearchEngine engine = new MainMethodSearchEngine(); int constraints = IJavaSearchScope.SOURCES; constraints |= IJavaSearchScope.APPLICATION_LIBRARIES; IJavaSearchScope scope = SearchEngine.createJavaSearchScope(javaElements, constraints); return engine.searchMainMethods(context, scope, true); } catch (InvocationTargetException e) { throw (CoreException)e.getTargetException(); } }
From source file:com.windowtester.swt.codegen.dialogs.SearchScopeHelper.java
License:Open Source License
public IType[] inProject(IJavaProject project) throws CoreException { int includeMask = IJavaSearchScope.SOURCES | IJavaSearchScope.APPLICATION_LIBRARIES | // IJavaSearchScope.SYSTEM_LIBRARIES | IJavaSearchScope.REFERENCED_PROJECTS; IJavaSearchScope searchScope = SearchEngine.createJavaSearchScope(new IJavaElement[] { project }, includeMask);// w w w . j av a 2 s .c om // // DEBUG: what does our scope encompass? // for (IPath path : searchScope.enclosingProjectsAndJars()) // System.out.println("will search " + path); // jar containing classes we want to match is seen, // but results within that jar are not being returned. SearchEngine se = new SearchEngine(); SearchPattern pattern = SearchPattern.createPattern(type.getFullyQualifiedName(), IJavaSearchConstants.CLASS, IJavaSearchConstants.IMPLEMENTORS, SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE); SearchRequestor requestor = new SearchRequestor() { public void acceptSearchMatch(SearchMatch match) throws CoreException { // System.err.println("found match " // + match.getElement().getClass() + ":" // + match.getElement()); results.add((IType) match.getElement()); } }; // long start = System.currentTimeMillis(); se.search(pattern, new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }, searchScope, requestor, monitor); //add "self" type results.add(type); // System.err.println("done in " + (System.currentTimeMillis() - start) // + " ms"); // for (Iterator iterator = results.iterator(); iterator.hasNext();) { // IType type = (IType) iterator.next(); // System.out.println(type); // } return (IType[]) results.toArray(new IType[] {}); }
From source file:com.yannicklerestif.metapojos.plugin.project.MetaPojosLaunchShortcut.java
License:Open Source License
@Override protected IType[] findTypes(Object[] elements, IRunnableContext context) throws InterruptedException, CoreException { try {/*from www . jav a 2 s. co m*/ if (elements.length == 1) { IType type = isMainMethod(elements[0]); if (type != null) { return new IType[] { type }; } } IJavaElement[] javaElements = getJavaElements(elements); MainMethodSearchEngine engine = new MainMethodSearchEngine(); int constraints = IJavaSearchScope.SOURCES; constraints |= IJavaSearchScope.APPLICATION_LIBRARIES; IJavaSearchScope scope = SearchEngine.createJavaSearchScope(javaElements, constraints); return engine.searchMainMethods(context, scope, true); } catch (InvocationTargetException e) { throw (CoreException) e.getTargetException(); } }
From source file:edu.brown.cs.bubbles.bedrock.BedrockCall.java
License:Open Source License
/********************************************************************************/ void getCallPath(String proj, String src, String tgt, boolean shortest, int lvls, IvyXmlWriter xw) throws BedrockException { IProject ip = our_plugin.getProjectManager().findProject(proj); IJavaProject ijp = JavaCore.create(ip); if (lvls < 0) lvls = MAX_LEVELS;/*from w ww .ja va 2 s .c o m*/ IJavaElement[] pelt = new IJavaElement[] { ijp }; int incl = IJavaSearchScope.SOURCES | IJavaSearchScope.APPLICATION_LIBRARIES | IJavaSearchScope.REFERENCED_PROJECTS; IJavaSearchScope scp = SearchEngine.createJavaSearchScope(pelt, incl); SearchEngine se = new SearchEngine(); SearchParticipant[] parts = new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }; SearchPattern p1 = SearchPattern.createPattern(src, IJavaSearchConstants.METHOD, IJavaSearchConstants.DECLARATIONS, SearchPattern.R_PATTERN_MATCH); SearchPattern p1a = SearchPattern.createPattern(fixConstructor(src), IJavaSearchConstants.CONSTRUCTOR, IJavaSearchConstants.DECLARATIONS, SearchPattern.R_PATTERN_MATCH); if (p1 == null || p1a == null) throw new BedrockException("Illegal source pattern " + src); SearchPattern p2 = SearchPattern.createPattern(tgt, IJavaSearchConstants.METHOD, IJavaSearchConstants.DECLARATIONS, SearchPattern.R_PATTERN_MATCH); SearchPattern p2a = SearchPattern.createPattern(fixConstructor(tgt), IJavaSearchConstants.CONSTRUCTOR, IJavaSearchConstants.DECLARATIONS, SearchPattern.R_PATTERN_MATCH); if (p2 == null || p2a == null) throw new BedrockException("Illegal target pattern " + tgt); SetHandler sh = new SetHandler(); try { se.search(p1, parts, scp, sh, null); BedrockPlugin.logD("CALL: Source A: " + sh.getSize() + " " + p1); if (sh.isEmpty()) se.search(p1a, parts, scp, sh, null); BedrockPlugin.logD("CALL: Source B: " + sh.getSize() + " " + p1a); } catch (CoreException e) { throw new BedrockException("Problem doing call search 1: " + e, e); } SetHandler th = new SetHandler(); try { se.search(p2, parts, scp, th, null); BedrockPlugin.logD("CALL: Target A: " + th.getSize() + " " + p2); if (th.isEmpty()) se.search(p2a, parts, scp, th, null); BedrockPlugin.logD("CALL: Target B: " + th.getSize() + " " + p2a); } catch (CoreException e) { throw new BedrockException("Problem doing call search 2: " + e, e); } Map<IMethod, CallNode> nodes = new HashMap<IMethod, CallNode>(); Queue<IMethod> workqueue = new LinkedList<IMethod>(); for (IMethod je : th.getElements()) { CallNode cn = new CallNode(je, 0); cn.setTarget(); nodes.put(je, cn); workqueue.add(je); } while (!workqueue.isEmpty()) { IMethod je = workqueue.remove(); CallNode cn = nodes.get(je); if (cn.isDone()) continue; cn.markDone(); BedrockPlugin.logD("CALL: WORK ON " + je.getKey() + " " + cn.getLevel() + " " + sh.contains(je)); if (shortest && sh.contains(je)) break; int lvl = cn.getLevel() + 1; if (lvl > lvls) continue; String nm = je.getElementName(); if (nm == null) continue; String cnm = je.getDeclaringType().getFullyQualifiedName(); if (cnm != null) nm = cnm.replace("$", ".") + "." + nm; nm += "("; String[] ptyps = je.getParameterTypes(); for (int i = 0; i < ptyps.length; ++i) { if (i > 0) nm += ","; nm += IvyFormat.formatTypeName(ptyps[i]); } nm += ")"; SearchPattern p3; try { BedrockPlugin.logD("CALL: Search for: " + nm + " " + je.isConstructor()); if (je.isConstructor()) { String nm1 = fixConstructor(nm); p3 = SearchPattern.createPattern(nm1, IJavaSearchConstants.CONSTRUCTOR, IJavaSearchConstants.REFERENCES, SearchPattern.R_EXACT_MATCH); } else { p3 = SearchPattern.createPattern(nm, IJavaSearchConstants.METHOD, IJavaSearchConstants.REFERENCES, SearchPattern.R_EXACT_MATCH); } CallHandler ch = new CallHandler(je, workqueue, nodes, lvl); se.search(p3, parts, scp, ch, null); } catch (CoreException e) { throw new BedrockException("Problem doing call search e: " + e, e); } } // TODO: restrict to single path if shortest is set xw.begin("PATH"); for (IMethod je : sh.getElements()) { CallNode cn = nodes.get(je); if (cn == null) continue; Set<IMethod> done = new HashSet<IMethod>(); cn.output(xw, done, nodes); } xw.end("PATH"); }
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 www . j a va 2s . 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); } }