Java Code Examples for org.eclipse.jdt.core.search.SearchMatch#getAccuracy()

The following examples show how to use org.eclipse.jdt.core.search.SearchMatch#getAccuracy() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RefactoringSearchEngine2.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public final void acceptSearchMatch(final SearchMatch match) throws CoreException {
	final SearchMatch accepted= fRequestor.acceptSearchMatch(match);
	if (accepted != null) {
		final IResource resource= accepted.getResource();
		if (!resource.equals(fLastResource)) {
			final IJavaElement element= JavaCore.create(resource);
			if (element instanceof ICompilationUnit) {
				fCollectedUnits.add((ICompilationUnit) element);
			}
		}
		if (fInaccurate && accepted.getAccuracy() == SearchMatch.A_INACCURATE && !fInaccurateMatches.contains(accepted)) {
			fStatus.addEntry(fSeverity, Messages.format(RefactoringCoreMessages.RefactoringSearchEngine_inaccurate_match, BasicElementLabels.getResourceName(accepted.getResource())), null, null, RefactoringStatusEntry.NO_CODE);
			fInaccurateMatches.add(accepted);
		}
	}
}
 
Example 2
Source File: RefactoringSearchEngine2.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public final void acceptSearchMatch(final SearchMatch match) throws CoreException {
	final SearchMatch accepted= fRequestor.acceptSearchMatch(match);
	if (accepted != null) {
		fCollectedMatches.add(accepted);
		final IResource resource= accepted.getResource();
		if (!resource.equals(fLastResource)) {
			if (fBinary) {
				final IJavaElement element= JavaCore.create(resource);
				if (!(element instanceof ICompilationUnit)) {
					final IProject project= resource.getProject();
					if (!fGrouping) {
						fStatus.addEntry(fSeverity, Messages.format(RefactoringCoreMessages.RefactoringSearchEngine_binary_match_ungrouped, BasicElementLabels.getResourceName(project)), null, null, RefactoringStatusEntry.NO_CODE);
					} else if (!fBinaryResources.contains(resource)) {
						fStatus.addEntry(fSeverity, Messages.format(RefactoringCoreMessages.RefactoringSearchEngine_binary_match_grouped, BasicElementLabels.getResourceName(project)), null, null, RefactoringStatusEntry.NO_CODE);
					}
					fBinaryResources.add(resource);
				}
			}
			if (fInaccurate && accepted.getAccuracy() == SearchMatch.A_INACCURATE && !fInaccurateMatches.contains(accepted)) {
				fStatus.addEntry(fSeverity, Messages.format(RefactoringCoreMessages.RefactoringSearchEngine_inaccurate_match, BasicElementLabels.getResourceName(resource)), null, null, RefactoringStatusEntry.NO_CODE);
				fInaccurateMatches.add(accepted);
			}
		}
	}
}
 
Example 3
Source File: RefactoringSearchEngine2.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public final void acceptSearchMatch(final SearchMatch match) throws CoreException {
	final SearchMatch accepted= fRequestor.acceptSearchMatch(match);
	if (accepted != null) {
		final IResource resource= accepted.getResource();
		if (!resource.equals(fLastResource)) {
			final IJavaElement element= JavaCore.create(resource);
			if (element instanceof ICompilationUnit)
				fCollectedUnits.add((ICompilationUnit) element);
		}
		if (fInaccurate && accepted.getAccuracy() == SearchMatch.A_INACCURATE && !fInaccurateMatches.contains(accepted)) {
			fStatus.addEntry(fSeverity, Messages.format(RefactoringCoreMessages.RefactoringSearchEngine_inaccurate_match, BasicElementLabels.getResourceName(accepted.getResource())), null, null, RefactoringStatusEntry.NO_CODE);
			fInaccurateMatches.add(accepted);
		}
	}
}
 
