Don't quite understand the PsiNameIdentifierOwner
I'm currently writing a custom language plugin for an OOP java-like language, trying to learn along the way.
Example bnf:
{
tokens=[
...
CLASS="class"
...
id="regexp:[a-zA-Z_]\w*"
]
}
class_declaration ::= class_modifiers class identifier extends_clause? class_body
class_modifiers ::= abstract? statemachine?
identifier ::= id
extends_clause ::= ...
class_body ::= ...
My previous understanding about the difference between PsiNameIdentifierOwner and PsiNamedElement was:
PsiNamedElement should be implemented by elements entirely representing the identifier, so for the above bnf it would be appropriate to make Identifier element implement PsiNamedElement and then I would define a Reference resolving to that Identifier element.
If however, I wanted references to resolve to the actual class declaration, I would need instead to make ClassDeclaration implement PsiNameIdentifierOwner and return nested Identifier element in getNameIdentifier() in addition to implementing getName as smth like getIdentifier().getText()
and setName having the logic to replace getIdentifier with a new Identifier element.
But having tried the second approach (for now without any references), it didn't seem to work. The Shift+F6 (my shortcut for Rename) does not bring up the rename dialog when the caret is inside the identifier element (which is what I want) but weirdly it actually brings it up when the caret is in the first child of class_declaration or the white space after that (which is what I don't want).
Where did I go wrong with this?
Please sign in to leave a comment.
Not sure if I did what I was supposed to, but after debugging some IDEA platform code I found out that I get the desired behavior after overriding getTextOffset() method for my ClassDeclaration and returning Identifier.getTextOffset() in there.