Skip to content

Commit

Permalink
Recalculate cached FQN if annotation name changed
Browse files Browse the repository at this point in the history
  • Loading branch information
mplushnikov committed Jan 13, 2018
1 parent e54c0b1 commit a061ab1
Showing 1 changed file with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ private static PsiAnnotation findAnnotationQuick(@Nullable PsiAnnotationOwner an
for (PsiAnnotation annotation : annotations) {
PsiJavaCodeReferenceElement referenceElement = annotation.getNameReferenceElement();
if (null != referenceElement) {
if (shortName.equals(referenceElement.getReferenceName())) {
final String referenceName = referenceElement.getReferenceName();
if (shortName.equals(referenceName)) {

if (referenceElement.isQualified() && referenceElement instanceof SourceJavaCodeReference) {
String possibleFullQualifiedName = ((SourceJavaCodeReference) referenceElement).getClassNameText();
Expand All @@ -67,7 +68,7 @@ private static PsiAnnotation findAnnotationQuick(@Nullable PsiAnnotationOwner an
}
}

final String annotationQualifiedName = getAndCacheFQN(annotation);
final String annotationQualifiedName = getAndCacheFQN(annotation, referenceName);
if (qualifiedName.equals(annotationQualifiedName)) {
return annotation;
}
Expand Down Expand Up @@ -97,7 +98,8 @@ private static PsiAnnotation findAnnotationQuick(@Nullable PsiAnnotationOwner an
for (PsiAnnotation annotation : annotations) {
final PsiJavaCodeReferenceElement referenceElement = annotation.getNameReferenceElement();
if (null != referenceElement) {
if (ArrayUtil.find(shortNames, referenceElement.getReferenceName()) > -1) {
final String referenceName = referenceElement.getReferenceName();
if (ArrayUtil.find(shortNames, referenceName) > -1) {

if (referenceElement.isQualified() && referenceElement instanceof SourceJavaCodeReference) {
final String possibleFullQualifiedName = ((SourceJavaCodeReference) referenceElement).getClassNameText();
Expand All @@ -107,7 +109,7 @@ private static PsiAnnotation findAnnotationQuick(@Nullable PsiAnnotationOwner an
}
}

final String annotationQualifiedName = getAndCacheFQN(annotation);
final String annotationQualifiedName = getAndCacheFQN(annotation, referenceName);
if (ArrayUtil.find(qualifiedNames, annotationQualifiedName) > -1) {
return annotation;
}
Expand All @@ -119,9 +121,10 @@ private static PsiAnnotation findAnnotationQuick(@Nullable PsiAnnotationOwner an
}

@Nullable
private static String getAndCacheFQN(PsiAnnotation annotation) {
private static String getAndCacheFQN(@NotNull PsiAnnotation annotation, @Nullable String referenceName) {
String annotationQualifiedName = annotation.getCopyableUserData(LOMBOK_ANNOTATION_FQN_KEY);
if (null == annotationQualifiedName) {
// if not cached or cache is not up to date (because existing annotation was renamed for example)
if (null == annotationQualifiedName || (null != referenceName && !annotationQualifiedName.endsWith(".".concat(referenceName)))) {
annotationQualifiedName = annotation.getQualifiedName();
if (null != annotationQualifiedName && annotationQualifiedName.indexOf('.') > -1) {
annotation.putCopyableUserData(LOMBOK_ANNOTATION_FQN_KEY, annotationQualifiedName);
Expand Down

0 comments on commit a061ab1

Please sign in to comment.