diff options
| author | Sarika Sinha | 2021-01-12 08:16:18 +0000 |
|---|---|---|
| committer | Sarika Sinha | 2021-01-12 08:16:18 +0000 |
| commit | 3679deb06ddea0b31023bd528ae01894ca7ba4c8 (patch) | |
| tree | ffc71bebfa64c83178369fc4c4c3adc696783830 | |
| parent | 73c7689754d2c147335db5a8818906f3db01a470 (diff) | |
| download | eclipse.jdt.core-3679deb06ddea0b31023bd528ae01894ca7ba4c8.tar.gz eclipse.jdt.core-3679deb06ddea0b31023bd528ae01894ca7ba4c8.tar.xz eclipse.jdt.core-3679deb06ddea0b31023bd528ae01894ca7ba4c8.zip | |
Bug 570248 - [AST] AST support for Local EnumsY20210113-0120Y20210112-1200
Change-Id: I4bf0552f8521d8b5e7a871fff05323457160e903
| -rw-r--r-- | org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter_16Test.java | 34 | ||||
| -rw-r--r-- | org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTConverter.java | 7 |
2 files changed, 39 insertions, 2 deletions
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter_16Test.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter_16Test.java index 8e500846ca..065b5fc2f1 100644 --- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter_16Test.java +++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter_16Test.java @@ -748,4 +748,38 @@ public class ASTConverter_16Test extends ConverterTestSetup { assertFalse("Is a CanonicalConstructor?", methodBinding.isCompactConstructor()); assertFalse("Is a CompactConstructor?", methodBinding.isCompactConstructor()); } + + public void testLocalEnum() throws CoreException { + if (!isJRE16) { + System.err.println("Test "+getName()+" requires a JRE 16"); + return; + } + String contents = "public class X {\n" + + " public static void main(String[] args) {\n" + + " enum Y1 { \n" + + " \n" + + " BLEU, \n" + + " BLANC, \n" + + " ROUGE,\n" + + " BLEU;\n" + + " public static void main(String[] args) {\n" + + " for(Y1 y: Y1.values()) {\n" + + " System.out.print(y);\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n"; + this.workingCopy = getWorkingCopy("/Converter_16/src/X.java", true/*resolve*/); + ASTNode node = buildAST( + contents, + this.workingCopy); + assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType()); + CompilationUnit compilationUnit = (CompilationUnit) node; + assertProblemsSize(compilationUnit, 0); + node = getASTNode(compilationUnit, 0, 0, 0); + assertEquals("Not an enum statement", ASTNode.ENUM_DECLARATION, node.getNodeType()); + } + + } diff --git a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTConverter.java b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTConverter.java index d4cc8ef850..209101ea41 100644 --- a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTConverter.java +++ b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTConverter.java @@ -2987,7 +2987,7 @@ class ASTConverter { } if (statement instanceof org.eclipse.jdt.internal.compiler.ast.TypeDeclaration) { ASTNode result = convert((org.eclipse.jdt.internal.compiler.ast.TypeDeclaration) statement); - if (result == null || !(result instanceof TypeDeclaration || result instanceof RecordDeclaration)) { + if (result == null || !(result instanceof TypeDeclaration || result instanceof RecordDeclaration || result instanceof EnumDeclaration)) { return createFakeEmptyStatement(statement); } TypeDeclarationStatement typeDeclarationStatement = new TypeDeclarationStatement(this.ast); @@ -2995,9 +2995,12 @@ class ASTConverter { // annotation and enum type declarations are not returned by the parser inside method bodies TypeDeclaration typeDeclaration = (TypeDeclaration) result; typeDeclarationStatement.setDeclaration(typeDeclaration); - } else { + } else if (result instanceof RecordDeclaration) { RecordDeclaration recordDeclaration = (RecordDeclaration) result; typeDeclarationStatement.setDeclaration(recordDeclaration); + } else { + EnumDeclaration enumDeclaration = (EnumDeclaration) result; + typeDeclarationStatement.setDeclaration(enumDeclaration); } switch(this.ast.apiLevel) { case AST.JLS2_INTERNAL : |
