Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » Clean way of getting fully qualified types of imethod parameters?
Clean way of getting fully qualified types of imethod parameters? [message #935161] Sat, 06 October 2012 19:08 Go to next message
Missing name Mising name is currently offline Missing name Mising nameFriend
Messages: 15
Registered: July 2009
Junior Member
I am trying to get the fully qualified types from an imethod without poking the imports.

Is there a way to resolve "Qzzzz;" into "xxx.yyy.zzz" for Icompilationunit cu?

Do I need to use the IClassFile?

Thanks a lot in advance!!!
Re: Clean way of getting fully qualified types of imethod parameters? [message #936105 is a reply to message #935161] Sun, 07 October 2012 17:42 Go to previous messageGo to next message
Missing name Mising name is currently offline Missing name Mising nameFriend
Messages: 15
Registered: July 2009
Junior Member
I meant the fully qualified names of the parameters in an imethod.

int method1(String s){
}

getParameterTypes() returns "QString;"

Is there a clean way to turn "QString:" into java.lang.String?

Thanks a sorry for the confusing post
Re: Clean way of getting fully qualified types of imethod parameters? [message #937238 is a reply to message #936105] Mon, 08 October 2012 20:22 Go to previous messageGo to next message
Missing name Mising name is currently offline Missing name Mising nameFriend
Messages: 15
Registered: July 2009
Junior Member
Would attaching source to an IClassFile bring the following out come:

Map the offset of the ICompilationUnit's method to the same method in the IClassFile so when I call
IClassFile.getElementAt(int) using the same offset from the CU returns the same IMethod from the IClassFile?

In the hope that this way IClassFile's IMethod.getParameterTypes() return the fully qualified names of those type

Thanks a lot!
Re: Clean way of getting fully qualified types of imethod parameters? [message #937491 is a reply to message #937238] Tue, 09 October 2012 02:21 Go to previous messageGo to next message
Stephan Herrmann is currently offline Stephan HerrmannFriend
Messages: 1853
Registered: July 2009
Senior Member
The name must be resolved relative to the declaring class, so from the IMethod fetch the parent IType, from where you can use IType.resolveType(String).
For further inspiration you may want to take a look at the implementation of the (jdt.ui internal) method org.eclipse.jdt.internal.corext.util.JavaModelUtil.getResolvedTypeName(String, IType).

HTH
Stephan
Re: Clean way of getting fully qualified types of imethod parameters? [message #937840 is a reply to message #937491] Tue, 09 October 2012 10:08 Go to previous messageGo to next message
Missing name Mising name is currently offline Missing name Mising nameFriend
Messages: 15
Registered: July 2009
Junior Member
Stephan Herrmann wrote on Mon, 08 October 2012 22:21
The name must be resolved relative to the declaring class, so from the IMethod fetch the parent IType, from where you can use IType.resolveType(String).
For further inspiration you may want to take a look at the implementation of the (jdt.ui internal) method org.eclipse.jdt.internal.corext.util.JavaModelUtil.getResolvedTypeName(String, IType).

HTH
Stephan


"The name must be resolved relative to the declaring class" I supposed it was necessary.

"so from the IMethod fetch the parent IType, from where you can use IType.resolveType(String)"

I swear I tried this but probably with the other things going on I may have messed it up.

"For further inspiration you may want to take a look at the implementation of the (jdt.ui internal) method org.eclipse.jdt.internal.corext.util.JavaModelUtil.getResolvedTypeName(String, IType)."

Thanks for the tip. Will look into it.

Again thanks!
Re: Clean way of getting fully qualified types of imethod parameters? [message #938367 is a reply to message #937491] Tue, 09 October 2012 20:22 Go to previous messageGo to next message
Missing name Mising name is currently offline Missing name Mising nameFriend
Messages: 15
Registered: July 2009
Junior Member
Stephan Herrmann wrote on Mon, 08 October 2012 22:21
The name must be resolved relative to the declaring class, so from the IMethod fetch the parent IType, from where you can use IType.resolveType(String).
For further inspiration you may want to take a look at the implementation of the (jdt.ui internal) method org.eclipse.jdt.internal.corext.util.JavaModelUtil.getResolvedTypeName(String, IType).

HTH
Stephan


It worked! The trick was to clean the output from getParameterType() which is "Qtype_name;". Once I passed type_name to resolveType, I got the info I needed

Thanks a lot!!
Re: Clean way of getting fully qualified types of imethod parameters? [message #938512 is a reply to message #938367] Tue, 09 October 2012 23:53 Go to previous message
Missing name Mising name is currently offline Missing name Mising nameFriend
Messages: 15
Registered: July 2009
Junior Member
I found a problem. I don't know if it's known.

Say:

public Type1 returnType1(Type1 t){
....
}

I can resolve the parameter t when calling the declaring IType resolveType().

But if I call getReturnType() afterwards on the IMethod I get an Exception saying that the return type is not in the correct format (?) I am calling getDeclaringType() just once before calling the mentioned methods

Is this a known problem? I can get around this but I thought about mentioning it.

[Updated on: Tue, 09 October 2012 23:55]

Report message to a moderator

Previous Topic:interface implemenation methods with reasonable argument names?
Next Topic:Problems During Content Assist (error on @ completion)
Goto Forum:
  


Current Time: Thu Apr 25 21:42:36 GMT 2024

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

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

Back to the top