Community
Participate
Working Groups
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.
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.
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?
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.
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.
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)
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.
As Olivier, the information you are looking for doesn't exist any longer in a classfile. We cannot solve this one.