List of usage examples for org.eclipse.jdt.core.search IJavaSearchConstants CONSTRUCTOR
int CONSTRUCTOR
To view the source code for org.eclipse.jdt.core.search IJavaSearchConstants CONSTRUCTOR.
Click Source Link
From source file:com.android.ide.eclipse.adt.SourceRevealer.java
License:Open Source License
private List<SearchMatch> searchForMethod(String fqmn) { if (fqmn.endsWith(CONSTRUCTOR_NAME)) { fqmn = fqmn.substring(0, fqmn.length() - CONSTRUCTOR_NAME.length() - 1); // -1: dot return searchForPattern(fqmn, IJavaSearchConstants.CONSTRUCTOR, MATCH_IS_METHOD_PREDICATE); }// w w w . j av a 2s .co m if (fqmn.endsWith(CLASS_CONSTRUCTOR)) { // Don't try to search for class init methods: Eclipse will throw NPEs if you do return Collections.emptyList(); } return searchForPattern(fqmn, IJavaSearchConstants.METHOD, MATCH_IS_METHOD_PREDICATE); }
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 *//*from w w w. jav a2 s . c om*/ 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.JavaQueryParticipant.java
License:Open Source License
private Set<IIndexedJavaRef> findMatches(PatternQuerySpecification query) { // Translate the IJavaSearchConstant element type constants to IJavaElement // type constants. int elementType; switch (query.getSearchFor()) { case IJavaSearchConstants.TYPE: elementType = IJavaElement.TYPE; break;/*w w w . j a va2 s . c o m*/ case IJavaSearchConstants.FIELD: elementType = IJavaElement.FIELD; break; case IJavaSearchConstants.METHOD: case IJavaSearchConstants.CONSTRUCTOR: // IJavaElement.METHOD represents both methods & ctors elementType = IJavaElement.METHOD; break; default: // We only support searching for types, fields, methods, and ctors return Collections.emptySet(); } return JavaRefIndex.getInstance().findElementReferences(query.getPattern(), elementType, query.isCaseSensitive()); }
From source file:com.google.gwt.eclipse.core.search.JavaQueryParticipantTest.java
License:Open Source License
public void testPatternSearch() throws CoreException { Match[] expected;//from w ww .j a va 2s .c om // Search for type references by simple name expected = new Match[] { createWindowsTestMatch(840, 50), createWindowsTestMatch(1207, 50), createWindowsTestMatch(1419, 50) }; assertSearchMatches(expected, createQuery("InnerSub", IJavaSearchConstants.TYPE)); // Search for type with different casing expected = new Match[] { createWindowsTestMatch(840, 50), createWindowsTestMatch(1207, 50), createWindowsTestMatch(1419, 50) }; assertSearchMatches(expected, createQuery("innersub", IJavaSearchConstants.TYPE)); // Search for type with different casing with case-sensitive enabled QuerySpecification query = new PatternQuerySpecification("innersub", IJavaSearchConstants.TYPE, true, IJavaSearchConstants.REFERENCES, WORKSPACE_SCOPE, ""); assertSearchMatches(NO_MATCHES, query); // Search for field references assertSearchMatch(createWindowsTestMatch(990, 5), createQuery("keith", IJavaSearchConstants.FIELD)); // Search for method references using * wildcard expected = new Match[] { createWindowsTestMatch(1174, 5), createWindowsTestMatch(1259, 5), createWindowsTestMatch(1340, 8) }; assertSearchMatches(expected, createQuery("sayH*", IJavaSearchConstants.METHOD)); // Search for method references using ? wildcard expected = new Match[] { createWindowsTestMatch(1174, 5), createWindowsTestMatch(1259, 5) }; assertSearchMatches(expected, createQuery("sayH?", IJavaSearchConstants.METHOD)); // Search for constructor references with qualified type name and parameters assertSearchMatch(createWindowsTestMatch(892, 3), createQuery("com.hello.client.JavaQueryParticipantTest.InnerSub.InnerSub(String)", IJavaSearchConstants.CONSTRUCTOR)); }
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 om 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: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;// w w w .j a v a2s . co 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 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();/* w w w. j av a 2 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:nz.ac.massey.cs.care.refactoring.executers.IntroduceFactoryRefactoring.java
License:Open Source License
/** * @param ctor/*from ww w .j a v a2 s . com*/ * @param methodBinding * @return a <code>SearchPattern</code> that finds all calls to the constructor * identified by the argument <code>methodBinding</code>. */ private SearchPattern createSearchPattern(IMethod ctor, IMethodBinding methodBinding) { Assert.isNotNull(methodBinding, RefactoringCoreMessages.IntroduceFactory_noBindingForSelectedConstructor); if (ctor != null) return SearchPattern.createPattern(ctor, IJavaSearchConstants.REFERENCES, SearchUtils.GENERICS_AGNOSTIC_MATCH_RULE); else { // perhaps a synthetic method? (but apparently not always... hmmm...) // Can't find an IMethod for this method, so build a string pattern instead StringBuffer buf = new StringBuffer(); buf.append(methodBinding.getDeclaringClass().getQualifiedName()).append("(");//$NON-NLS-1$ for (int i = 0; i < fArgTypes.length; i++) { if (i != 0) buf.append(","); //$NON-NLS-1$ buf.append(fArgTypes[i].getQualifiedName()); } buf.append(")"); //$NON-NLS-1$ return SearchPattern.createPattern(buf.toString(), IJavaSearchConstants.CONSTRUCTOR, IJavaSearchConstants.REFERENCES, SearchUtils.GENERICS_AGNOSTIC_MATCH_RULE); } }
From source file:org.eclim.plugin.jdt.command.search.SearchCommand.java
License:Open Source License
/** * Translates the string type to the int equivalent. * * @param type The String type./*from w w w .j a va 2 s. c o m*/ * @return The int type. */ protected int getType(String type) { if (TYPE_ANNOTATION.equals(type)) { return IJavaSearchConstants.ANNOTATION_TYPE; } else if (TYPE_CLASS.equals(type)) { return IJavaSearchConstants.CLASS; } else if (TYPE_CLASS_OR_ENUM.equals(type)) { return IJavaSearchConstants.CLASS_AND_ENUM; } else if (TYPE_CLASS_OR_INTERFACE.equals(type)) { return IJavaSearchConstants.CLASS_AND_INTERFACE; } else if (TYPE_CONSTRUCTOR.equals(type)) { return IJavaSearchConstants.CONSTRUCTOR; } else if (TYPE_ENUM.equals(type)) { return IJavaSearchConstants.ENUM; } else if (TYPE_FIELD.equals(type)) { return IJavaSearchConstants.FIELD; } else if (TYPE_INTERFACE.equals(type)) { return IJavaSearchConstants.INTERFACE; } else if (TYPE_METHOD.equals(type)) { return IJavaSearchConstants.METHOD; } else if (TYPE_PACKAGE.equals(type)) { return IJavaSearchConstants.PACKAGE; } return IJavaSearchConstants.TYPE; }
From source file:org.jboss.byteman.eclipse.validation.BytemanJavaValidator.java
License:Open Source License
@Check(CheckType.FAST) public void checkMethodClause(EventMethod eventMethod) { // delete any previous cache of possible trigger methods getContext().remove(RULE_METHOD_KEY); String methodName = eventMethod.getName(); // we can only check the method if we already know the possible classes List<TypeSearchResult> types = (List<TypeSearchResult>) getContext().get(RULE_CLASS_KEY); if (types == null) { error("unknown trigger method " + methodName, BytemanPackage.eINSTANCE.getEventMethod_Name()); } else if (methodName.equals("<clinit>")) { // cannot verify presence of <clinit> via search // just check it has no arguments ParameterTypes parameterTypes = eventMethod.getParameterTypes(); if (parameterTypes != null) { EList<String> paramTypeNames = parameterTypes.getParamTypeNames(); int paramTypeCount = paramTypeNames.size(); if (paramTypeCount != 0) { error("invalid parameter types for class initializer" + methodName, BytemanPackage.eINSTANCE.getEventMethod_ParameterTypes()); }// w w w .ja va 2 s.co m } } else { boolean isConstructor = methodName.equals("<init>"); // look for methods on each of the possible types ParameterTypes parameterTypes = eventMethod.getParameterTypes(); EList<String> paramTypeNames; int paramTypeCount; if (parameterTypes != null) { paramTypeNames = parameterTypes.getParamTypeNames(); paramTypeCount = paramTypeNames.size(); } else { paramTypeNames = null; // -1 indicates any method with the relevant signature will do // whereas 0 indicates an empty parameter list () paramTypeCount = -1; } final List<MethodSearchResult> methods = new ArrayList<MethodSearchResult>(); // accumulate matching methods SearchEngine searchEngine = new SearchEngine(); IJavaSearchScope scope = SearchEngine.createWorkspaceScope(); SearchParticipant[] participants = new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }; for (TypeSearchResult result : types) { String typeName = result.name.replace('$', '.'); // now build type qualified method name StringBuilder builder = new StringBuilder(); builder.append(typeName); // append method name to type name except when it is a constructor or class initializer if (!isConstructor) { builder.append('.'); builder.append(methodName); } if (paramTypeCount >= 0) { String separator = ""; builder.append("("); for (int i = 0; i < paramTypeCount; i++) { builder.append(separator); String paramTypeName = paramTypeNames.get(i); // ho hum eclipse doesn't like $ to separate embedded types if (paramTypeName.indexOf('$') > 0) { paramTypeName = paramTypeName.replace('$', '.'); } builder.append(paramTypeName); separator = ","; } builder.append(")"); } final String stringPattern = builder.toString(); int searchFor = (isConstructor ? IJavaSearchConstants.CONSTRUCTOR : IJavaSearchConstants.METHOD); int limitTo = IJavaSearchConstants.DECLARATIONS; int matchType = SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE; SearchPattern pattern = SearchPattern.createPattern(stringPattern, searchFor, limitTo, matchType); final TypeSearchResult typeResult = result; SearchRequestor requestor = new SearchRequestor() { @Override public void acceptSearchMatch(SearchMatch match) throws CoreException { // only accept if we have an accurate match if (match.getAccuracy() == SearchMatch.A_ACCURATE) { MethodSearchResult methodResult = new MethodSearchResult(stringPattern, typeResult, match); methods.add(methodResult); } } }; try { searchEngine.search(pattern, participants, scope, requestor, null); } catch (CoreException e) { // TODO : ho hum not sure if this will happen when we have // no such method or because something is wrong with paths etc // but just ignore for now } } // if we have no matches then plant an error if (methods.isEmpty()) { error("unknown trigger method " + methodName, BytemanPackage.eINSTANCE.getEventMethod_Name()); } else { // cache details of potential trigger methods for current rule getContext().put(RULE_METHOD_KEY, methods); } } }