private List<Location> findReferences(IJavaElement element, IProgressMonitor monitor) throws JavaModelException, CoreException { if (element == null) { return Collections.emptyList(); } SearchPattern pattern = SearchPattern.createPattern(element, IJavaSearchConstants.REFERENCES); final List<Location> result = new ArrayList<>(); SearchEngine engine = new SearchEngine(); engine.search(pattern, new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }, createSearchScope(), new SearchRequestor() { @Override public void acceptSearchMatch(SearchMatch match) throws CoreException { Object o = match.getElement(); if (o instanceof IJavaElement) { IJavaElement element = (IJavaElement) o; ICompilationUnit compilationUnit = (ICompilationUnit) element .getAncestor(IJavaElement.COMPILATION_UNIT); if (compilationUnit == null) { return; } Location location = JDTUtils.toLocation(compilationUnit, match.getOffset(), match.getLength()); result.add(location); } } }, monitor); return result; }