Bug 421101 - [dom ast] Use generics in DOM APIs
Summary: [dom ast] Use generics in DOM APIs
Status: ASSIGNED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 4.4   Edit
Hardware: All All
: P4 enhancement (vote)
Target Milestone: ---   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 562669 (view as bug list)
Depends on: 416586 421017
Blocks:
  Show dependency tree
 
Reported: 2013-11-05 13:09 EST by Markus Keller CLA
Modified: 2020-05-02 16:41 EDT (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 Markus Keller CLA 2013-11-05 13:09:35 EST
Using generics in DOM APIs sounds as easy as turning "(element type: XXX)" comments into proper type arguments, but there are quite a few caveats:

ChildPropertyDescriptor and ChildListPropertyDescriptor should also get a type parameter, so that APIs like ASTRewrite#getListRewrite(ASTNode, ChildListPropertyDescriptor) can return a properly-typed ListRewrite<T>.

Some child list properties have type IExtendedModifier or IDocElement (bug 416586), which are not subtypes of ASTNode. We probably need a new super-interface IASTNode. But this introduces problems in all APIs that currently use ASTNode.

A few helper methods like ASTNode#copySubtree(AST, ASTNode) or ASTRewrite#createCopyTarget(ASTNode) should get a method type parameter.
Comment 1 Markus Keller CLA 2015-12-15 14:38:30 EST
https://wiki.eclipse.org/Generify_A_Java_Project#Required_Projects contains a few helpful regular expressions for this undertaking.

> ChildPropertyDescriptor and ChildListPropertyDescriptor should also get a type
> parameter

StructuralPropertyDescriptor probably also needs a type parameter <N extends IASTNode> for the nodeClass field. Then, the Child(List)PropertyDescriptor classes would get two type parameters. The only thing that this changes is everything.

The "// stuff nodeClass at head of list for future ref" in ASTNode#createPropertyList(..) would make this part of ASTNodes' implementation effectively unchecked. Code like this should be replaced by a proper fluent builder:
 
	static {
		List properyList = new ArrayList(2);
		createPropertyList(BooleanLiteral.class, properyList);
		addProperty(BOOLEAN_VALUE_PROPERTY, properyList);
		PROPERTY_DESCRIPTORS = reapPropertyList(properyList);
	}
Comment 2 Stephan Herrmann CLA 2020-05-02 16:41:32 EDT
*** Bug 562669 has been marked as a duplicate of this bug. ***