Why do PSI element types have to have a separate interface and an implementation class?

I don't use GrammarKit BNF in my custom language parser, so I create the PSI element type classes manually, and I don't want to spend the effort creating two files for the same element type. Is there any reason or restriction?

 

In addition, I am writing a reference contributor, but PlatformPatterns.psiElement() is only matching the PsiComment elements in my file, where the PsiComments are the only non-custom element type used in my custom language (apart from whitespaces). I am not sure if this bug is related to not separating interfaces and implementations.

0

There's no such restriction. One can use implementation classes directly.

Please add some snippets to illustrate the problems.

0

I even System.out.println() directly to check what elements I have traversed:

https://github.com/SOF3/libglocal-idea-plugin/blob/master/src/io/github/sof3/libglocal/idea/ref/LibglocalReferenceContributor.java#L19

No errors spotted in the event log, live idea.log (in IntelliJ's Run tool window) or main output. I'm using PhpStorm.

I used PsiViewer to make sure the file consists not only comment elements.

0

So the full steps are:

  1. Override getReferences() and return 
    PsiReferenceService.getService().getContributedReferences(this)
  2. Implement 
    ContributedReferenceHost
  3. PsiReferenceRegistrar.registerReferenceProvider() to handle the reference contribution

Thanks, this works.

But why aren't the first 2 steps mentioned in the tutorial?

 

0

请先登录再写评论。