Skip to content

Commit

Permalink
Add Expression2 Class
Browse files Browse the repository at this point in the history
  • Loading branch information
ty-bnn committed Dec 1, 2024
1 parent 34befa8 commit 81cf187
Show file tree
Hide file tree
Showing 4 changed files with 142 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3261,7 +3261,7 @@ public boolean match(ImplicitTypeDeclaration node, Object other) {
}

/**
* @since 3.40
* @since 3.39
*/
public boolean match(Operator node, Object other) {
if (!(other instanceof Operator)) {
Expand All @@ -3271,4 +3271,12 @@ public boolean match(Operator node, Object other) {
return node.getOperator().equals(o.getOperator());
}

/**
* @since 3.39
* TODO: if something went wrong, implement all nodes matcher which I made changes. Like ArrayAccess...
*/
public boolean match(Expression2 node, Object other) {
return true;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -1111,6 +1111,11 @@ public abstract class ASTNode {
*/
public static final int OPERATOR = 119;

/**
* @since 3.39
*/
public static final int EXPRESSION2 = 120;

/**
* Returns the node class for the corresponding node type.
*
Expand Down Expand Up @@ -1361,6 +1366,8 @@ public static Class nodeClassForType(int nodeType) {
return ImplicitTypeDeclaration.class;
case OPERATOR :
return Operator.class;
case EXPRESSION2 :
return Expression2.class;
}
throw new IllegalArgumentException();
}
Expand Down
17 changes: 15 additions & 2 deletions org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTVisitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -2167,12 +2167,19 @@ public boolean visit(ImplicitTypeDeclaration implicitTypeDeclaration) {

/**
* @param operator
* @since 3.40
* @since 3.39
*/
public boolean visit(Operator operator) {
return true;
}

/**
* @since 3.39
*/
public boolean visit(Expression2 expression) {
return true;
}

/**
* End of visit the given type-specific AST node.
* <p>
Expand Down Expand Up @@ -3641,10 +3648,16 @@ public void endVisit(ImplicitTypeDeclaration node) {
}

/**
* @since 3.40
* @since 3.39
*/
public void endVisit(Operator node) {
// default implementation: do nothing
}

/**
* @since 3.39
*/
public void endVisit(Expression2 node) {
// default implementation: do nothing
}
}
111 changes: 111 additions & 0 deletions org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/Expression2.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
package org.eclipse.jdt.core.dom;

import java.util.ArrayList;
import java.util.List;

/**
* @since 3.39
*/
@SuppressWarnings({ "rawtypes" })
public class Expression2 extends ASTNode {
/**
* @since 3.39
*/
public static final ChildListPropertyDescriptor ELEMENTS_PROPERTY =
new ChildListPropertyDescriptor(Expression2.class, "elements", ASTNode.class, NO_CYCLE_RISK); //$NON-NLS-1$

private static final List PROPERTY_DESCRIPTORS;

static {
List properyList = new ArrayList(5);
createPropertyList(Expression2.class, properyList);
addProperty(ELEMENTS_PROPERTY, properyList);
PROPERTY_DESCRIPTORS = reapPropertyList(properyList);
}

public static List propertyDescriptors(int apiLevel) {
return PROPERTY_DESCRIPTORS;
}

private ASTNode.NodeList elements = new ASTNode.NodeList(ELEMENTS_PROPERTY);

Expression2(AST ast) {
super(ast);
}

@Override
final List internalStructuralPropertiesForType(int apiLevel) {
return propertyDescriptors(apiLevel);
}

@Override
final Object internalGetSetObjectProperty(SimplePropertyDescriptor property, boolean get, Object value) {
// allow default implementation to flag the error
return super.internalGetSetObjectProperty(property, get, value);
}

@Override
final ASTNode internalGetSetChildProperty(ChildPropertyDescriptor property, boolean get, ASTNode child) {
// allow default implementation to flag the error
return super.internalGetSetChildProperty(property, get, child);
}

@Override
final List internalGetChildListProperty(ChildListPropertyDescriptor property) {
if (property == ELEMENTS_PROPERTY) {
return elements();
}
// allow default implementation to flag the error
return super.internalGetChildListProperty(property);
}

@Override
final int getNodeType0() {
return EXPRESSION2;
}

@Override
ASTNode clone0(AST target) {
Expression2 result = new Expression2(target);
result.setSourceRange(getStartPosition(), getLength());
result.elements().addAll(ASTNode.copySubtrees(target, elements()));
return result;
}

@Override
final boolean subtreeMatch0(ASTMatcher matcher, Object other) {
// dispatch to correct overloaded match method
return matcher.match(this, other);
}

@Override
void accept0(ASTVisitor visitor) {
boolean visitChildren = visitor.visit(this);
if (visitChildren) {
// visit children in normal left to right reading order
acceptChildren(visitor, this.elements);
}
visitor.endVisit(this);
}

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


@Override
int memSize() {
// treat Operator as free
return BASE_NODE_SIZE + 4 * 4;
}

@Override
int treeSize() {
return
memSize()
+ (this.elements == null ? 0 : this.elements.listSize());
}
}

0 comments on commit 81cf187

Please sign in to comment.