I have the IResource
object of a Java class. I need to get the fully qualified class name from this object.
My IResource.getFullPath().toString()
gives me /myProject/src/abc/def/Myclass.java
. I want to get abc.def.Myclass
from it.
How can I get the fully qualified class name?
Not sure if you want the fully qualified class name or the fully qualified location in the file system. I'll mention both:
Class name:
((IType) JavaCore.create(iFile)).getFullyQualifiedName()
Also, make sure to check for nulls and instanceof.
Resource location:
iFile.getLocation()
package abc.def;
public class MyClass {
public void displayName() {
System.out.println(this.class.getCanonicalName());// adc.def.MyClass
};
};
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.