Bug 77359 - [1.5][dom] Pull up of type declaration facilities
Summary: [1.5][dom] Pull up of type declaration facilities
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.1   Edit
Hardware: PC All
: P3 enhancement (vote)
Target Milestone: 3.1 M4   Edit
Assignee: Jim des Rivieres CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-11-01 06:50 EST by Tobias Widmer CLA
Modified: 2004-12-14 23:20 EST (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tobias Widmer CLA 2004-11-01 06:50:28 EST
In order to better support the uniform treatment of (annotation/enum) type 
declarations, several methods should be pulled up to AbstractTypeDeclaration:

- getFields, getMethods, getTypes
- get/set SuperclassType
- superInterfaceTypes, typeParameters

Moreover, AbstractTypeDeclaration could offer methods to get the appropriate 
structural property descriptors of the subclass (e.g. the 
BODY_DECLARATIONS_PROPERTY)
Comment 1 Jim des Rivieres CLA 2004-11-01 13:14:07 EST
The problem is that these node types are quite dissimilar:

superInterfaceTypes() - annotation types do not have these

get/setSuperclassType() - annotation types and enum do not have these

typeParameters() - annotation types and enum do not have these

getField() - enum types have enum constants, but they are not field 
declarations

getMethod() - annotation types have AnnotationTypeMemberDeclarations, which
are not methods

In short, pulling this functionality up to AbstractTypeDeclaration would make 
the API more irregular.


Comment 2 Tobias Widmer CLA 2004-11-02 04:49:44 EST
I agree for getMethods() and getFields(). But the fact that abstract type 
declarations do not necessarily offer superclass types/superinterface types 
and type parameters does not contradict the need for uniform treatment of type 
declarations.

More important: There is currently no way to transparently get structural 
property descriptors based on an object of type AbstractTypeDeclaration (e.g. 
during a list rewrite). In order to handle e.g. body declarations one has to 
differentiate between three different types doing type tests, which is somehow 
cumbersome.

Methods as 'ChildListPropertyDescriptor 
AbstractTypeDeclaration#getBodyDeclarationsDescriptor()' would be helpful in 
these cases.
Comment 3 Jim des Rivieres CLA 2004-11-08 12:15:11 EST
On your first point, the nodes do not have a uniform structure. Adding 
superInterfaceTypes, etc. to annotations might make things more uniform for 
some clients, but not for all (e.g., these unused properties need to be 
ignored during serialization). So I'm reluctant to add unused properties 
unless there would be a significant advantage from doing so.

On your second point, we would need to add the following reified property 
methods to the abstract node classes to match what these abstract classes 
current support in the non-reified forms.

Annotation
public ChildPropertyDescriptor getTypeNameProperty();

AbstractTypeDeclaration
public ChildListPropertyDescriptor getBodyDeclarationsProperty();
public ChildPropertyDescriptor getNameProperty();

BodyDeclaration
public SimplePropertyDescriptor getModifiersProperty();
public ChildListPropertyDescriptor getModifiers2Property();
public ChildPropertyDescriptor getJavadocProperty();

VariableDeclaration
public SimplePropertyDescriptor getExtraDimensionsProperty();
public ChildPropertyDescriptor getInitializerProperty();
public ChildPropertyDescriptor getNameProperty();

These changes would make the API more uniform. We can add them if you think 
they will be helpful.
Comment 4 Tobias Widmer CLA 2004-11-08 12:53:25 EST
ad 1) I can see your point. However, the superclass/supertype, 
superInterfacetypes, and typeParameters properties are optional anyway. If 
there is a way to have these methods in AbstractTypeDeclaration returning null 
or an empty list, resp., without actually introducing unused properties in the 
subtypes, the implementation of these methods should not break existing 
clients. From the JDT UI side (in particular refactoring), such methods would 
be very helpful (e.g transparent handling of generic types, move refactorings, 
etc.). Otherwise, many type tests have to be performed.

If there is any chance to implement this without breaking too many internal 
clients in JDT Core, it would be a great help.

ad 2) This is exactly what we need! We would be glad if you can add them.
Comment 5 Jim des Rivieres CLA 2004-11-08 14:18:05 EST
re: 1) I don't see a good way to do this. Although the property values are 
optional, we would otherwise need to treat them as real properties whose value 
happens to be ignored by serialization (like the return type of a method 
declaration when used for a constructor).

re: 2) I will add these methods. On BodyDeclaration, rather than introduce a 
new method which would be deprecated in 3.1 as well, I would only handle the 
JLS3 properties:
public ChildListPropertyDescriptor getModifiersProperty(); // for JLS3 property
public ChildPropertyDescriptor getJavadocProperty();

Comment 6 Tobias Widmer CLA 2004-11-09 04:34:28 EST
Agreed.
Comment 7 Jim des Rivieres CLA 2004-11-09 08:46:00 EST
The new methods are included in v_521. (I was late in updating the build 
notes.)
Comment 8 Olivier Thomann CLA 2004-12-14 23:20:05 EST
Verified in 200412140800