Bug 36819 - AST: binding of a anonymous class constructor
Summary: AST: binding of a anonymous class constructor
Status: RESOLVED WONTFIX
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 2.1   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.0 M1   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-04-23 16:00 EDT by Martin Aeschlimann CLA
Modified: 2003-06-02 06:12 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Martin Aeschlimann CLA 2003-04-23 16:00:37 EDT
2.1
When requesting the method bindings for an annonymous class
(ITypeBinding.getDeclaredMethods[]), you get, besides the methods defined in
source, a binding for the class' 'default constructor'. It has a empty name, and
is not synthetic.
compilationUnit.findDeclaringNode() of this binding returns null.

Maybe it would be better not to return such a binding, or mark it as synthetic.
Comment 1 Olivier Thomann CLA 2003-04-24 11:34:12 EDT
The problem is that no compiler (javac or jikes) tag such constructor as
synthetic. Therefore we cannot do it that way.
It is fairly easy to filter out this method binding in user code. I will discuss
with Jim to find out if it does make sense to filter it out in getDeclaredMethods.
Comment 2 Olivier Thomann CLA 2003-04-24 12:10:46 EDT
I would not fix this one.
The actual result is not wrong according to the specs. A default constructor is
never tagged as synthetic. But in this case it is not difficult to figure out
that you don't need to use this binding:
if (typeBinding.isAnonymous() && methodBinding.isConstructor()) {
   // you want to ignore it.
}
Ok to close?
Comment 3 Martin Aeschlimann CLA 2003-04-24 12:37:42 EDT
The IBinding.isSynthetic is doc'd:
 * Returns whether this binding is synthetic. A synthetic binding is one that
 * was made up by the compiler, rather than something declared in the 
 * source code.

I agree that this is a minor thing, workaround exists. Its really about making
the AST even better. I think every user of findDeclaringMethods will stumble
over this node. What is the value of it? The AST is representing the source, can
we really argue that this is something the compiler creates?

Can I detect this if the constructor is from a non-anonymous class? This is a
known problem with the IJavaModel nodes.
Comment 4 Olivier Thomann CLA 2003-04-24 16:13:28 EDT
I agree. The problem is that default constructors are not tagged as synthetic
even if they are strictly speaking. The synthetic attribute has been introduced
with the inner classes. We cannot change it.
isSynthetic() will return true only and only if the corresponding info (method
info or field info) has been tagged as synthetic in the .class file. I would say
the name getDeclaredMethods is not good. It should rather be getMethods(). Same
thing for the fields.
If we remove it for anonymous type binding, it should also be removed from top
level type binding and for them we have no clue that they are a default
constructor. So I don't think we improve our behavior there.
Comment 5 Martin Aeschlimann CLA 2003-04-25 10:20:22 EDT
I guess we're in trouble because the compiler defines the meaning of syntetic,
so it would be bad to have a one of our own. We should then change/improve the
doc of IBinding.isSynthetic, that there are bindings not in source but not
marked as syntetic.

And maybe we would need an new method IBinding.existsInSource to really know if
a default constructor exists or was just implicit.
It's easy to know this for an anonymous class but for a normal type declaration
you  can not tell if a default constructor i really in source or was implicit.
That's no problem for me now. (Ok to move to later)
Comment 6 Olivier Thomann CLA 2003-04-28 09:31:22 EDT
This is not simply a matter of moving later. I don't see a good way to solve 
it. It is easy to detect such a case for an anonymous type binding, but it is 
simply impossible for a top level class. We might have a solution using debug 
attributes, but then what do you do when you don't have any debug attributes?
In this case, I am sorry, but I think it is up to the user to filter out these 
method bindings.
Comment 7 Philipe Mulet CLA 2003-04-29 11:30:11 EDT
As Olivier, the information you are looking for doesn't exist any longer in a 
classfile. 

We cannot solve this one.