1
1
package io .avaje .validation .generator ;
2
2
3
- import static io .avaje .validation .generator .APContext .logError ;
4
- import static io .avaje .validation .generator .APContext .typeElement ;
5
-
6
- import java .util .Optional ;
7
- import java .util .Set ;
8
- import java .util .function .Supplier ;
9
- import java .util .regex .Pattern ;
10
-
11
3
import javax .lang .model .element .AnnotationMirror ;
12
4
import javax .lang .model .element .Element ;
13
5
import javax .lang .model .element .Modifier ;
14
6
import javax .lang .model .element .TypeElement ;
15
- import javax .lang .model .element .VariableElement ;
16
7
import javax .lang .model .type .TypeMirror ;
8
+ import java .util .Optional ;
9
+ import java .util .Set ;
10
+ import java .util .function .Supplier ;
11
+
12
+ import static io .avaje .validation .generator .APContext .logError ;
13
+ import static io .avaje .validation .generator .APContext .typeElement ;
17
14
18
15
final class Util {
19
16
@@ -27,7 +24,9 @@ static boolean isValid(Element e) {
27
24
|| JakartaValidPrism .isPresent (e );
28
25
}
29
26
30
- /** Return true if the element has a Nullable annotation. */
27
+ /**
28
+ * Return true if the element has a Nullable annotation.
29
+ */
31
30
public static boolean isNullable (Element p ) {
32
31
for (final AnnotationMirror mirror : p .getAnnotationMirrors ()) {
33
32
if ("Nullable" .equalsIgnoreCase (shortName (mirror .getAnnotationType ().toString ()))) {
@@ -37,12 +36,19 @@ public static boolean isNullable(Element p) {
37
36
return false ;
38
37
}
39
38
40
- static boolean validImportType (String type , String adapterPackage ) {
39
+ static boolean validImportType (String type , String packageName ) {
41
40
return type .indexOf ('.' ) > -1
42
- && !type .startsWith ("java.lang." )
43
- && type .replace (adapterPackage + "." , "" ).transform (s -> s .contains ("." ))
44
- || (type .startsWith ("java.lang." )
45
- && type .replace ("java.lang." , "" ).transform (s -> s .contains ("." )));
41
+ && !type .startsWith ("java.lang." )
42
+ && importDifferentPackage (type , packageName )
43
+ || importJavaLangSubpackage (type );
44
+ }
45
+
46
+ private static boolean importDifferentPackage (String type , String packageName ) {
47
+ return type .replace (packageName + '.' , "" ).indexOf ('.' ) > 0 ;
48
+ }
49
+
50
+ private static boolean importJavaLangSubpackage (String type ) {
51
+ return type .startsWith ("java.lang." ) && importDifferentPackage (type , "java.lang" );
46
52
}
47
53
48
54
static String shortName (String fullType ) {
@@ -78,7 +84,9 @@ static String initLower(String name) {
78
84
return sb .toString ();
79
85
}
80
86
81
- /** Return the base type given the ValidationAdapter type. */
87
+ /**
88
+ * Return the base type given the ValidationAdapter type.
89
+ */
82
90
static String baseTypeOfAdapter (String adapterFullName ) {
83
91
final var element = typeElement (adapterFullName );
84
92
if (element == null ) {
0 commit comments