Constants and PsiManager

I'm trying to write a plugin which will pull all

public static final String

variables out into a properties file, as part of an
externalization process. I'm to the point where I
can identify the PsiField objects which need to be
pulled out. (Though i'm a little unhappy about
having to use the "getText()" method along with
"indexOf()" to do things, but i can't find a better
way so far).

What i want to do at that point is to evaluate the
RHS of the expression, so i can place that in a properties
file. So a declaration like this:

public static final String RESOURCE_1 = "some value 1";

would yield the following in the properties file:

RESOURCE_1=some value 1

Now, keep in mind, there may be more than just string literals on the RHS. Is there a good way to do this, or should i just deal with string literals as a limitation to my plugin?

PsiClass classes[] = file.getClasses();
PsiClass theClass = null;
for (int i=0;i<classes.length;i++)
PsiClass clazz = classes+;
PsiModifierList ml = clazz.getModifierList();

if (clazz.getModifierList().getText().indexOf("public") != -1)
theClass = clazz;

if (theClass != null)
ArrayList al = new ArrayList();
PsiField fields[] = theClass.getFields();
for (int i=0;i<fields.length;i++)
PsiField f = fields+;
PsiType ftype = f.getType();

PsiModifierList ml = f.getModifierList();
String mt = ml.getText();
if (mt.indexOf("public") != -1 &&
mt.indexOf("static") !=- -1 &&
mt.indexOf("final") != -1 &&
(ftype.getText().equals(String.class.getName()) ||

1 comment
Comment actions Permalink

Use getModifierList().hasModifierProperty(PsiModifier.ABSTRACT) instead.
com.intellij.psi.PsiModifier has all modifier constants you are looking for.



Please sign in to leave a comment.