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 {
99
1010 void read ();
1111
12- void writeImports (Append writer );
12+ void writeImports (Append writer , String adapterPackage );
1313
1414 void writeFields (Append writer );
1515
Original file line number Diff line number Diff line change @@ -80,19 +80,17 @@ public void read() {
8080 }
8181
8282 private Set <String > importTypes () {
83- if (Util .validImportType (type )) {
84- importTypes .add (type );
85- }
83+ importTypes .add (type );
8684 for (final FieldReader allField : allFields ) {
8785 allField .addImports (importTypes );
8886 }
8987 return importTypes ;
9088 }
9189
9290 @ Override
93- public void writeImports (Append writer ) {
91+ public void writeImports (Append writer , String adapterPackage ) {
9492 for (final String importType : importTypes ()) {
95- if (Util .validImportType (importType )) {
93+ if (Util .validImportType (importType , adapterPackage )) {
9694 writer .append ("import %s;" , importType ).eol ();
9795 }
9896 }
Original file line number Diff line number Diff line change @@ -80,19 +80,20 @@ List<TypeElement> allAnnotationAdapters() {
8080 Collection <String > allImports () {
8181 final Set <String > packageImports = new TreeSet <>();
8282 for (final String adapterFullName : allTypes ) {
83- packageImports .add (ProcessorUtils . packageOf ( adapterFullName ) + ".*" );
83+ packageImports .add (adapterFullName );
8484 packageImports .add (ProcessorUtils .extractEnclosingFQN (Util .baseTypeOfAdapter (adapterFullName )));
8585 }
8686
8787 for (final var adapter : annotationAdapters ) {
8888 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 )));
9192
9293 ConstraintAdapterPrism .getInstanceOn (adapter )
93- .value ()
94- .toString ()
95- .transform (packageImports ::add );
94+ .value ()
95+ .toString ()
96+ .transform (packageImports ::add );
9697 }
9798
9899 return packageImports ;
Original file line number Diff line number Diff line change @@ -90,18 +90,16 @@ public boolean hasValidationAnnotation() {
9090 public void read () {}
9191
9292 private Set <String > importTypes () {
93- if (Util .validImportType (type )) {
94- importTypes .add (type );
95- }
93+ importTypes .add (type );
9694
9795 annotations .keySet ().forEach (t -> importTypes .addAll (t .importTypes ()));
9896 return importTypes ;
9997 }
10098
10199 @ Override
102- public void writeImports (Append writer ) {
100+ public void writeImports (Append writer , String adapterPackage ) {
103101 for (final String importType : importTypes ()) {
104- if (Util .validImportType (importType )) {
102+ if (Util .validImportType (importType , adapterPackage )) {
105103 writer .append ("import %s;" , importType ).eol ();
106104 }
107105 }
Original file line number Diff line number Diff line change @@ -101,7 +101,7 @@ private void writeFields() {
101101 }
102102
103103 private void writeImports () {
104- beanReader .writeImports (writer );
104+ beanReader .writeImports (writer , adapterPackage );
105105 }
106106
107107 private void writePackage () {
Original file line number Diff line number Diff line change @@ -131,12 +131,13 @@ private void writeMetaDataEntry(List<String> entries) {
131131
132132 private void writeImports () {
133133 importTypes .add (Constants .VALIDATOR );
134- importTypes .add (Constants .VALID_SPI );
135134 importTypes .add ("io.avaje.validation.spi.GeneratedComponent" );
135+ importTypes .add ("io.avaje.validation.spi.MetaData" );
136+ importTypes .add ("io.avaje.validation.spi.Generated" );
136137 importTypes .addAll (metaData .allImports ());
137138
138139 for (final String importType : importTypes ) {
139- if (Util .validImportType (importType )) {
140+ if (Util .validImportType (importType , metaData . packageName () )) {
140141 writer .append ("import %s;" , importType ).eol ();
141142 }
142143 }
Original file line number Diff line number Diff line change @@ -53,7 +53,7 @@ void write() throws IOException {
5353 }
5454
5555 private void writeImports () {
56- beanReader .writeImports (writer );
56+ beanReader .writeImports (writer , adapterPackage );
5757 }
5858
5959 private void writePackage () {
Original file line number Diff line number Diff line change @@ -37,10 +37,12 @@ public static boolean isNullable(Element p) {
3737 return false ;
3838 }
3939
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 ("." )));
4446 }
4547
4648 static String shortName (String fullType ) {
Original file line number Diff line number Diff line change @@ -44,17 +44,15 @@ public String shortName() {
4444 }
4545
4646 private Set <String > importTypes () {
47- if (Util .validImportType (type )) {
48- importTypes .add (type );
49- }
47+ importTypes .add (type );
5048 paramAnnotations .forEach (a -> a .addImports (importTypes ));
5149 returnElementAnnotation .addImports (importTypes );
5250 return importTypes ;
5351 }
5452
55- public void writeImports (Append writer ) {
53+ public void writeImports (Append writer , String packageName ) {
5654 for (final String importType : importTypes ()) {
57- if (Util .validImportType (importType )) {
55+ if (Util .validImportType (importType , packageName )) {
5856 writer .append ("import %s;" , importType ).eol ();
5957 }
6058 }
You can’t perform that action at this time.
0 commit comments