PsiReference () { return new PsiReference() { @Nullable private PsiClass getReferencedClass() { LOG.assertTrue(getParent() instanceof PsiAnnotationParameterList && getParent().getParent() instanceof PsiAnnotation); PsiAnnotation annotation = (PsiAnnotation)getParent().getParent(); PsiJavaCodeReferenceElement nameRef = annotation.getNameReferenceElement(); if (nameRef == null) return null; PsiElement target = nameRef.resolve(); return target instanceof PsiClass ? (PsiClass)target : null; } @NotNull @Override public PsiElement getElement() { return PsiNameValuePairImpl.this; } @NotNull @Override public TextRange getRangeInElement() { PsiIdentifier id = getNameIdentifier(); if (id != null) { return new TextRange(0, id.getTextLength()); } return TextRange.EMPTY_RANGE; } @Override public PsiElement resolve() { PsiClass refClass = getReferencedClass(); if (refClass == null) return null; String name = getName(); if (name == null) name = PsiAnnotation.DEFAULT_REFERENCED_METHOD_NAME; MethodSignature signature = MethodSignatureUtil .createMethodSignature(name, PsiType.EMPTY_ARRAY, PsiTypeParameter.EMPTY_ARRAY, PsiSubstitutor.EMPTY); return MethodSignatureUtil.findMethodBySignature(refClass, signature, false); } @Override @NotNull public String getCanonicalText() { String name = getName(); return name != null ? name : PsiAnnotation.DEFAULT_REFERENCED_METHOD_NAME; } @Override public PsiElement handleElementRename(@NotNull String newElementName) throws IncorrectOperationException { PsiIdentifier nameIdentifier = getNameIdentifier(); if (nameIdentifier != null) { PsiImplUtil.setName(nameIdentifier, newElementName); } else if (ElementType.ANNOTATION_MEMBER_VALUE_BIT_SET.contains(getNode().getFirstChildNode().getElementType())) { PsiElementFactory factory = JavaPsiFacade.getElementFactory(getProject()); nameIdentifier = factory.createIdentifier(newElementName); addBefore(nameIdentifier, SourceTreeToPsiMap.treeElementToPsi(getNode().getFirstChildNode())); } return PsiNameValuePairImpl.this; } @Override public PsiElement bindToElement(@NotNull PsiElement element) throws IncorrectOperationException { throw new IncorrectOperationException("Not implemented"); } @Override public boolean isReferenceTo(@NotNull PsiElement element) { return element instanceof PsiMethod && element.equals(resolve()); } @Override public boolean isSoft() { return false; } }; }