title: Intellij custom language plugin reference from Java code
body: <p>I need to create a <a href="https://plugins.jetbrains.com/docs/intellij/references-and-resolve.html" rel="nofollow noreferrer">Reference</a> to my custom language elements from Java code. This is needed for rename refactoring support and other things. Basically I want to create a functionality similar to what Android Studio does when renaming resources in xml files also renames the corresponding fields in <code>R.string</code> class.</p>
  <p>I've been able to successfully register references from string literals via <code>PsiReferenceContributor</code> and <code>PsiReferenceProvider</code> following <a href="https://plugins.jetbrains.com/docs/intellij/reference-contributor.html#define-a-reference-contributor" rel="nofollow noreferrer">this</a> example. But when I try to apply a similar pattern for <code>PsiIdentifier::class.java</code> or other psi types, the reference provider method <code>getReferencesByElement</code> doesn't get triggered, see code</p>
  <pre><code>override fun registerReferenceProviders(registrar: PsiReferenceRegistrar) {
      registrar.registerReferenceProvider(
          psiElement(PsiIdentifier::class.java), // PsiIdentifier instead of PsiLiteralExpression
          object : PsiReferenceProvider() {
              override fun getReferencesByElement(
                  element: PsiElement,
                  context: ProcessingContext
              ): Array&lt;PsiReference&gt; {
                  // not triggered ever
              }
          }
      )
  }
  </code></pre>
  <p>Then I stumbled upon <code>PsiScopeProcessor</code> class, which is a little more difficult to use. But I wonder if it is what should be used in my case and if there are other options. If I really do have to use <code>PsiScopeProcessor</code>, then are there any simple enough plugins doing similar thing that I should take a look at as an example?</p>