Skip to content

Commit 198a4f2

Browse files
committed
Dev: switch to kapt
1 parent 16a1d33 commit 198a4f2

2 files changed

Lines changed: 28 additions & 22 deletions

File tree

compiler/src/main/java/com/readdle/codegen/JavaSwiftProcessor.java

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -57,31 +57,31 @@ public synchronized void init(ProcessingEnvironment processingEnv) {
5757
filer = processingEnv.getFiler();
5858
messager = processingEnv.getMessager();
5959

60-
messager.printMessage(Diagnostic.Kind.NOTE, "JavaSwiftProcessor init started");
60+
note("JavaSwiftProcessor init started");
6161

6262
String packageJson = processingEnv.getOptions().get(PACKAGE_OPTION);
6363

6464
moduleDescriptor = new Gson().fromJson(packageJson, SwiftModuleDescriptor.class);
6565
if (moduleDescriptor == null) {
66-
messager.printMessage(Diagnostic.Kind.ERROR, "No package description with option: com.readdle.codegen.package", null);
66+
error(null, "No package description with option: com.readdle.codegen.package");
6767
return;
6868
}
6969

70-
messager.printMessage(Diagnostic.Kind.NOTE, "Package moduleName: " + moduleDescriptor.moduleName);
70+
note("Package moduleName: " + moduleDescriptor.moduleName);
7171

7272
if (moduleDescriptor.importPackages != null) {
7373
for (String anImport : moduleDescriptor.importPackages) {
74-
messager.printMessage(Diagnostic.Kind.NOTE, "Package import: " + anImport);
74+
note("Package import: " + anImport);
7575
}
7676
}
7777

7878
if (moduleDescriptor.customTypeMappings != null) {
7979
for (String key : moduleDescriptor.customTypeMappings.keySet()) {
80-
messager.printMessage(Diagnostic.Kind.NOTE, "Package custom mapping: " + key + " -> " + moduleDescriptor.customTypeMappings.get(key));
80+
note("Package custom mapping: " + key + " -> " + moduleDescriptor.customTypeMappings.get(key));
8181
}
8282
}
8383

84-
messager.printMessage(Diagnostic.Kind.NOTE, "JavaSwiftProcessor init finished successfully");
84+
note("JavaSwiftProcessor init finished successfully");
8585
}
8686

8787
@Override
@@ -120,7 +120,7 @@ public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment
120120

