Skip to main content



      Home
Home » Language IDEs » Java Development Tools (JDT) » super class from IClassFile
super class from IClassFile [message #198510] Mon, 14 March 2005 16:19 Go to next message
Eclipse UserFriend
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 #198519 is a reply to message #198510] Mon, 14 March 2005 17:29 Go to previous messageGo to next message
Eclipse UserFriend
Use IType#newSupertypeHierarchy(...) to get the resolved super types of
your IType.

Jerome

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
Re: super class from IClassFile [message #198527 is a reply to message #198510] Mon, 14 March 2005 17:35 Go to previous messageGo to next message
Eclipse UserFriend
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
Re: super class from IClassFile [message #198550 is a reply to message #198527] Tue, 15 March 2005 05:26 Go to previous messageGo to next message
Eclipse UserFriend
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
Re: super class from IClassFile [message #198850 is a reply to message #198550] Wed, 16 March 2005 16:13 Go to previous message
Eclipse UserFriend
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
Previous Topic:Change output folder to a folder outside of project
Next Topic:Why is importing JDT projects, so counter-intuitive?
Goto Forum:
  


Current Time: Sun Jun 08 07:08:59 EDT 2025

Powered by FUDForum. Page generated in 0.02989 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top