Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » Can't set modifier to Method declaration
Can't set modifier to Method declaration [message #717759] Mon, 22 August 2011 09:10 Go to next message
Jamling Li is currently offline Jamling LiFriend
Messages: 9
Registered: August 2011
Junior Member
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]

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 Go to previous messageGo to next message
Satyam Kandula is currently offline Satyam KandulaFriend
Messages: 444
Registered: July 2009
Senior Member
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);
Re: Can't set modifier to Method declaration [message #718665 is a reply to message #717783] Thu, 25 August 2011 01:39 Go to previous message
Jamling Li is currently offline Jamling LiFriend
Messages: 9
Registered: August 2011
Junior Member
thank you, I have resolved this question.
under JSL3, MethodDeclaration#modifies().addAll(Modifiers.PUBLIC | Modifers.STATIC);
Previous Topic:How set "launch configuration" in Eclipse?
Next Topic:PATH to Firefox
Goto Forum:
  


Current Time: Thu Apr 25 08:13:25 GMT 2024

Powered by FUDForum. Page generated in 0.03199 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top