121121
private boolean processImpl(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
122122
Filer filer = processingEnv.getFiler();
123-
messager.printMessage(Diagnostic.Kind.NOTE, "JavaSwiftProcessor start code generation");
123+
note("JavaSwiftProcessor start code generation");
124124

125125
try {
126126
generateJavaSwift(filer);
@@ -129,13 +129,13 @@ private boolean processImpl(Set<? extends TypeElement> annotations, RoundEnviron
129129
error(null, "Can't write to file: " + e.getMessage());
130130
}
131131

132-
messager.printMessage(Diagnostic.Kind.NOTE, "SwiftValue to process: "
132+
note("SwiftValue to process: "
133133
+ roundEnv.getElementsAnnotatedWith(SwiftValue.class).size());
134-
messager.printMessage(Diagnostic.Kind.NOTE, "SwiftReference to process: "
134+
note("SwiftReference to process: "
135135
+ roundEnv.getElementsAnnotatedWith(SwiftReference.class).size());
136-
messager.printMessage(Diagnostic.Kind.NOTE, "SwiftDelegate to process: "
136+
note("SwiftDelegate to process: "
137137
+ roundEnv.getElementsAnnotatedWith(SwiftDelegate.class).size());
138-
messager.printMessage(Diagnostic.Kind.NOTE, "SwiftBlock to process: "
138+
note("SwiftBlock to process: "
139139
+ roundEnv.getElementsAnnotatedWith(SwiftBlock.class).size());
140140

141141
Map<String, SwiftValueDescriptor> swiftValues = new HashMap<>();
@@ -241,9 +241,9 @@ private boolean processImpl(Set<? extends TypeElement> annotations, RoundEnviron
241241
try {
242242
File file = valueDescriptor.generateCode();
243243
/* Logging */
244-
messager.printMessage(Diagnostic.Kind.NOTE, "Generate SwiftValue " + file.getName() + ":");
244+
note("Generate SwiftValue " + file.getName() + ":");
245245
for (WritableElement function : valueDescriptor.getFunctions()) {
246-
messager.printMessage(Diagnostic.Kind.NOTE, function.toString(valueDescriptor.getJavaFullName()));
246+
note(function.toString(valueDescriptor.getJavaFullName()));
247247
}
248248
/* Logging */
249249
} catch (IOException e) {
@@ -257,9 +257,9 @@ private boolean processImpl(Set<? extends TypeElement> annotations, RoundEnviron
257257
try {
258258
File file = referenceDescriptor.generateCode();
259259
/* Logging */
260-
messager.printMessage(Diagnostic.Kind.NOTE, "Generate SwiftReference " + file.getName() + ":");
260+
note("Generate SwiftReference " + file.getName() + ":");
261261
for (WritableElement function : referenceDescriptor.functions) {
262-
messager.printMessage(Diagnostic.Kind.NOTE, function.toString(referenceDescriptor.getJavaFullName()));
262+
note(function.toString(referenceDescriptor.getJavaFullName()));
263263
}
264264
/* Logging */
265265
} catch (IOException e) {
@@ -273,9 +273,9 @@ private boolean processImpl(Set<? extends TypeElement> annotations, RoundEnviron
273273
try {
274274
File file = delegateDescriptor.generateCode();
275275
/* Logging */
276-
messager.printMessage(Diagnostic.Kind.NOTE, "Generate SwiftDelegate" + file.getName() + ":");
276+
note("Generate SwiftDelegate" + file.getName() + ":");
277277
for (WritableElement function : delegateDescriptor.functions) {
278-
messager.printMessage(Diagnostic.Kind.NOTE, function.toString(delegateDescriptor.getJavaFullName()));
278+
note(function.toString(delegateDescriptor.getJavaFullName()));
279279
}
280280
/* Logging */
281281
} catch (IOException e) {
@@ -289,7 +289,7 @@ private boolean processImpl(Set<? extends TypeElement> annotations, RoundEnviron
289289
try {
290290
File file = blockDescriptor.generateCode();
291291
/* Logging */
292-
messager.printMessage(Diagnostic.Kind.NOTE, "Generate SwiftBlock" + file.getName());
292+
note("Generate SwiftBlock" + file.getName());
293293
/* Logging */
294294
} catch (IOException e) {
295295
e.printStackTrace();
@@ -298,7 +298,7 @@ private boolean processImpl(Set<? extends TypeElement> annotations, RoundEnviron
298298
}
299299
}
300300

301-
messager.printMessage(Diagnostic.Kind.NOTE, "JavaSwiftProcessor finished successfully!");
301+
note("JavaSwiftProcessor finished successfully!");
302302

303303
return false;
304304
}
@@ -307,7 +307,7 @@ private void generateJavaSwift(Filer filer) throws IOException {
307307
String swiftFilePath = filer.getResource(StandardLocation.SOURCE_OUTPUT, FOLDER, "SwiftJava.swift").toUri().getPath();
308308
File swiftExtensionFile = new File(swiftFilePath);
309309
swiftExtensionFile.getParentFile().mkdir();
310-
messager.printMessage(Diagnostic.Kind.NOTE, "JavaSwiftProcessor will generate sources at: " + swiftExtensionFile.getParent());
310+
note("JavaSwiftProcessor will generate sources at: " + swiftExtensionFile.getParent());
311311
SwiftWriter swiftWriter = new SwiftWriter(swiftExtensionFile);
312312
swiftWriter.emitImports(new String[0]);
313313
swiftWriter.emitEmptyLine();
@@ -329,6 +329,10 @@ private void generateJavaSwift(Filer filer) throws IOException {
329329
swiftWriter.close();
330330
}
331331

332+
private void note(String msg) {
333+
messager.printMessage(Diagnostic.Kind.WARNING, msg);
334+
}
335+
332336
private void error(Element e, String msg, Object... args) {
333337
messager.printMessage(Diagnostic.Kind.ERROR, String.format(msg, args), e);
334338
}

sample/build.gradle

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@ apply plugin: 'com.readdle.android.swift'
33

44
apply plugin: 'kotlin-android'
55
apply plugin: 'kotlin-android-extensions'
6+
apply plugin: 'kotlin-kapt'
67

78
swift {
9+
useKapt true
810
cleanEnabled true
911
debug {
10-
abiFilters("arm64-v8a")
12+
abiFilters("x86_64")
1113
extraBuildFlags("-Xswiftc", "-DDEBUG")
1214
}
1315
}
@@ -44,7 +46,7 @@ android {
4446
}
4547

4648
dependencies {
47-
annotationProcessor project(':compiler')
49+
kapt project(':compiler')
4850
implementation project(':library')
4951

5052
implementation 'com.android.support:appcompat-v7:28.0.0'

0 commit comments

Comments
 (0)