Skip to content

Commit

Permalink
Issue #285 - Revue
Browse files Browse the repository at this point in the history
  • Loading branch information
boretti committed May 19, 2020
1 parent b7a440c commit f836acf
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
Expand Up @@ -56,5 +56,9 @@ default boolean isAssignableWithErasure(TypeElement fromField, TypeMirror compar
return fromField != null && getProcessingEnv().getTypeUtils().isAssignable(fromField.asType(),
getProcessingEnv().getTypeUtils().erasure(compareWith));
}

default String getAnnotationProcessorVersion() {
return getClass().getPackage().getImplementationVersion();
}

}
Expand Up @@ -32,6 +32,7 @@

import javax.lang.model.element.TypeElement;

import ch.powerunit.extensions.matchers.common.CommonUtils;
import ch.powerunit.extensions.matchers.common.ListJoining;
import ch.powerunit.extensions.matchers.provideprocessor.fields.AbstractFieldDescription;
import ch.powerunit.extensions.matchers.provideprocessor.fields.FieldDescriptionMetaData;
Expand Down Expand Up @@ -104,13 +105,13 @@ public String generateMetadata() {
+ " public static final Metadata METADATA = new Metadata();\n\n"
+ " public static final class Metadata {\n\n"
+ " private Metadata() {}\n\n"
+ " public static final String ANNOTATION_PROCESSOR_VERSION = \"" + getClass().getPackage().getImplementationVersion() + "\";\n\n"
+ " public static final String ANNOTATION_PROCESSOR_VERSION = \"" + getAnnotationProcessorVersion() + "\";\n\n"
+ " public static final String SOURCE_CLASS_NAME = \"" + getFullyQualifiedNameOfClassAnnotatedWithProvideMatcherWithGeneric() + "\";\n\n"
+ " public static final Class<"+getFullyQualifiedNameOfClassAnnotated()+"> SOURCE_CLASS = " + getFullyQualifiedNameOfClassAnnotated() + ".class;\n\n"
+ " public static final String SOURCE_PARENT_CLASS_NAME = " + fullyQualifiedNameOfSuperClassOfClassAnnotated.map(n->"\""+n+"\"").orElse("null") + ";\n\n"
+ " public static final String[] FIELD_NAMES = new String[]{ " +ListJoining.<AbstractFieldDescription>joinWithMapperAndDelimiter(f->"\""+f.getFieldName()+"\"", ", ").asString(fields) + " };\n\n"
+ " public static final String[] FIELD_TYPES = new String[]{ " +ListJoining.<AbstractFieldDescription>joinWithMapperAndDelimiter(f->"\""+f.getFieldType()+"\"", ", ").asString(fields) + " };\n\n"
+ " public static final String[] FIELD_ACCESSORS = new String[]{ " +ListJoining.<AbstractFieldDescription>joinWithMapperAndDelimiter(f->"\""+f.getFieldAccessor()+"\"", ", ").asString(fields) + " };\n\n"
+ " public static final String SOURCE_PARENT_CLASS_NAME = " + fullyQualifiedNameOfSuperClassOfClassAnnotated.map(CommonUtils::toJavaSyntax).orElse("null") + ";\n\n"
+ " public static final String[] FIELD_NAMES = new String[]{ " +ListJoining.<AbstractFieldDescription>joinWithMapperAndDelimiter(f->CommonUtils.toJavaSyntax(f.getFieldName()), ", ").asString(fields) + " };\n\n"
+ " public static final String[] FIELD_TYPES = new String[]{ " +ListJoining.<AbstractFieldDescription>joinWithMapperAndDelimiter(f->CommonUtils.toJavaSyntax(f.getFieldType()), ", ").asString(fields) + " };\n\n"
+ " public static final String[] FIELD_ACCESSORS = new String[]{ " +ListJoining.<AbstractFieldDescription>joinWithMapperAndDelimiter(f->CommonUtils.toJavaSyntax(f.getFieldAccessor()), ", ").asString(fields) + " };\n\n"
+ " public static final boolean[] FIELD_IGNORED = new boolean[]{ " +ListJoining.<AbstractFieldDescription>joinWithMapperAndDelimiter(f->Boolean.toString(f instanceof IgoreFieldDescription), ", ").asString(fields) + " };\n\n"
+ " }\n";
// @formatter:on
Expand Down
Expand Up @@ -79,15 +79,12 @@ public Collection<DSLMethod> process() {
return processFileWithIOExceptionAndResult(
() -> getFiler().createSourceFile(getFullyQualifiedNameOfGeneratedClass(), te),
jfo -> new PrintWriter(jfo.openWriter()), wjfo -> {
wjfo.println("package " + getPackageNameOfGeneratedClass() + ";");
wjfo.println();
wjfo.println("package " + getPackageNameOfGeneratedClass() + ";\n");
wjfo.println(generateMainJavaDoc());
wjfo.println(generateGeneratedAnnotation(ProvidesMatchersAnnotationsProcessor.class,
annotation.get().comments()));
wjfo.println("public final class " + simpleName + " {");
wjfo.println();
wjfo.println(" private " + simpleName + "() {}");
wjfo.println();
wjfo.println("public final class " + simpleName + " {\n");
wjfo.println(" private " + simpleName + "() {}\n");
wjfo.println(generateMatchers());
wjfo.println();
wjfo.println(generatePublicInterface());
Expand All @@ -97,7 +94,6 @@ public Collection<DSLMethod> process() {
Collection<DSLMethod> tmp = generateDSLStarter();
tmp.stream().map(m -> addPrefix(" ", m.asStaticImplementation())).forEach(wjfo::println);
wjfo.println();
wjfo.println();
wjfo.println(generateMetadata());
wjfo.println("}");
return tmp;
Expand Down

0 comments on commit f836acf

Please sign in to comment.