File tree Expand file tree Collapse file tree 4 files changed +21
-5
lines changed
main/java/io/avaje/inject/generator
test/java/io/avaje/inject/generator Expand file tree Collapse file tree 4 files changed +21
-5
lines changed Original file line number Diff line number Diff line change @@ -115,6 +115,8 @@ private void init() {
115
115
String annType = annotationType .toString ();
116
116
if (qualifier != null ) {
117
117
this .name = Util .shortName (annType );
118
+ } else if (annType .indexOf ('.' ) == -1 ) {
119
+ context .logWarn ("skip when no package on annotation " + annType );
118
120
} else {
119
121
if (IncludeAnnotations .include (annType )) {
120
122
importTypes .add (annType );
@@ -377,7 +379,7 @@ private Set<String> importTypes() {
377
379
importTypes .add (generated );
378
380
}
379
381
importTypes .add (Constants .BUILDER );
380
- if (Util .notVoid (type )) {
382
+ if (Util .validImportType (type )) {
381
383
importTypes .add (type );
382
384
}
383
385
requestParams .addImports (importTypes );
@@ -386,7 +388,7 @@ private Set<String> importTypes() {
386
388
387
389
void writeImports (Append writer ) {
388
390
for (String importType : importTypes ()) {
389
- if (Util .notVoid (importType )) {
391
+ if (Util .validImportType (importType )) {
390
392
writer .append ("import %s;" , importType ).eol ();
391
393
}
392
394
}
Original file line number Diff line number Diff line change @@ -96,7 +96,7 @@ private void writePackage() {
96
96
writer .append (Constants .IMPORT_BUILDERFACTORY ).eol ();
97
97
98
98
for (String type : ordering .getImportTypes ()) {
99
- if (Util .notVoid (type )) {
99
+ if (Util .validImportType (type )) {
100
100
writer .append ("import %s;" , type ).eol ();
101
101
}
102
102
}
Original file line number Diff line number Diff line change @@ -13,8 +13,8 @@ static boolean isVoid(String type) {
13
13
return "void" .equalsIgnoreCase (type );
14
14
}
15
15
16
- static boolean notVoid (String type ) {
17
- return ! isVoid ( type ) ;
16
+ static boolean validImportType (String type ) {
17
+ return type . indexOf ( '.' ) > 0 ;
18
18
}
19
19
20
20
static String classOfMethod (String method ) {
Original file line number Diff line number Diff line change 3
3
import org .junit .jupiter .api .Test ;
4
4
5
5
import static org .junit .jupiter .api .Assertions .assertEquals ;
6
+ import static org .junit .jupiter .api .Assertions .assertFalse ;
6
7
import static org .junit .jupiter .api .Assertions .assertNull ;
8
+ import static org .junit .jupiter .api .Assertions .assertTrue ;
7
9
8
10
public class UtilTest {
9
11
@@ -38,4 +40,16 @@ public void addForInterface() {
38
40
assertEquals ("Bar" , Util .addForInterface ("com.foo.Bar" ));
39
41
}
40
42
43
+ @ Test
44
+ public void validImportType () {
45
+ assertTrue (Util .validImportType ("my.Foo" ));
46
+ assertTrue (Util .validImportType ("other.pack.Foo" ));
47
+ }
48
+
49
+ @ Test
50
+ public void validImportType_not () {
51
+ assertFalse (Util .validImportType ("void" ));
52
+ assertFalse (Util .validImportType ("Foo" ));
53
+ assertFalse (Util .validImportType ("NoPackage" ));
54
+ }
41
55
}
You can’t perform that action at this time.
0 commit comments