Example 4
Source File: RefactoringSearchEngine2.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public final void acceptSearchMatch(final SearchMatch match) throws CoreException {
	final SearchMatch accepted= fRequestor.acceptSearchMatch(match);
	if (accepted != null) {
		fCollectedMatches.add(accepted);
		final IResource resource= accepted.getResource();
		if (!resource.equals(fLastResource)) {
			if (fBinary) {
				final IJavaElement element= JavaCore.create(resource);
				if (!(element instanceof ICompilationUnit)) {
					final IProject project= resource.getProject();
					if (!fGrouping)
						fStatus.addEntry(fSeverity, Messages.format(RefactoringCoreMessages.RefactoringSearchEngine_binary_match_ungrouped, BasicElementLabels.getResourceName(project)), null, null, RefactoringStatusEntry.NO_CODE);
					else if (!fBinaryResources.contains(resource))
						fStatus.addEntry(fSeverity, Messages.format(RefactoringCoreMessages.RefactoringSearchEngine_binary_match_grouped, BasicElementLabels.getResourceName(project)), null, null, RefactoringStatusEntry.NO_CODE);
					fBinaryResources.add(resource);
				}
			}
			if (fInaccurate && accepted.getAccuracy() == SearchMatch.A_INACCURATE && !fInaccurateMatches.contains(accepted)) {
				fStatus.addEntry(fSeverity, Messages.format(RefactoringCoreMessages.RefactoringSearchEngine_inaccurate_match, BasicElementLabels.getResourceName(resource)), null, null, RefactoringStatusEntry.NO_CODE);
				fInaccurateMatches.add(accepted);
			}
		}
	}
}
 
Example 5
Source File: MethodReferencesSearchRequestor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void acceptSearchMatch(SearchMatch match) {
       if (fRequireExactMatch && (match.getAccuracy() != SearchMatch.A_ACCURATE)) {
           return;
       }

       if (match.isInsideDocComment()) {
           return;
       }

       if (match.getElement() != null && match.getElement() instanceof IMember) {
           IMember member= (IMember) match.getElement();
           switch (member.getElementType()) {
               case IJavaElement.METHOD:
               case IJavaElement.TYPE:
               case IJavaElement.FIELD:
               case IJavaElement.INITIALIZER:
                   fSearchResults.addMember(member, member, match.getOffset(), match.getOffset()+match.getLength());
                   break;
           }
       }
   }
 
Example 6
Source File: MoveCuUpdateCreator.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void acceptSearchMatch(SearchMatch match) throws CoreException {
	if (filterMatch(match)) {
		return;
	}

	/*
	 * Processing is done in collector to reuse the buffer which was
	 * already required by the search engine to locate the matches.
	 */
	// [start, end[ include qualification.
	IJavaElement element = SearchUtils.getEnclosingJavaElement(match);
	int accuracy = match.getAccuracy();
	int start = match.getOffset();
	int length = match.getLength();
	boolean insideDocComment = match.isInsideDocComment();
	IResource res = match.getResource();
	if (element.getAncestor(IJavaElement.IMPORT_DECLARATION) != null) {
		collectMatch(TypeReference.createImportReference(element, accuracy, start, length, insideDocComment, res));
	} else {
		ICompilationUnit unit = (ICompilationUnit) element.getAncestor(IJavaElement.COMPILATION_UNIT);
		if (unit != null) {
			IBuffer buffer = unit.getBuffer();
			String matchText = buffer.getText(start, length);
			if (fSource.isDefaultPackage()) {
				collectMatch(TypeReference.createSimpleReference(element, accuracy, start, length, insideDocComment, res, matchText));
			} else {
				// assert: matchText doesn't start nor end with comment
				int simpleNameStart = getLastSimpleNameStart(matchText);
				if (simpleNameStart != 0) {
					collectMatch(TypeReference.createQualifiedReference(element, accuracy, start, length, insideDocComment, res, start + simpleNameStart));
				} else {
					collectMatch(TypeReference.createSimpleReference(element, accuracy, start, length, insideDocComment, res, matchText));
				}
			}
		}
	}
}
 
