Skip to content

Commit 231ea9e

Browse files
authored
Merge pull request #1039 from mrglavas/1027#qualified-names
BeanValidationDiagnosticsCollector: Use qualified names and equals() for checking built-in types.
2 parents a50967b + 2d461b3 commit 231ea9e

File tree

2 files changed

+13
-20
lines changed

2 files changed

+13
-20
lines changed

src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/beanvalidation/BeanValidationConstants.java

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -59,17 +59,10 @@ public class BeanValidationConstants {
5959
public static final String INSTANT = "java.time.Instant";
6060
public static final String CALENDAR = "java.util.Calendar";
6161
public static final String DATE = "java.util.Date";
62-
public static final String BOOLEAN = "Boolean";
63-
public static final String CHAR_SEQUENCE = "CharSequence";
64-
public static final String STRING = "String";
65-
public static final String DOUBLE = "Double";
66-
public static final String FLOAT = "Float";
67-
public static final String LONG = "Long";
68-
public static final String INTEGER = "Integer";
69-
public static final String SHORT = "Short";
70-
public static final String BYTE = "Byte";
71-
public static final String BIG_INTEGER = "BigInteger";
72-
public static final String BIG_DECIMAL = "BigDecimal";
62+
public static final String CHAR_SEQUENCE = "java.lang.CharSequence";
63+
public static final String STRING = "java.lang.String";
64+
public static final String BIG_INTEGER = "java.math.BigInteger";
65+
public static final String BIG_DECIMAL = "java.math.BigDecimal";
7366

7467
public static final String DIAGNOSTIC_SOURCE = "jakarta-bean-validation";
7568
public static final String DIAGNOSTIC_CODE_INVALID_TYPE = "FixTypeOfElement";

src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/beanvalidation/BeanValidationDiagnosticsCollector.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,9 @@ private void validAnnotation(PsiElement element, PsiAnnotation annotation, Strin
103103
}
104104
} else if (matchedAnnotation.equals(DECIMAL_MAX) || matchedAnnotation.equals(DECIMAL_MIN)
105105
|| matchedAnnotation.equals(DIGITS)) {
106-
if (!type.getCanonicalText().endsWith(BIG_DECIMAL)
107-
&& !type.getCanonicalText().endsWith(BIG_INTEGER)
108-
&& !type.getCanonicalText().endsWith(CHAR_SEQUENCE)
106+
if (!type.getCanonicalText().equals(BIG_DECIMAL)
107+
&& !type.getCanonicalText().equals(BIG_INTEGER)
108+
&& !type.getCanonicalText().equals(CHAR_SEQUENCE)
109109
&& !type.equals(PsiTypes.byteType())
110110
&& !type.equals(PsiTypes.shortType())
111111
&& !type.equals(PsiTypes.intType())
@@ -136,8 +136,8 @@ private void validAnnotation(PsiElement element, PsiAnnotation annotation, Strin
136136
source, DIAGNOSTIC_CODE_INVALID_TYPE, annotationName, DiagnosticSeverity.Error));
137137
}
138138
} else if (matchedAnnotation.equals(MIN) || matchedAnnotation.equals(MAX)) {
139-
if (!type.getCanonicalText().endsWith(BIG_DECIMAL)
140-
&& !type.getCanonicalText().endsWith(BIG_INTEGER)
139+
if (!type.getCanonicalText().equals(BIG_DECIMAL)
140+
&& !type.getCanonicalText().equals(BIG_INTEGER)
141141
&& !type.equals(PsiTypes.byteType())
142142
&& !type.equals(PsiTypes.shortType())
143143
&& !type.equals(PsiTypes.intType())
@@ -150,8 +150,8 @@ private void validAnnotation(PsiElement element, PsiAnnotation annotation, Strin
150150
}
151151
} else if (matchedAnnotation.equals(NEGATIVE) || matchedAnnotation.equals(NEGATIVE_OR_ZERO)
152152
|| matchedAnnotation.equals(POSITIVE) || matchedAnnotation.equals(POSITIVE_OR_ZERO)) {
153-
if (!type.getCanonicalText().endsWith(BIG_DECIMAL)
154-
&& !type.getCanonicalText().endsWith(BIG_INTEGER)
153+
if (!type.getCanonicalText().equals(BIG_DECIMAL)
154+
&& !type.getCanonicalText().equals(BIG_INTEGER)
155155
&& !type.equals(PsiTypes.byteType())
156156
&& !type.equals(PsiTypes.shortType())
157157
&& !type.equals(PsiTypes.intType())
@@ -199,8 +199,8 @@ private void validAnnotation(PsiElement element, PsiAnnotation annotation, Strin
199199
}
200200

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

0 commit comments

Comments
 (0)