Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[jdt-dev] Unexpected behaviour in anonymous classes management

Hi, I'm using jdt to extract informations from java source code. Basically, I organize informations given back by subtypes of IJavaElement. I've found a strange behaviour when dealing with anonymous classes. As I expected, they come to the user as object of kind IType. The problem I noticed is with the fully qualified name. Suppose a situation like this:

package first
public class Example{

   public void methodA(){
// just a random interface- does not matter for the example Comparable c= new Comparable{
               public int compareTo(Object o) {
               //body does not matter here
               return 0;
               }
       }
       Comparable c1= new Comparable{
               public int compareTo(Object o) {
               //body does not matter here
               return 0;
               }
       }
   }
}

Here i get back for the first anonymous class (the one whose instance is assigned to c) the fully qualified name first.Example.1, while for the second (the one whose instance is assigned to c1) the fully qualified name is first.Example.2, a situation which i find correct.

But consider the case in which the two definitions lie in two different methods:

package first
public class Example{

   public void methodA(){
// just a random interface- does not matter for the example Comparable c= new Comparable{
               public int compareTo(Object o) {
               //body does not matter here
               return 0;
               }
       }
   }
   public void methodB(){
       Comparable c1= new Comparable{
               public int compareTo(Object o) {
               //body does not matter here
               return 0;
               }
       }
   }
}

Here i get back the same fully qualified name (first.Example.1) for both classes. Is this behaviour intentional? I think the reason is in the way jdt deals with the occurrenceCount field: since the parents of the classes (the methods) are different, the occurrenceCount goes back from 1. But this gives back same fq name for the classes, and I'm not sure this is correct. Hope to hear you, thanks for the attention.







Back to the top