Skip to content

Commit

Permalink
Replace Type Node to Elements Node
Browse files Browse the repository at this point in the history
  • Loading branch information
ty-bnn committed Dec 6, 2024
1 parent 7a65e53 commit dd3fdbd
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 56 deletions.
50 changes: 30 additions & 20 deletions org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ArrayType.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,17 @@ public class ArrayType extends Type {
* The "elementType" structural property of this node type (child type: {@link Type}) (added in JLS8 API).
* Cannot be an array type.
* @since 3.10
* @deprecated replaced by ELEMENTS_PROPERTY.
*/
public static final ChildPropertyDescriptor ELEMENT_TYPE_PROPERTY =
new ChildPropertyDescriptor(ArrayType.class, "elementType", Type.class, MANDATORY, CYCLE_RISK); //$NON-NLS-1$

/**
* @since 3.39
*/
public static final ChildListPropertyDescriptor ELEMENTS_PROPERTY =
new ChildListPropertyDescriptor(ArrayType.class, "elements", Expression.class, NO_CYCLE_RISK); //$NON-NLS-1$

/**
* The "dimensions" structural property of this node type (element type: {@link Dimension}) (added in JLS8 API).
* @since 3.10
Expand Down Expand Up @@ -93,7 +100,7 @@ public class ArrayType extends Type {

propertyList = new ArrayList(3);
createPropertyList(ArrayType.class, propertyList);
addProperty(ELEMENT_TYPE_PROPERTY, propertyList);
addProperty(ELEMENTS_PROPERTY, propertyList);
addProperty(DIMENSIONS_PROPERTY, propertyList);
PROPERTY_DESCRIPTORS_8_0 = reapPropertyList(propertyList);
}
Expand Down Expand Up @@ -123,9 +130,15 @@ public static List propertyDescriptors(int apiLevel) {
/**
* The element type (before JLS8: component type); lazily initialized; defaults to a simple type with
* an unspecified, but legal, name.
* @deprecated replaced by elements.
*/
private volatile Type type;

/**
* @since 3.39
*/
private ASTNode.NodeList elements = new ASTNode.NodeList(ELEMENTS_PROPERTY);

/**
* List of dimensions this node has with optional annotations
* (element type: {@link Dimension}).
Expand Down Expand Up @@ -184,27 +197,15 @@ final List internalGetChildListProperty(ChildListPropertyDescriptor property) {
if (property == DIMENSIONS_PROPERTY) {
return dimensions();
}
if (property == ELEMENTS_PROPERTY) {
return elements();
}
// allow default implementation to flag the error
return super.internalGetChildListProperty(property);
}

@Override
final ASTNode internalGetSetChildProperty(ChildPropertyDescriptor property, boolean get, ASTNode child) {
if (property == COMPONENT_TYPE_PROPERTY) {
if (get) {
return getComponentType();
} else {
setComponentType((Type) child);
return null;
}
} else if (property == ELEMENT_TYPE_PROPERTY) {
if (get) {
return getElementType();
} else {
setElementType((Type) child);
return null;
}
}
// allow default implementation to flag the error
return super.internalGetSetChildProperty(property, get, child);
}
Expand All @@ -222,7 +223,7 @@ ASTNode clone0(AST target) {
result.setComponentType((Type) getComponentType().clone(target));
} else {
result = new ArrayType(target, 0);
result.setElementType((Type) getElementType().clone(target));
result.elements().addAll(ASTNode.copySubtrees(target, elements()));
result.dimensions().addAll(
ASTNode.copySubtrees(target, dimensions()));
}
Expand All @@ -244,7 +245,7 @@ void accept0(ASTVisitor visitor) {
if (this.ast.apiLevel < AST.JLS8_INTERNAL) {
acceptChild(visitor, getComponentType());
} else {
acceptChild(visitor, getElementType());
acceptChildren(visitor, this.elements);
acceptChildren(visitor, this.dimensions);
}
}
Expand Down Expand Up @@ -318,6 +319,7 @@ private void internalSetType(Type componentType, ChildPropertyDescriptor propert
* </p>
*
* @return the element type node
* @deprecated replaced by elements.
*/
public Type getElementType() {
if (this.ast.apiLevel() < AST.JLS8_INTERNAL) {
Expand All @@ -342,6 +344,7 @@ public Type getElementType() {
* </ul>
* @exception UnsupportedOperationException if this operation is used below JLS8
* @since 3.10
* @deprecated replaced by elements.
*/
public void setElementType(Type type) {
unsupportedIn2_3_4();
Expand All @@ -351,6 +354,13 @@ public void setElementType(Type type) {
internalSetType(type, ELEMENT_TYPE_PROPERTY);
}

/**
* @since 3.39
*/
public List elements() {
return this.elements;
}

/**
* Returns the number of dimensions in this array type.
* <p>
Expand Down Expand Up @@ -403,8 +413,8 @@ int memSize() {
int treeSize() {
return
memSize()
+ (this.type == null ? 0 : (this.ast.apiLevel() < AST.JLS8_INTERNAL ? getComponentType().treeSize() : getElementType().treeSize())
+ (this.dimensions == null ? 0 : this.dimensions.listSize()));
+ (this.elements == null ? 0 : this.elements.listSize())
+ (this.dimensions == null ? 0 : this.dimensions.listSize());
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,17 @@ public class ParameterizedType extends Type {

/**
* The "type" structural property of this node type (child type: {@link Type}).
* @deprecated replaced by ELEMENTS_PROPERTY.
*/
public static final ChildPropertyDescriptor TYPE_PROPERTY =
new ChildPropertyDescriptor(ParameterizedType.class, "type", Type.class, MANDATORY, CYCLE_RISK); //$NON-NLS-1$

/**
* @since 3.39
*/
public static final ChildListPropertyDescriptor ELEMENTS_PROPERTY =
new ChildListPropertyDescriptor(ArrayAccess.class, "elements", Expression.class, NO_CYCLE_RISK); //$NON-NLS-1$

/**
* The "typeArguments" structural property of this node type (element type: {@link Type}).
*/
Expand All @@ -60,7 +67,7 @@ public class ParameterizedType extends Type {
static {
List propertyList = new ArrayList(3);
createPropertyList(ParameterizedType.class, propertyList);
addProperty(TYPE_PROPERTY, propertyList);
addProperty(ELEMENTS_PROPERTY, propertyList);
addProperty(TYPE_ARGUMENTS_PROPERTY, propertyList);
PROPERTY_DESCRIPTORS = reapPropertyList(propertyList);
}
Expand All @@ -82,9 +89,15 @@ public static List propertyDescriptors(int apiLevel) {
/**
* The type node; lazily initialized; defaults to an unspecified, but legal,
* type.
* @deprecated replaced by elements.
*/
private volatile Type type;

/**
* @since 3.39
*/
private ASTNode.NodeList elements = new ASTNode.NodeList(ELEMENTS_PROPERTY);

/**
* The type arguments (element type: {@link Type}).
* Defaults to an empty list.
Expand Down Expand Up @@ -114,14 +127,6 @@ final List internalStructuralPropertiesForType(int apiLevel) {

@Override
final ASTNode internalGetSetChildProperty(ChildPropertyDescriptor property, boolean get, ASTNode child) {
if (property == TYPE_PROPERTY) {
if (get) {
return getType();
} else {
setType((Type) child);
return null;
}
}
// allow default implementation to flag the error
return super.internalGetSetChildProperty(property, get, child);
}
Expand All @@ -131,6 +136,9 @@ final List internalGetChildListProperty(ChildListPropertyDescriptor property) {
if (property == TYPE_ARGUMENTS_PROPERTY) {
return typeArguments();
}
if (property == ELEMENTS_PROPERTY) {
return elements();
}
// allow default implementation to flag the error
return super.internalGetChildListProperty(property);
}
Expand All @@ -144,7 +152,7 @@ final int getNodeType0() {
ASTNode clone0(AST target) {
ParameterizedType result = new ParameterizedType(target);
result.setSourceRange(getStartPosition(), getLength());
result.setType((Type) getType().clone(target));
result.elements().addAll(ASTNode.copySubtrees(target, elements()));
result.typeArguments().addAll(
ASTNode.copySubtrees(target, typeArguments()));
return result;
Expand All @@ -161,7 +169,7 @@ void accept0(ASTVisitor visitor) {
boolean visitChildren = visitor.visit(this);
if (visitChildren) {
// visit children in normal left to right reading order
acceptChild(visitor, getType());
acceptChildren(visitor, this.elements);
acceptChildren(visitor, this.typeArguments);
}
visitor.endVisit(this);
Expand All @@ -171,6 +179,7 @@ void accept0(ASTVisitor visitor) {
* Returns the type of this parameterized type.
*
* @return the type of this parameterized type
* @deprecated replaced by elements.
*/
public Type getType() {
if (this.type == null) {
Expand All @@ -194,6 +203,7 @@ public Type getType() {
* <li>the node belongs to a different AST</li>
* <li>the node already has a parent</li>
* </ul>
* @deprecated replaced by elements.
*/
public void setType(Type type) {
if (type == null) {
Expand All @@ -205,6 +215,13 @@ public void setType(Type type) {
postReplaceChild(oldChild, type, TYPE_PROPERTY);
}

/**
* @since 3.39
*/
public List elements() {
return this.elements;
}

/**
* Returns the live ordered list of type arguments of this parameterized
* type. For the parameterized type to be plausible, the list should contain
Expand All @@ -231,7 +248,7 @@ int memSize() {
int treeSize() {
return
memSize()
+ (this.type == null ? 0 : getType().treeSize())
+ (this.elements == null ? 0 : this.elements.listSize())
+ this.typeArguments.listSize();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,17 @@ public class QualifiedType extends AnnotatableType {

/**
* The "qualifier" structural property of this node type (child type: {@link Type}).
* @deprecated replaced by ELEMENTS_PROPERTY.
*/
public static final ChildPropertyDescriptor QUALIFIER_PROPERTY =
new ChildPropertyDescriptor(QualifiedType.class, "qualifier", Type.class, MANDATORY, CYCLE_RISK); //$NON-NLS-1$

/**
* @since 3.39
*/
public static final ChildListPropertyDescriptor ELEMENTS_PROPERTY =
new ChildListPropertyDescriptor(QualifiedType.class, "elements", Expression.class, NO_CYCLE_RISK); //$NON-NLS-1$

/**
* The "annotations" structural property of this node type (element type: {@link Annotation}).
* @since 3.10
Expand Down Expand Up @@ -118,7 +125,7 @@ public class QualifiedType extends AnnotatableType {

propertyList = new ArrayList(4);
createPropertyList(QualifiedType.class, propertyList);
addProperty(QUALIFIER_PROPERTY, propertyList);
addProperty(ELEMENTS_PROPERTY, propertyList);
addProperty(ANNOTATIONS_PROPERTY, propertyList);
addProperty(NAME_PROPERTY, propertyList);
PROPERTY_DESCRIPTORS_8_0 = reapPropertyList(propertyList);
Expand Down Expand Up @@ -147,9 +154,15 @@ public static List propertyDescriptors(int apiLevel) {
/**
* The type node; lazily initialized; defaults to a type with
* an unspecified, but legal, simple name.
* @deprecated replaced by elements.
*/
private volatile Type qualifier;

/**
* @since 3.39
*/
private ASTNode.NodeList elements = new ASTNode.NodeList(ELEMENTS_PROPERTY);

/**
* The name being qualified; lazily initialized; defaults to a unspecified,
* legal Java identifier.
Expand Down Expand Up @@ -189,20 +202,15 @@ final List internalGetChildListProperty(ChildListPropertyDescriptor property) {
if (property == ANNOTATIONS_PROPERTY) {
return annotations();
}
if (property == ELEMENTS_PROPERTY) {
return elements();
}
// allow default implementation to flag the error
return super.internalGetChildListProperty(property);
}

@Override
final ASTNode internalGetSetChildProperty(ChildPropertyDescriptor property, boolean get, ASTNode child) {
if (property == QUALIFIER_PROPERTY) {
if (get) {
return getQualifier();
} else {
setQualifier((Type) child);
return null;
}
}
if (property == NAME_PROPERTY) {
if (get) {
return getName();
Expand All @@ -224,7 +232,7 @@ final int getNodeType0() {
ASTNode clone0(AST target) {
QualifiedType result = new QualifiedType(target);
result.setSourceRange(getStartPosition(), getLength());
result.setQualifier((Type) getQualifier().clone(target));
result.elements().addAll(ASTNode.copySubtrees(target, elements()));
if (this.ast.apiLevel >= AST.JLS8_INTERNAL) {
result.annotations().addAll(
ASTNode.copySubtrees(target, annotations()));
Expand All @@ -244,7 +252,7 @@ void accept0(ASTVisitor visitor) {
boolean visitChildren = visitor.visit(this);
if (visitChildren) {
// visit children in normal left to right reading order
acceptChild(visitor, getQualifier());
acceptChildren(visitor, this.elements);
if (this.ast.apiLevel >= AST.JLS8_INTERNAL) {
acceptChildren(visitor, this.annotations);
}
Expand All @@ -257,6 +265,7 @@ void accept0(ASTVisitor visitor) {
* Returns the qualifier of this qualified type.
*
* @return the qualifier of this qualified type
* @deprecated replaced by elements.
*/
public Type getQualifier() {
if (this.qualifier == null) {
Expand All @@ -280,6 +289,7 @@ public Type getQualifier() {
* <li>the node belongs to a different AST</li>
* <li>the node already has a parent</li>
* </ul>
* @deprecated replaced by elements.
*/
public void setQualifier(Type type) {
if (type == null) {
Expand All @@ -291,6 +301,13 @@ public void setQualifier(Type type) {
postReplaceChild(oldChild, type, QUALIFIER_PROPERTY);
}

/**
* @since 3.39
*/
public List elements() {
return this.elements;
}

/**
* Returns the name part of this qualified type.
*
Expand Down Expand Up @@ -339,7 +356,7 @@ int memSize() {
int treeSize() {
return
memSize()
+ (this.qualifier == null ? 0 : getQualifier().treeSize())
+ (this.elements == null ? 0 : this.elements.listSize())
+ (this.annotations == null ? 0 : this.annotations.listSize())
+ (this.name == null ? 0 : getName().treeSize());
}
Expand Down
Loading

0 comments on commit dd3fdbd

Please sign in to comment.