List of usage examples for org.eclipse.jdt.core.search IJavaSearchConstants METHOD
int METHOD
To view the source code for org.eclipse.jdt.core.search IJavaSearchConstants METHOD.
Click Source Link
From source file:ca.ecliptical.pde.ds.search.DescriptorQueryParticipant.java
License:Open Source License
public void search(ISearchRequestor requestor, QuerySpecification query, IProgressMonitor monitor) throws CoreException { if (debug.isDebugging()) debug.trace(String.format("Query: %s", query)); //$NON-NLS-1$ // we only look for straight references switch (query.getLimitTo()) { case IJavaSearchConstants.REFERENCES: case IJavaSearchConstants.ALL_OCCURRENCES: break;/*from w w w . j ava2 s . c o m*/ default: return; } // we only look for types and methods if (query instanceof ElementQuerySpecification) { searchElement = ((ElementQuerySpecification) query).getElement(); switch (searchElement.getElementType()) { case IJavaElement.TYPE: case IJavaElement.METHOD: break; default: return; } } else { String pattern = ((PatternQuerySpecification) query).getPattern(); boolean ignoreMethodParams = false; searchFor = ((PatternQuerySpecification) query).getSearchFor(); switch (searchFor) { case IJavaSearchConstants.UNKNOWN: case IJavaSearchConstants.METHOD: int leftParen = pattern.lastIndexOf('('); int rightParen = pattern.indexOf(')'); ignoreMethodParams = leftParen == -1 || rightParen == -1 || leftParen >= rightParen; // no break case IJavaSearchConstants.TYPE: case IJavaSearchConstants.CLASS: case IJavaSearchConstants.CLASS_AND_INTERFACE: case IJavaSearchConstants.CLASS_AND_ENUM: case IJavaSearchConstants.INTERFACE: case IJavaSearchConstants.INTERFACE_AND_ANNOTATION: break; default: return; } // searchPattern = PatternConstructor.createPattern(pattern, ((PatternQuerySpecification) query).isCaseSensitive()); int matchMode = getMatchMode(pattern) | SearchPattern.R_ERASURE_MATCH; if (((PatternQuerySpecification) query).isCaseSensitive()) matchMode |= SearchPattern.R_CASE_SENSITIVE; searchPattern = new SearchPatternDescriptor(pattern, matchMode, ignoreMethodParams); } HashSet<IPath> scope = new HashSet<IPath>(); for (IPath path : query.getScope().enclosingProjectsAndJars()) { scope.add(path); } if (scope.isEmpty()) return; this.requestor = requestor; // look through all active bundles IPluginModelBase[] wsModels = PluginRegistry.getWorkspaceModels(); IPluginModelBase[] exModels = PluginRegistry.getExternalModels(); monitor.beginTask(Messages.DescriptorQueryParticipant_taskName, wsModels.length + exModels.length); try { // workspace models for (IPluginModelBase model : wsModels) { if (monitor.isCanceled()) throw new OperationCanceledException(); if (!model.isEnabled() || !(model instanceof IBundlePluginModelBase)) { monitor.worked(1); if (debug.isDebugging()) debug.trace(String.format("Non-bundle model: %s", model)); //$NON-NLS-1$ continue; } IProject project = model.getUnderlyingResource().getProject(); if (!scope.contains(project.getFullPath())) { monitor.worked(1); if (debug.isDebugging()) debug.trace(String.format("Project out of scope: %s", project.getName())); //$NON-NLS-1$ continue; } // we can only search in Java bundle projects (for now) if (!project.hasNature(JavaCore.NATURE_ID)) { monitor.worked(1); if (debug.isDebugging()) debug.trace(String.format("Non-Java project: %s", project.getName())); //$NON-NLS-1$ continue; } PDEModelUtility.modifyModel(new ModelModification(project) { @Override protected void modifyModel(IBaseModel model, IProgressMonitor monitor) throws CoreException { if (model instanceof IBundlePluginModelBase) searchBundle((IBundlePluginModelBase) model, monitor); } }, new SubProgressMonitor(monitor, 1)); } // external models SearchablePluginsManager spm = PDECore.getDefault().getSearchablePluginsManager(); IJavaProject javaProject = spm.getProxyProject(); if (javaProject == null || !javaProject.exists() || !javaProject.isOpen()) { monitor.worked(exModels.length); if (debug.isDebugging()) debug.trace("External Plug-in Search project inaccessible!"); //$NON-NLS-1$ return; } for (IPluginModelBase model : exModels) { if (monitor.isCanceled()) throw new OperationCanceledException(); BundleDescription bd; if (!model.isEnabled() || (bd = model.getBundleDescription()) == null) { monitor.worked(1); if (debug.isDebugging()) debug.trace(String.format("Non-bundle model: %s", model)); //$NON-NLS-1$ continue; } // check scope ArrayList<IClasspathEntry> cpEntries = new ArrayList<IClasspathEntry>(); ClasspathUtilCore.addLibraries(model, cpEntries); ArrayList<IPath> cpEntryPaths = new ArrayList<IPath>(cpEntries.size()); for (IClasspathEntry cpEntry : cpEntries) { cpEntryPaths.add(cpEntry.getPath()); } cpEntryPaths.retainAll(scope); if (cpEntryPaths.isEmpty()) { monitor.worked(1); if (debug.isDebugging()) debug.trace(String.format("External bundle out of scope: %s", model.getInstallLocation())); //$NON-NLS-1$ continue; } if (!spm.isInJavaSearch(bd.getSymbolicName())) { monitor.worked(1); if (debug.isDebugging()) debug.trace(String.format("Non-searchable external model: %s", bd.getSymbolicName())); //$NON-NLS-1$ continue; } searchBundle(model, javaProject, new SubProgressMonitor(monitor, 1)); } } finally { monitor.done(); } }
From source file:ca.ecliptical.pde.ds.search.DescriptorQueryParticipant.java
License:Open Source License
private void searchModel(DSModel dsModel, IJavaProject javaProject, Object matchElement, IProgressMonitor monitor) throws CoreException { IDSComponent component = dsModel.getDSComponent(); if (component == null) { if (debug.isDebugging()) debug.trace(String.format("No component definition found in file: %s", //$NON-NLS-1$ dsModel.getUnderlyingResource() == null ? dsModel.getInstallLocation() : dsModel.getUnderlyingResource().getFullPath())); // TODO de-uglify! return;//from w ww .j av a 2 s .co m } IDSImplementation impl = component.getImplementation(); if (impl == null) { if (debug.isDebugging()) debug.trace(String.format("No component implementation found in file: %s", //$NON-NLS-1$ dsModel.getUnderlyingResource() == null ? dsModel.getInstallLocation() : dsModel.getUnderlyingResource().getFullPath())); // TODO de-uglify! return; } IType implClassType = null; String implClassName = impl.getClassName(); if (implClassName != null) implClassType = javaProject.findType(implClassName, monitor); if ((searchElement != null && searchElement.getElementType() == IJavaElement.TYPE) || searchFor == IJavaSearchConstants.TYPE || searchFor == IJavaSearchConstants.CLASS || searchFor == IJavaSearchConstants.CLASS_AND_INTERFACE || searchFor == IJavaSearchConstants.CLASS_AND_ENUM || searchFor == IJavaSearchConstants.UNKNOWN) { // match specific type references if (matches(searchElement, searchPattern, implClassType)) reportMatch(requestor, impl.getDocumentAttribute(IDSConstants.ATTRIBUTE_IMPLEMENTATION_CLASS), matchElement); } if ((searchElement != null && searchElement.getElementType() == IJavaElement.TYPE) || searchFor == IJavaSearchConstants.TYPE || searchFor == IJavaSearchConstants.CLASS || searchFor == IJavaSearchConstants.CLASS_AND_INTERFACE || searchFor == IJavaSearchConstants.CLASS_AND_ENUM || searchFor == IJavaSearchConstants.INTERFACE || searchFor == IJavaSearchConstants.INTERFACE_AND_ANNOTATION || searchFor == IJavaSearchConstants.UNKNOWN) { IDSService service = component.getService(); if (service != null) { IDSProvide[] provides = service.getProvidedServices(); if (provides != null) { for (IDSProvide provide : provides) { String ifaceName = provide.getInterface(); IType ifaceType = javaProject.findType(ifaceName, monitor); if (matches(searchElement, searchPattern, ifaceType)) reportMatch(requestor, provide.getDocumentAttribute(IDSConstants.ATTRIBUTE_PROVIDE_INTERFACE), matchElement); } } } IDSReference[] references = component.getReferences(); if (references != null) { for (IDSReference reference : references) { String ifaceName = reference.getReferenceInterface(); IType ifaceType = javaProject.findType(ifaceName, monitor); if (matches(searchElement, searchPattern, ifaceType)) reportMatch(requestor, reference.getDocumentAttribute(IDSConstants.ATTRIBUTE_REFERENCE_INTERFACE), matchElement); } } } if ((searchElement != null && searchElement.getElementType() == IJavaElement.METHOD) || searchFor == IJavaSearchConstants.METHOD || searchFor == IJavaSearchConstants.UNKNOWN) { // match specific method references String activate = component.getActivateMethod(); if (activate == null) activate = "activate"; //$NON-NLS-1$ IMethod activateMethod = findActivateMethod(implClassType, activate, monitor); if (matches(searchElement, searchPattern, activateMethod)) { if (component.getActivateMethod() == null) reportMatch(requestor, component, matchElement); else reportMatch(requestor, component.getDocumentAttribute(IDSConstants.ATTRIBUTE_COMPONENT_ACTIVATE), matchElement); } String modified = component.getModifiedMethod(); if (modified != null) { IMethod modifiedMethod = findActivateMethod(implClassType, modified, monitor); if (matches(searchElement, searchPattern, modifiedMethod)) reportMatch(requestor, component.getDocumentAttribute(IDSConstants.ATTRIBUTE_COMPONENT_MODIFIED), matchElement); } String deactivate = component.getDeactivateMethod(); if (deactivate == null) deactivate = "deactivate"; //$NON-NLS-1$ IMethod deactivateMethod = findDeactivateMethod(implClassType, deactivate, monitor); if (matches(searchElement, searchPattern, deactivateMethod)) { if (component.getDeactivateMethod() == null) reportMatch(requestor, component, matchElement); else reportMatch(requestor, component.getDocumentAttribute(IDSConstants.ATTRIBUTE_COMPONENT_DEACTIVATE), matchElement); } IDSReference[] references = component.getReferences(); if (references != null) { for (IDSReference reference : references) { String refIface = reference.getReferenceInterface(); if (refIface == null) { if (debug.isDebugging()) debug.trace(String.format("No reference interface specified: %s", reference)); //$NON-NLS-1$ continue; } String bind = reference.getReferenceBind(); if (bind != null) { IMethod bindMethod = findBindMethod(implClassType, bind, refIface, monitor); if (matches(searchElement, searchPattern, bindMethod)) reportMatch(requestor, reference.getDocumentAttribute(IDSConstants.ATTRIBUTE_REFERENCE_BIND), matchElement); } String unbind = reference.getReferenceUnbind(); if (unbind != null) { IMethod unbindMethod = findBindMethod(implClassType, unbind, refIface, monitor); if (matches(searchElement, searchPattern, unbindMethod)) reportMatch(requestor, reference.getDocumentAttribute(IDSConstants.ATTRIBUTE_REFERENCE_UNBIND), matchElement); } String updated = reference.getXMLAttributeValue("updated"); //$NON-NLS-1$ if (updated != null) { IMethod updatedMethod = findUpdatedMethod(implClassType, updated, monitor); if (matches(searchElement, searchPattern, updatedMethod)) reportMatch(requestor, reference.getDocumentAttribute("updated"), matchElement); //$NON-NLS-1$ } } } } }
From source file:ca.uvic.chisel.javasketch.internal.JavaSearchUtils.java
License:Open Source License
public static SearchPattern createMethodDeclarationPattern(ITraceClassMethod method) { if (method == null) { return null; }/*from w w w .ja v a 2 s. c o m*/ ITraceClass callingClass = method.getTraceClass(); if (callingClass == null) { return null; } String className = callingClass.getName(); className = Signature.toString(className); boolean isConstructor = false; String methodName = method.getName(); isConstructor = methodName.startsWith("<init"); if (isConstructor) { int lastDotIndex = className.lastIndexOf('.'); if (lastDotIndex >= 0) { methodName = className.substring(lastDotIndex + 1); } } String methodString = Signature.toString(method.getSignature(), methodName, null, false, true); String returnType = ""; if (!isConstructor) { int returnIndex = methodString.indexOf(' '); if (returnIndex > 0) { returnType = " " + methodString.substring(0, returnIndex); methodString = methodString.substring(returnIndex + 1, methodString.length()); } } return SearchPattern.createPattern(className + '.' + methodString + returnType, IJavaSearchConstants.METHOD, IJavaSearchConstants.DECLARATIONS, SearchPattern.R_EXACT_MATCH); }
From source file:ccw.editors.clojure.ClojureProposalProcessor.java
License:Open Source License
private List<ICompletionProposal> computeAndAddJavaInstanceMethodCompletionProposal( final PrefixInfo prefixInfo) { final List<ICompletionProposal> proposals = new ArrayList<ICompletionProposal>(); if (!checkJavaPrefixLength(prefixInfo)) { return Collections.emptyList(); }//w w w.j a v a2 s. c o m final String methodPrefix = prefixInfo.prefix.substring(1); System.out.println("method prefix:" + methodPrefix); boolean isPattern = (methodPrefix.contains("*") || methodPrefix.contains("?")); boolean autoAddEndWildcard = isPattern && !methodPrefix.endsWith("*"); SearchPattern pattern = SearchPattern.createPattern(autoAddEndWildcard ? methodPrefix + "*" : methodPrefix, IJavaSearchConstants.METHOD, // | IJavaSearchConstants.FIELD, // IJavaSearchConstants.TYPE, IJavaSearchConstants.DECLARATIONS, isPattern ? SearchPattern.R_PATTERN_MATCH : SearchPattern.R_PREFIX_MATCH); if (pattern != null) { IJavaProject editedFileProject = editor.getAssociatedProject(); if (editedFileProject != null) { IJavaSearchScope scope = SearchEngine .createJavaSearchScope(new IJavaElement[] { editedFileProject }); SearchRequestor requestor = new SearchRequestor() { private int counter; @Override public void beginReporting() { super.beginReporting(); System.out.println("begin reporting"); counter = 0; } @Override public void acceptSearchMatch(SearchMatch match) throws CoreException { counter++; if (counter >= MAX_JAVA_SEARCH_RESULT_NUMBER) { System.out.println("too much results (>" + MAX_JAVA_SEARCH_RESULT_NUMBER + "), throwing exception"); throw new CoreException(Status.OK_STATUS); } proposals.add(new MethodLazyCompletionProposal((IMethod) match.getElement(), methodPrefix, prefixInfo.prefixOffset + 1, null, editor)); } @Override public void endReporting() { super.endReporting(); System.out.println("end reporting : count=" + counter); } }; SearchEngine searchEngine = new SearchEngine(); try { searchEngine.search(pattern, new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }, scope, requestor, null /* no progress monitor */); assistant.setStatusMessage(MESSAGE_JAVA_COMPLETION); } catch (CoreException e) { if (e.getStatus() != Status.OK_STATUS) { CCWPlugin.logWarning("java code proposal search error in clojure dev", e); } else { errorMessage = ERROR_MESSAGE_TOO_MANY_COMPLETIONS; assistant.setStatusMessage(ERROR_MESSAGE_TOO_MANY_COMPLETIONS); } } } } return proposals; }
From source file:com.android.ide.eclipse.adt.internal.editors.Hyperlinks.java
License:Open Source License
/** * Opens a Java method referenced by the given on click attribute method name * * @param project the project containing the click handler * @param method the method name of the on click handler * @return true if the method was opened, false otherwise *///from ww w. j a va 2s .c om public static boolean openOnClickMethod(IProject project, String method) { // Search for the method in the Java index, filtering by the required click handler // method signature (public and has a single View parameter), and narrowing the scope // first to Activity classes, then to the whole workspace. final AtomicBoolean success = new AtomicBoolean(false); SearchRequestor requestor = new SearchRequestor() { @Override public void acceptSearchMatch(SearchMatch match) throws CoreException { Object element = match.getElement(); if (element instanceof IMethod) { IMethod methodElement = (IMethod) element; String[] parameterTypes = methodElement.getParameterTypes(); if (parameterTypes != null && parameterTypes.length == 1 && ("Qandroid.view.View;".equals(parameterTypes[0]) //$NON-NLS-1$ || "QView;".equals(parameterTypes[0]))) { //$NON-NLS-1$ // Check that it's public if (Flags.isPublic(methodElement.getFlags())) { JavaUI.openInEditor(methodElement); success.getAndSet(true); } } } } }; try { IJavaSearchScope scope = null; IType activityType = null; IJavaProject javaProject = BaseProjectHelper.getJavaProject(project); if (javaProject != null) { activityType = javaProject.findType(CLASS_ACTIVITY); if (activityType != null) { scope = SearchEngine.createHierarchyScope(activityType); } } if (scope == null) { scope = SearchEngine.createWorkspaceScope(); } SearchParticipant[] participants = new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }; int matchRule = SearchPattern.R_PATTERN_MATCH | SearchPattern.R_CASE_SENSITIVE; SearchPattern pattern = SearchPattern.createPattern("*." + method, IJavaSearchConstants.METHOD, IJavaSearchConstants.DECLARATIONS, matchRule); SearchEngine engine = new SearchEngine(); engine.search(pattern, participants, scope, requestor, new NullProgressMonitor()); boolean ok = success.get(); if (!ok && activityType != null) { // TODO: Create a project+dependencies scope and search only that scope // Try searching again with a complete workspace scope this time scope = SearchEngine.createWorkspaceScope(); engine.search(pattern, participants, scope, requestor, new NullProgressMonitor()); // TODO: There could be more than one match; add code to consider them all // and pick the most likely candidate and open only that one. ok = success.get(); } return ok; } catch (CoreException e) { AdtPlugin.log(e, null); } return false; }
From source file:com.android.ide.eclipse.adt.internal.editors.xml.Hyperlinks.java
License:Open Source License
/** * Opens a Java method referenced by the given on click attribute method name * * @param project the project containing the click handler * @param method the method name of the on click handler * @return true if the method was opened, false otherwise *//* w ww . j a v a 2 s . c om*/ public static boolean openOnClickMethod(IProject project, String method) { // Search for the method in the Java index, filtering by the required click handler // method signature (public and has a single View parameter), and narrowing the scope // first to Activity classes, then to the whole workspace. final AtomicBoolean success = new AtomicBoolean(false); SearchRequestor requestor = new SearchRequestor() { @Override public void acceptSearchMatch(SearchMatch match) throws CoreException { Object element = match.getElement(); if (element instanceof IMethod) { IMethod methodElement = (IMethod) element; String[] parameterTypes = methodElement.getParameterTypes(); if (parameterTypes != null && parameterTypes.length == 1 && ("Qandroid.view.View;".equals(parameterTypes[0]) //$NON-NLS-1$ || "QView;".equals(parameterTypes[0]))) { //$NON-NLS-1$ // Check that it's public if (Flags.isPublic(methodElement.getFlags())) { JavaUI.openInEditor(methodElement); success.getAndSet(true); } } } } }; try { IJavaSearchScope scope = null; IType activityType = null; IJavaProject javaProject = BaseProjectHelper.getJavaProject(project); if (javaProject != null) { activityType = javaProject.findType(SdkConstants.CLASS_ACTIVITY); if (activityType != null) { scope = SearchEngine.createHierarchyScope(activityType); } } if (scope == null) { scope = SearchEngine.createWorkspaceScope(); } SearchParticipant[] participants = new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }; int matchRule = SearchPattern.R_PATTERN_MATCH | SearchPattern.R_CASE_SENSITIVE; SearchPattern pattern = SearchPattern.createPattern("*." + method, IJavaSearchConstants.METHOD, IJavaSearchConstants.DECLARATIONS, matchRule); SearchEngine engine = new SearchEngine(); engine.search(pattern, participants, scope, requestor, new NullProgressMonitor()); boolean ok = success.get(); if (!ok && activityType != null) { // TODO: Create a project+dependencies scope and search only that scope // Try searching again with a complete workspace scope this time scope = SearchEngine.createWorkspaceScope(); engine.search(pattern, participants, scope, requestor, new NullProgressMonitor()); // TODO: There could be more than one match; add code to consider them all // and pick the most likely candidate and open only that one. ok = success.get(); } return ok; } catch (CoreException e) { AdtPlugin.log(e, null); } return false; }
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); }//from w ww .j a va 2s.com 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.android.ide.eclipse.auidt.SourceRevealer.java
License:Open Source License
private List<SearchMatch> searchForMethod(String fqmn) { return searchForPattern(fqmn, IJavaSearchConstants.METHOD, MATCH_IS_METHOD_PREDICATE); }
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 {// ww w .j a v a 2s. 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 {// w w w . j a va 2 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) { } }