Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a test case for #2402 #2584

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1956,5 +1956,45 @@ public void testBug568629() throws JavaModelException {
assertEquals("Syntax error, insert \"AssignmentOperator Expression\" to complete Expression",cu.getProblems()[6].getMessage());
}


}
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<String, String> 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);
}
}
Loading