List of usage examples for org.eclipse.jdt.core.search IJavaSearchConstants DECLARATIONS
int DECLARATIONS
To view the source code for org.eclipse.jdt.core.search IJavaSearchConstants DECLARATIONS.
Click Source Link
From source file:com.iw.plugins.spindle.ui.widgets.TypeChooserWidget.java
License:Mozilla Public License
public void configure(final IJavaProject project, final IRunnableContext context) { try {/*from w w w .j a va 2 s.c o m*/ final boolean baseIsInterface = fHierarchyRoot.isInterface(); fSearchResults = new ArrayList(); IRunnableWithProgress runnable = new IRunnableWithProgress() { public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { IJavaSearchScope scope = null; try { // we want to rip out the JRE entry as there's no chance of finding a tapestry class there. ArrayList roots = new ArrayList(); IClasspathEntry[] classpath = project.getRawClasspath(); for (int i = 0; i < classpath.length; i++) { if (classpath[i].getEntryKind() == IClasspathEntry.CPE_CONTAINER) { IPath cpPath = classpath[i].getPath(); if (JavaRuntime.JRE_CONTAINER.equals(cpPath.segment(0))) continue; } roots.add(project.findPackageFragmentRoots(classpath[i])); } scope = SearchEngine.createJavaSearchScope( (IJavaElement[]) roots.toArray(new IJavaElement[roots.size()]), true); } catch (JavaModelException e1) { scope = SearchEngine.createJavaSearchScope(new IJavaElement[] { project }, true); } ISearchPattern pattern = SearchEngine.createSearchPattern("*", IJavaSearchConstants.TYPE, IJavaSearchConstants.DECLARATIONS, true); SearchEngine engine = new SearchEngine(); IJavaSearchResultCollector collector = new IJavaSearchResultCollector() { public void aboutToStart() { } public void accept(IResource resource, int start, int end, IJavaElement enclosingElement, int accuracy) throws CoreException { if (accuracy != EXACT_MATCH) return; if (enclosingElement.getElementType() != IJavaElement.TYPE) return; IType type = (IType) enclosingElement; System.out.println(type.getFullyQualifiedName()); if (baseIsInterface) { if (!CoreUtils.implementsInterface(type, fHierarchyRoot.getElementName())) return; } else { if (!CoreUtils.extendsType(type, fHierarchyRoot)) return; } System.out.println(type.getFullyQualifiedName()); fSearchResults.add(type); } public void done() { } public IProgressMonitor getProgressMonitor() { return monitor; } }; try { engine.search(ResourcesPlugin.getWorkspace(), pattern, scope, collector); } catch (JavaModelException e) { UIPlugin.log(e); } } }; context.run(false, true, runnable); } catch (InvocationTargetException e) { UIPlugin.log(e); } catch (InterruptedException e) { //do nothing; } catch (JavaModelException e) { UIPlugin.log(e); } }
From source file:com.iw.plugins.spindle.util.FieldBindingsPreferencePage.java
License:Mozilla Public License
public static IJavaElement[] unfold(String folded) { if (folded != null && !"".equals(folded.trim())) { ISearchPattern searchPattern = null; StringTokenizer tok = new StringTokenizer(folded, ","); while (tok.hasMoreTokens()) { String fragment = tok.nextToken(); if (searchPattern == null) { searchPattern = SearchEngine.createSearchPattern(fragment, IJavaSearchConstants.PACKAGE, IJavaSearchConstants.DECLARATIONS, false); } else { searchPattern = SearchEngine.createOrSearchPattern(searchPattern, SearchEngine.createSearchPattern(fragment, IJavaSearchConstants.PACKAGE, IJavaSearchConstants.DECLARATIONS, false)); }//from w w w . java 2 s . co m } try { UnfoldSearchCollector collector = new UnfoldSearchCollector(); long start = new Date().getTime(); new SearchEngine().search(TapestryPlugin.getDefault().getWorkspace(), searchPattern, SearchEngine.createWorkspaceScope(), collector); return collector.getFoundElements(); } catch (JavaModelException jmex) { jmex.printStackTrace(); } } return new IJavaElement[0]; }
From source file:com.iw.plugins.spindle.util.PublicStaticFieldSearchEngine.java
License:Mozilla Public License
/** * Searches for all types with public static fields in the given scope. * Valid styles are IJavaElementSearchConstants.CONSIDER_BINARIES and * IJavaElementSearchConstants.CONSIDER_EXTERNAL_JARS *//*from w w w . java 2 s . c o m*/ public IType[] searchPublicStaticMethods(IProgressMonitor pm, IJavaSearchScope scope, int style) throws JavaModelException { List typesFound = new ArrayList(200); IJavaSearchResultCollector collector = new FieldCollector(typesFound, style, pm); new SearchEngine().search(TapestryPlugin.getDefault().getWorkspace(), "*", IJavaSearchConstants.FIELD, IJavaSearchConstants.DECLARATIONS, scope, collector); return (IType[]) typesFound.toArray(new IType[typesFound.size()]); }
From source file:com.liferay.ide.portlet.ui.editor.PortletURLHyperlinkDetector.java
License:Open Source License
private IMethod[] findPortletMethods(IDocument document, String nameValue) { IMethod[] retval = null;//w ww. ja v a2 s . c o m final IFile file = DOMUtils.getFile(document); if (file != null && file.exists()) { final IJavaProject project = JavaCore.create(file.getProject()); if (project != null && project.exists()) { try { final IType portlet = project.findType("javax.portlet.Portlet"); if (portlet != null) { final List<IMethod> methods = new ArrayList<IMethod>(); final SearchRequestor requestor = new ActionMethodCollector(methods); final IJavaSearchScope scope = SearchEngine.createStrictHierarchyScope(project, portlet, true, false, null); final SearchPattern search = SearchPattern.createPattern(nameValue, IJavaSearchConstants.METHOD, IJavaSearchConstants.DECLARATIONS, SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE); new SearchEngine().search(search, new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }, scope, requestor, new NullProgressMonitor()); retval = methods.toArray(new IMethod[0]); } } catch (JavaModelException e) { } catch (CoreException e) { } } } return retval; }
From source file:com.liferay.ide.service.ui.editor.ServiceMethodHyperlinkDetector.java
License:Open Source License
private IMethodWrapper getServiceWrapperMethod(final IMethod method) { IMethodWrapper retval = null;// www .j av a2 s. c o m try { final IJavaElement methodClass = method.getParent(); final IType methodClassType = method.getDeclaringType(); final String methodClassName = methodClass.getElementName(); if (methodClassName.endsWith("Util") && JdtFlags.isPublic(method) && JdtFlags.isStatic(method)) { final String packageName = methodClassType.getPackageFragment().getElementName(); final String baseServiceName = methodClassName.substring(0, methodClassName.length() - 4); // as per liferay standard wrapper type will be in service package with Wrapper suffix // e.g. com.example.service.FooUtil.getBar() --> com.example.service.FooWrapper.getBar() final String fullyQualifiedName = packageName + "." + baseServiceName + "Wrapper"; final IType wrapperType = findType(methodClass, fullyQualifiedName); if (wrapperType != null) { IMethod[] wrapperBaseMethods = wrapperType.findMethods(method); if (!CoreUtil.isNullOrEmpty(wrapperBaseMethods)) { // look for classes that implement this wrapper final List<IMethod> overrides = new ArrayList<IMethod>(); final SearchRequestor requestor = new WrapperMethodCollector(overrides, method); final IJavaSearchScope scope = SearchEngine.createStrictHierarchyScope(null, wrapperType, true, false, null); final SearchPattern search = SearchPattern.createPattern(method.getElementName(), IJavaSearchConstants.METHOD, IJavaSearchConstants.DECLARATIONS, SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE); new SearchEngine().search(search, new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }, scope, requestor, new NullProgressMonitor()); if (overrides.size() > 1) { retval = new IMethodWrapper(wrapperBaseMethods[0], true); } else if (overrides.size() == 1) { retval = new IMethodWrapper(overrides.get(0), false); } } } } } catch (Exception e) { } return retval; }
From source file:com.liferay.ide.xml.search.ui.java.HierarchyTypeClassNameExtractor.java
License:Open Source License
@Override protected String[] doExtractClassNames(Node node, IFile file, String pathForClass, String findByAttrName, boolean findByParentNode, String xpathFactoryProviderId, NamespaceInfos namespaceInfo) throws XPathExpressionException { String[] retval = null;/* w w w. j a v a 2 s .c o m*/ final IJavaProject project = JavaCore.create(file.getProject()); try { final IType type = project.findType(this.typeName); if (type != null) { final TypeNameRequestor requestor = new TypeNameRequestor(); final IJavaSearchScope scope = SearchEngine.createStrictHierarchyScope(project, type, true, false, null); final SearchPattern search = SearchPattern.createPattern("*", IJavaSearchConstants.CLASS, IJavaSearchConstants.DECLARATIONS, 0); new SearchEngine().search(search, new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }, scope, requestor, new NullProgressMonitor()); retval = requestor.getResults().toArray(new String[0]); } } catch (Exception e) { } return retval; }
From source file:com.liferay.ide.xml.search.ui.JSPMarkerResolutionGenerator.java
License:Open Source License
private List<IType> findTypes(IJavaProject javaProject, String typeName) { List<IType> retval = Collections.emptyList(); try {//ww w .jav a2 s . c om final IType type = javaProject.findType(typeName); if (type != null) { final TypeInProjectRequestor requestor = new TypeInProjectRequestor(); final IJavaSearchScope scope = SearchEngine.createStrictHierarchyScope(javaProject, type, true, false, null); final SearchPattern search = SearchPattern.createPattern("*", IJavaSearchConstants.CLASS, IJavaSearchConstants.DECLARATIONS, 0); new SearchEngine().search(search, new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }, scope, requestor, new NullProgressMonitor()); retval = requestor.getResults(); } } catch (Exception e) { } return retval; }
From source file:com.mg.merp.wb.bai.BAiPlugin.java
License:Open Source License
private static IType getBAiAsType() { SearchPattern pattern = SearchPattern.createPattern(BAI_TYPE_NAME, IJavaSearchConstants.TYPE, IJavaSearchConstants.DECLARATIONS, SearchPattern.R_EQUIVALENT_MATCH); IJavaSearchScope scope = SearchEngine.createWorkspaceScope(); class BAiTypeSearchRequestor extends SearchRequestor { private IType baiType = null; @Override/*from w w w .j a va 2 s .c o m*/ public void acceptSearchMatch(SearchMatch match) throws CoreException { baiType = (IType) match.getElement(); } /** * * @return ? (AbstractBusinessAddin * ?? , , ..) */ public IType getBaiType() { return baiType; } } BAiTypeSearchRequestor requestor = new BAiTypeSearchRequestor(); SearchEngine searchEngine = new SearchEngine(); try { searchEngine.search(pattern, new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }, scope, requestor, null); } catch (CoreException e) { return null; } return requestor.getBaiType(); }
From source file:com.siteview.mde.internal.ui.search.dependencies.DependencyExtentOperation.java
License:Open Source License
private void searchForTypesUsed(SearchEngine engine, IJavaElement parent, IType[] types, IJavaSearchScope scope) throws CoreException { for (int i = 0; i < types.length; i++) { if (types[i].isAnonymous()) continue; TypeReferenceSearchRequestor requestor = new TypeReferenceSearchRequestor(); engine.search(SearchPattern.createPattern(types[i], IJavaSearchConstants.REFERENCES), new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }, scope, requestor, null); if (requestor.containMatches()) { TypeDeclarationSearchRequestor decRequestor = new TypeDeclarationSearchRequestor(); engine.search(SearchPattern.createPattern(types[i], IJavaSearchConstants.DECLARATIONS), new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }, SearchEngine.createJavaSearchScope(new IJavaElement[] { parent }), decRequestor, null); Match match = decRequestor.getMatch(); if (match != null) fSearchResult.addMatch(match); }//w w w . ja v a2s. c om } }
From source file:com.vmware.vfabric.ide.eclipse.tcserver.insight.internal.ui.link.JavaElementLocationHandler.java
License:Open Source License
private static IType[] findTypes(String typeName, IProgressMonitor monitor) throws CoreException { final List<IType> results = new ArrayList<IType>(); SearchRequestor collector = new SearchRequestor() { @Override/*w w w. ja va 2s .com*/ public void acceptSearchMatch(SearchMatch match) throws CoreException { Object element = match.getElement(); if (element instanceof IType) { results.add((IType) element); } } }; SearchEngine engine = new SearchEngine(); SearchPattern pattern = SearchPattern.createPattern(typeName, IJavaSearchConstants.TYPE, IJavaSearchConstants.DECLARATIONS, SearchPattern.R_EXACT_MATCH); engine.search(pattern, new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }, SearchEngine.createWorkspaceScope(), collector, monitor); return results.toArray(new IType[results.size()]); }