39
39
})
40
40
public abstract class BaseProcessor extends AbstractProcessor {
41
41
42
- private static final String HTTP_CONTROLLERS_TXT = "controllers.txt" ;
43
-
42
+ private static final String HTTP_CONTROLLERS_TXT = "testAPI/controllers.txt" ;
44
43
protected String contextPathString ;
45
44
46
45
protected Map <String , String > packagePaths = new HashMap <>();
47
46
48
- private final Set <String > controllerFQNs = new HashSet <>();
47
+ private final Set <String > clientFQNs = new HashSet <>();
49
48
50
49
@ Override
51
50
public SourceVersion getSupportedSourceVersion () {
@@ -68,10 +67,12 @@ public synchronized void init(ProcessingEnvironment processingEnv) {
68
67
var txtFilePath = APContext .getBuildResource (HTTP_CONTROLLERS_TXT );
69
68
70
69
if (txtFilePath .toFile ().exists ()) {
71
- Files .lines (txtFilePath ).forEach (controllerFQNs ::add );
70
+ Files .lines (txtFilePath ).forEach (clientFQNs ::add );
72
71
}
73
72
if (APContext .isTestCompilation ()) {
74
- controllerFQNs .stream ().map (APContext ::typeElement ).forEach (this ::writeClientAdapter );
73
+ for (var path : clientFQNs ) {
74
+ TestClientWriter .writeActual (path );
75
+ }
75
76
}
76
77
} catch (IOException e ) {
77
78
e .printStackTrace ();
@@ -124,7 +125,7 @@ public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment
124
125
try {
125
126
Files .write (
126
127
APContext .getBuildResource (HTTP_CONTROLLERS_TXT ),
127
- controllerFQNs ,
128
+ clientFQNs ,
128
129
StandardOpenOption .CREATE ,
129
130
StandardOpenOption .WRITE );
130
131
} catch (IOException e ) {
@@ -175,26 +176,22 @@ private void writeAdapter(TypeElement controller) {
175
176
try {
176
177
177
178
writeControllerAdapter (reader );
178
- controllerFQNs . add ( controller . getQualifiedName (). toString () );
179
+ writeClientAdapter ( reader );
179
180
180
181
} catch (final Throwable e ) {
181
182
logError (reader .beanType (), "Failed to write $Route class " + e );
182
183
}
183
184
}
184
185
185
- private void writeClientAdapter (TypeElement controller ) {
186
- final var packageFQN = elements ().getPackageOf (controller ).getQualifiedName ().toString ();
187
- final var contextPath = Util .combinePath (contextPathString , packagePath (packageFQN ));
188
- final var reader = new ControllerReader (controller , contextPath );
189
- reader .read (true );
186
+ private void writeClientAdapter (ControllerReader reader ) {
187
+
190
188
try {
191
- if (controller .getInterfaces ().isEmpty ()
192
- && "java.lang.Object" .equals (controller .getSuperclass ().toString ())) {
189
+ if (reader . beanType () .getInterfaces ().isEmpty ()
190
+ && "java.lang.Object" .equals (reader . beanType () .getSuperclass ().toString ())) {
193
191
new TestClientWriter (reader ).write ();
192
+ clientFQNs .add (reader .beanType ().getQualifiedName ().toString () + "$TestAPI" );
194
193
}
195
- writeControllerAdapter (reader );
196
-
197
- } catch (final Throwable e ) {
194
+ } catch (final IOException e ) {
198
195
logError (reader .beanType (), "Failed to write $Route class " + e );
199
196
}
200
197
}
0 commit comments