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

The following examples show how to use org.eclipse.jdt.core.search.SearchMatch#getResource() . 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: 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 6
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 7
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 8
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()]);
}