Skip to main content



      Home
Home » Language IDEs » Java Development Tools (JDT) » Getting type argument qualified type signatures
Getting type argument qualified type signatures [message #243310] Mon, 30 April 2007 17:15 Go to next message
Eclipse UserFriend
Given a class defined as follows:

public class MyClass
{
List<SomeObject> getListOfSomeObject();
}

Given that I have IType for MyClass from which I obtain the IMethod for
"getListOfSomeObject", is there any way to get a fully qualified signature
back for the return type that looks like this:

"Ljava.util.List<E:Lcom.somepackage.SomeObject;>;"


I know I can use the IType for MyClass to do a resolveType() on the return
type signature I obtain for "getListOfSomeObject". But this seems to
truncate the type argument informatino and just give me "Ljava.util.List;".


--Cam
Re: Getting type argument qualified type signatures [message #243316 is a reply to message #243310] Tue, 01 May 2007 12:00 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: myawn.ebay.com

Cameron Bateman wrote:
> Given a class defined as follows:
>
> public class MyClass
> {
> List<SomeObject> getListOfSomeObject();
> }
>
> Given that I have IType for MyClass from which I obtain the IMethod for
> "getListOfSomeObject", is there any way to get a fully qualified
> signature back for the return type that looks like this:
>
> "Ljava.util.List<E:Lcom.somepackage.SomeObject;>;"
>
>
> I know I can use the IType for MyClass to do a resolveType() on the
> return type signature I obtain for "getListOfSomeObject". But this
> seems to truncate the type argument informatino and just give me
> "Ljava.util.List;".
>
>
> --Cam
>

That's because at runtime, the complete type information is
Ljava.util.List;. All of the paramaterized type information is erased
by the compiler.
Re: Getting type argument qualified type signatures [message #243319 is a reply to message #243310] Tue, 01 May 2007 12:03 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: myawn.ebay.com

Cameron Bateman wrote:
> Given a class defined as follows:
>
> public class MyClass
> {
> List<SomeObject> getListOfSomeObject();
> }
>
> Given that I have IType for MyClass from which I obtain the IMethod for
> "getListOfSomeObject", is there any way to get a fully qualified
> signature back for the return type that looks like this:
>
> "Ljava.util.List<E:Lcom.somepackage.SomeObject;>;"
>
>
> I know I can use the IType for MyClass to do a resolveType() on the
> return type signature I obtain for "getListOfSomeObject". But this
> seems to truncate the type argument informatino and just give me
> "Ljava.util.List;".
>
>
> --Cam
>

That's because at runtime, Ljava.util.List; IS the complete type. All
of the paramaterized type information is erased by the compiler.
Re: Getting type argument qualified type signatures [message #243328 is a reply to message #243319] Tue, 01 May 2007 14:18 Go to previous messageGo to next message
Eclipse UserFriend
> That's because at runtime, Ljava.util.List; IS the complete type. All
> of the paramaterized type information is erased by the compiler.
Re: Getting type argument qualified type signatures [message #243332 is a reply to message #243319] Tue, 01 May 2007 14:26 Go to previous messageGo to next message
Eclipse UserFriend
> That's because at runtime, Ljava.util.List; IS the complete type. All
> of the paramaterized type information is erased by the compiler.

Sorry about the last post. 'Post' is unfortuately the default enter on
this page in my browser...

I am aware of runtime type erasure, but I'm interested in doing design
(compile) time analysis. For a method like:

List<SomeObject> getListOfSomeObject();

I am able to determine from the IMethod I can get back that List has a
argument called QSomeObject; and given that I have the enclosing IType I
can usually get to Lcom.package.SomeObject; by calling resolveType.
However to get to Ljava.util.List<E:Lcom.package.SomeObject;>; requires me
to do a lot of strange contortions especially if I want to account for all
the special cases such as if the return type has multiple type parameters
or if it's type arguments themselves have type arguments.

So I wondered if there's an easier way to do that. Given that JDT needs
to do exactly this kind of analysis to determine, for example, whether
something like:

List<...> myList = getListOfSomeObject();

is a valid assignment, I figured there may be something in the API that I
did not see or understand that I could use to do this analysis in my own
code.


--Cam
Re: Getting type argument qualified type signatures [message #243404 is a reply to message #243332] Thu, 03 May 2007 12:08 Go to previous messageGo to next message
Eclipse UserFriend
Are you using the DOM AST ? If so, then you can ask bindings for their
signatures, which will yield this very information.

Cameron Bateman wrote:
>> That's because at runtime, Ljava.util.List; IS the complete type.
>> All of the paramaterized type information is erased by the compiler.
>
> Sorry about the last post. 'Post' is unfortuately the default enter on
> this page in my browser...
>
> I am aware of runtime type erasure, but I'm interested in doing design
> (compile) time analysis. For a method like:
>
> List<SomeObject> getListOfSomeObject();
>
> I am able to determine from the IMethod I can get back that List has a
> argument called QSomeObject; and given that I have the enclosing IType I
> can usually get to Lcom.package.SomeObject; by calling resolveType.
> However to get to Ljava.util.List<E:Lcom.package.SomeObject;>; requires
> me to do a lot of strange contortions especially if I want to account
> for all the special cases such as if the return type has multiple type
> parameters or if it's type arguments themselves have type arguments.
>
> So I wondered if there's an easier way to do that. Given that JDT needs
> to do exactly this kind of analysis to determine, for example, whether
> something like:
>
> List<...> myList = getListOfSomeObject();
>
> is a valid assignment, I figured there may be something in the API that
> I did not see or understand that I could use to do this analysis in my
> own code.
>
>
> --Cam
>
Re: Getting type argument qualified type signatures [message #243429 is a reply to message #243404] Thu, 03 May 2007 15:26 Go to previous message
Eclipse UserFriend
Philippe Mulet wrote:

> Are you using the DOM AST ? If so, then you can ask bindings for their
> signatures, which will yield this very information.

My usage scenario involves resolving bean information for JSF managed
beans. My starting point is usually a fully qualified class name (i.e.
com.foo.MyBean). I then want to be able to resolve this name to a type
within the current project classpath (currently I try to resolve to an
IType). I need the IType to do things like resolve methods on the type so
I can determine valid bean properties. I need it to work seemlessly
regardless of whether the type is binary or source since the class name
could be coming from anywhere on the classpath (obviously certain
information may be limited if it's binary).

Could this also be done with the DOM AST? When I looked at it, it seemed
more oriented toward automatically creating and editing Java code based on
a DOM.


--Cam
Previous Topic:Creating project from existing source!
Next Topic:Eclipse compiler and static initializers
Goto Forum:
  


Current Time: Wed Jul 23 10:42:20 EDT 2025

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

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

Back to the top