Skip to content

Commit

Permalink
Create common method to generate diagnostic.
Browse files Browse the repository at this point in the history
Signed-off-by: Paul Gooderham <turkeyonmarblerye@gmail.com>
  • Loading branch information
turkeylurkey committed Jul 24, 2023
1 parent 23f978d commit 3d5a7fd
Showing 1 changed file with 17 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -160,14 +160,11 @@ private void validAnnotation(IMember element, IAnnotation annotation, String mat
DIAGNOSTIC_CODE_INVALID_TYPE, annotationName, DiagnosticSeverity.Error));
}
} else if (matchedAnnotation.equals(EMAIL)) {
if (!type.equals(getSignatureFormatOfType(STRING))
&& !type.equals(getSignatureFormatOfType(CHAR_SEQUENCE))) {
String source = isMethod ?
Messages.getMessage("AnnotationStringMethods", "@" + annotationName) :
Messages.getMessage("AnnotationStringFields", "@" + annotationName);
diagnostics.add(createDiagnostic(element, declaringType.getCompilationUnit(),
source, DIAGNOSTIC_CODE_INVALID_TYPE, annotationName, DiagnosticSeverity.Error));
}
checkStringOnly(element, declaringType, diagnostics, annotationName, isMethod, type);
} else if (matchedAnnotation.equals(NOT_BLANK)) {
checkStringOnly(element, declaringType, diagnostics, annotationName, isMethod, type);
} else if (matchedAnnotation.equals(PATTERN)) {
checkStringOnly(element, declaringType, diagnostics, annotationName, isMethod, type);
} else if (matchedAnnotation.equals(FUTURE) || matchedAnnotation.equals(FUTURE_OR_PRESENT)
|| matchedAnnotation.equals(PAST) || matchedAnnotation.equals(PAST_OR_PRESENT)) {
String dataType = getDataTypeName(type);
Expand Down Expand Up @@ -214,24 +211,6 @@ private void validAnnotation(IMember element, IAnnotation annotation, String mat
diagnostics.add(createDiagnostic(element, declaringType.getCompilationUnit(),
source, DIAGNOSTIC_CODE_INVALID_TYPE, annotationName, DiagnosticSeverity.Error));
}
} else if (matchedAnnotation.equals(NOT_BLANK)) {
if (!type.equals(getSignatureFormatOfType(STRING))
&& !type.equals(getSignatureFormatOfType(CHAR_SEQUENCE))) {
String source = isMethod ?
Messages.getMessage("AnnotationStringMethods", "@" + annotationName) :
Messages.getMessage("AnnotationStringFields", "@" + annotationName);
diagnostics.add(createDiagnostic(element, declaringType.getCompilationUnit(),
source, DIAGNOSTIC_CODE_INVALID_TYPE, annotationName, DiagnosticSeverity.Error));
}
} else if (matchedAnnotation.equals(PATTERN)) {
if (!type.equals(getSignatureFormatOfType(STRING))
&& !type.equals(getSignatureFormatOfType(CHAR_SEQUENCE))) {
String source = isMethod ?
Messages.getMessage("AnnotationStringMethods", "@" + annotationName) :
Messages.getMessage("AnnotationStringFields", "@" + annotationName);
diagnostics.add(createDiagnostic(element, declaringType.getCompilationUnit(),
source, DIAGNOSTIC_CODE_INVALID_TYPE, annotationName, DiagnosticSeverity.Error));
}
}

// These ones contains check on all collection types which requires resolving
Expand Down Expand Up @@ -266,6 +245,18 @@ private void validAnnotation(IMember element, IAnnotation annotation, String mat
}
}

private void checkStringOnly(IMember element, IType declaringType, List<Diagnostic> diagnostics,
String annotationName, boolean isMethod, String type) throws JavaModelException {
if (!type.equals(getSignatureFormatOfType(STRING))
&& !type.equals(getSignatureFormatOfType(CHAR_SEQUENCE))) {
String source = isMethod ?
Messages.getMessage("AnnotationStringMethods", "@" + annotationName) :
Messages.getMessage("AnnotationStringFields", "@" + annotationName);
diagnostics.add(createDiagnostic(element, declaringType.getCompilationUnit(),
source, DIAGNOSTIC_CODE_INVALID_TYPE, annotationName, DiagnosticSeverity.Error));
}
}

/*
* Refer to Class signature documentation for the formating
* https://www.ibm.com/support/knowledgecenter/sl/SS5JSH_9.5.0/org.eclipse.jdt.
Expand Down

0 comments on commit 3d5a7fd

Please sign in to comment.