PsiReference () { if (getNode().findChildByType(RegExpTT.NAME) == null) { return null; } return new PsiReference() { @NotNull @Override public PsiElement getElement() { return RegExpNamedGroupRefImpl.this; } @NotNull @Override public TextRange getRangeInElement() { final ASTNode nameNode = getNode().findChildByType(RegExpTT.NAME); assert nameNode != null; final int startOffset = getNode().getFirstChildNode().getTextLength(); return new TextRange(startOffset, startOffset + nameNode.getTextLength()); } @Override public PsiElement resolve() { return RegExpNamedGroupRefImpl.this.resolve(); } @Override @NotNull public String getCanonicalText() { return getRangeInElement().substring(getText()); } @Override public PsiElement handleElementRename(@NotNull String newElementName) throws IncorrectOperationException { throw new UnsupportedOperationException(); } @Override public PsiElement bindToElement(@NotNull PsiElement element) throws IncorrectOperationException { throw new UnsupportedOperationException(); } @Override public boolean isReferenceTo(@NotNull PsiElement element) { return resolve() == element; } @Override public Object @NotNull [] getVariants() { return SyntaxTraverser.psiTraverser(getContainingFile()).filter(RegExpGroup.class) .filter(RegExpGroup::isAnyNamedGroup).toArray(new RegExpGroup[0]); } @Override public boolean isSoft() { return false; } }; }