Skip to content

Commit

Permalink
Merge pull request #1071 from mrglavas/1070#reduce-code-duplication
Browse files Browse the repository at this point in the history
BeanValidationDiagnosticsCollector: Refactoring method and field annotation processing loops into one method.
  • Loading branch information
mrglavas authored Nov 7, 2024
2 parents bdb5c2d + c038bc2 commit cc044cc
Showing 1 changed file with 12 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,40 +35,34 @@ protected String getDiagnosticSource() {
}

public void collectDiagnostics(PsiJavaFile unit, List<Diagnostic> diagnostics) {

if (unit != null) {
PsiClass[] alltypes;
PsiField[] allFields;
PsiAnnotation[] annotations;
PsiMethod[] allMethods;

alltypes = unit.getClasses();
for (PsiClass type : alltypes) {
allFields = type.getFields();
for (PsiField field : allFields) {
annotations = field.getAnnotations();
for (PsiAnnotation annotation : annotations) {
String matchedAnnotation = getMatchedJavaElementName(type, annotation.getQualifiedName(),
SET_OF_ANNOTATIONS.toArray(new String[0]));
if (matchedAnnotation != null) {
validAnnotation(field, annotation, matchedAnnotation, diagnostics);
}
}
processAnnotations(field, type, diagnostics);
}
allMethods = type.getMethods();
for (PsiMethod method : allMethods) {
annotations = method.getAnnotations();
for (PsiAnnotation annotation : annotations) {
String matchedAnnotation = getMatchedJavaElementName(type, annotation.getQualifiedName(),
SET_OF_ANNOTATIONS.toArray(new String[0]));
if (matchedAnnotation != null) {
validAnnotation(method, annotation, matchedAnnotation, diagnostics);
}
}
processAnnotations(method, type, diagnostics);
}
}
}
}

private void processAnnotations(PsiJvmModifiersOwner psiModifierOwner, PsiClass type, List<Diagnostic> diagnostics) {
PsiAnnotation[] annotations = psiModifierOwner.getAnnotations();
for (PsiAnnotation annotation : annotations) {
String matchedAnnotation = getMatchedJavaElementName(type, annotation.getQualifiedName(),
SET_OF_ANNOTATIONS.toArray(new String[0]));
if (matchedAnnotation != null) {
validAnnotation(psiModifierOwner, annotation, matchedAnnotation, diagnostics);
}
}
}

private void validAnnotation(PsiElement element, PsiAnnotation annotation, String matchedAnnotation,
Expand Down

0 comments on commit cc044cc

Please sign in to comment.