I have the IType object of a class. I want to know if the class is an abstract class or not. Is there any method available in the IType or ICompilationUnit to determine the same (other than reflection).
How to find if the IType is an abstract class
Asked Answered
You tagged eclipse-plugin, is there any other problem than these guys understood? –
Pulp
IType type = ...;
boolean isAbstract = Flags.isAbstract(type.getFlags());
You could get the IType's fully qualified name (maybe using IType.getTypeQualifiedName()), then use Class.forName() on that name to get the Class object, then use the Modifier.isAbstract() as others have recommended.
Java's Class object is part of the reflection suite, so this way still kinda uses reflection...
Class clazz = IType.class;
Modifier.isAbstract(clazz.getModifiers())
He didn't ask if
IType
is itself an abstract class, he asked how to tell if a class in Eclipse workspace (represented by an IType
) is abstract. –
Atonality Add the following import:
import java.lang.reflect.Modifier;
Then test it with the following:
if(Modifier.isAbstract(IType.class.getModifiers()))
//do something...
He didn't ask if
IType
is itself an abstract class, he asked how to tell if a class in Eclipse workspace (represented by an IType
) is abstract. –
Atonality © 2022 - 2024 — McMap. All rights reserved.