File tree Expand file tree Collapse file tree 9 files changed +28
-30
lines changed
validator-generator/src/main/java/io/avaje/validation/generator Expand file tree Collapse file tree 9 files changed +28
-30
lines changed Original file line number Diff line number Diff line change @@ -9,7 +9,7 @@ interface BeanReader {
9
9
10
10
void read ();
11
11
12
- void writeImports (Append writer );
12
+ void writeImports (Append writer , String adapterPackage );
13
13
14
14
void writeFields (Append writer );
15
15
Original file line number Diff line number Diff line change @@ -80,19 +80,17 @@ public void read() {
80
80
}
81
81
82
82
private Set <String > importTypes () {
83
- if (Util .validImportType (type )) {
84
- importTypes .add (type );
85
- }
83
+ importTypes .add (type );
86
84
for (final FieldReader allField : allFields ) {
87
85
allField .addImports (importTypes );
88
86
}
89
87
return importTypes ;
90
88
}
91
89
92
90
@ Override
93
- public void writeImports (Append writer ) {
91
+ public void writeImports (Append writer , String adapterPackage ) {
94
92
for (final String importType : importTypes ()) {
95
- if (Util .validImportType (importType )) {
93
+ if (Util .validImportType (importType , adapterPackage )) {
96
94
writer .append ("import %s;" , importType ).eol ();
97
95
}
98
96
}
Original file line number Diff line number Diff line change @@ -80,19 +80,20 @@ List<TypeElement> allAnnotationAdapters() {
80
80
Collection <String > allImports () {
81
81
final Set <String > packageImports = new TreeSet <>();
82
82
for (final String adapterFullName : allTypes ) {
83
- packageImports .add (ProcessorUtils . packageOf ( adapterFullName ) + ".*" );
83
+ packageImports .add (adapterFullName );
84
84
packageImports .add (ProcessorUtils .extractEnclosingFQN (Util .baseTypeOfAdapter (adapterFullName )));
85
85
}
86
86
87
87
for (final var adapter : annotationAdapters ) {
88
88
final var adapterFullName = adapter .getQualifiedName ().toString ();
89
- packageImports .add (ProcessorUtils .packageOf (adapterFullName ) + ".*" );
90
- packageImports .add (ProcessorUtils .extractEnclosingFQN (Util .baseTypeOfAdapter (adapterFullName )));
89
+ packageImports .add (adapterFullName );
90
+ packageImports .add (
91
+ ProcessorUtils .extractEnclosingFQN (Util .baseTypeOfAdapter (adapterFullName )));
91
92
92
93
ConstraintAdapterPrism .getInstanceOn (adapter )
93
- .value ()
94
- .toString ()
95
- .transform (packageImports ::add );
94
+ .value ()
95
+ .toString ()
96
+ .transform (packageImports ::add );
96
97
}
97
98
98
99
return packageImports ;
Original file line number Diff line number Diff line change @@ -90,18 +90,16 @@ public boolean hasValidationAnnotation() {
90
90
public void read () {}
91
91
92
92
private Set <String > importTypes () {
93
- if (Util .validImportType (type )) {
94
- importTypes .add (type );
95
- }
93
+ importTypes .add (type );
96
94
97
95
annotations .keySet ().forEach (t -> importTypes .addAll (t .importTypes ()));
98
96
return importTypes ;
99
97
}
100
98
101
99
@ Override
102
- public void writeImports (Append writer ) {
100
+ public void writeImports (Append writer , String adapterPackage ) {
103
101
for (final String importType : importTypes ()) {
104
- if (Util .validImportType (importType )) {
102
+ if (Util .validImportType (importType , adapterPackage )) {
105
103
writer .append ("import %s;" , importType ).eol ();
106
104
}
107
105
}
Original file line number Diff line number Diff line change @@ -101,7 +101,7 @@ private void writeFields() {
101
101
}
102
102
103
103
private void writeImports () {
104
- beanReader .writeImports (writer );
104
+ beanReader .writeImports (writer , adapterPackage );
105
105
}
106
106
107
107
private void writePackage () {
Original file line number Diff line number Diff line change @@ -131,12 +131,13 @@ private void writeMetaDataEntry(List<String> entries) {
131
131
132
132
private void writeImports () {
133
133
importTypes .add (Constants .VALIDATOR );
134
- importTypes .add (Constants .VALID_SPI );
135
134
importTypes .add ("io.avaje.validation.spi.GeneratedComponent" );
135
+ importTypes .add ("io.avaje.validation.spi.MetaData" );
136
+ importTypes .add ("io.avaje.validation.spi.Generated" );
136
137
importTypes .addAll (metaData .allImports ());
137
138
138
139
for (final String importType : importTypes ) {
139
- if (Util .validImportType (importType )) {
140
+ if (Util .validImportType (importType , metaData . packageName () )) {
140
141
writer .append ("import %s;" , importType ).eol ();
141
142
}
142
143
}
Original file line number Diff line number Diff line change @@ -53,7 +53,7 @@ void write() throws IOException {
53
53
}
54
54
55
55
private void writeImports () {
56
- beanReader .writeImports (writer );
56
+ beanReader .writeImports (writer , adapterPackage );
57
57
}
58
58
59
59
private void writePackage () {
Original file line number Diff line number Diff line change @@ -37,10 +37,12 @@ public static boolean isNullable(Element p) {
37
37
return false ;
38
38
}
39
39
40
- static boolean validImportType (String type ) {
41
- return type .indexOf ('.' ) > 0 && !type .startsWith ("java.lang." )
42
- || (type .startsWith ("java.lang." )
43
- && type .replace ("java.lang." , "" ).transform (s -> s .contains ("." )));
40
+ static boolean validImportType (String type , String adapterPackage ) {
41
+ 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 ("." )));
44
46
}
45
47
46
48
static String shortName (String fullType ) {
Original file line number Diff line number Diff line change @@ -44,17 +44,15 @@ public String shortName() {
44
44
}
45
45
46
46
private Set <String > importTypes () {
47
- if (Util .validImportType (type )) {
48
- importTypes .add (type );
49
- }
47
+ importTypes .add (type );
50
48
paramAnnotations .forEach (a -> a .addImports (importTypes ));
51
49
returnElementAnnotation .addImports (importTypes );
52
50
return importTypes ;
53
51
}
54
52
55
- public void writeImports (Append writer ) {
53
+ public void writeImports (Append writer , String packageName ) {
56
54
for (final String importType : importTypes ()) {
57
- if (Util .validImportType (importType )) {
55
+ if (Util .validImportType (importType , packageName )) {
58
56
writer .append ("import %s;" , importType ).eol ();
59
57
}
60
58
}
You can’t perform that action at this time.
0 commit comments