Example usage for org.eclipse.jdt.core JavaCore newTypeHierarchy

List of usage examples for org.eclipse.jdt.core JavaCore newTypeHierarchy

Introduction

In this page you can find the example usage for org.eclipse.jdt.core JavaCore newTypeHierarchy.

Prototype

public static ITypeHierarchy newTypeHierarchy(IRegion region, WorkingCopyOwner owner, IProgressMonitor monitor)
        throws JavaModelException 

Source Link

Document

Creates and returns a type hierarchy for all types in the given region, considering subtypes within that region and considering types in the working copies with the given owner.

Usage

From source file:org.eclipse.ajdt.internal.ui.refactoring.RippleMethodFinder2.java

License:Open Source License

private void createHierarchyOfDeclarations(IProgressMonitor pm, WorkingCopyOwner owner)
        throws JavaModelException {
    IRegion region = JavaCore.newRegion();
    for (Iterator iter = fDeclarations.iterator(); iter.hasNext();) {
        // AspectJ Change
        // original
        //          IType declaringType= ((IMethod) iter.next()).getDeclaringType();
        // new// w ww.  j a v a 2s.co  m
        IType declaringType = getType((IMethod) iter.next());
        // AspectJ end
        region.add(declaringType);
    }
    fHierarchy = JavaCore.newTypeHierarchy(region, owner, pm);
}

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 {// w ww  .  j  a  va  2 s  .com
        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();
    }/*from  w  ww.ja va 2s  .c om*/

    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();
    }
}