Home » Language IDEs » Java Development Tools (JDT) » Promlems with IType.getFullyQualifiedName() for inner classes
Promlems with IType.getFullyQualifiedName() for inner classes [message #216417] |
Thu, 06 October 2005 07:33  |
Eclipse User |
|
|
|
Hi all,
Our plugin deals with .class files. User selects some classes
Package Explorer view, then plugin collects objects of IType
type from user selection. Then, we need to resolve paths to
..class files from this selection. The following code is used:
IType type = getNextTypeFromSelection();
String fqName = type.getFullyQualifiedName();
IPath path = getPathToCompiledElement(fgName);
...
where getFullyQualifiedName() is expected to return names like
my.package.MyClass,
my.package.MyClass$MyInner,
my.package.MyClass$1
etc...
getPathToCompiledElement(name) -- my method, that looks for
file named name.class in output folder.
The code works well, but there are problems with inner classes.
1) first problem - inner-inner classes, e.g.
class A {
class B {
void foo() {
new Object() {
// class A$B$1 is here
};
}
}
}
for this inner-inner class, getFullyQualifiedName() returns
A$B$1, but actual class file is A$2.class. I'm not sure, is
it bug or not, and I have work-around for that.
2) another problem - when there are several anonymous inner
classes in one class:
class A {
void test1() {
new Object() {
// class A$1 is here
};
}
void test2() {
new Object() {
// class A$2 is here
};
}
}
for both inner IType's, getFullyQualifiedName() returns
A$1, while I'm expecting A$1 and A$2. Debugger shows, that
IType objects are different (have different methods, etc.).
Is it right behaviour for getFullyQualifiedName() method?
I've seen it on 3.0.2, but people get that behavoiur on
3.1, too.
thanks,
/Sergey
|
|
|
Re: Promlems with IType.getFullyQualifiedName() for inner classes [message #216427 is a reply to message #216417] |
Thu, 06 October 2005 07:51   |
Eclipse User |
|
|
|
Sorry, but this works as specified. Please see the spec for IType#getTypeQualifiedName()
(the name contains the occurrence count of the inner type, not the class file name).
The rational is that the Java model is source based. It doesn't know about the .class file.
So you cannot assume the name of an anonymous .class file (this name is generated at codegen
time).
It looks like you would need support described in https://bugs.eclipse.org/bugs/show_bug.cgi?id=6584
which is unfortunately not high priority.
Jerome
Sergey Bushkov wrote:
> Hi all,
>
> Our plugin deals with .class files. User selects some classes
> Package Explorer view, then plugin collects objects of IType
> type from user selection. Then, we need to resolve paths to
> ..class files from this selection. The following code is used:
>
> IType type = getNextTypeFromSelection();
> String fqName = type.getFullyQualifiedName();
> IPath path = getPathToCompiledElement(fgName);
> ...
>
> where getFullyQualifiedName() is expected to return names like
> my.package.MyClass,
> my.package.MyClass$MyInner,
> my.package.MyClass$1
> etc...
>
> getPathToCompiledElement(name) -- my method, that looks for
> file named name.class in output folder.
>
> The code works well, but there are problems with inner classes.
>
> 1) first problem - inner-inner classes, e.g.
> class A {
> class B {
> void foo() {
> new Object() {
> // class A$B$1 is here
> };
> }
> }
> }
> for this inner-inner class, getFullyQualifiedName() returns
> A$B$1, but actual class file is A$2.class. I'm not sure, is
> it bug or not, and I have work-around for that.
>
> 2) another problem - when there are several anonymous inner
> classes in one class:
> class A {
> void test1() {
> new Object() {
> // class A$1 is here
> };
> }
> void test2() {
> new Object() {
> // class A$2 is here
> };
> }
> }
>
> for both inner IType's, getFullyQualifiedName() returns
> A$1, while I'm expecting A$1 and A$2. Debugger shows, that
> IType objects are different (have different methods, etc.).
>
> Is it right behaviour for getFullyQualifiedName() method?
>
> I've seen it on 3.0.2, but people get that behavoiur on
> 3.1, too.
>
> thanks,
> /Sergey
|
|
|
Re: Problems with IType.getFullyQualifiedName() for inner classes [message #216432 is a reply to message #216427] |
Thu, 06 October 2005 08:08   |
Eclipse User |
|
|
|
Thanks, Jerome,
I see, we have to use work-around here.
But does it mean ("the name contains the occurrence count of
the inner type"), that it should return different numbers
for different inner classes, like MyClass$1, MyClass$2, etc.?
In my case, it returns just MyClass$1 for all inner classes.
/Sergey
Jerome Lanneluc wrote:
> Sorry, but this works as specified. Please see the spec for
> IType#getTypeQualifiedName()
> (the name contains the occurrence count of the inner type, not the class
> file name).
>
> The rational is that the Java model is source based. It doesn't know
> about the .class file.
> So you cannot assume the name of an anonymous .class file (this name is
> generated at codegen
> time).
>
> It looks like you would need support described in
> https://bugs.eclipse.org/bugs/show_bug.cgi?id=6584
> which is unfortunately not high priority.
>
> Jerome
|
|
|
Re: Problems with IType.getFullyQualifiedName() for inner classes [message #216446 is a reply to message #216432] |
Thu, 06 October 2005 10:14   |
Eclipse User |
|
|
|
The occurrence count for local types is relative to the method that defines
them. So in your case, you have 1 anonymous in each method that both have
an occurrence count of 1.
I agree this is unfortunate as you cannot make the distinction on the fully
qualified name. However the IType handles won't be equals (since their parent
(an IMethod) is different. Can you use the handle instead of the qualified name ?
Note that if you need a String, you can use IJavaElement#getHandleIdentifer().
These should be different for the 2 local classes.
Jerome
Sergey Bushkov wrote:
> Thanks, Jerome,
>
> I see, we have to use work-around here.
>
> But does it mean ("the name contains the occurrence count of
> the inner type"), that it should return different numbers
> for different inner classes, like MyClass$1, MyClass$2, etc.?
>
> In my case, it returns just MyClass$1 for all inner classes.
>
> /Sergey
>
> Jerome Lanneluc wrote:
>
>> Sorry, but this works as specified. Please see the spec for
>> IType#getTypeQualifiedName()
>> (the name contains the occurrence count of the inner type, not the
>> class file name).
>>
>> The rational is that the Java model is source based. It doesn't know
>> about the .class file.
>> So you cannot assume the name of an anonymous .class file (this name
>> is generated at codegen
>> time).
>>
>> It looks like you would need support described in
>> https://bugs.eclipse.org/bugs/show_bug.cgi?id=6584
>> which is unfortunately not high priority.
>>
>> Jerome
|
|
|
Re: Problems with IType.getFullyQualifiedName() for inner classes [message #216470 is a reply to message #216446] |
Thu, 06 October 2005 12:14  |
Eclipse User |
|
|
|
Thanks again, it's clearer now.
/Sergey
Jerome Lanneluc wrote:
> The occurrence count for local types is relative to the method that defines
> them. So in your case, you have 1 anonymous in each method that both have
> an occurrence count of 1.
>
> I agree this is unfortunate as you cannot make the distinction on the fully
> qualified name. However the IType handles won't be equals (since their
> parent
> (an IMethod) is different. Can you use the handle instead of the
> qualified name ?
>
> Note that if you need a String, you can use
> IJavaElement#getHandleIdentifer().
> These should be different for the 2 local classes.
>
> Jerome
|
|
|
Goto Forum:
Current Time: Sun May 11 07:33:11 EDT 2025
Powered by FUDForum. Page generated in 0.04897 seconds
|