Any method to calculate constant operations?

There is a lot of codes using our old platform need to be adapted to our new platform. So, I have to make out a plugin to help developers to simplify this work.

There is a requirement that make the annotations on method from the old style to the new style:
This is quite easy. I just scan the method and add new annotations on those method.
The old value can be achieved by calling PsiLiteralExpression.getValue().
The perfix-value is added by:
private PsiExpression getExpressionFromText(String value, PsiAnnotation annotation) {
    return JavaPsiFacade.getInstance(project).getElementFactory().createExpressionFromText("\"" + PREFIX + value + "\"",

But there are some cases making the situation quite difficult. E.g.:
private static final String BASE_LOCATION = "/mgr/mer"; // in some other class
private static final Integer TOP_USER_LIMIT=10 //in some other class
private static final Integer TOP_GUEST_LIMIT=10 //in some other class
@Location({"/sys/topUser?limit="+TOP_USER_LIMIT, /sys/topGuest?limit="+TOP_GUEST_LIMIT})
@Uri({"cmbus:///sys/topUser?limit="+TOP_USER_LIMIT, cmbus:///sys/topGuest?limit="+TOP_GUEST_LIMIT})

So, I can't get the value directly, and don't know how to generate the PsiExpression in these situations.

Is there any method to calculate these constants, so I can put the target values into the annotations easily?
Comment actions Permalink

Hi Meilun,

There's an intention that determines the value of String concatenation: CopyConcatenatedStringToClipboardIntention.

You may be able to use the logic as a starting point.

It will even work if there are values like true or 4 in the concatenation.

Comment actions Permalink

Thanks, it looks very helpful.


Please sign in to leave a comment.