Skip to content

Commit

Permalink
[OpenLiberty#1025]: Refactored isMatchedAnnotation function with prop…
Browse files Browse the repository at this point in the history
…er comments
  • Loading branch information
dessina-devasia committed Oct 30, 2024
1 parent 8d9fff9 commit e3a92c3
Showing 1 changed file with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,19 @@ public void collectDiagnostics(PsiJavaFile unit, List<Diagnostic> diagnostics) {
* false otherwise.
*/
protected static boolean isMatchedAnnotation(PsiClass unit, PsiAnnotation annotation, String annotationFQName) {
// Get the qualified name of the annotation element
String elementName = annotation.getQualifiedName();

// Preliminary check to ensure elementName ends with the expected suffix
if (nameEndsWith(annotationFQName, elementName) && unit != null) {
// For performance reason, we check if the import of annotation name is
// declared

// Check if the annotation is directly imported in the file for performance
if (isImportedJavaElement(unit, annotationFQName))
return true;
// only check fully qualified annotations

// Check if the fully qualified names match when import is not available
if (annotationFQName.equals(elementName)) {
// Resolve the annotation reference to check its fully qualified name
PsiReference ref = annotation.getReference();
PsiElement def = ref.resolve();
if (def instanceof PsiAnnotation) {
Expand All @@ -143,7 +148,7 @@ protected static boolean isMatchedAnnotation(PsiClass unit, PsiAnnotation annota
}
}
}
return false;
return false; // Return false if no match is found
}

/**
Expand Down

0 comments on commit e3a92c3

Please sign in to comment.