List of usage examples for org.eclipse.jdt.core IRegion contains
boolean contains(IJavaElement element);
From source file:edu.brown.cs.bubbles.bedrock.BedrockJava.java
License:Open Source License
/********************************************************************************/ void handleFindHierarchy(String proj, String pkg, String cls, boolean all, IvyXmlWriter xw) throws BedrockException { IJavaProject ijp = getJavaProject(proj); IRegion rgn = JavaCore.newRegion(); IType fortype = null;/*from w ww. j a v a2 s .c om*/ boolean havejp = (ijp != null); if (ijp == null && (pkg != null || cls != null)) { IJavaElement[] aps = getAllProjects(); if (aps.length == 0) return; if (cls != null) { for (IJavaElement ije : aps) { IJavaProject xjp = ije.getJavaProject(); try { if (xjp.findType(cls) != null) { ijp = xjp; break; } } catch (JavaModelException e) { } } } if (ijp == null) ijp = aps[0].getJavaProject(); } int addct = 0; if (cls != null && ijp != null) { try { IType typ = ijp.findType(cls); fortype = typ; // rgn.add(typ); // ++addct; } catch (JavaModelException e) { BedrockPlugin.logE("Problem getting type by name: " + e); } } if (pkg != null && ijp != null) { String ppth = "/" + pkg.replace(".", "/"); try { for (IPackageFragmentRoot ipr : ijp.getPackageFragmentRoots()) { IPath rpath = ipr.getPath(); Path npath = new Path(rpath.toString() + ppth); IPackageFragment ipf = ijp.findPackageFragment(npath); if (ipf != null) { rgn.add(ipf); ++addct; } } } catch (Exception e) { BedrockPlugin.logE("Problem getting package fragments for " + ppth + ": " + e); } } else if (havejp && ijp != null) { if (all) { rgn.add(ijp); ++addct; } else { try { for (IPackageFragment ipf : ijp.getPackageFragments()) { for (ICompilationUnit icu : ipf.getCompilationUnits()) { IType ity = ((ITypeRoot) icu).findPrimaryType(); if (ity != null) { rgn.add(ity); ++addct; } } } } catch (Throwable e) { BedrockPlugin.logE("Problem getting package fragments: " + e); } } } else { for (IJavaElement pi : getAllProjects()) { IJavaProject xjp = pi.getJavaProject(); if (xjp != null && !rgn.contains(xjp)) { rgn.add(xjp); ++addct; } // String pnm = pi.getJavaProject().getProject().getName(); // handleFindHierarchy(pnm,null,null,all,xw); } } if (addct > 0 && ijp != null) { try { BedrockPlugin.logD("FIND TYPE HIERARCHY FOR " + fortype + " " + addct + " " + rgn); ITypeHierarchy ith; if (fortype != null) ith = ijp.newTypeHierarchy(fortype, rgn, null); else ith = ijp.newTypeHierarchy(rgn, null); BedrockUtil.outputTypeHierarchy(ith, xw); } catch (JavaModelException e) { BedrockPlugin.logE("Problem outputing type hierarchy: " + e); } catch (NullPointerException e) { // this is a bug in Eclipse that should be fixed } } }
From source file:org.eclipse.che.plugin.java.testing.JavaTestFinder.java
License:Open Source License
private List<String> findClassesInContainer(IJavaElement container, String testMethodAnnotation, String testClassAnnotation) { List<String> result = new LinkedList<>(); IRegion region = getRegion(container); try {//from w w w .j a v a2 s. c om ITypeHierarchy hierarchy = JavaCore.newTypeHierarchy(region, null, null); IType[] allClasses = hierarchy.getAllClasses(); // search for all types with references to RunWith and Test and all subclasses HashSet<IType> candidates = new HashSet<>(allClasses.length); SearchRequestor requestor = new AnnotationSearchRequestor(hierarchy, candidates); IJavaSearchScope scope = SearchEngine.createJavaSearchScope(allClasses, IJavaSearchScope.SOURCES); int matchRule = SearchPattern.R_CASE_SENSITIVE; SearchPattern testPattern = SearchPattern.createPattern(testMethodAnnotation, IJavaSearchConstants.ANNOTATION_TYPE, IJavaSearchConstants.ANNOTATION_TYPE_REFERENCE, matchRule); SearchPattern runWithPattern = isNullOrEmpty(testClassAnnotation) ? testPattern : SearchPattern.createPattern(testClassAnnotation, IJavaSearchConstants.ANNOTATION_TYPE, IJavaSearchConstants.ANNOTATION_TYPE_REFERENCE, matchRule); SearchPattern annotationsPattern = SearchPattern.createOrPattern(runWithPattern, testPattern); SearchParticipant[] searchParticipants = new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }; new SearchEngine().search(annotationsPattern, searchParticipants, scope, requestor, null); // find all classes in the region for (IType candidate : candidates) { if (isAccessibleClass(candidate) && !Flags.isAbstract(candidate.getFlags()) && region.contains(candidate)) { result.add(candidate.getFullyQualifiedName()); } } } catch (CoreException e) { LOG.info("Can't build project hierarchy.", e); } return result; }
From source file:org.jboss.tools.arquillian.core.internal.util.ArquillianSearchEngine.java
License:Open Source License
public static void findTestsInContainer(IJavaElement element, Set result, IProgressMonitor pm, boolean checkDeployment, boolean checkTest, boolean checkSuite) throws CoreException { if (element == null || result == null) { throw new IllegalArgumentException(); }//ww w . ja v a 2 s . c o m if (element instanceof IType) { if (isArquillianJUnitTest((IType) element, checkDeployment, checkTest, true)) { result.add(element); return; } } if (pm == null) pm = new NullProgressMonitor(); try { pm.beginTask(JUnitMessages.JUnit4TestFinder_searching_description, 4); IRegion region = CoreTestSearchEngine.getRegion(element); ITypeHierarchy hierarchy = JavaCore.newTypeHierarchy(region, null, new SubProgressMonitor(pm, 1)); IType[] allClasses = hierarchy.getAllClasses(); // search for all types with references to RunWith and Test and all subclasses HashSet candidates = new HashSet(allClasses.length); SearchRequestor requestor = new AnnotationSearchRequestor(hierarchy, candidates); IJavaSearchScope scope = SearchEngine.createJavaSearchScope(allClasses, IJavaSearchScope.SOURCES); int matchRule = SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE; SearchPattern runWithPattern = SearchPattern.createPattern(Annotation.RUN_WITH.getName(), IJavaSearchConstants.ANNOTATION_TYPE, IJavaSearchConstants.ANNOTATION_TYPE_REFERENCE, matchRule); //SearchPattern testPattern= SearchPattern.createPattern(Annotation.TEST.getName(), IJavaSearchConstants.ANNOTATION_TYPE, IJavaSearchConstants.ANNOTATION_TYPE_REFERENCE, matchRule); //SearchPattern annotationsPattern= SearchPattern.crateOrPattern(runWithPattern, testPattern); SearchPattern annotationsPattern = runWithPattern; SearchParticipant[] searchParticipants = new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }; new SearchEngine().search(annotationsPattern, searchParticipants, scope, requestor, new SubProgressMonitor(pm, 2)); // find all classes in the region for (Iterator iterator = candidates.iterator(); iterator.hasNext();) { IType curr = (IType) iterator.next(); if (isAccessibleClass(curr) && !Flags.isAbstract(curr.getFlags()) && region.contains(curr)) { ITypeBinding binding = getTypeBinding(curr); if (binding != null && isTest(binding, true, true, true)) { result.add(curr); } } } if (checkSuite) { CoreTestSearchEngine.findSuiteMethods(element, result, new SubProgressMonitor(pm, 1)); } } finally { pm.done(); } }