Create Expression from text OpenApi

Answered

How can I create a simple PsiExpression like the one below?

String variable = "hello";

-->    "myString"+variable+"otherString"

After having created it I would like to parse it with the following command:

(String) JavaConstantExpressionEvaluator.computeConstantExpression(
(PsiExpression) expression, true);
2 comments
Comment actions Permalink
Official comment

JavaPsiFacade.getElementFactory(project).createExpressionFromText creates a PsiExpression object. To make the reference inside resolve to a specific variable, please pass some context that has the variable declaration in its scope.

Please sign in to leave a comment.