Search in sources :

Example 36 with ITypeHierarchy

use of org.eclipse.jdt.core.ITypeHierarchy in project bndtools by bndtools.

the class JUnitShortcut method isTestable.

/*
     * Check if this element can be tested
     */
private static boolean isTestable(IType type) throws JavaModelException {
    assert type != null;
    int flags = type.getFlags();
    if (!type.isClass() || Flags.isAbstract(flags) || !Flags.isPublic(flags))
        return false;
    //
    // One of the super classes/interfaces must be a Junit class/interface
    //
    ITypeHierarchy hierarchy = type.newSupertypeHierarchy(null);
    for (IType z : hierarchy.getAllSupertypes(type)) {
        if (z.getFullyQualifiedName().startsWith("junit."))
            return true;
    }
    if (isJUnit4(type))
        return true;
    for (IType z : hierarchy.getAllSuperclasses(type)) {
        if (isJUnit4(z))
            return true;
    }
    return false;
}
Also used : ITypeHierarchy(org.eclipse.jdt.core.ITypeHierarchy) IType(org.eclipse.jdt.core.IType)

Example 37 with ITypeHierarchy

use of org.eclipse.jdt.core.ITypeHierarchy in project xtext-xtend by eclipse.

the class DispatchRenameSupport method getSubTypes.

protected Iterable<JvmGenericType> getSubTypes(JvmGenericType type, ResourceSet tempResourceSet) {
    IType javaType = (IType) javaElementFinder.findExactElementFor(type);
    List<JvmGenericType> allSubTypes = newArrayList();
    try {
        ITypeHierarchy typeHierarchy = javaType.newTypeHierarchy(javaType.getJavaProject(), new NullProgressMonitor());
        for (IType subType : typeHierarchy.getSubtypes(javaType)) {
            EObject jvmSubType = jvmElementFinder.getCorrespondingJvmElement(subType, tempResourceSet);
            if (jvmSubType instanceof JvmGenericType) {
                EObject indexJvmSubType = jvmElementFinder.findJvmElementDeclarationInIndex(jvmSubType, subType.getJavaProject().getProject(), type.eResource().getResourceSet());
                if (indexJvmSubType instanceof JvmGenericType) {
                    allSubTypes.add((JvmGenericType) indexJvmSubType);
                } else {
                    EObject jvmSubTypeInOtherResourceSet = type.eResource().getResourceSet().getEObject(EcoreUtil2.getPlatformResourceOrNormalizedURI(jvmSubType), true);
                    if (jvmSubTypeInOtherResourceSet instanceof JvmGenericType)
                        allSubTypes.add((JvmGenericType) jvmSubTypeInOtherResourceSet);
                }
            }
        }
    } catch (JavaModelException e) {
        LOG.error("Error calculating subtypes", e);
    }
    return allSubTypes;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) ITypeHierarchy(org.eclipse.jdt.core.ITypeHierarchy) JavaModelException(org.eclipse.jdt.core.JavaModelException) EObject(org.eclipse.emf.ecore.EObject) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) IType(org.eclipse.jdt.core.IType)

Aggregations

ITypeHierarchy (org.eclipse.jdt.core.ITypeHierarchy)37 IType (org.eclipse.jdt.core.IType)25 IMethod (org.eclipse.jdt.core.IMethod)14 SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)11 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)8 ArrayList (java.util.ArrayList)6 RefactoringStatus (org.eclipse.ltk.core.refactoring.RefactoringStatus)5 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)4 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)4 ModifierKeyword (org.eclipse.jdt.core.dom.Modifier.ModifierKeyword)4 MethodOverrideTester (org.eclipse.jdt.internal.corext.util.MethodOverrideTester)4 Type (org.eclipse.che.ide.ext.java.shared.dto.model.Type)3 JavaModelException (org.eclipse.jdt.core.JavaModelException)3 HashSet (java.util.HashSet)2 LinkedList (java.util.LinkedList)2 IJavaElement (org.eclipse.jdt.core.IJavaElement)2 MethodDeclaration (org.eclipse.jdt.core.dom.MethodDeclaration)2 RefactoringStatusContext (org.eclipse.ltk.core.refactoring.RefactoringStatusContext)2 HashMap (java.util.HashMap)1 List (java.util.List)1