diff --git a/src/main/java/ch/powerunit/extensions/matchers/provideprocessor/fields/DefaultFieldDescription.java b/src/main/java/ch/powerunit/extensions/matchers/provideprocessor/fields/DefaultFieldDescription.java index 85deb6d7a..75cc59977 100644 --- a/src/main/java/ch/powerunit/extensions/matchers/provideprocessor/fields/DefaultFieldDescription.java +++ b/src/main/java/ch/powerunit/extensions/matchers/provideprocessor/fields/DefaultFieldDescription.java @@ -24,6 +24,8 @@ import java.util.Collections; import java.util.List; +import javax.lang.model.element.TypeElement; + import ch.powerunit.extensions.matchers.provideprocessor.ProvidesMatchersAnnotatedElementData; import ch.powerunit.extensions.matchers.provideprocessor.fields.lang.BuilderDeclaration; @@ -37,48 +39,42 @@ public DefaultFieldDescription(ProvidesMatchersAnnotatedElementData containingEl protected Collection getSpecificFieldDslMethodFor() { return Collections.emptyList(); } - + protected final BuilderDeclaration getDslMethodBuilder() { return FieldDSLMethodBuilder.of(this); } @Override protected final Collection getFieldDslMethodFor() { + String ft = mirror.getFieldType(); + String fn = mirror.getFieldName(); List tmp = new ArrayList<>(); - - tmp.add(FieldDSLMethodBuilder.of(this) - .withDeclaration("org.hamcrest.Matcher matcher") + tmp.add(FieldDSLMethodBuilder.of(this).withDeclaration("org.hamcrest.Matcher matcher") .withJavaDoc("", "matcher a Matcher on the field", SEE_TEXT_FOR_HAMCREST_MATCHER) - .havingImplementation(mirror.getFieldName() + "= new " + mirror.getMethodFieldName() - + "Matcher(matcher);\nreturn this;")); - - tmp.add(FieldDSLMethodBuilder.of(this).withDeclaration(mirror.getFieldType() + " value") + .havingImplementation(fn + "= new " + mirror.getMethodFieldName() + "Matcher(matcher);\nreturn this;")); + tmp.add(FieldDSLMethodBuilder.of(this).withDeclaration(ft + " value") .withJavaDoc("", "value an expected value for the field, which will be compared using the is matcher", SEE_TEXT_FOR_IS_MATCHER) .havingDefault(MATCHERS + ".is(value)")); - tmp.add(FieldDSLMethodBuilder.of(this) .withGenericDeclaration("<_TARGETFIELD>", "As", - "java.util.function.Function<" + mirror.getFieldType() + "java.util.function.Function<" + ft + ",_TARGETFIELD> converter,org.hamcrest.Matcher matcher") .withJavaDoc("by converting the received field before validat it", "converter a function to convert the field\nmatcher a matcher on the resulting\n<_TARGETFIELD> The type which this field must be converter") .havingDefault("asFeatureMatcher(\" \",converter,matcher)")); - - if (fullyQualifiedNameMatcherInSameRound != null - && mirror.getFieldTypeAsTypeElement().getTypeParameters().isEmpty()) { - String name = mirror.getFieldTypeAsTypeElement().getSimpleName().toString(); + TypeElement te = mirror.getFieldTypeAsTypeElement(); + if (fullyQualifiedNameMatcherInSameRound != null && te.getTypeParameters().isEmpty()) { + String name = te.getSimpleName().toString(); String lname = name.substring(0, 1).toLowerCase() + name.substring(1); - tmp.add(FieldDSLMethodBuilder.of(this) .withExplicitDeclaration(fullyQualifiedNameMatcherInSameRound + "." + name + "Matcher" + "<" - + defaultReturnMethod + "> " + mirror.getFieldName() + "With()") + + defaultReturnMethod + "> " + fn + "With()") .withJavaDoc("by starting a matcher for this field") .havingImplementation(fullyQualifiedNameMatcherInSameRound + "." + name + "Matcher tmp = " - + fullyQualifiedNameMatcherInSameRound + "." + lname + "WithParent(this);\n" - + mirror.getFieldName() + "(tmp);\nreturn tmp;")); + + fullyQualifiedNameMatcherInSameRound + "." + lname + "WithParent(this);\n" + fn + + "(tmp);\nreturn tmp;")); } - tmp.addAll(getSpecificFieldDslMethodFor()); return tmp; } diff --git a/src/main/java/ch/powerunit/extensions/matchers/provideprocessor/fields/FieldDescriptionMirror.java b/src/main/java/ch/powerunit/extensions/matchers/provideprocessor/fields/FieldDescriptionMirror.java index 4d7fa4c2a..2ec89b0a7 100644 --- a/src/main/java/ch/powerunit/extensions/matchers/provideprocessor/fields/FieldDescriptionMirror.java +++ b/src/main/java/ch/powerunit/extensions/matchers/provideprocessor/fields/FieldDescriptionMirror.java @@ -30,10 +30,10 @@ public class FieldDescriptionMirror { - protected final String fieldName; - protected final String fieldType; - protected final TypeElement fieldTypeAsTypeElement; - protected final Element fieldElement; + private final String fieldName; + private final String fieldType; + private final TypeElement fieldTypeAsTypeElement; + private final Element fieldElement; public FieldDescriptionMirror(ProvidesMatchersAnnotatedElementData containingElementMirror, String fieldName, String fieldType, Element fieldElement) { diff --git a/src/main/java/ch/powerunit/extensions/matchers/provideprocessor/fields/FieldDescriptionProvider.java b/src/main/java/ch/powerunit/extensions/matchers/provideprocessor/fields/FieldDescriptionProvider.java index 76ba19222..93bd22205 100644 --- a/src/main/java/ch/powerunit/extensions/matchers/provideprocessor/fields/FieldDescriptionProvider.java +++ b/src/main/java/ch/powerunit/extensions/matchers/provideprocessor/fields/FieldDescriptionProvider.java @@ -20,6 +20,7 @@ package ch.powerunit.extensions.matchers.provideprocessor.fields; import javax.annotation.processing.ProcessingEnvironment; +import javax.lang.model.element.Element; import javax.lang.model.element.ExecutableElement; import javax.lang.model.type.ArrayType; import javax.lang.model.type.DeclaredType; @@ -93,11 +94,12 @@ public Type visitUnknown(TypeMirror t, ProcessingEnvironment processingEnv) { public static AbstractFieldDescription of(ProvidesMatchersAnnotatedElementData containingElementMirror, FieldDescriptionMirror mirror) { + Element te = mirror.getFieldElement(); ProcessingEnvironment processingEnv = containingElementMirror.getRoundMirror().getProcessingEnv(); - Type type = new ExtracTypeVisitor().visit((mirror.getFieldElement() instanceof ExecutableElement) - ? ((ExecutableElement) mirror.getFieldElement()).getReturnType() : mirror.getFieldElement().asType(), + Type type = new ExtracTypeVisitor().visit( + (te instanceof ExecutableElement) ? ((ExecutableElement) te).getReturnType() : te.asType(), processingEnv); - if (mirror.getFieldElement().getAnnotation(IgnoreInMatcher.class) != null) { + if (te.getAnnotation(IgnoreInMatcher.class) != null) { return new IgoreFieldDescription(containingElementMirror, mirror); }