1
1
package io .avaje .inject .generator ;
2
2
3
+ import io .avaje .inject .Factory ;
4
+ import io .avaje .inject .spi .Generated ;
5
+ import io .avaje .inject .spi .Proxy ;
6
+
3
7
import javax .lang .model .element .Element ;
4
8
import javax .lang .model .element .ElementKind ;
5
9
import javax .lang .model .element .Modifier ;
6
10
import javax .lang .model .element .TypeElement ;
7
11
import javax .lang .model .type .TypeMirror ;
12
+ import java .lang .annotation .Annotation ;
8
13
import java .util .ArrayList ;
9
14
import java .util .List ;
10
15
@@ -25,6 +30,8 @@ final class TypeExtendsReader {
25
30
private final String beanSimpleName ;
26
31
private final String baseTypeRaw ;
27
32
private final boolean baseTypeIsInterface ;
33
+ private final boolean publicAccess ;
34
+ private final boolean autoProvide ;
28
35
private boolean closeable ;
29
36
/**
30
37
* The implied qualifier name based on naming convention.
@@ -40,6 +47,24 @@ final class TypeExtendsReader {
40
47
this .beanSimpleName = baseType .getSimpleName ().toString ();
41
48
this .baseTypeRaw = Util .unwrapProvider (baseGenericType .toString ());
42
49
this .baseTypeIsInterface = baseType .getKind () == ElementKind .INTERFACE ;
50
+ this .publicAccess = baseType .getModifiers ().contains (Modifier .PUBLIC );
51
+ this .autoProvide = autoProvide ();
52
+ }
53
+
54
+ private boolean autoProvide () {
55
+ return publicAccess
56
+ && baseType .getAnnotation (Factory .class ) == null
57
+ && baseType .getAnnotation (Proxy .class ) == null
58
+ && baseType .getAnnotation (Generated .class ) == null
59
+ && !isController ();
60
+ }
61
+
62
+ private boolean isController () {
63
+ try {
64
+ return baseType .getAnnotation ((Class <Annotation >) Class .forName (Constants .CONTROLLER )) != null ;
65
+ } catch (final ClassNotFoundException e ) {
66
+ return false ;
67
+ }
43
68
}
44
69
45
70
GenericType baseType () {
@@ -83,16 +108,13 @@ String providesAspect() {
83
108
}
84
109
85
110
String autoProvides () {
86
- if (!providesAspect .isEmpty ()) {
111
+ if (!autoProvide || ! providesAspect .isEmpty ()) {
87
112
return null ;
88
113
}
89
- if (baseTypeIsInterface ) {
114
+ if (baseTypeIsInterface || interfaceTypes . isEmpty () ) {
90
115
return baseTypeRaw ;
91
116
}
92
- if (!interfaceTypes .isEmpty ()) {
93
- return interfaceTypes .get (0 );
94
- }
95
- return null ;
117
+ return interfaceTypes .get (0 );
96
118
}
97
119
98
120
List <String > provides () {
0 commit comments