Skip to content

Commit

Permalink
Added NullEnumConstantDeclaration node and resolved the issue.
Browse files Browse the repository at this point in the history
  • Loading branch information
subyssurendran666 committed Jan 3, 2025
1 parent 4402f51 commit ced167b
Show file tree
Hide file tree
Showing 5 changed files with 167 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2024 IBM Corporation and others.
* Copyright (c) 2000, 2025 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -9528,7 +9528,8 @@ public void testNodeTypeConstants() throws Exception {
ASTNode.JAVADOC_TEXT_ELEMENT,
ASTNode.RECORD_PATTERN,
ASTNode.EitherOr_MultiPattern,
ASTNode.UNNAMED_CLASS
ASTNode.UNNAMED_CLASS,
ASTNode.NUll_ENUM_CONSTANT_DECLARATION
};

// assert that nodeType values are correct:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2024 IBM Corporation and others.
* Copyright (c) 2000, 2025 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -1831,6 +1831,9 @@ public EnumConstantDeclaration convert(org.eclipse.jdt.internal.compiler.ast.Fie
if (anonymousType != null) {
AnonymousClassDeclaration anonymousClassDeclaration = new AnonymousClassDeclaration(this.ast);
int start = retrieveStartBlockPosition(anonymousType.sourceEnd, anonymousType.bodyEnd);
if(start < 0) {
return createFakeEnumConstantDeclaration(enumConstant);
}
int end = retrieveRightBrace(anonymousType.bodyEnd +1, declarationSourceEnd);
if (end == -1) end = anonymousType.bodyEnd;
anonymousClassDeclaration.setSourceRange(start, end - start + 1);
Expand Down Expand Up @@ -4814,6 +4817,16 @@ protected Pattern createFakeNullPattern(org.eclipse.jdt.internal.compiler.ast.Pa
return nullPattern;
}

protected EnumConstantDeclaration createFakeEnumConstantDeclaration(org.eclipse.jdt.internal.compiler.ast.FieldDeclaration enumConstant) {
if (enumConstant == null) return null;
NullEnumConstantDeclaration nullEnumConstantDeclaration = new NullEnumConstantDeclaration(this.ast);
nullEnumConstantDeclaration.setFlags(nullEnumConstantDeclaration.getFlags() | ASTNode.MALFORMED);
int start = enumConstant.sourceStart;
int end = enumConstant.sourceEnd;
nullEnumConstantDeclaration.setSourceRange(start, end - start + 1);
return nullEnumConstantDeclaration;
}

/**
* @return a new modifier
*/
Expand Down
11 changes: 10 additions & 1 deletion org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTNode.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2024 IBM Corporation and others.
* Copyright (c) 2000, 2025 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -1081,6 +1081,13 @@ public abstract class ASTNode {
*/
public static final int UNNAMED_CLASS = 115;

/**
* Node type constant indicating a node of type
* <code>NullPattern</code>.
* @see NullPattern
* @since 3.41
*/
public static final int NUll_ENUM_CONSTANT_DECLARATION = 116;
/**
* Returns the node class for the corresponding node type.
*
Expand Down Expand Up @@ -1215,6 +1222,8 @@ public static Class nodeClassForType(int nodeType) {
return NameQualifiedType.class;
case NORMAL_ANNOTATION :
return NormalAnnotation.class;
case NUll_ENUM_CONSTANT_DECLARATION :
return NullEnumConstantDeclaration.class;
case NULL_LITERAL :
return NullLiteral.class;
case NULL_PATTERN :
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2023 IBM Corporation and others.
* Copyright (c) 2000, 2025 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -1235,6 +1235,23 @@ public boolean visit(NullPattern node) {
return true;
}

/**
* Visits the given type-specific AST node.
* <p>
* The default implementation does nothing and return true.
* Subclasses may reimplement.
* </p>
*
* @param node the node to visit
* @return <code>true</code> if the children of this node should be
* visited, and <code>false</code> if the children of this node should
* be skipped
* @since 3.41
*/
public boolean visit(NullEnumConstantDeclaration node) {
return true;
}

/**
* Visits the given type-specific AST node.
* <p>
Expand Down Expand Up @@ -2883,6 +2900,19 @@ public void endVisit(NullPattern node) {
// default implementation: do nothing
}

/**
* End of visit the given type-specific AST node.
* <p>
* The default implementation does nothing. Subclasses may reimplement.
* </p>
*
* @param node the node to visit
* @since 3.41
*/
public void endVisit(NullEnumConstantDeclaration node) {
//default implementation: do nothing
}

/**
* End of visit the given type-specific AST node.
* <p>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
/*******************************************************************************
* Copyright (c) 2025 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/

package org.eclipse.jdt.core.dom;

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

/**
* Null EnumConstantDeclaration node.
*
* @since 3.41
* @noinstantiate This class is not intended to be instantiated by clients.
*/
@SuppressWarnings("rawtypes")
public class NullEnumConstantDeclaration extends EnumConstantDeclaration {

/**
* Null EnumConstantDeclaration Pattern node.
*
* @since 3.27
* @noinstantiate This class is not intended to be instantiated by clients.
*/
private static final List PROPERTY_DESCRIPTORS;

static {
List propertyList = new ArrayList(1);
createPropertyList(NullPattern.class, propertyList);
PROPERTY_DESCRIPTORS = reapPropertyList(propertyList);
}

/**
* Returns a list of structural property descriptors for this node type.
* Clients must not modify the result.
*
* @param apiLevel the API level; one of the
* <code>AST.JLS*</code> constants
* @return a list of property descriptors (element type:
* {@link StructuralPropertyDescriptor})
* @since 3.38
*/
public static List propertyDescriptors(int apiLevel) {
return PROPERTY_DESCRIPTORS;
}

/**
* Creates a new unparented null literal node owned by the given AST.
* <p>
* N.B. This constructor is package-private.
* </p>
*
* @param ast the AST that is to own this node
*/
NullEnumConstantDeclaration(AST ast) {
super(ast);
supportedOnlyIn21();
}

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

// @Override
// final int getNodeType0() {
// return Null_ENUM_CONSTANT_DECLARATION;
// }

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

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

@Override
void accept0(ASTVisitor visitor) {
visitor.visit(this);
visitor.endVisit(this);
}

@Override
int memSize() {
return BASE_NODE_SIZE;
}

@Override
int treeSize() {
return memSize();
}

}

0 comments on commit ced167b

Please sign in to comment.