I need to create a static String variable with a default value (e.g. public static final String COUNTRY=”INDIA”;) using Eclipse AST. I’m able to create such a varibale using SingleVariableDecleration or FieldDecleration. But I’m not sure how to initialize the same using AST.
This is what I could implement==>
public static final String COUNTRY;
This is what I could not implement==>
public static final String COUNTRY*=”INDIA”;*
Please help me to know how can I do this. Thanks in advance,
Shyam
First create a VariableDeclarationFragment in which you can specify the initializer. Then use this fragment to set FieldDeclaration.FRAGMENTS_PROPERTY.
You should use the AST View plugin to visualize the AST of Java source, this helps in creating the AST nodes for given source by hand which is what you are trying to do.