Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
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 11:33 Go to next message
Sergey Bushkov is currently offline Sergey BushkovFriend
Messages: 29
Registered: July 2009
Junior Member
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 11:51 Go to previous messageGo to next message
Jerome Lanneluc is currently offline Jerome LannelucFriend
Messages: 572
Registered: July 2009
Senior Member
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 12:08 Go to previous messageGo to next message
Sergey Bushkov is currently offline Sergey BushkovFriend
Messages: 29
Registered: July 2009
Junior Member
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 14:14 Go to previous messageGo to next message
Jerome Lanneluc is currently offline Jerome LannelucFriend
Messages: 572
Registered: July 2009
Senior Member
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 16:14 Go to previous message
Sergey Bushkov is currently offline Sergey BushkovFriend
Messages: 29
Registered: July 2009
Junior Member
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
Previous Topic:putting breakpoint in jsp compiled java code
Next Topic:Side effects by deactivating javabuilder
Goto Forum:
  


Current Time: Tue Jul 16 20:33:12 GMT 2024

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

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

Back to the top