Skip to content

Commit

Permalink
Revert "update FieldAccess"
Browse files Browse the repository at this point in the history
This reverts commit b7e526b.
  • Loading branch information
ty-bnn committed Dec 1, 2024
1 parent 240929d commit 800e3b8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 56 deletions.
29 changes: 10 additions & 19 deletions org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -2259,26 +2259,17 @@ public Expression convert(org.eclipse.jdt.internal.compiler.ast.FieldReference r
if (this.resolveBindings) {
recordNodes(fieldAccess, reference);
}

List<Expression> names = new ArrayList<>();
org.eclipse.jdt.internal.compiler.ast.Expression exp = reference;
while (exp instanceof org.eclipse.jdt.internal.compiler.ast.FieldReference) {
org.eclipse.jdt.internal.compiler.ast.FieldReference ref = (org.eclipse.jdt.internal.compiler.ast.FieldReference) exp;
final SimpleName simpleName = new SimpleName(this.ast);
simpleName.internalSetIdentifier(new String(ref.token));
int sourceStart = (int)(ref.nameSourcePosition>>>32);
int length = (int)(ref.nameSourcePosition & 0xFFFFFFFF) - sourceStart + 1;
simpleName.setSourceRange(sourceStart, length);
if (this.resolveBindings) {
recordNodes(simpleName, reference);
}
names.add(simpleName);
exp = ref.receiver;
Expression receiver = convert(reference.receiver);
fieldAccess.setExpression(receiver);
final SimpleName simpleName = new SimpleName(this.ast);
simpleName.internalSetIdentifier(new String(reference.token));
int sourceStart = (int)(reference.nameSourcePosition>>>32);
int length = (int)(reference.nameSourcePosition & 0xFFFFFFFF) - sourceStart + 1;
simpleName.setSourceRange(sourceStart, length);
fieldAccess.setName(simpleName);
if (this.resolveBindings) {
recordNodes(simpleName, reference);
}
Collections.reverse(names);
fieldAccess.fieldNames().addAll(names);
Expression receiver = convert(exp);
fieldAccess.setExpression(convert(exp));
fieldAccess.setSourceRange(receiver.getStartPosition(), reference.sourceEnd - receiver.getStartPosition() + 1);
return fieldAccess;
}
Expand Down
49 changes: 12 additions & 37 deletions org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/FieldAccess.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,18 +71,10 @@ public class FieldAccess extends Expression {
/**
* The "name" structural property of this node type (child type: {@link SimpleName}).
* @since 3.0
* @deprecated replaced by NAMES_PROPERTY.
*/
public static final ChildPropertyDescriptor NAME_PROPERTY =
new ChildPropertyDescriptor(FieldAccess.class, "name", SimpleName.class, MANDATORY, NO_CYCLE_RISK); //$NON-NLS-1$

/**
* The "names" structural property of this node type (element type: {@link SimpleName}).
* @since 3.40
*/
public static final ChildListPropertyDescriptor NAMES_PROPERTY =
new ChildListPropertyDescriptor(FieldAccess.class, "names", SimpleName.class, NO_CYCLE_RISK); //$NON-NLS-1$

/**
* A list of property descriptors (element type:
* {@link StructuralPropertyDescriptor}),
Expand All @@ -94,7 +86,7 @@ public class FieldAccess extends Expression {
List properyList = new ArrayList(3);
createPropertyList(FieldAccess.class, properyList);
addProperty(EXPRESSION_PROPERTY, properyList);
addProperty(NAMES_PROPERTY, properyList);
addProperty(NAME_PROPERTY, properyList);
PROPERTY_DESCRIPTORS = reapPropertyList(properyList);
}

Expand Down Expand Up @@ -122,12 +114,9 @@ public static List propertyDescriptors(int apiLevel) {
/**
* The field; lazily initialized; defaults to an unspecified,
* but legal, simple field name.
* @deprecated replaced by fieldNames.
*/
private volatile SimpleName fieldName;

private ASTNode.NodeList fieldNames = new ASTNode.NodeList(NAMES_PROPERTY);

/**
* Creates a new unparented node for a field access expression owned by the
* given AST. By default, the expression and field are both unspecified,
Expand Down Expand Up @@ -157,17 +146,16 @@ final ASTNode internalGetSetChildProperty(ChildPropertyDescriptor property, bool
return null;
}
}
// allow default implementation to flag the error
return super.internalGetSetChildProperty(property, get, child);
}

@Override
final List internalGetChildListProperty(ChildListPropertyDescriptor property) {
if (property == NAMES_PROPERTY) {
return fieldNames();
if (property == NAME_PROPERTY) {
if (get) {
return getName();
} else {
setName((SimpleName) child);
return null;
}
}
// allow default implementation to flag the error
return super.internalGetChildListProperty(property);
return super.internalGetSetChildProperty(property, get, child);
}

@Override
Expand All @@ -180,7 +168,7 @@ ASTNode clone0(AST target) {
FieldAccess result = new FieldAccess(target);
result.setSourceRange(getStartPosition(), getLength());
result.setExpression((Expression) getExpression().clone(target));
result.fieldNames().addAll(ASTNode.copySubtrees(target, fieldNames()));
result.setName((SimpleName) getName().clone(target));
return result;
}

Expand All @@ -196,7 +184,7 @@ void accept0(ASTVisitor visitor) {
if (visitChildren) {
// visit children in normal left to right reading order
acceptChild(visitor, getExpression());
acceptChildren(visitor, this.fieldNames);
acceptChild(visitor, getName());
}
visitor.endVisit(this);
}
Expand Down Expand Up @@ -244,7 +232,6 @@ public void setExpression(Expression expression) {
* Returns the name of the field accessed in this field access expression.
*
* @return the field name
* @deprecated replaced by fieldNames.
*/
public SimpleName getName() {
if (this.fieldName == null) {
Expand All @@ -268,7 +255,6 @@ public SimpleName getName() {
* <li>the node belongs to a different AST</li>
* <li>the node already has a parent</li>
* </ul>
* @deprecated replaced by fieldNames.
*/
public void setName(SimpleName fieldName) {
if (fieldName == null) {
Expand All @@ -280,17 +266,6 @@ public void setName(SimpleName fieldName) {
postReplaceChild(oldChild, fieldName, NAME_PROPERTY);
}

/**
* Returns the live ordered list of field names.
*
* @return the live list of field names
* (element type: {@link SimpleName})
* @since 3.40
*/
public List fieldNames() {
return this.fieldNames;
}

@Override
int memSize() {
// treat Code as free
Expand Down Expand Up @@ -318,7 +293,7 @@ int treeSize() {
return
memSize()
+ (this.expression == null ? 0 : getExpression().treeSize())
+ (this.fieldNames == null ? 0 : this.fieldNames.listSize());
+ (this.fieldName == null ? 0 : getName().treeSize());
}
}

0 comments on commit 800e3b8

Please sign in to comment.