Example 7
Source File: RefactoringSearchEngine.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
public static ICompilationUnit[] findAffectedCompilationUnits(SearchPattern pattern, IJavaSearchScope scope, final IProgressMonitor pm, RefactoringStatus status, final boolean tolerateInAccurateMatches) throws JavaModelException {

		boolean hasNonCuMatches = false;

		class ResourceSearchRequestor extends SearchRequestor {
			boolean hasPotentialMatches = false;
			Set<IResource> resources = new HashSet<>(5);
			private IResource fLastResource;

			@Override
			public void acceptSearchMatch(SearchMatch match) {
				if (!tolerateInAccurateMatches && match.getAccuracy() == SearchMatch.A_INACCURATE) {
					hasPotentialMatches = true;
				}
				if (fLastResource != match.getResource()) {
					fLastResource = match.getResource();
					resources.add(fLastResource);
				}
			}
		}
		ResourceSearchRequestor requestor = new ResourceSearchRequestor();
		try {
			new SearchEngine().search(pattern, SearchUtils.getDefaultSearchParticipants(), scope, requestor, pm);
		} catch (CoreException e) {
			throw new JavaModelException(e);
		}

		List<IJavaElement> result = new ArrayList<>(requestor.resources.size());
		for (Iterator<IResource> iter = requestor.resources.iterator(); iter.hasNext();) {
			IResource resource = iter.next();
			IJavaElement element = JavaCore.create(resource);
			if (element instanceof ICompilationUnit) {
				result.add(element);
			} else {
				hasNonCuMatches = true;
			}
		}
		addStatusErrors(status, requestor.hasPotentialMatches, hasNonCuMatches);
		return result.toArray(new ICompilationUnit[result.size()]);
	}
 
