Skip to main content

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


Please enter a bug report for this against JDT/Core.






Antonio Cuomo <myskin83@xxxxxxxxx>
Sent by: jdt-dev-bounces@xxxxxxxxxxx

07/05/2008 06:51 PM

Please respond to
"Eclipse JDT general developers list." <jdt-dev@xxxxxxxxxxx>

To
jdt-dev@xxxxxxxxxxx
cc
Subject
[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.





_______________________________________________
jdt-dev mailing list
jdt-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/jdt-dev



Sauf indication contraire ci-dessus:/ Unless stated otherwise above:
Compagnie IBM France
Siège Social : Tour Descartes, 2, avenue Gambetta, La Défense 5, 92400 Courbevoie
RCS Nanterre 552 118 465
Forme Sociale : S.A.S.
Capital Social : 542.737.118 euros
SIREN/SIRET : 552 118 465 02430


Back to the top