Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BeanValidationDiagnosticsCollector: Use qualified names and equals() for checking built-in types. #1039

Merged
merged 2 commits into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,10 @@ public class BeanValidationConstants {
public static final String INSTANT = "java.time.Instant";
public static final String CALENDAR = "java.util.Calendar";
public static final String DATE = "java.util.Date";
public static final String BOOLEAN = "Boolean";
public static final String CHAR_SEQUENCE = "CharSequence";
public static final String STRING = "String";
public static final String DOUBLE = "Double";
public static final String FLOAT = "Float";
public static final String LONG = "Long";
public static final String INTEGER = "Integer";
public static final String SHORT = "Short";
public static final String BYTE = "Byte";
public static final String BIG_INTEGER = "BigInteger";
public static final String BIG_DECIMAL = "BigDecimal";
public static final String CHAR_SEQUENCE = "java.lang.CharSequence";
public static final String STRING = "java.lang.String";
public static final String BIG_INTEGER = "java.math.BigInteger";
public static final String BIG_DECIMAL = "java.math.BigDecimal";

public static final String DIAGNOSTIC_SOURCE = "jakarta-bean-validation";
public static final String DIAGNOSTIC_CODE_INVALID_TYPE = "FixTypeOfElement";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ private void validAnnotation(PsiElement element, PsiAnnotation annotation, Strin
}
} else if (matchedAnnotation.equals(DECIMAL_MAX) || matchedAnnotation.equals(DECIMAL_MIN)
|| matchedAnnotation.equals(DIGITS)) {
if (!type.getCanonicalText().endsWith(BIG_DECIMAL)
&& !type.getCanonicalText().endsWith(BIG_INTEGER)
&& !type.getCanonicalText().endsWith(CHAR_SEQUENCE)
if (!type.getCanonicalText().equals(BIG_DECIMAL)
&& !type.getCanonicalText().equals(BIG_INTEGER)
&& !type.getCanonicalText().equals(CHAR_SEQUENCE)
&& !type.equals(PsiTypes.byteType())
&& !type.equals(PsiTypes.shortType())
&& !type.equals(PsiTypes.intType())
Expand Down Expand Up @@ -136,8 +136,8 @@ private void validAnnotation(PsiElement element, PsiAnnotation annotation, Strin
source, DIAGNOSTIC_CODE_INVALID_TYPE, annotationName, DiagnosticSeverity.Error));
}
} else if (matchedAnnotation.equals(MIN) || matchedAnnotation.equals(MAX)) {
if (!type.getCanonicalText().endsWith(BIG_DECIMAL)
&& !type.getCanonicalText().endsWith(BIG_INTEGER)
if (!type.getCanonicalText().equals(BIG_DECIMAL)
&& !type.getCanonicalText().equals(BIG_INTEGER)
&& !type.equals(PsiTypes.byteType())
&& !type.equals(PsiTypes.shortType())
&& !type.equals(PsiTypes.intType())
Expand All @@ -150,8 +150,8 @@ private void validAnnotation(PsiElement element, PsiAnnotation annotation, Strin
}
} else if (matchedAnnotation.equals(NEGATIVE) || matchedAnnotation.equals(NEGATIVE_OR_ZERO)
|| matchedAnnotation.equals(POSITIVE) || matchedAnnotation.equals(POSITIVE_OR_ZERO)) {
if (!type.getCanonicalText().endsWith(BIG_DECIMAL)
&& !type.getCanonicalText().endsWith(BIG_INTEGER)
if (!type.getCanonicalText().equals(BIG_DECIMAL)
&& !type.getCanonicalText().equals(BIG_INTEGER)
&& !type.equals(PsiTypes.byteType())
&& !type.equals(PsiTypes.shortType())
&& !type.equals(PsiTypes.intType())
Expand Down Expand Up @@ -199,8 +199,8 @@ private void validAnnotation(PsiElement element, PsiAnnotation annotation, Strin
}

private void checkStringOnly(PsiElement element, List<Diagnostic> diagnostics, String annotationName, boolean isMethod, PsiType type) {
if (!type.getCanonicalText().endsWith(STRING)
&& !type.getCanonicalText().endsWith(CHAR_SEQUENCE)) {
if (!type.getCanonicalText().equals(STRING)
&& !type.getCanonicalText().equals(CHAR_SEQUENCE)) {
String source = isMethod ?
Messages.getMessage("AnnotationStringMethods", "@" + getSimpleName(annotationName)) :
Messages.getMessage("AnnotationStringFields", "@" + getSimpleName(annotationName));
Expand Down
Loading