Example 8
Source File: CollectingSearchRequestor.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Returns whether the given match should be filtered out.
 * The default implementation filters out matches in binaries iff
 * {@link #CollectingSearchRequestor(ReferencesInBinaryContext)} has been called with a
 * non-<code>null</code> argument. Accurate binary matches are added to the {@link ReferencesInBinaryContext}.
 *
 * @param match the match to test
 * @return <code>true</code> iff the given match should <em>not</em> be collected
 * @throws CoreException
 */
public boolean filterMatch(SearchMatch match) throws CoreException {
	if (fBinaryRefs == null) {
		return false;
	}

	if (match.getAccuracy() == SearchMatch.A_ACCURATE && isBinaryElement(match.getElement())) {
		// binary classpaths are often incomplete -> avoiding false positives from inaccurate matches
		fBinaryRefs.add(match);
		return true;
	}

	return false;
}
 
Example 9
Source File: TargetProvider.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public ICompilationUnit[] getAffectedCompilationUnits(final RefactoringStatus status, ReferencesInBinaryContext binaryRefs, IProgressMonitor pm) throws CoreException {
	IMethod method= (IMethod)fMethodBinding.getJavaElement();
	Assert.isTrue(method != null);

	SearchPattern pattern= SearchPattern.createPattern(method, IJavaSearchConstants.REFERENCES, SearchUtils.GENERICS_AGNOSTIC_MATCH_RULE);
	IJavaSearchScope scope= RefactoringScopeFactory.create(method, true, false);
	final HashSet<ICompilationUnit> affectedCompilationUnits= new HashSet<ICompilationUnit>();
	CollectingSearchRequestor requestor= new CollectingSearchRequestor(binaryRefs) {
		private ICompilationUnit fLastCU;
		@Override
		public void acceptSearchMatch(SearchMatch match) throws CoreException {
			if (filterMatch(match))
				return;
			if (match.isInsideDocComment())
				return; // TODO: should warn user (with something like a ReferencesInBinaryContext)

			ICompilationUnit unit= SearchUtils.getCompilationUnit(match);
			if (match.getAccuracy() == SearchMatch.A_INACCURATE) {
				if (unit != null) {
					status.addError(RefactoringCoreMessages.TargetProvider_inaccurate_match,
						JavaStatusContext.create(unit, new SourceRange(match.getOffset(), match.getLength())));
				} else {
					status.addError(RefactoringCoreMessages.TargetProvider_inaccurate_match);
				}
			} else if (unit != null) {
				if (! unit.equals(fLastCU)) {
					fLastCU= unit;
					affectedCompilationUnits.add(unit);
				}
			}
		}
	};
	new SearchEngine().search(pattern, SearchUtils.getDefaultSearchParticipants(), scope, requestor, new SubProgressMonitor(pm, 1));
	return affectedCompilationUnits.toArray(new ICompilationUnit[affectedCompilationUnits.size()]);
}
 
Example 10
Source File: MoveCuUpdateCreator.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void acceptSearchMatch(SearchMatch match) throws CoreException {
	if (filterMatch(match))
		return;

	/*
	 * Processing is done in collector to reuse the buffer which was
	 * already required by the search engine to locate the matches.
	 */
	// [start, end[ include qualification.
	IJavaElement element= SearchUtils.getEnclosingJavaElement(match);
	int accuracy= match.getAccuracy();
	int start= match.getOffset();
	int length= match.getLength();
	boolean insideDocComment= match.isInsideDocComment();
	IResource res= match.getResource();
	if (element.getAncestor(IJavaElement.IMPORT_DECLARATION) != null) {
		collectMatch(TypeReference.createImportReference(element, accuracy, start, length, insideDocComment, res));
	} else {
		ICompilationUnit unit= (ICompilationUnit) element.getAncestor(IJavaElement.COMPILATION_UNIT);
		if (unit != null) {
			IBuffer buffer= unit.getBuffer();
			String matchText= buffer.getText(start, length);
			if (fSource.isDefaultPackage()) {
				collectMatch(TypeReference.createSimpleReference(element, accuracy, start, length, insideDocComment, res, matchText));
			} else {
				// assert: matchText doesn't start nor end with comment
				int simpleNameStart= getLastSimpleNameStart(matchText);
				if (simpleNameStart != 0) {
					collectMatch(TypeReference.createQualifiedReference(element, accuracy, start, length, insideDocComment, res, start + simpleNameStart));
				} else {
					collectMatch(TypeReference.createSimpleReference(element, accuracy, start, length, insideDocComment, res, matchText));
				}
			}
		}
	}
}
 
Example 11
Source File: CollectingSearchRequestor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Returns whether the given match should be filtered out.
 * The default implementation filters out matches in binaries iff
 * {@link #CollectingSearchRequestor(ReferencesInBinaryContext)} has been called with a
 * non-<code>null</code> argument. Accurate binary matches are added to the {@link ReferencesInBinaryContext}.
 *
 * @param match the match to test
 * @return <code>true</code> iff the given match should <em>not</em> be collected
 * @throws CoreException
 */
public boolean filterMatch(SearchMatch match) throws CoreException {
	if (fBinaryRefs == null)
		return false;

	if (match.getAccuracy() == SearchMatch.A_ACCURATE && isBinaryElement(match.getElement())) {
		// binary classpaths are often incomplete -> avoiding false positives from inaccurate matches
		fBinaryRefs.add(match);
		return true;
	}

	return false;
}
 
Example 12
Source File: NewSearchResultCollector.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void acceptSearchMatch(SearchMatch match) throws CoreException {
	IJavaElement enclosingElement= (IJavaElement) match.getElement();
	if (enclosingElement != null) {
		if (fIgnorePotentials && (match.getAccuracy() == SearchMatch.A_INACCURATE))
			return;
		boolean isWriteAccess= false;
		boolean isReadAccess= false;
		if (match instanceof FieldReferenceMatch) {
			FieldReferenceMatch fieldRef= ((FieldReferenceMatch) match);
			isWriteAccess= fieldRef.isWriteAccess();
			isReadAccess= fieldRef.isReadAccess();
		} else if (match instanceof FieldDeclarationMatch) {
			isWriteAccess= true;
		} else if (match instanceof LocalVariableReferenceMatch) {
			LocalVariableReferenceMatch localVarRef= ((LocalVariableReferenceMatch) match);
			isWriteAccess= localVarRef.isWriteAccess();
			isReadAccess= localVarRef.isReadAccess();
		} else if (match instanceof LocalVariableDeclarationMatch) {
			isWriteAccess= true;
		}
		boolean isSuperInvocation= false;
		if (match instanceof MethodReferenceMatch) {
			MethodReferenceMatch methodRef= (MethodReferenceMatch) match;
			isSuperInvocation= methodRef.isSuperInvocation();
		}
		fSearch.addMatch(new JavaElementMatch(enclosingElement, match.getRule(), match.getOffset(), match.getLength(), match.getAccuracy(), isReadAccess, isWriteAccess, match.isInsideDocComment(), isSuperInvocation));
	}
}
 
Example 13
Source File: MethodOccurenceCollector.java    From eclipse.jdt.ls with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public void acceptSearchMatch(ICompilationUnit unit, SearchMatch match) throws CoreException {
	if (match instanceof MethodReferenceMatch
			&& ((MethodReferenceMatch) match).isSuperInvocation()
			&& match.getAccuracy() == SearchMatch.A_INACCURATE) {
		return; // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=156491
	}

	if (match.isImplicit()) { // see bug 94062
		collectMatch(match);
		return;
	}

	int start= match.getOffset();
	int length= match.getLength();
	String matchText= unit.getBuffer().getText(start, length);

	//direct match:
	if (fName.equals(matchText)) {
		collectMatch(match);
		return;
	}

	// lambda expression
	if (match instanceof MethodDeclarationMatch
			&& match.getElement() instanceof IMethod
			&& ((IMethod) match.getElement()).isLambdaMethod()) {
		// don't touch the lambda
		return;
	}

	//Not a standard reference -- use scanner to find last identifier token before left parenthesis:
	IScanner scanner= getScanner(unit);
	scanner.setSource(matchText.toCharArray());
	int simpleNameStart= -1;
	int simpleNameEnd= -1;
	try {
		int token = scanner.getNextToken();
		while (token != ITerminalSymbols.TokenNameEOF && token != ITerminalSymbols.TokenNameLPAREN) { // reference in code includes arguments in parentheses
			if (token == InternalTokenNameIdentifier) {
				simpleNameStart= scanner.getCurrentTokenStartPosition();
				simpleNameEnd= scanner.getCurrentTokenEndPosition();
			}
			token = scanner.getNextToken();
		}
	} catch (InvalidInputException e){
		//ignore
	}
	if (simpleNameStart != -1) {
		match.setOffset(start + simpleNameStart);
		match.setLength(simpleNameEnd + 1 - simpleNameStart);
	}
	collectMatch(match);
}
 
Example 14
Source File: ImplementationCollector.java    From eclipse.jdt.ls with Eclipse Public License 2.0 4 votes vote down vote up
private List<T> findMethodImplementations(IProgressMonitor monitor) throws CoreException {
	IMethod method = (IMethod) javaElement;
	try {
		if (cannotBeOverriddenMethod(method)) {
			return null;
		}
	} catch (JavaModelException e) {
		JavaLanguageServerPlugin.logException("Find method implementations failure ", e);
		return null;
	}

	CompilationUnit ast = CoreASTProvider.getInstance().getAST(typeRoot, CoreASTProvider.WAIT_YES, monitor);
	if (ast == null) {
		return null;
	}

	ASTNode node = NodeFinder.perform(ast, region.getOffset(), region.getLength());
	ITypeBinding parentTypeBinding = null;
	if (node instanceof SimpleName) {
		ASTNode parent = node.getParent();
		if (parent instanceof MethodInvocation) {
			Expression expression = ((MethodInvocation) parent).getExpression();
			if (expression == null) {
				parentTypeBinding= Bindings.getBindingOfParentType(node);
			} else {
				parentTypeBinding = expression.resolveTypeBinding();
			}
		} else if (parent instanceof SuperMethodInvocation) {
			// Directly go to the super method definition
			return Collections.singletonList(mapper.convert(method, 0, 0));
		} else if (parent instanceof MethodDeclaration) {
			parentTypeBinding = Bindings.getBindingOfParentType(node);
		}
	}
	final IType receiverType = getType(parentTypeBinding);
	if (receiverType == null) {
		return null;
	}

	final List<T> results = new ArrayList<>();
	try {
		String methodLabel = JavaElementLabelsCore.getElementLabel(method, JavaElementLabelsCore.DEFAULT_QUALIFIED);
		monitor.beginTask(Messages.format(JavaElementImplementationHyperlink_search_method_implementors, methodLabel), 10);
		SearchRequestor requestor = new SearchRequestor() {
			@Override
			public void acceptSearchMatch(SearchMatch match) throws CoreException {
				if (match.getAccuracy() == SearchMatch.A_ACCURATE) {
					Object element = match.getElement();
					if (element instanceof IMethod) {
						IMethod methodFound = (IMethod) element;
						if (!JdtFlags.isAbstract(methodFound)) {
							T result = mapper.convert(methodFound, match.getOffset(), match.getLength());
							if (result != null) {
								results.add(result);
							}
						}
					}
				}
			}
		};

		IJavaSearchScope hierarchyScope;
		if (receiverType.isInterface()) {
			hierarchyScope = SearchEngine.createHierarchyScope(method.getDeclaringType());
		} else {
			if (isFullHierarchyNeeded(new SubProgressMonitor(monitor, 3), method, receiverType)) {
				hierarchyScope = SearchEngine.createHierarchyScope(receiverType);
			} else {
				boolean isMethodAbstract = JdtFlags.isAbstract(method);
				hierarchyScope = SearchEngine.createStrictHierarchyScope(null, receiverType, true, isMethodAbstract, null);
			}
		}

		int limitTo = IJavaSearchConstants.DECLARATIONS | IJavaSearchConstants.IGNORE_DECLARING_TYPE | IJavaSearchConstants.IGNORE_RETURN_TYPE;
		SearchPattern pattern = SearchPattern.createPattern(method, limitTo);
		Assert.isNotNull(pattern);
		SearchParticipant[] participants = new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() };
		SearchEngine engine = new SearchEngine();
		engine.search(pattern, participants, hierarchyScope, requestor, new SubProgressMonitor(monitor, 7));
		if (monitor.isCanceled()) {
			throw new OperationCanceledException();
		}
	} finally {
		monitor.done();
	}
	return results;
}
 
Example 15
Source File: MethodOccurenceCollector.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public void acceptSearchMatch(ICompilationUnit unit, SearchMatch match) throws CoreException {
	if (match instanceof MethodReferenceMatch
			&& ((MethodReferenceMatch) match).isSuperInvocation()
			&& match.getAccuracy() == SearchMatch.A_INACCURATE) {
		return; // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=156491
	}

	if (match.isImplicit()) { // see bug 94062
		collectMatch(match);
		return;
	}

	int start= match.getOffset();
	int length= match.getLength();
	String matchText= unit.getBuffer().getText(start, length);

	//direct match:
	if (fName.equals(matchText)) {
		collectMatch(match);
		return;
	}

	// lambda expression
	if (match instanceof MethodDeclarationMatch
			&& match.getElement() instanceof IMethod
			&& ((IMethod) match.getElement()).isLambdaMethod()) {
		// don't touch the lambda
		return;
	}

	//Not a standard reference -- use scanner to find last identifier token before left parenthesis:
	IScanner scanner= getScanner(unit);
	scanner.setSource(matchText.toCharArray());
	int simpleNameStart= -1;
	int simpleNameEnd= -1;
	try {
		int token = scanner.getNextToken();
		while (token != ITerminalSymbols.TokenNameEOF && token != ITerminalSymbols.TokenNameLPAREN) { // reference in code includes arguments in parentheses
			if (token == ITerminalSymbols.TokenNameIdentifier) {
				simpleNameStart= scanner.getCurrentTokenStartPosition();
				simpleNameEnd= scanner.getCurrentTokenEndPosition();
			}
			token = scanner.getNextToken();
		}
	} catch (InvalidInputException e){
		//ignore
	}
	if (simpleNameStart != -1) {
		match.setOffset(start + simpleNameStart);
		match.setLength(simpleNameEnd + 1 - simpleNameStart);
	}
	collectMatch(match);
}
 
Example 16
Source File: RefactoringSearchEngine.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public static ICompilationUnit[] findAffectedCompilationUnits(SearchPattern pattern,
		IJavaSearchScope scope, final IProgressMonitor pm, RefactoringStatus status, final boolean tolerateInAccurateMatches) throws JavaModelException {

	boolean hasNonCuMatches= false;

	class ResourceSearchRequestor extends SearchRequestor{
		boolean hasPotentialMatches= false ;
		Set<IResource> resources= new HashSet<IResource>(5);
		private IResource fLastResource;

		@Override
		public void acceptSearchMatch(SearchMatch match) {
			if (!tolerateInAccurateMatches && match.getAccuracy() == SearchMatch.A_INACCURATE) {
				hasPotentialMatches= true;
			}
			if (fLastResource != match.getResource()) {
				fLastResource= match.getResource();
				resources.add(fLastResource);
			}
		}
	}
	ResourceSearchRequestor requestor = new ResourceSearchRequestor();
	try {
		new SearchEngine().search(pattern, SearchUtils.getDefaultSearchParticipants(), scope, requestor, pm);
	} catch (CoreException e) {
		throw new JavaModelException(e);
	}

	List<IJavaElement> result= new ArrayList<IJavaElement>(requestor.resources.size());
	for (Iterator<IResource> iter= requestor.resources.iterator(); iter.hasNext(); ) {
		IResource resource= iter.next();
		IJavaElement element= JavaCore.create(resource);
		if (element instanceof ICompilationUnit) {
			result.add(element);
		} else {
			hasNonCuMatches= true;
		}
	}
	addStatusErrors(status, requestor.hasPotentialMatches, hasNonCuMatches);
	return result.toArray(new ICompilationUnit[result.size()]);
}