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.android.ide.eclipse.adt.SourceRevealer.java
License:Open Source License
private List<SearchMatch> searchForPattern(String pattern, int searchFor, Predicate<SearchMatch> filterPredicate) { SearchEngine se = new SearchEngine(); SearchPattern searchPattern = SearchPattern.createPattern(pattern, searchFor, IJavaSearchConstants.DECLARATIONS, SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE); SearchResultAccumulator requestor = new SearchResultAccumulator(filterPredicate); try {/* w ww . j av a 2s. co m*/ se.search(searchPattern, new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }, SearchEngine.createWorkspaceScope(), requestor, new NullProgressMonitor()); } catch (CoreException e) { AdtPlugin.printErrorToConsole(e.getMessage()); return Collections.emptyList(); } return requestor.getMatches(); }
From source file:com.android.ide.eclipse.pdt.internal.SourceRevealer.java
License:Apache License
@Override public boolean revealMethod(String fqmn, String fileName, int lineNumber, String perspective) { SearchEngine se = new SearchEngine(); SearchPattern searchPattern = SearchPattern.createPattern(fqmn, IJavaSearchConstants.METHOD, IJavaSearchConstants.DECLARATIONS, SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE); MethodSearchRequestor requestor = new MethodSearchRequestor(perspective); try {//from www . j ava 2 s .c om se.search(searchPattern, new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }, SearchEngine.createWorkspaceScope(), requestor, new NullProgressMonitor()); } catch (CoreException e) { return false; } return requestor.didMatch(); }
From source file:com.android.ide.eclipse.traceview.editors.TraceviewEditor.java
License:Apache License
public void handleMethod(MethodData method) { // it's a bit complicated to convert the signature we have with what the // search engine require, so we'll search by name only and test the signature // when we get the result(s). String methodName = method.getMethodName(); String className = method.getClassName().replaceAll("/", "."); //$NON-NLS-1$ //$NON-NLS-21$ String fqmn = className + "." + methodName; //$NON-NLS-1$ try {/*from www . j a v a2 s . c o m*/ SearchEngine se = new SearchEngine(); se.search( SearchPattern.createPattern(fqmn, IJavaSearchConstants.METHOD, IJavaSearchConstants.DECLARATIONS, SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE), new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }, SearchEngine.createWorkspaceScope(), new TraceSearchRequestor(method), new NullProgressMonitor()); } catch (CoreException e) { } }
From source file:com.codenvy.ide.ext.java.server.internal.core.search.matching.VariablePattern.java
License:Open Source License
public VariablePattern(int patternKind, char[] name, int limitTo, int matchRule) { super(patternKind, matchRule); this.fineGrain = limitTo & FINE_GRAIN_MASK; if (this.fineGrain == 0) { switch (limitTo & 0xF) { case IJavaSearchConstants.DECLARATIONS: this.findDeclarations = true; break; case IJavaSearchConstants.REFERENCES: this.readAccess = true; this.writeAccess = true; break; case IJavaSearchConstants.READ_ACCESSES: this.readAccess = true; break; case IJavaSearchConstants.WRITE_ACCESSES: this.writeAccess = true; break; case IJavaSearchConstants.ALL_OCCURRENCES: this.findDeclarations = true; this.readAccess = true; this.writeAccess = true; break; }/* w w w. j a va2s. c om*/ this.findReferences = this.readAccess || this.writeAccess; } this.name = (this.isCaseSensitive || this.isCamelCase) ? name : CharOperation.toLowerCase(name); }
From source file:com.github.ajaxsys.jdtx.utils.JDTUtils.java
License:Open Source License
/** * Find the IMethod in the workspace corresponding to a method signature. * * This doesn't work for elements declared in inner classes. It's possible * this is a 3.2 bug fixed in 3.3//from w w w. ja va 2 s. co m * * @return null if not found */ @Deprecated public static IMethod findJavaMethodInWorkspaceBrokenForInnerClasses(String methodSig) { // dammit ... this doesn't work for inner classes. System.err.println("Search for " + methodSig); SearchPattern p = SearchPattern.createPattern(methodSig, IJavaSearchConstants.METHOD, IJavaSearchConstants.DECLARATIONS, SearchPattern.R_EXACT_MATCH); IJavaSearchScope scope = SearchEngine.createWorkspaceScope(); SearchEngine engine = new SearchEngine(); final Collection<IJavaElement> kludge = new ArrayList<IJavaElement>(); SearchRequestor requestor = new SearchRequestor() { @Override public void acceptSearchMatch(SearchMatch match) throws CoreException { kludge.add((IJavaElement) match.getElement()); } }; try { engine.search(p, new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }, scope, requestor, null); } catch (CoreException e) { e.printStackTrace(); } if (kludge.size() == 1) { return (IMethod) kludge.iterator().next(); } else { System.err.println("RETURNED " + kludge.size() + " " + kludge); return null; } }
From source file:com.github.ajaxsys.jdtx.utils.JDTUtils.java
License:Open Source License
/** * Use the search engine to find all methods in a java element *//*w w w . j a v a2 s. co m*/ public static Collection<IMethod> findMethods(IJavaElement elt) { if (elt instanceof ICompilationUnit) { Collection<IMethod> result = new ArrayList<IMethod>(); for (IType type : getClasses((ICompilationUnit) elt)) { try { for (IMethod m : type.getMethods()) { result.add(m); } } catch (JavaModelException e) { e.printStackTrace(); } } return result; } else { final Collection<IMethod> result = new ArrayList<IMethod>(); SearchPattern p = SearchPattern.createPattern("*", IJavaSearchConstants.METHOD, IJavaSearchConstants.DECLARATIONS, SearchPattern.R_PATTERN_MATCH); SearchPattern p2 = SearchPattern.createPattern("*", IJavaSearchConstants.CONSTRUCTOR, IJavaSearchConstants.DECLARATIONS, SearchPattern.R_PATTERN_MATCH); IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] { elt }, IJavaSearchScope.SOURCES); SearchEngine engine = new SearchEngine(); SearchRequestor requestor = new SearchRequestor() { @Override public void acceptSearchMatch(SearchMatch match) throws CoreException { if (match.getElement() instanceof IMethod) { result.add((IMethod) match.getElement()); } } }; try { engine.search(p, new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }, scope, requestor, null); engine.search(p2, new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }, scope, requestor, null); } catch (CoreException e) { e.printStackTrace(); } return result; } }
From source file:com.google.gwt.eclipse.core.search.JavaQueryParticipantTest.java
License:Open Source License
public void testLimitTo() throws CoreException { IJavaElement element = getTestType1().getField("keith"); QuerySpecification query;//ww w .ja v a2s . c o m // Limit to: references query = new ElementQuerySpecification(element, IJavaSearchConstants.REFERENCES, WORKSPACE_SCOPE, ""); assertSearchMatch(createWindowsTestMatch(990, 5), query); // Limit to: all occurrences (declaration and all references, although in // this case we're only using our search engine so we'll only have refs) query = new ElementQuerySpecification(element, IJavaSearchConstants.ALL_OCCURRENCES, WORKSPACE_SCOPE, ""); assertSearchMatch(createWindowsTestMatch(990, 5), query); // Limit to: read accesses (we don't differentiate between read/write // accesses, so this returns all references) query = new ElementQuerySpecification(element, IJavaSearchConstants.READ_ACCESSES, WORKSPACE_SCOPE, ""); assertSearchMatch(createWindowsTestMatch(990, 5), query); // Limit to: write accesses (we don't differentiate between read/write // accesses, so this returns all references) query = new ElementQuerySpecification(element, IJavaSearchConstants.WRITE_ACCESSES, WORKSPACE_SCOPE, ""); assertSearchMatch(createWindowsTestMatch(990, 5), query); // Limit to: declarations (unsupported) query = new ElementQuerySpecification(element, IJavaSearchConstants.DECLARATIONS, WORKSPACE_SCOPE, ""); assertSearchMatches(NO_MATCHES, query); // Limit to: implementors (unsupported) query = new ElementQuerySpecification(element, IJavaSearchConstants.IMPLEMENTORS, WORKSPACE_SCOPE, ""); assertSearchMatches(NO_MATCHES, query); }
From source file:com.ibm.wala.ide.util.JdtUtil.java
License:Open Source License
/** * Find the IMethod in the workspace corresponding to a method signature. * //w w w . j a va2 s .c o m * This doesn't work for elements declared in inner classes. It's possible this is a 3.2 bug fixed in 3.3 * * @return null if not found */ @Deprecated public static IMethod findJavaMethodInWorkspaceBrokenForInnerClasses(String methodSig) { // dammit ... this doesn't work for inner classes. System.err.println("Search for " + methodSig); SearchPattern p = SearchPattern.createPattern(methodSig, IJavaSearchConstants.METHOD, IJavaSearchConstants.DECLARATIONS, SearchPattern.R_EXACT_MATCH); IJavaSearchScope scope = SearchEngine.createWorkspaceScope(); SearchEngine engine = new SearchEngine(); final Collection<IJavaElement> kludge = HashSetFactory.make(); SearchRequestor requestor = new SearchRequestor() { @Override public void acceptSearchMatch(SearchMatch match) throws CoreException { kludge.add((IJavaElement) match.getElement()); } }; try { engine.search(p, new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }, scope, requestor, null); } catch (CoreException e) { e.printStackTrace(); } if (kludge.size() == 1) { return (IMethod) kludge.iterator().next(); } else { System.err.println("RETURNED " + kludge.size() + " " + kludge); return null; } }
From source file:com.ibm.wala.ide.util.JdtUtil.java
License:Open Source License
/** * Use the search engine to find all methods in a java element */// ww w. j a va 2s. c o m public static Collection<IMethod> findMethods(IJavaElement elt) { if (elt instanceof ICompilationUnit) { Collection<IMethod> result = HashSetFactory.make(); for (IType type : getClasses((ICompilationUnit) elt)) { try { for (IMethod m : type.getMethods()) { result.add(m); } } catch (JavaModelException e) { e.printStackTrace(); } } return result; } else { final Collection<IMethod> result = HashSetFactory.make(); SearchPattern p = SearchPattern.createPattern("*", IJavaSearchConstants.METHOD, IJavaSearchConstants.DECLARATIONS, SearchPattern.R_PATTERN_MATCH); SearchPattern p2 = SearchPattern.createPattern("*", IJavaSearchConstants.CONSTRUCTOR, IJavaSearchConstants.DECLARATIONS, SearchPattern.R_PATTERN_MATCH); IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] { elt }, IJavaSearchScope.SOURCES); SearchEngine engine = new SearchEngine(); SearchRequestor requestor = new SearchRequestor() { @Override public void acceptSearchMatch(SearchMatch match) throws CoreException { if (match.getElement() instanceof IMethod) { result.add((IMethod) match.getElement()); } } }; try { engine.search(p, new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }, scope, requestor, null); engine.search(p2, new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }, scope, requestor, null); } catch (CoreException e) { e.printStackTrace(); } return result; } }
From source file:com.iw.plugins.spindle.ant.AntScriptGenerator.java
License:Mozilla Public License
/** * /*from w ww .ja va 2s .c o m*/ */ private void harvestServletJars(IProgressMonitor monitor) { try { IJavaProject jproject = fTapestryProject.getJavaProject(); if (jproject == null) return; // let's locate all occurances of a package in the project classpath that // we know should be // from the java servlet jar.. SearchPattern pattern = SearchPattern.createPattern("javax.servlet.http", IJavaSearchConstants.PACKAGE, IJavaSearchConstants.DECLARATIONS, SearchPattern.R_EXACT_MATCH); IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] { jproject }); //we could get lots of hits for various reasons so lets collect the ones // we are interested in.. //we collect the roots (jars) that contain the package of interest. final List roots = new ArrayList(); SearchRequestor requestor = new SearchRequestor() { public void acceptSearchMatch(SearchMatch match) throws CoreException { //only keep the roots that are in jar files and that we have not // already seen! Object element = match.getElement(); if (element instanceof IPackageFragment) { IPackageFragment frag = (IPackageFragment) element; if (frag.getKind() == IPackageFragmentRoot.K_BINARY) { IPackageFragmentRoot root = (IPackageFragmentRoot) frag.getParent(); if (!roots.contains(root)) roots.add(root); } } } }; // Search - do the search SearchEngine searchEngine = new SearchEngine(); searchEngine.search(pattern, new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }, scope, requestor, monitor); if (!roots.isEmpty()) fServletAPIRoots = roots; } catch (CoreException e) { UIPlugin.log(e); } }