How to get value string in ExpressionTree

Hello everybody,

I have a question :
How to get just string in the value of ExpresionTree ?

Please help me. I don’t understand.

Hello,

Check the return type in the declaration of the firstToken() and lastToken() methods. It’s not any kind of Tree, it’s a SyntaxToken. Try setting the correct variable type, then you should be able to access the value() of the token.

Note that depending on what you are trying to achieve, that might be the wrong approach you are trying here. Through the Java Analyzer API, you have access to the full syntax tree of the analyzed code. Transforming it back to a String is going against the principle of transforming it into a tree in the first place. Try maybe to rather check if the given expression is of a given type, matching your expectations. i.e. for instance something like:

if (expression.is(Tree.Kind.IDENTIFIER)) {
  IdentifierTree identifier = (IdentifierTree) expression;
  // ...

Hope this helps,
Michael

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.