List of usage examples for org.eclipse.jdt.core.search SearchPattern R_FULL_MATCH
int R_FULL_MATCH
To view the source code for org.eclipse.jdt.core.search SearchPattern R_FULL_MATCH.
Click Source Link
From source file:edu.washington.cs.cupid.scripting.java.quickfix.ClasspathProcessor.java
License:Open Source License
private List<IJavaCompletionProposal> buildMissingBundleProposals(final IInvocationContext context, final IProblemLocation location) { final List<IJavaCompletionProposal> proposals = Lists.newArrayList(); String className = location.getProblemArguments()[0]; SearchRequestor requestor = new SearchRequestor() { @Override/*from w w w . j a v a 2 s . c o m*/ public void acceptSearchMatch(SearchMatch match) throws CoreException { if (match instanceof TypeDeclarationMatch) { if (match.getElement() instanceof IType) { IType type = (IType) match.getElement(); Bundle bundle = null; try { bundle = ClasspathUtil.bundleForClass(type.getFullyQualifiedName()); } catch (ClassNotFoundException e) { throw new RuntimeException("Internal error finding bundle for class ", e); } proposals.add( new AddBundleCompletion(context.getCompilationUnit().getJavaProject(), bundle)); } else { throw new RuntimeException("Unexpected match of type " + match.getElement().getClass()); } } } }; SearchEngine engine = new SearchEngine(); try { engine.search( SearchPattern.createPattern(className, IJavaSearchConstants.TYPE, IJavaSearchConstants.DECLARATIONS, SearchPattern.R_FULL_MATCH), // pattern new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }, SearchEngine.createWorkspaceScope(), //scope, requestor, // searchRequestor null // progress monitor ); } catch (CoreException ex) { // NO OP } return proposals; }
From source file:edu.washington.cs.cupid.wizards.TypeUtil.java
License:Open Source License
/** * Search for <code>className</code> in the workspace. * @param className a simple or qualified class name * @return instances of the type/*from w ww. j a va 2s . com*/ * @throws CoreException if an error occurred during the search */ public static List<IType> fetchTypes(String className) throws CoreException { if (className == null) { throw new NullPointerException("Class name to search for cannot be null"); } final List<IType> result = Lists.newArrayList(); SearchRequestor requestor = new SearchRequestor() { @Override public void acceptSearchMatch(SearchMatch match) throws CoreException { if (match instanceof TypeDeclarationMatch) { if (match.getElement() instanceof IType) { result.add((IType) match.getElement()); } else { throw new RuntimeException("Unexpected match of type " + match.getElement().getClass()); } } } }; SearchEngine engine = new SearchEngine(); engine.search( SearchPattern.createPattern(className, IJavaSearchConstants.TYPE, IJavaSearchConstants.DECLARATIONS, SearchPattern.R_FULL_MATCH), // pattern new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }, SearchEngine.createWorkspaceScope(), //scope, requestor, // searchRequestor null // progress monitor ); return result; }
From source file:org.eclipse.mat.jdt.OpenSourceFileJob.java
License:Open Source License
private void collectMatches(IProgressMonitor monitor) throws JavaModelException { matches = new ArrayList<IType>(); new SearchEngine().searchAllTypeNames(packageName != null ? packageName.toCharArray() : null, // SearchPattern.R_FULL_MATCH | SearchPattern.R_CASE_SENSITIVE, // typeName.toCharArray(), // SearchPattern.R_FULL_MATCH | SearchPattern.R_CASE_SENSITIVE, // IJavaSearchConstants.TYPE, // SearchEngine.createWorkspaceScope(), // new TypeNameMatchRequestor() { @Override//from w w w.j ava 2 s .com public void acceptTypeNameMatch(TypeNameMatch match) { try { IType type = match.getType(); type = resolveInnerTypes(type); matches.add(type); } catch (JavaModelException e) { throw new RuntimeException(e); } } }, // IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, // monitor); }
From source file:org.eclipse.recommenders.rcp.JavaElementResolver.java
License:Open Source License
private Optional<IType> resolveType(final ITypeName recType) { // TODO woah, what a hack just to find a nested/anonymous type... this // definitely needs refactoring! ensureIsNotNull(recType);//from w ww . j av a2s .co m if (recType.isArrayType()) { // TODO see https://bugs.eclipse.org/bugs/show_bug.cgi?id=339806 // should throw an exception? or return an Array type? log(ERROR_ARRAY_TYPE_IN_JAVA_ELEMENT_RESOLVER, recType); return absent(); } if (recType.isNestedType()) { final ITypeName declaringType = recType.getDeclaringType(); final String simpleName = StringUtils.substringAfterLast(recType.getIdentifier(), "$"); //$NON-NLS-1$ final IType parent = resolveType(declaringType).orNull(); if (parent != null) { try { for (final IType nested : parent.getTypes()) { final String key = nested.getKey(); if (key.equals(recType.getIdentifier() + ';')) { return fromNullable(nested); } } for (final IMethod m : parent.getMethods()) { for (final IJavaElement children : m.getChildren()) { if (children instanceof IType) { final IType nested = (IType) children; if (nested.getKey().endsWith(simpleName + ';')) { return of(nested); } final String key = nested.getKey(); if (key.equals(recType.getIdentifier() + ';')) { return fromNullable(nested); } } } } } catch (final Exception x) { return absent(); } } return absent(); } final IType[] res = new IType[1]; final IJavaSearchScope scope = SearchEngine.createWorkspaceScope(); final SearchEngine search = new SearchEngine(); final String srcTypeName = Names.vm2srcTypeName(recType.getIdentifier()); final SearchPattern pattern = SearchPattern.createPattern(srcTypeName, IJavaSearchConstants.TYPE, IJavaSearchConstants.DECLARATIONS, SearchPattern.R_FULL_MATCH); try { search.search(pattern, SearchUtils.getDefaultSearchParticipants(), scope, new SearchRequestor() { @Override public void acceptSearchMatch(final SearchMatch match) throws CoreException { IType element = (IType) match.getElement(); // with the current settings the engine matches 'Lnull' with 'Ljava/lang/ref/ReferenceQueue$Null' if (toRecType(element).equals(recType)) { res[0] = element; } } }, null); } catch (final CoreException e) { throwUnhandledException(e); } return fromNullable(res[0]); }
From source file:org.eclipse.recommenders.utils.rcp.JavaElementResolver.java
License:Open Source License
private Optional<IType> resolveType(final ITypeName recType) { // TODO woah, what a hack just to find a nested/anonymous type... this // definitely needs refactoring! ensureIsNotNull(recType);//from w w w. j a va 2s .c o m if (recType.isArrayType()) { // TODO see https://bugs.eclipse.org/bugs/show_bug.cgi?id=339806 // should throw an exception? or return an Array type? System.err.println("array type in JavaElementResolver. Decision bug 339806 pending...?"); return absent(); } if (recType.isNestedType()) { final ITypeName declaringType = recType.getDeclaringType(); final String simpleName = StringUtils.substringAfterLast(recType.getIdentifier(), "$"); final IType parent = resolveType(declaringType).orNull(); if (parent != null) { try { for (final IType nested : parent.getTypes()) { final String key = nested.getKey(); if (key.equals(recType.getIdentifier() + ";")) { return fromNullable(nested); } } // int count = 0; for (final IMethod m : parent.getMethods()) { for (final IJavaElement children : m.getChildren()) { if (children instanceof IType) { final IType nested = (IType) children; // count++; if (nested.getKey().endsWith(simpleName + ";")) { return of(nested); } // if (String.valueOf(count).equals(simpleName)) { // return of(nested); // } final String key = nested.getKey(); if (key.equals(recType.getIdentifier() + ";")) { return fromNullable(nested); } } } } } catch (final Exception x) { // final IType type = // parent.getType(recType.getClassName()); return absent(); } } return absent(); } final IType[] res = new IType[1]; final IJavaSearchScope scope = SearchEngine.createWorkspaceScope(); final SearchEngine search = new SearchEngine(); final String srcTypeName = Names.vm2srcTypeName(recType.getIdentifier()); final SearchPattern pattern = SearchPattern.createPattern(srcTypeName, IJavaSearchConstants.TYPE, IJavaSearchConstants.DECLARATIONS, SearchPattern.R_FULL_MATCH); try { search.search(pattern, SearchUtils.getDefaultSearchParticipants(), scope, new SearchRequestor() { @Override public void acceptSearchMatch(final SearchMatch match) throws CoreException { IType element = (IType) match.getElement(); // with the current settings the engine matches 'Lnull' with 'Ljava/lang/ref/ReferenceQueue$Null' if (toRecType(element).equals(recType)) { res[0] = element; } } }, null); } catch (final CoreException e) { throwUnhandledException(e); } return fromNullable(res[0]); }