List of usage examples for org.eclipse.jdt.core.search SearchPattern R_CASE_SENSITIVE
int R_CASE_SENSITIVE
To view the source code for org.eclipse.jdt.core.search SearchPattern R_CASE_SENSITIVE.
Click Source Link
From source file:bndtools.internal.pkgselection.JavaSearchScopePackageLister.java
License:Open Source License
@Override public String[] getPackages(boolean includeNonSource, IPackageFilter filter) throws PackageListException { final List<IJavaElement> packageList = new LinkedList<IJavaElement>(); final SearchRequestor requestor = new SearchRequestor() { @Override/* www .j a v a 2 s .c om*/ public void acceptSearchMatch(SearchMatch match) throws CoreException { IJavaElement enclosingElement = (IJavaElement) match.getElement(); String name = enclosingElement.getElementName(); if (name.length() > 0) { // Do not include default pkg packageList.add(enclosingElement); } } }; final SearchPattern pattern = SearchPattern.createPattern("*", IJavaSearchConstants.PACKAGE, IJavaSearchConstants.DECLARATIONS, SearchPattern.R_PATTERN_MATCH | SearchPattern.R_CASE_SENSITIVE); IRunnableWithProgress operation = new IRunnableWithProgress() { @Override public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { try { new SearchEngine().search(pattern, SearchUtils.getDefaultSearchParticipants(), scope, requestor, monitor); } catch (CoreException e) { throw new InvocationTargetException(e); } } }; try { runContext.run(true, true, operation); } catch (InvocationTargetException e) { throw new PackageListException(e.getCause()); } catch (InterruptedException e) { throw new PackageListException("Operation interrupted"); } // Remove non-source and excludes Set<String> packageNames = new LinkedHashSet<String>(); for (Iterator<IJavaElement> iter = packageList.iterator(); iter.hasNext();) { boolean omit = false; IJavaElement element = iter.next(); if (!includeNonSource) { IPackageFragment pkgFragment = (IPackageFragment) element; try { if (pkgFragment.getCompilationUnits().length == 0) { omit = true; } } catch (JavaModelException e) { throw new PackageListException(e); } } if (filter != null && !filter.select(element.getElementName())) { omit = true; } if (!omit) { packageNames.add(element.getElementName()); } } return packageNames.toArray(new String[0]); }
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 www . j ava 2 s . com*/ 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.mcgill.cs.swevo.jayfx.FastConverter.java
License:Open Source License
/** * Returns a Java element associated with pElement. This method cannot track * local or anonymous types or any of their members, primitive types, or * array types. It also cannot find initializers, default constructors that * are not explicitly declared, or non-top-level types outside the project * analyzed. If such types are passed as argument, a ConversionException is * thrown./*w w w .j a va2 s .c om*/ * * @param pElement * The element to convert. Never null. * @return Never null. * @throws ConversionException * If the element cannot be */ public IJavaElement getJavaElement(final IElement pElement) throws ConversionException { // assert( pElement!= null ); IJavaElement lReturn = null; if (pElement.getCategory() == Category.CLASS) { lReturn = this.aTypeMap.get(pElement.getId()); if (lReturn == null) // TODO Make this smarter in the case of multiple projects if (this.aTypeMap.size() > 0) try { lReturn = this.aTypeMap.values().iterator().next().getJavaProject() .findType(pElement.getId()); } catch (final JavaModelException pException) { // noting } if (lReturn == null) throw new ConversionException("Cannot find type " + pElement); } else if (pElement.getCategory() == Category.PACKAGE) { String id = pElement.getId(); final SearchPattern pattern = SearchPattern.createPattern(id, IJavaSearchConstants.PACKAGE, IJavaSearchConstants.DECLARATIONS, SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE); Collection<SearchMatch> matches = SearchEngineUtil.search(pattern, null); if (matches.isEmpty()) throw new ConversionException("Cannot find type " + pElement); else lReturn = (IJavaElement) matches.iterator().next().getElement(); } else { final IJavaElement lDeclaringClass = this.getJavaElement(pElement.getDeclaringClass()); if (pElement.getCategory() == Category.FIELD) { lReturn = ((IType) lDeclaringClass).getField(((FieldElement) pElement).getSimpleName()); if (lReturn == null) throw new ConversionException("Cannot find field " + pElement); } else if (pElement.getCategory() == Category.METHOD) try { final IMethod[] lMethods = ((IType) lDeclaringClass).getMethods(); lReturn = this.findMethod((MethodElement) pElement, lMethods); // if( lReturn == null && // isDefaultConstructor((MethodElement)pElement)) { // // } if (lReturn == null) throw new ConversionException("Cannot find method " + pElement); } catch (final JavaModelException pException) { throw new ConversionException("Cannot convert method " + pElement); } else throw new ConversionException("Unsupported element type " + pElement.getClass().getName()); } // assert( lReturn != null ); return lReturn; }
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 *//* w w w . j av a2s. c o m*/ 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.layout.gle2.CustomViewFinder.java
License:Open Source License
private Pair<List<String>, List<String>> findViews(final boolean layoutsOnly) { final Set<String> customViews = new HashSet<String>(); final Set<String> thirdPartyViews = new HashSet<String>(); ProjectState state = Sdk.getProjectState(mProject); final List<IProject> libraries = state != null ? state.getFullLibraryProjects() : Collections.<IProject>emptyList(); SearchRequestor requestor = new SearchRequestor() { @Override//from w w w . jav a 2s .c om public void acceptSearchMatch(SearchMatch match) throws CoreException { // Ignore matches in comments if (match.isInsideDocComment()) { return; } Object element = match.getElement(); if (element instanceof ResolvedBinaryType) { // Third party view ResolvedBinaryType type = (ResolvedBinaryType) element; IPackageFragment fragment = type.getPackageFragment(); IPath path = fragment.getPath(); String last = path.lastSegment(); // Filter out android.jar stuff if (last.equals(FN_FRAMEWORK_LIBRARY)) { return; } if (!isValidView(type, layoutsOnly)) { return; } IProject matchProject = match.getResource().getProject(); if (mProject == matchProject || libraries.contains(matchProject)) { String fqn = type.getFullyQualifiedName(); thirdPartyViews.add(fqn); } } else if (element instanceof ResolvedSourceType) { // User custom view IProject matchProject = match.getResource().getProject(); if (mProject == matchProject || libraries.contains(matchProject)) { ResolvedSourceType type = (ResolvedSourceType) element; if (!isValidView(type, layoutsOnly)) { return; } String fqn = type.getFullyQualifiedName(); fqn = fqn.replace('$', '.'); customViews.add(fqn); } } } }; try { IJavaProject javaProject = BaseProjectHelper.getJavaProject(mProject); if (javaProject != null) { String className = layoutsOnly ? CLASS_VIEWGROUP : CLASS_VIEW; IType viewType = javaProject.findType(className); if (viewType != null) { IJavaSearchScope scope = SearchEngine.createHierarchyScope(viewType); SearchParticipant[] participants = new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }; int matchRule = SearchPattern.R_PATTERN_MATCH | SearchPattern.R_CASE_SENSITIVE; SearchPattern pattern = SearchPattern.createPattern("*", IJavaSearchConstants.CLASS, IJavaSearchConstants.IMPLEMENTORS, matchRule); SearchEngine engine = new SearchEngine(); engine.search(pattern, participants, scope, requestor, new NullProgressMonitor()); } } } catch (CoreException e) { AdtPlugin.log(e, null); } List<String> custom = new ArrayList<String>(customViews); List<String> thirdParty = new ArrayList<String>(thirdPartyViews); if (!layoutsOnly) { // Update our cached answers (unless we were filtered on only layouts) mCustomViews = custom; mThirdPartyViews = thirdParty; } return Pair.of(custom, thirdParty); }
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 *///from w w w. java 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(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> 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 . ja v a2s . c o 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.auidt.internal.editors.layout.gle2.CustomViewFinder.java
License:Open Source License
private Pair<List<String>, List<String>> findViews(final boolean layoutsOnly) { final Set<String> customViews = new HashSet<String>(); final Set<String> thirdPartyViews = new HashSet<String>(); ProjectState state = Sdk.getProjectState(mProject); final List<IProject> libraries = state != null ? state.getFullLibraryProjects() : Collections.<IProject>emptyList(); SearchRequestor requestor = new SearchRequestor() { @Override//from w w w .ja v a 2s . c o m public void acceptSearchMatch(SearchMatch match) throws CoreException { // Ignore matches in comments if (match.isInsideDocComment()) { return; } Object element = match.getElement(); if (element instanceof ResolvedBinaryType) { // Third party view ResolvedBinaryType type = (ResolvedBinaryType) element; IPackageFragment fragment = type.getPackageFragment(); IPath path = fragment.getPath(); String last = path.lastSegment(); // Filter out android.jar stuff /* if (last.equals(FN_FRAMEWORK_LIBRARY)) { return; }*/ if (last.equals(FN_FRAMEWORK_LIBRARY)) { return; } if (!isValidView(type, layoutsOnly)) { return; } IProject matchProject = match.getResource().getProject(); if (mProject == matchProject || libraries.contains(matchProject)) { String fqn = type.getFullyQualifiedName(); thirdPartyViews.add(fqn); } } else if (element instanceof ResolvedSourceType) { // User custom view IProject matchProject = match.getResource().getProject(); if (mProject == matchProject || libraries.contains(matchProject)) { ResolvedSourceType type = (ResolvedSourceType) element; if (!isValidView(type, layoutsOnly)) { return; } String fqn = type.getFullyQualifiedName(); fqn = fqn.replace('$', '.'); customViews.add(fqn); } } } }; try { IJavaProject javaProject = BaseProjectHelper.getJavaProject(mProject); if (javaProject != null) { String className = layoutsOnly ? CLASS_VIEWGROUP : CLASS_VIEW; IType viewType = javaProject.findType(className); if (viewType != null) { IJavaSearchScope scope = SearchEngine.createHierarchyScope(viewType); SearchParticipant[] participants = new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }; int matchRule = SearchPattern.R_PATTERN_MATCH | SearchPattern.R_CASE_SENSITIVE; SearchPattern pattern = SearchPattern.createPattern("*", IJavaSearchConstants.CLASS, IJavaSearchConstants.IMPLEMENTORS, matchRule); SearchEngine engine = new SearchEngine(); engine.search(pattern, participants, scope, requestor, new NullProgressMonitor()); } } } catch (CoreException e) { AdtPlugin.log(e, null); } List<String> custom = new ArrayList<String>(customViews); List<String> thirdParty = new ArrayList<String>(thirdPartyViews); if (!layoutsOnly) { // Update our cached answers (unless we were filtered on only layouts) mCustomViews = custom; mThirdPartyViews = thirdParty; } return Pair.of(custom, thirdParty); }
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 {// w w w . j a v a2 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 {/* w w w . jav a 2 s . com*/ 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) { } }