List of usage examples for org.eclipse.jdt.core.search SearchMatch getAccuracy
public final int getAccuracy()
From source file:edu.brown.cs.bubbles.bedrock.BedrockUtil.java
License:Open Source License
/********************************************************************************/ static void outputSearchMatch(SearchMatch mat, IvyXmlWriter xw) { xw.begin("MATCH"); xw.field("OFFSET", mat.getOffset()); xw.field("LENGTH", mat.getLength()); xw.field("STARTOFFSET", mat.getOffset()); xw.field("ENDOFFSET", mat.getOffset() + mat.getLength()); IResource irc = mat.getResource();// w w w.ja v a2 s . c om if (irc != null) { File f = mat.getResource().getLocation().toFile(); switch (irc.getType()) { case IResource.FILE: xw.field("FILE", f.toString()); break; case IResource.PROJECT: xw.field("PROJECT", f.toString()); break; case IResource.FOLDER: xw.field("FOLDER", f.toString()); break; case IResource.ROOT: xw.field("ROOT", f.toString()); break; } } xw.field("ACCURACY", mat.getAccuracy()); xw.field("EQUIV", mat.isEquivalent()); xw.field("ERASURE", mat.isErasure()); xw.field("EXACT", mat.isExact()); xw.field("IMPLICIT", mat.isImplicit()); xw.field("INDOCCMMT", mat.isInsideDocComment()); xw.field("RAW", mat.isRaw()); Object o = mat.getElement(); BedrockPlugin.logD("MATCH ELEMENT " + o); if (o instanceof IJavaElement) { IJavaElement nelt = (IJavaElement) o; outputJavaElement(nelt, false, xw); } xw.end("MATCH"); }
From source file:org.eclim.plugin.jdt.command.complete.CompletionProposalCollector.java
License:Open Source License
public void completionFailure(IProblem problem) { ICompilationUnit src = getCompilationUnit(); IJavaProject javaProject = src.getJavaProject(); IProject project = javaProject.getProject(); // undefined type or attempting to complete static members of an unimported // type//from w w w. j ava2 s. c om if (problem.getID() == IProblem.UndefinedType || problem.getID() == IProblem.UnresolvedVariable) { try { SearchPattern pattern = SearchPattern.createPattern(problem.getArguments()[0], IJavaSearchConstants.TYPE, IJavaSearchConstants.DECLARATIONS, SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE); IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] { javaProject }); SearchRequestor requestor = new SearchRequestor(); SearchEngine engine = new SearchEngine(); SearchParticipant[] participants = new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }; engine.search(pattern, participants, scope, requestor, null); if (requestor.getMatches().size() > 0) { imports = new ArrayList<String>(); for (SearchMatch match : requestor.getMatches()) { if (match.getAccuracy() != SearchMatch.A_ACCURATE) { continue; } IJavaElement element = (IJavaElement) match.getElement(); String name = null; switch (element.getElementType()) { case IJavaElement.TYPE: IType type = (IType) element; if (Flags.isPublic(type.getFlags())) { name = type.getFullyQualifiedName(); } break; case IJavaElement.METHOD: case IJavaElement.FIELD: name = ((IType) element.getParent()).getFullyQualifiedName() + '.' + element.getElementName(); break; } if (name != null) { name = name.replace('$', '.'); if (!ImportUtils.isImportExcluded(project, name)) { imports.add(name); } } } } } catch (Exception e) { throw new RuntimeException(e); } } IResource resource = src.getResource(); String relativeName = resource.getProjectRelativePath().toString(); if (new String(problem.getOriginatingFileName()).endsWith(relativeName)) { String filename = resource.getLocation().toString(); // ignore the problem if a temp file is being used and the problem is that // the type needs to be defined in its own file. if (problem.getID() == IProblem.PublicClassMustMatchFileName && filename.indexOf("__eclim_temp_") != -1) { return; } FileOffsets offsets = FileOffsets.compile(filename); int[] lineColumn = offsets.offsetToLineColumn(problem.getSourceStart()); error = new Error(problem.getMessage(), filename.replace("__eclim_temp_", ""), lineColumn[0], lineColumn[1], problem.isWarning()); } }
From source file:org.eclim.plugin.jdt.command.launching.JavaCommand.java
License:Open Source License
private String findMainClass(IJavaProject javaProject) throws Exception { ArrayList<IJavaElement> srcs = new ArrayList<IJavaElement>(); for (IClasspathEntry entry : javaProject.getResolvedClasspath(true)) { if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { for (IPackageFragmentRoot root : javaProject.findPackageFragmentRoots(entry)) { srcs.add(root);//from www .ja v a 2 s . co m } } } final ArrayList<IMethod> methods = new ArrayList<IMethod>(); int context = IJavaSearchConstants.DECLARATIONS; int type = IJavaSearchConstants.METHOD; int matchType = SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE; IJavaSearchScope scope = SearchEngine.createJavaSearchScope(srcs.toArray(new IJavaElement[srcs.size()])); SearchPattern pattern = SearchPattern.createPattern("main(String[])", type, context, matchType); SearchRequestor requestor = new SearchRequestor() { public void acceptSearchMatch(SearchMatch match) { if (match.getAccuracy() != SearchMatch.A_ACCURATE) { return; } try { IMethod method = (IMethod) match.getElement(); String[] params = method.getParameterTypes(); if (params.length != 1) { return; } if (!Signature.SIG_VOID.equals(method.getReturnType())) { return; } int flags = method.getFlags(); if (!Flags.isPublic(flags) || !Flags.isStatic(flags)) { return; } methods.add(method); } catch (JavaModelException e) { // ignore } } }; SearchEngine engine = new SearchEngine(); SearchParticipant[] participants = new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }; engine.search(pattern, participants, scope, requestor, null); // if we found only 1 result, we can use it. if (methods.size() == 1) { IMethod method = methods.get(0); ICompilationUnit cu = method.getCompilationUnit(); IPackageDeclaration[] packages = cu.getPackageDeclarations(); if (packages != null && packages.length > 0) { return packages[0].getElementName() + "." + cu.getElementName(); } return cu.getElementName(); } return null; }
From source file:org.eclim.plugin.jdt.command.search.ImplementorsSearchRequestor.java
License:Open Source License
@Override public void acceptSearchMatch(SearchMatch match) throws CoreException { if (match.getAccuracy() == SearchMatch.A_ACCURATE) { Object element = match.getElement(); if (element instanceof IMethod) { IMethod method = (IMethod) element; if (!JdtFlags.isAbstract(method)) { super.acceptSearchMatch(match); }/*from ww w . jav a 2s. c o m*/ } } }
From source file:org.eclim.plugin.jdt.command.search.SearchRequestor.java
License:Open Source License
@Override public void acceptSearchMatch(SearchMatch match) throws CoreException { if (match.getAccuracy() == SearchMatch.A_ACCURATE) { matches.add(match);/*from ww w . ja v a 2 s . c om*/ } }
From source file:org.eclim.plugin.jdt.command.src.JavaCommand.java
License:Open Source License
private String findMainClass(IJavaProject javaProject) throws Exception { final String projectPath = ProjectUtils.getPath(javaProject.getProject()); final ArrayList<IMethod> methods = new ArrayList<IMethod>(); int context = IJavaSearchConstants.DECLARATIONS; int type = IJavaSearchConstants.METHOD; int matchType = SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE; IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] { javaProject }); SearchPattern pattern = SearchPattern.createPattern("main(String[])", type, context, matchType); SearchRequestor requestor = new SearchRequestor() { public void acceptSearchMatch(SearchMatch match) { if (match.getAccuracy() != SearchMatch.A_ACCURATE) { return; }/*from w w w . java 2 s . c o m*/ IPath location = match.getResource().getRawLocation(); if (location == null) { return; } String path = location.toOSString().replace('\\', '/'); if (!path.toLowerCase().startsWith(projectPath.toLowerCase())) { return; } IJavaElement element = (IJavaElement) match.getElement(); if (element.getElementType() != IJavaElement.METHOD) { return; } IMethod method = (IMethod) element; String[] params = method.getParameterTypes(); if (params.length != 1) { return; } methods.add(method); } }; if (pattern != null) { SearchEngine engine = new SearchEngine(); SearchParticipant[] participants = new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }; engine.search(pattern, participants, scope, requestor, null); // if we found only 1 result, we can use it. if (methods.size() == 1) { IMethod method = methods.get(0); ICompilationUnit cu = method.getCompilationUnit(); IPackageDeclaration[] packages = cu.getPackageDeclarations(); if (packages != null && packages.length > 0) { return packages[0].getElementName() + "." + cu.getElementName(); } return cu.getElementName(); } } return null; }
From source file:org.eclim.plugin.jdt.util.TypeUtils.java
License:Open Source License
/** * Find types by the supplied fully qualified name or unqualified class name. * * @param javaProject The java project to be searched. * @param name The name to search./*from w w w . java 2 s . c om*/ * * @return A possibly empty array of IType results found. */ public static IType[] findTypes(IJavaProject javaProject, String name) throws Exception { SearchPattern pattern = SearchPattern.createPattern(name, IJavaSearchConstants.TYPE, IJavaSearchConstants.DECLARATIONS, SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE); IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] { javaProject }); SearchRequestor requestor = new SearchRequestor(); SearchEngine engine = new SearchEngine(); SearchParticipant[] participants = new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }; engine.search(pattern, participants, scope, requestor, null); ArrayList<IType> types = new ArrayList<IType>(); if (requestor.getMatches().size() > 0) { for (SearchMatch match : requestor.getMatches()) { if (match.getAccuracy() != SearchMatch.A_ACCURATE) { continue; } IJavaElement element = (IJavaElement) match.getElement(); if (element.getElementType() == IJavaElement.TYPE) { types.add((IType) element); } } } return types.toArray(new IType[types.size()]); }
From source file:org.eclipse.ajdt.internal.ui.refactoring.pullout.PullOutRefactoring.java
License:Open Source License
/** * Check whether references to moved elements become broken. Update status message * accordingly (but only if allowModifierConversion is set to false). * //from w w w . j a va2 s .com * @return true if no references become broken */ private boolean checkIncomingReferences(ITDCreator movedMember, RefactoringStatus status) throws CoreException { if (movedMember.wasPublic()) return true; //Always ok if member was already public boolean ok = true; IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] { javaProject }); SearchPattern pattern = SearchPattern.createPattern(movedMember.getMember(), IJavaSearchConstants.REFERENCES); SearchEngine engine = new SearchEngine(); final Set<SearchMatch> references = new HashSet<SearchMatch>(); engine.search(pattern, new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }, scope, new SearchRequestor() { @Override public void acceptSearchMatch(SearchMatch match) throws CoreException { if (match.getAccuracy() == SearchMatch.A_ACCURATE && !match.isInsideDocComment()) references.add(match); } }, new NullProgressMonitor()); String referredPkg = getPackageName(targetAspect); // since the element is moved it's package *will* be... for (SearchMatch match : references) { if (match.getElement() instanceof IJavaElement) { IJavaElement referingElement = (IJavaElement) match.getElement(); if (!isMoved(referingElement)) { if (movedMember.wasPrivate()) { ok = false; if (isAllowMakePublic()) { movedMember.addModifier(Modifier.PUBLIC); } else { status.addWarning( "The moved private member '" + movedMember.getElementName() + "' will not be accessible" + " after refactoring.", makeContext(match)); } } else if (movedMember.wasPackageVisible() || movedMember.wasProtected()) { String referringPkg = getPackageName(referingElement); if (referringPkg != null && !referringPkg.equals(referredPkg)) { ok = false; if (isAllowMakePublic()) { movedMember.addModifier(Modifier.PUBLIC); } else { status.addWarning( "The moved member '" + movedMember.getElementName() + "' may not be accessible " + "after refactoring", makeContext(match)); } } } } } } return ok; }
From source file:org.eclipse.che.plugin.java.testing.AnnotationSearchRequestor.java
License:Open Source License
@Override public void acceptSearchMatch(SearchMatch match) throws CoreException { if (match.getAccuracy() == SearchMatch.A_ACCURATE && !match.isInsideDocComment()) { Object element = match.getElement(); if (element instanceof IType || element instanceof IMethod) { IMember member = (IMember) element; IType type = member.getElementType() == IJavaElement.TYPE ? (IType) member : member.getDeclaringType(); addTypeAndSubtypes(type);//w ww .j a va 2 s . c o m } } }
From source file:org.eclipse.core.tools.search.FindUnusedMembers.java
License:Open Source License
private boolean hasReferences(IMember member, IProgressMonitor monitor) throws JavaModelException { final class ReferenceFound extends Error { private static final long serialVersionUID = 1L; }//from w w w. j a va 2 s.co m try { IJavaSearchScope searchScope = RefactoringScopeFactory.create(member.getDeclaringType()); SearchPattern pattern = SearchPattern.createPattern(member, IJavaSearchConstants.REFERENCES); SearchRequestor requestor = new SearchRequestor() { public void acceptSearchMatch(SearchMatch match) throws CoreException { if (match.getAccuracy() == SearchMatch.A_ACCURATE) { throw new ReferenceFound(); } } }; new SearchEngine().search(pattern, new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }, searchScope, requestor, monitor); } catch (CoreException e) { throw new JavaModelException(e); } catch (ReferenceFound e) { return true; } return false; }