if (elem instanceof ICompilationUnit) {
ICompilationUnit unit = (ICompilationUnit) elem;
try {
IType primaryType = unit.findPrimaryType();
if (primaryType != null) {
ITypeHierarchy supertypeHierarchy = primaryType.newSupertypeHierarchy(new NullProgressMonitor());
if (supertypeHierarchy.contains(getDefaultWOComponentType())) {
setSuperClass(primaryType.getFullyQualifiedName(), true);
}
}
} catch (JavaModelException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
// auto-populate implementing interface (if selected)
initSuperInterfaces(elem);
// if the package fragment isn't set default to Main.class's package
if (getPackageFragment() == null || getPackageFragment().isDefaultPackage()) {
IPackageFragmentRoot froot = getPackageFragmentRoot();
if (froot != null) {
IJavaElement compilationUnit = findMainClass(froot);
if (compilationUnit instanceof ICompilationUnit) {
IType type = ((ICompilationUnit) compilationUnit).findPrimaryType();
if (type != null) {
setPackageFragment(type.getPackageFragment(), true);
}
}
}
}
}
// if the superclass isn't initialised set the default
boolean requiresSuperclass = getSuperClass() == null || getSuperClass().matches("\\s*");
if (!requiresSuperclass) {
requiresSuperclass = true;
try {
IType supertype = getJavaProject().findType(getSuperClass());
ITypeHierarchy supertypeHierarchy = supertype.newSupertypeHierarchy(new NullProgressMonitor());
if (supertypeHierarchy.contains(getDefaultWOComponentType())) {
requiresSuperclass = false;
}
} catch (JavaModelException e) {
// nothing to do, invalid type
} catch (NullPointerException e) {