Skip to content

Commit 58b421e

Browse files
committed
Dev: add @SwiftModule annotation, remove all importPackages attributes
1 parent 90478a4 commit 58b421e

11 files changed

Lines changed: 53 additions & 24 deletions

File tree

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

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.readdle.codegen.anotation.SwiftBlock;
44
import com.readdle.codegen.anotation.SwiftDelegate;
5+
import com.readdle.codegen.anotation.SwiftModule;
56
import com.readdle.codegen.anotation.SwiftReference;
67
import com.readdle.codegen.anotation.SwiftValue;
78

@@ -42,6 +43,9 @@ interface WritableElement {
4243
private Filer filer;
4344
private Messager messager;
4445

46+
private String moduleName;
47+
private String[] importPackages;
48+
4549
@Override
4650
public synchronized void init(ProcessingEnvironment processingEnv) {
4751
super.init(processingEnv);
@@ -83,6 +87,16 @@ public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment
8387
Map<String, SwiftDelegateDescriptor> swiftDelegates = new HashMap<>();
8488
Map<String, SwiftBlockDescriptor> swiftBlocks = new HashMap<>();
8589

90+
for (Element annotatedElement : roundEnv.getElementsAnnotatedWith(SwiftModule.class)) {
91+
SwiftModule swiftModule = annotatedElement.getAnnotation(SwiftModule.class);
92+
moduleName = swiftModule.moduleName();
93+
importPackages = swiftModule.importPackages();
94+
}
95+
96+
if (moduleName == null || importPackages == null) {
97+
messager.printMessage(Diagnostic.Kind.ERROR, "No package description with SwiftModule.class", null);
98+
}
99+
86100
for (Element annotatedElement : roundEnv.getElementsAnnotatedWith(SwiftValue.class)) {
87101
// Check if a class has been annotated with @SwiftValue
88102
if (annotatedElement.getKind() != ElementKind.CLASS) {
@@ -94,7 +108,7 @@ public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment
94108
TypeElement typeElement = (TypeElement) annotatedElement;
95109

96110
try {
97-
SwiftValueDescriptor swiftValueDescriptor = new SwiftValueDescriptor(typeElement, filer);
111+
SwiftValueDescriptor swiftValueDescriptor = new SwiftValueDescriptor(typeElement, filer, importPackages);
98112
swiftValues.put(swiftValueDescriptor.getSwiftType(), swiftValueDescriptor);
99113
}
100114
catch (IllegalArgumentException e) {
@@ -115,7 +129,7 @@ public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment
115129
TypeElement typeElement = (TypeElement) annotatedElement;
116130

117131
try {
118-
SwiftReferenceDescriptor swiftReferenceDescriptor = new SwiftReferenceDescriptor(typeElement, filer);
132+
SwiftReferenceDescriptor swiftReferenceDescriptor = new SwiftReferenceDescriptor(typeElement, filer, importPackages);
119133
swiftReferences.put(swiftReferenceDescriptor.getSwiftType(), swiftReferenceDescriptor);
120134
}
121135
catch (IllegalArgumentException e) {
@@ -136,7 +150,7 @@ public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment
136150
TypeElement typeElement = (TypeElement) annotatedElement;
137151

138152
try {
139-
SwiftDelegateDescriptor delegateDescriptor = new SwiftDelegateDescriptor(typeElement, filer);
153+
SwiftDelegateDescriptor delegateDescriptor = new SwiftDelegateDescriptor(typeElement, filer, importPackages);
140154
swiftDelegates.put(delegateDescriptor.simpleTypeName, delegateDescriptor);
141155
}
142156
catch (IllegalArgumentException e) {
@@ -157,7 +171,7 @@ public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment
157171
TypeElement typeElement = (TypeElement) annotatedElement;
158172

159173
try {
160-
SwiftBlockDescriptor blockDescriptor = new SwiftBlockDescriptor(typeElement, filer);
174+
SwiftBlockDescriptor blockDescriptor = new SwiftBlockDescriptor(typeElement, filer, importPackages);
161175
swiftBlocks.put(blockDescriptor.simpleTypeName, blockDescriptor);
162176
}
163177
catch (IllegalArgumentException e) {

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,14 @@ class SwiftBlockDescriptor {
3939
private String sig;
4040
private List<SwiftParamDescriptor> params = new LinkedList<>();
4141

42-
SwiftBlockDescriptor(TypeElement classElement, Filer filer) throws IllegalArgumentException {
42+
SwiftBlockDescriptor(TypeElement classElement, Filer filer, String[] importPackages) throws IllegalArgumentException {
4343
this.annotatedClassElement = classElement;
44+
this.importPackages = importPackages;
4445

4546
// Get the full QualifiedTypeName
4647
try {
4748
SwiftBlock annotation = classElement.getAnnotation(SwiftBlock.class);
48-
importPackages = annotation.importPackages();
49-
blockSignature = annotation.signature();
49+
blockSignature = annotation.value();
5050
simpleTypeName = classElement.getSimpleName().toString();
5151
javaFullName = classElement.getQualifiedName().toString().replace(".", "/");
5252

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,14 @@ class SwiftDelegateDescriptor {
3838

3939
private boolean isInterface;
4040

41-
SwiftDelegateDescriptor(TypeElement classElement, Filer filer) throws IllegalArgumentException {
41+
SwiftDelegateDescriptor(TypeElement classElement, Filer filer, String[] importPackages) throws IllegalArgumentException {
4242
this.annotatedClassElement = classElement;
4343
this.isInterface = classElement.getKind() == ElementKind.INTERFACE;
44+
this.importPackages = importPackages;
4445

4546
// Get the full QualifiedTypeName
4647
try {
4748
SwiftDelegate annotation = classElement.getAnnotation(SwiftDelegate.class);
48-
importPackages = annotation.importPackages();
4949
protocols = annotation.protocols();
5050
simpleTypeName = classElement.getSimpleName().toString();
5151
javaFullName = classElement.getQualifiedName().toString().replace(".", "/");
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.readdle.codegen;
2+
3+
public class SwiftModuleDescriptor {
4+
5+
private String moduleName;
6+
private String[] imports;
7+
8+
}

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,12 @@ class SwiftReferenceDescriptor {
3434

3535
List<JavaSwiftProcessor.WritableElement> functions = new LinkedList<>();
3636

37-
SwiftReferenceDescriptor(TypeElement classElement, Filer filer) throws IllegalArgumentException {
37+
SwiftReferenceDescriptor(TypeElement classElement, Filer filer, String[] importPackages) throws IllegalArgumentException {
3838
this.annotatedClassElement = classElement;
39+
this.importPackages = importPackages;
3940

4041
// Get the full QualifiedTypeName
4142
try {
42-
SwiftReference annotation = classElement.getAnnotation(SwiftReference.class);
43-
importPackages = annotation.importPackages();
4443
simpleTypeName = classElement.getSimpleName().toString();
4544
javaFullName = classElement.getQualifiedName().toString().replace(".", "/");
4645
} catch (MirroredTypeException mte) {

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,12 @@ class SwiftValueDescriptor {
3232

3333
List<SwiftFuncDescriptor> functions = new LinkedList<>();
3434

35-
SwiftValueDescriptor(TypeElement classElement, Filer filer) throws IllegalArgumentException {
35+
SwiftValueDescriptor(TypeElement classElement, Filer filer, String[] importPackages) throws IllegalArgumentException {
3636
this.annotatedClassElement = classElement;
37+
this.importPackages = importPackages;
3738

3839
// Get the full QualifiedTypeName
3940
try {
40-
SwiftValue annotation = classElement.getAnnotation(SwiftValue.class);
41-
importPackages = annotation.importPackages();
4241
simpleTypeName = classElement.getSimpleName().toString();
4342
javaPackage = classElement.getQualifiedName().toString().replace("." + simpleTypeName, "");
4443
javaFullName = classElement.getQualifiedName().toString().replace(".", "/");

library/src/main/java/com/readdle/codegen/anotation/SwiftBlock.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
@Target(ElementType.TYPE) @Retention(RetentionPolicy.CLASS)
99
public @interface SwiftBlock {
1010

11-
String[] importPackages() default {};
12-
13-
String signature() default "";
11+
String value() default "";
1412

1513
}

library/src/main/java/com/readdle/codegen/anotation/SwiftDelegate.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
@Target(ElementType.TYPE) @Retention(RetentionPolicy.CLASS)
1010
public @interface SwiftDelegate {
1111

12-
String[] importPackages() default {};
13-
1412
String[] protocols() default {};
1513

1614
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.readdle.codegen.anotation;
2+
3+
4+
import java.lang.annotation.ElementType;
5+
import java.lang.annotation.Retention;
6+
import java.lang.annotation.RetentionPolicy;
7+
import java.lang.annotation.Target;
8+
9+
@Retention(RetentionPolicy.CLASS)
10+
@Target(ElementType.PACKAGE)
11+
public @interface SwiftModule {
12+
13+
String moduleName() default "";
14+
15+
String[] importPackages() default {};
16+
17+
}

library/src/main/java/com/readdle/codegen/anotation/SwiftReference.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,4 @@
88
@Target(ElementType.TYPE) @Retention(RetentionPolicy.CLASS)
99
public @interface SwiftReference {
1010

11-
String[] importPackages() default {};
12-
1311
}

0 commit comments

Comments
 (0)