Skip to content

Commit

Permalink
enumConstantDeclaration's setSource start position fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
subyssurendran666 authored and mpalat committed Jan 29, 2025
1 parent 2fd9321 commit 89c7b3e
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2024 GK Software SE and others.
* Copyright (c) 2024, 2025 GK Software SE and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand All @@ -14,6 +14,7 @@
package org.eclipse.jdt.core.tests.dom;

import java.util.HashMap;
import java.util.Hashtable;
import java.util.List;
import java.util.Map;
import junit.framework.Test;
Expand Down Expand Up @@ -529,4 +530,37 @@ public final class X implements A {}
assertTrue(Modifier.isStrictfp(aBinding.getModifiers()));
assertTrue(Modifier.isPublic(aBinding.getModifiers()));
}

public void testBug549248_01() throws CoreException {
String contents = """
public enum X {
JAPAN(new java.lang.String[] {"1","2"}){
@Override
public String getGreeting() {
return "Hello from Japan!";
}
},
public enum LoginType {
public com.naver.linewebtoon.common.localization.X.LoginType EMAIL = "null";
}
}
""";

ASTParser parser = ASTParser.newParser(AST.getJLSLatest());
parser.setSource(contents.toCharArray());
parser.setEnvironment(null, null, null, true);
parser.setResolveBindings(false);

Hashtable<String, String> options = JavaCore.getDefaultOptions();
options.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_23);
options.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_23);
options.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_23);

parser.setCompilerOptions(options);

ASTNode node = parser.createAST(null);

assertNotNull("ASTNode creation failed. Node is null!", node);
}
}
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,8 +1831,13 @@ 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 == -1) start = anonymousType.bodyStart;

int end = retrieveRightBrace(anonymousType.bodyEnd +1, declarationSourceEnd);
if (end == -1) end = anonymousType.bodyEnd;

if(end < start) start = end;

anonymousClassDeclaration.setSourceRange(start, end - start + 1);
enumConstantDeclaration.setAnonymousClassDeclaration(anonymousClassDeclaration);
buildBodyDeclarations(anonymousType, anonymousClassDeclaration);
Expand Down

0 comments on commit 89c7b3e

Please sign in to comment.