Can't set modifier to Method declaration [message #717759] |
Mon, 22 August 2011 09:10  |
Eclipse User |
|
|
|
I use jdt(Ver=3.6.2.v_A76_R36x, API=JSL3) to generate a member method or field
I find the output method has no modifiers.
MethodDeclaration#setModifier(int) is @Deprecated,So I use MethodDeclaration#setFlag(int) method.
I tried parameter Modifier.PUBLIC, Modifier.ModifierKeyword.PUBLIC_KEYWORD.toFlagValue(), neither works.
Code:
MethodDeclaration md = ast.newMethodDeclaration();
md.setFlags(Modifier.ModifierKeyword.PUBLIC_KEYWORD.toFlagValue());
md.setReturnType2(ast.newPrimitiveType(PrimitiveType.VOID));
// md.setFlags(Modifier.PUBLIC | Modifier.STATIC);
md.setName(ast.newSimpleName("onCreate"));
Output:
void onCreate( ...
Question:
Where public keyword gone? how to add modifier? why ? or a Bug?
[Updated on: Mon, 22 August 2011 09:22] by Moderator Report message to a moderator
|
|
|
Re: Can't set modifier to Method declaration [message #717783 is a reply to message #717759] |
Mon, 22 August 2011 11:01   |
Eclipse User |
|
|
|
setModifier is replaced with setProperty of MODIFIERS2_PROPERTY. However, if you have to modify the code, you should something like.
ListRewrite listRewrite= rewrite.getListRewrite(md, MethodDeclaration.MODIFIERS2_PROPERTY);
listRewrite.insertFirst(ast.newModifier(Modifier.ModifierKeyword.PUBLIC_KEYWORD), null);
|
|
|
|
Powered by
FUDForum. Page generated in 0.07431 seconds