Having a problem with the ast.newSimpleName() method.
I am not able to create a SimpleName of the sort ‘SomeJava.class’. But the method works fine for names like ‘SWT.None’ or ‘SomeJava.None’.
Here is the code :
MethodInvocation loggerInstance = ast.newMethodInvocation();
loggerInstance.setExpression(ast.newSimpleName("Logger"));
loggerInstance.setName(ast.newSimpleName("getLogger"));
String[] name1 = {className.replace(".java", ""),"None"};
String[] name2 = {className.replace(".java", ""), "class"};
loggerInstance.arguments().add(ast.newName(name1)); // This works
loggerInstance.arguments().add(ast.newName(name2)); // This doesn't
Should i use any thing else other than SimpleName for this. Thanks in advance.
Edit : This is the statement i want to construct:
Logger.getLogger(ClientTest.class);
During my analysis, i found out that the problem arises when using the “class” literal. Not sure how to overcome this.
ast.newName("class");
ast.newSimpleName("class");
Got it from ASTView. Finally downloaded and installed it. 🙂
It should be a generated as a TypeLiteral, not as a SimpleName/Name.