From 36c4df4b0de3dcd2df0f506dc116a273ec923e56 Mon Sep 17 00:00:00 2001 From: r0texx <95041046+r0texx@users.noreply.github.com> Date: Mon, 17 Jun 2024 11:20:22 +0300 Subject: [PATCH] Update StandAloneASTParserTest.java --- .../tests/dom/StandAloneASTParserTest.java | 44 ++++++++++++++++++- 1 file changed, 42 insertions(+), 2 deletions(-) diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/dom/StandAloneASTParserTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/dom/StandAloneASTParserTest.java index c1b51acd74f..4b6ae168745 100644 --- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/dom/StandAloneASTParserTest.java +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/dom/StandAloneASTParserTest.java @@ -1956,5 +1956,45 @@ public void testBug568629() throws JavaModelException { assertEquals("Syntax error, insert \"AssignmentOperator Expression\" to complete Expression",cu.getProblems()[6].getMessage()); } - -} \ No newline at end of file + public void testBugGithub2402() throws JavaModelException { + String contents = + "package test;\n" + + "\n" + + "public class TestClass {\n" + + " @com.Missing\n" + + " public TestClass() {\n" + + " new test.TestClass();\n" + + " }\n" + + "}\n" + + "\n" + + "class com {\n" + + "}\n"; + + ASTParser parser = ASTParser.newParser(AST.JLS20); + parser.setResolveBindings(true); + parser.setStatementsRecovery(true); + parser.setBindingsRecovery(true); + parser.setKind(ASTParser.K_COMPILATION_UNIT); + parser.setEnvironment(new String[0], new String[0], null, false); + parser.setSource(contents.toCharArray()); + parser.setUnitName("test.TestClass"); + + Map options = JavaCore.getDefaultOptions(); + options.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_17); + options.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_17); + options.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_17); + parser.setCompilerOptions(options); + ASTNode node = parser.createAST(null); + assertTrue("Should be a compilation unit", node instanceof CompilationUnit); + + CompilationUnit cu = (CompilationUnit) node; + TypeDeclaration type = (TypeDeclaration) cu.types().get(0); + MethodDeclaration method = (MethodDeclaration) type.bodyDeclarations().get(0); + ExpressionStatement stmt = (ExpressionStatement) method.getBody().statements().get(0); + ClassInstanceCreation expr = (ClassInstanceCreation) stmt.getExpression(); + IMethodBinding ctorBinding = expr.resolveConstructorBinding(); + assertNotNull(ctorBinding); + IAnnotationBinding[] annotations = ctorBinding.getAnnotations(); + assertNotNull(annotations); + } +}