List of usage examples for org.eclipse.jdt.core.search SearchEngine searchDeclarationsOfReferencedTypes
public void searchDeclarationsOfReferencedTypes(IWorkspace workspace, IJavaElement enclosingElement, IJavaSearchResultCollector resultCollector) throws JavaModelException
From source file:de.devboost.eclipse.jdtutilities.ClassDependencyUtility.java
License:Open Source License
/** * Returns the paths of all Java elements that are references by the element * at the given path.//from www . j ava2 s. c o m */ public Set<String> findReferencesFrom(String path) throws CoreException { Set<String> result = new LinkedHashSet<String>(); List<IType> types = getTypes(path); if (types.isEmpty()) { return result; } SearchEngine engine = new SearchEngine(); SearchRequestor requestor = new DependencySearchRequestor(result); IProgressMonitor monitor = new NullProgressMonitor(); for (IType type : types) { engine.searchDeclarationsOfReferencedTypes(type, requestor, monitor); } return result; }
From source file:net.sourceforge.metrics.ui.dependencies.TangleAnalyzer.java
License:Open Source License
/** * @param packages/*w ww.j av a 2 s.co m*/ * @return */ private void getDependencies(List<IJavaElement> packages) { try { SearchEngine searchEngine = new SearchEngine(); // fill in the packageName->{IType}* map by getting all type // declarations in scope IJavaElement[] packs = packages.toArray(new IJavaElement[] {}); IJavaSearchScope scope = SearchEngine.createJavaSearchScope(packs); SearchPattern pattern = SearchPattern.createPattern("*", IJavaSearchConstants.TYPE, IJavaSearchConstants.DECLARATIONS, SearchPattern.R_PATTERN_MATCH); TypeCollector c = new TypeCollector(result); monitor.subTask("Collecting types in packages"); searchEngine.search(pattern, new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }, scope, c, monitor); if (monitor.isCanceled()) { return; } // get all type references to these types. // Have to do multiple searches to get proper relationship :-( Set<String> typesInScope = result.keySet(); monitor.worked(400); monitor.subTask("Collecting type dependencies"); int scale = 500 / typesInScope.size(); for (Object element : typesInScope) { if (monitor.isCanceled()) { return; } String handle = (String) element; IJavaElement type = JavaCore.create(handle); searchEngine.searchDeclarationsOfReferencedTypes(type, new RefCollector(result.get(handle), typesInScope, type), monitor); monitor.worked(scale); } } catch (CoreException e) { e.printStackTrace(); } }