super class from IClassFile [message #198510] |
Mon, 14 March 2005 16:19  |
Eclipse User |
|
|
|
Hi,
I am doing some introspection of some .class files that don't have an
source associated with them. I am able to introspect a .class file from
my workspace - the problem is i want to also introspect that classes
super class.
i can get the methods and fields of a .class with the following:
IClassFile cf = (IClassFile) JavaCore.createClassFileFrom(classFile);
IType classType = cf.getType();
from classType i can get the methods and fields.
now if i do
classType.getSuperclassName()
i can get the name of the superclass.
how do i get its methods and fields?
thanks
Anthony Perritano
|
|
|
|
|
|
Re: super class from IClassFile [message #198850 is a reply to message #198550] |
Wed, 16 March 2005 16:13  |
Eclipse User |
|
|
|
your right - what i am doing is in my RCP app, when the user creates a
project a jar is extracted inside the project in a folder called jars.
so when i create the project i set the classpath with the JRE container
like so:
IPath jarPath = curnitsPath.append("wiseproject" + ".jar");
IFolder jarFolder = root.getFolder(jarPath);
IClasspathEntry jEntry = JavaCore.newLibraryEntry(jarPath, null, null);
IClasspathEntry[] jlassPath = { jEntry,
JavaRuntime.getDefaultJREContainerEntry()};
javaProject.setRawClasspath(jlassPath, monitor);
resulting .classpath
<classpath>
<classpathentry kind="lib" path="jars/wiseproject.jar"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="output" path="bin"/>
</classpath>
this worked and i am able to get foo's super class fooS. with:
IType[] allSuperclasses =
hierarchy.getAllSuperclasses(hierarchy.getType());
However, if the super class is a class such as JFrame, JComponent or
even Object, getAllSuperclasses returns null.
what do i need to do so getAllSuperclasses returns all the classes on
including JFrame, JComponent and object.
thanks
Anthony
Jerome Lanneluc wrote:
> It sounds like your classpath is not correctly set.
>
> Jerome
>
> Anthony Perritano wrote:
>
>> i was able to get the hierarchy by doing
>>
>> ITypeHierarchy hierarchy = fooType.newSupertypeHierarchy(null);
>>
>> to get the class that my Foo class extends
>> however, when i do:
>>
>> IType[] allTypes = hierarchy.getAllTypes()
>>
>> returns just Foo
>>
>> or
>>
>> IType superclass = hierarchy.getSuperclass(classType);
>>
>> return nulls
>>
>> am I missing something? what do i need to do?
>>
>> thanks
>> Anthony Perritano
>>
>> Anthony Perritano wrote:
>>
>>> Hi,
>>> I am doing some introspection of some .class files that don't have an
>>> source associated with them. I am able to introspect a .class file
>>> from my workspace - the problem is i want to also introspect that
>>> classes super class.
>>>
>>> i can get the methods and fields of a .class with the following:
>>>
>>>
>>> IClassFile cf = (IClassFile) JavaCore.createClassFileFrom(classFile);
>>> IType classType = cf.getType();
>>>
>>> from classType i can get the methods and fields.
>>>
>>> now if i do
>>>
>>> classType.getSuperclassName()
>>>
>>> i can get the name of the superclass.
>>>
>>> how do i get its methods and fields?
>>>
>>> thanks
>>> Anthony Perritano
|
|
|
Powered by
FUDForum. Page generated in 0.02989 seconds