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;
}
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;
}
Aggregations