Skip to content

Commit

Permalink
Merge 40e0d9e into 81968ef
Browse files Browse the repository at this point in the history
  • Loading branch information
boretti committed May 19, 2020
2 parents 81968ef + 40e0d9e commit 101c8cc
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 9 deletions.
Original file line number Diff line number Diff line change
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();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@

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;
import ch.powerunit.extensions.matchers.provideprocessor.fields.IgoreFieldDescription;
Expand Down Expand Up @@ -92,4 +94,25 @@ public GeneratedMatcher asXml() {
return gm;
}

public String generateMetadata() {
// @formatter:off
return "\n\n"
+ " // ---------------------------------------------------------------------------\n"
+ " // METADATA\n\n"
+ " /**\n"
+ " * Metadata regarding this matcher.\n"
+ " */\n"
+ " public static final Metadata METADATA = new Metadata();\n\n"
+" public static final class FieldMetadata {\n public final String NAME, TYPE, ACCESSOR;\n public final boolean IGNORED;\n private FieldMetadata(String name, String type, String accessor, boolean ignored) {\n NAME=name; TYPE=type; ACCESSOR=accessor; IGNORED=ignored;\n }\n }\n\n"
+ " public static final class Metadata {\n\n"
+ " private Metadata() {}\n\n"
+ " public final String ANNOTATION_PROCESSOR_VERSION = \"" + getAnnotationProcessorVersion() + "\";\n\n"
+ " public final String SOURCE_CLASS_NAME = \"" + getFullyQualifiedNameOfClassAnnotatedWithProvideMatcherWithGeneric() + "\";\n\n"
+ " public final Class<"+getFullyQualifiedNameOfClassAnnotated()+"> SOURCE_CLASS = " + getFullyQualifiedNameOfClassAnnotated() + ".class;\n\n"
+ " public final String SOURCE_PARENT_CLASS_NAME = " + fullyQualifiedNameOfSuperClassOfClassAnnotated.map(CommonUtils::toJavaSyntax).orElse("null") + ";\n\n"
+ " public final FieldMetadata[] FIELDS = new FieldMetadata[]{ " +ListJoining.<AbstractFieldDescription>joinWithMapperAndDelimiter(f->f.generateMetadata("FieldMetadata"), ", ").asString(fields) + " };\n\n"
+ " }\n";
// @formatter:on
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +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("// Generated by version " + getClass().getPackage().getImplementationVersion());
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,6 +93,8 @@ public Collection<DSLMethod> process() {
wjfo.println();
Collection<DSLMethod> tmp = generateDSLStarter();
tmp.stream().map(m -> addPrefix(" ", m.asStaticImplementation())).forEach(wjfo::println);
wjfo.println();
wjfo.println(generateMetadata());
wjfo.println("}");
return tmp;
}, e -> traceErrorAndDump(getMessager(), getFiler(), e, te));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import javax.lang.model.type.DeclaredType;
import javax.lang.model.type.TypeMirror;

import ch.powerunit.extensions.matchers.common.CommonUtils;
import ch.powerunit.extensions.matchers.provideprocessor.ProvidesMatchersAnnotatedElementData;
import ch.powerunit.extensions.matchers.provideprocessor.RoundMirror;
import ch.powerunit.extensions.matchers.provideprocessor.xml.GeneratedMatcherField;
Expand All @@ -35,7 +36,7 @@ public abstract class FieldDescriptionMetaData extends AbstractFieldDescriptionC
public static final String SEE_TEXT_FOR_IS_MATCHER = "org.hamcrest.Matchers#is(java.lang.Object)";
public static final String SEE_TEXT_FOR_HAMCREST_MATCHER = "org.hamcrest.Matchers The main class from hamcrest that provides default matchers.";
public static final String MATCHERS = "org.hamcrest.Matchers";

protected final String generic;
protected final String defaultReturnMethod;
protected final String fullyQualifiedNameMatcherInSameRound;
Expand Down Expand Up @@ -151,4 +152,10 @@ public GeneratedMatcherField asGeneratedMatcherField() {
return gmf;
}

public String generateMetadata(String className) {
return "new " + className + "(" + CommonUtils.toJavaSyntax(getFieldName()) + ","
+ CommonUtils.toJavaSyntax(getFieldType()) + "," + CommonUtils.toJavaSyntax(getFieldAccessor()) + ","
+ Boolean.toString(this instanceof IgoreFieldDescription) + ")";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
*/
package ch.powerunit.extensions.matchers.samples.iterable;

import java.util.List;
import java.util.Objects;
import java.util.Set;

Expand Down

0 comments on commit 101c8cc

Please sign in to comment.