Highlight string literal parts in a specific method call Follow
Please take a look at my question on SO.
Thank you in advance!
Please sign in to leave a comment.
This can be achieved in custom plugin using Annotator API https://plugins.jetbrains.com/docs/intellij/syntax-highlighting-and-error-highlighting.html#annotator
Thank you for the reference. I was able to implement the Annotator and it does get hooked, however I'm stuck now with specific logic.
Let's say I have a literal in java code:
Given my super simple implementation without any logic:
bold is changed color text:
Actual result: "I want 45 to be BLUE and 'text' to be YELLOW" -> whole literal gets colored including double quotes.
Expected result: "I want 45 to be BLUE and 'text' to be YELLOW" -> only number is colored excluding double quotes as well.
I tried to search how can I split PsiLiteralExpression element into expressions by SPACE and exclude double quotes but this doesn't seem possible. Even if it is, the annotate(...) method provides annotation holder for given element and if I get string splitted I need to get annotation holders for each to process separately - how? :)
So the question is, how inside a method I can annotate different parts of a literal excluding quotes?
Specify explicit range via
Yann Cebron Done, thanks.
now I get almost the desired result but its very bad implemented:
As you can see I go up by the tree to match my condition. This looks completely rubbish ;(
I just want to apply my highlighting on a literal being a parameter of specific method.
I have Step class with method translate(String literal) and this is the only place for processing.
Is there any easier way to do so?
Use https://plugins.jetbrains.com/docs/intellij/element-patterns.html instead
Yeah, I looked at this, however it seems to be difficult.
I'd be very grateful if you can help me with writing my "finder"
PsiLiteralExpression should be a parameter of translate(java.lang.String) method call of class org.self.Step anywhere in the project.
Done, improved the code, however without pattern matching.