[Custom Language] How to create reference contributor for an element with stub

已回答

In the stub tutorial, if i want to create a stub for an element, the element need extend StubBasedPsiElementBase<XXXElementStub>. But the reference contributor tutorial tells the element need extend XXXNamedElementImpl. Is this conflict?

The stub tutorial: Stub Indexes | IntelliJ Platform Plugin SDK (jetbrains.com)
The reference tutorial: 10. Reference Contributor | IntelliJ Platform Plugin SDK (jetbrains.com)

0

Hi,

Please clarify what you mean. StubBasedPsiElementBase is a class, and PsiNameIdentifierOwner is an interface. You can extend a class and implement an interface at the same time. I don't see any conflict.

If it's not what you mean, then clarify the case.

0

Hi karol, 

Yes, the PsiNameIdentifierOwner is an interface, but the tutorial i  need to create an abstract class to implement it.

in the reference contributor tutorial, i add the "mixin" to my code and generate. 

mixin="org.intellij.sdk.language.psi.impl.SimpleNamedElementImpl" 
implements="org.intellij.sdk.language.psi.SimpleNamedElement"

Then the element extends SimpleNamedElementImpl. At the same time, the element need extend StubBasedPsiElementBase to accomplish the stub index

0

Implement a stub class, make your mixin extend StubBasedPsiElementBase<...>, and include stub class to the property rule:

property ::= (KEY? SEPARATOR VALUE?) | KEY {
mixin
="org.intellij.sdk.language.psi.impl.SimpleNamedElementImpl"
implements="org.intellij.sdk.language.psi.SimpleNamedElement"
stubClass="org.intellij.sdk.language.psi.PropertyStub"
}

 

0

Can I ask for what the functional result of this is? I'm not using gammar-kit anymore and encountered the same issue.

MyPsiElement implements PsiNamedElement for reference and within MyStubElementType I'm not sure how to implement 

override fun createPsi(stub: MyStub): MyPsiElement

In regular cases this is solved as MyPsiElement extends StubBasedPsiElementBase that has constructor accepting a stub

public StubBasedPsiElementBase(@NotNull T stub, @NotNull IStubElementType<?,?> nodeType)

But since I'm extending PsiNamedElement I cannot extend StubBasedElementBase and have no idea how to implement that createPsi

0

请先登录再写评论。