i.e. if we have a TYPE_USE annotation:
@Target({ElementType.TYPE_USE})
public @interface Test {}
can be applied to on the creation of an Object, i.e.:
Map m = new @Test Map();
In JavaParser (as of version 3.13.10)
if we parse:
Statement st = StaticJavaParser.parseStatement("N n = new @Test N();");
System.out.println("ST " + st );
the output is:
"N n = new N();" //missing @Test annotation
here's a quick test to verify what I found... it doesn't appear to JUST be a print problem:
public void testMissingTypeUseAnnotationOnObjectCreationExpr(){
ExpressionStmt es = (ExpressionStmt)StaticJavaParser.parseStatement("N n = new @Test N();");
VariableDeclarationExpr vd = es.getExpression().asVariableDeclarationExpr();
VariableDeclarator var = vd.getVariable(0);
ObjectCreationExpr init = (ObjectCreationExpr)var.getInitializer().get();
//here we expect the Type to have the @Test annotation
assertFalse( init.getType().getAnnotations().isEmpty() );
}
Thanks! This will be fixed ASAP.
(Note that JavaParser doesn't know what kind of annotation it is, so it has some standard rules for which node they end up on. See here for example: https://static.javadoc.io/com.github.javaparser/javaparser-core/3.14.0/com/github/javaparser/ast/body/MethodDeclaration.html )
"matozoid added Bug report Grammar labels 3 hours from now"
I think github is having a time issue.....