|
27 | 27 | import com.interguess.autoimpl.annotationprocessor.collectors.FieldCollector; |
28 | 28 | import com.interguess.autoimpl.annotationprocessor.collectors.MethodCollector; |
29 | 29 | import com.interguess.autoimpl.annotationprocessor.utils.ResourceFileLoaderUtil; |
| 30 | +import com.interguess.autoimpl.api.annotations.AutoImpl; |
30 | 31 | import com.interguess.autoimpl.api.method.MethodType; |
31 | 32 | import com.interguess.autoimpl.api.method.MethodTypeMatcher; |
32 | 33 | import com.interguess.autoimpl.common.method.MethodTypeMatcherImpl; |
@@ -56,12 +57,35 @@ public ImplementationClassGenerator(final @NotNull ProcessingEnvironment process |
56 | 57 | } |
57 | 58 |
|
58 | 59 | public void generateForInterface(final @NotNull TypeElement interfaceElement) { |
| 60 | + final AutoImpl autoImplAnnotation = interfaceElement.getAnnotation(AutoImpl.class); |
| 61 | + |
| 62 | + if (autoImplAnnotation == null) { |
| 63 | + this.processingEnv.getMessager().printMessage( |
| 64 | + Diagnostic.Kind.ERROR, |
| 65 | + "The interface must be annotated with @AutoImpl to generate an implementation class.", |
| 66 | + interfaceElement |
| 67 | + ); |
| 68 | + |
| 69 | + return; |
| 70 | + } |
| 71 | + |
| 72 | + if (!autoImplAnnotation.value().matches("[A-Z][a-zA-Z0-9_]*")) { |
| 73 | + this.processingEnv.getMessager().printMessage( |
| 74 | + Diagnostic.Kind.ERROR, |
| 75 | + "The value of @AutoImpl must be a valid class name suffix (start with an uppercase letter and contain only letters, digits, and underscores).", |
| 76 | + interfaceElement |
| 77 | + ); |
| 78 | + |
| 79 | + return; |
| 80 | + } |
| 81 | + |
59 | 82 | final String interfaceName = interfaceElement.getSimpleName().toString(); |
60 | 83 | final String packageName = this.processingEnv.getElementUtils().getPackageOf(interfaceElement).getQualifiedName().toString(); |
61 | | - final String className = interfaceName + "Impl"; |
| 84 | + final String className = interfaceName + autoImplAnnotation.value(); |
62 | 85 | final String qualifiedClassName = packageName + "." + className; |
63 | 86 |
|
64 | 87 | final FieldCollector fieldCollector = new FieldCollector(); |
| 88 | + |
65 | 89 | final MethodCollector methodCollector = new MethodCollector(); |
66 | 90 |
|
67 | 91 | for (final Element enclosed : interfaceElement.getEnclosedElements()) { |
|
0 commit comments