From a42200bdfcb6c340fc5c482d7a0bb1f2b634417c Mon Sep 17 00:00:00 2001 From: boretti Date: Sun, 22 Apr 2018 17:21:52 +0200 Subject: [PATCH] quality --- ...MatchersAnnotatedElementMatcherMirror.java | 42 +++++++++---------- 1 file changed, 20 insertions(+), 22 deletions(-) diff --git a/src/main/java/ch/powerunit/extensions/matchers/provideprocessor/ProvidesMatchersAnnotatedElementMatcherMirror.java b/src/main/java/ch/powerunit/extensions/matchers/provideprocessor/ProvidesMatchersAnnotatedElementMatcherMirror.java index c10ef488d..0eda367ee 100644 --- a/src/main/java/ch/powerunit/extensions/matchers/provideprocessor/ProvidesMatchersAnnotatedElementMatcherMirror.java +++ b/src/main/java/ch/powerunit/extensions/matchers/provideprocessor/ProvidesMatchersAnnotatedElementMatcherMirror.java @@ -46,8 +46,11 @@ public abstract class ProvidesMatchersAnnotatedElementMatcherMirror private static final String JAVADOC_ANDWITH = " /**\n * Add a matcher on the object itself and not on a specific field.\n *

\n * This method, when used more than once, just add more matcher to the list.\n * @param otherMatcher the matcher on the object itself.\n * @return the DSL to continue\n */\n"; + private final String dslInterfaceDescription; + public ProvidesMatchersAnnotatedElementMatcherMirror(TypeElement typeElement, RoundMirror roundMirror) { super(typeElement, roundMirror); + this.dslInterfaceDescription = "DSL interface for matcher on " + getDefaultLinkForAnnotatedClass(); } public String generatePublicInterface() { @@ -70,10 +73,6 @@ private String generateExposedPublicInterface() { .append("\n\n").append(generateAsPublicInterface()).append(" }\n").toString(); } - private String getDslInterfaceMatcherDescription() { - return "DSL interface for matcher on " + getDefaultLinkForAnnotatedClass(); - } - private String generateAsPublicInterface() { String fully = getFullyQualifiedNameOfClassAnnotatedWithProvideMatcherWithGeneric(); String otherMatcher = "org.hamcrest.Matcher otherMatcher"; @@ -82,34 +81,34 @@ private String generateAsPublicInterface() { StringBuilder sb = new StringBuilder(JAVADOC_ANDWITH).append(" ").append(interfaceWithGeneric) .append(" andWith(").append(otherMatcher).append(");\n\n"); - sb.append(JAVADOC_ANDWITHAS).append(" default <_TARGETOBJECT> ").append(interfaceWithGeneric) - .append(" andWithAs(java.util.function.Function<").append(fully) - .append(",_TARGETOBJECT> converter,org.hamcrest.Matcher otherMatcher) {\n") - .append(" return andWith(asFeatureMatcher(\" \",converter,otherMatcher));\n") - .append(" }\n\n"); + sb.append(JAVADOC_ANDWITHAS) + .append(String.format( + " default <_TARGETOBJECT> %1$s andWithAs(java.util.function.Function<%2$s,_TARGETOBJECT> converter,org.hamcrest.Matcher otherMatcher) {\n return andWith(asFeatureMatcher(\" \",converter,otherMatcher));\n }\n\n", + interfaceWithGeneric, fully)); sb.append(addPrefix(" ", generateJavaDocWithoutParamNeitherParent( "Method that return the matcher itself and accept one single Matcher on the object itself.", JAVADOC_WARNING_SYNTAXIC_SUGAR_NO_CHANGE_ANYMORE, Optional.of("otherMatcher the matcher on the object itself."), Optional.of("the matcher")))) - .append("\n").append(" default org.hamcrest.Matcher<").append(fully).append("> buildWith(") - .append(otherMatcher).append(") {\n return andWith(otherMatcher);\n }\n\n"); + .append(String.format( + "\n default org.hamcrest.Matcher<%1$s> buildWith(%2$s) {\n return andWith(otherMatcher);\n }\n\n", + fully, otherMatcher)); sb.append(addPrefix(" ", generateJavaDocWithoutParamNeitherParent( "Method that return the parent builder and accept one single Matcher on the object itself.", JAVADOC_WARNING_PARENT_MAY_BE_VOID, Optional.of("otherMatcher the matcher on the object itself."), - Optional.of("the parent builder or null if not applicable")))).append(" default _PARENT endWith(") - .append(otherMatcher).append("){\n return andWith(otherMatcher).end();\n }\n"); + Optional.of("the parent builder or null if not applicable")))) + .append(String.format( + " default _PARENT endWith(%1$s){\n return andWith(otherMatcher).end();\n }\n", + otherMatcher)); return sb.toString(); } private String generateMainParentPublicInterface() { StringBuilder sb = new StringBuilder(); - sb.append(addPrefix(" ", - generateJavaDoc(getDslInterfaceMatcherDescription() + " to support the end syntaxic sugar", - Optional.empty(), Optional.empty(), Optional.empty(), true, true))) - .append("\n"); + sb.append(addPrefix(" ", generateJavaDoc(dslInterfaceDescription + " to support the end syntaxic sugar", + Optional.empty(), Optional.empty(), Optional.empty(), true, true))).append("\n"); sb.append(" public static interface " + simpleNameOfGeneratedInterfaceMatcher + "EndSyntaxicSugar" + getFullGenericParent() + " extends org.hamcrest.Matcher<" + getFullyQualifiedNameOfClassAnnotatedWithProvideMatcherWithGeneric() + "> {\n"); @@ -124,11 +123,10 @@ private String generateMainParentPublicInterface() { private String generateMainBuildPublicInterface() { String fullyWithGeneric = getFullyQualifiedNameOfClassAnnotatedWithProvideMatcherWithGeneric(); return new StringBuilder(addPrefix(" ", - generateJavaDoc(getDslInterfaceMatcherDescription() + " to support the build syntaxic sugar", - Optional.empty(), Optional.empty(), Optional.empty(), true, false))) - .append("\n public static interface ").append(simpleNameOfGeneratedInterfaceMatcher) - .append("BuildSyntaxicSugar").append(fullGeneric) - .append(" extends org.hamcrest.Matcher<") + generateJavaDoc(dslInterfaceDescription + " to support the build syntaxic sugar", Optional.empty(), + Optional.empty(), Optional.empty(), true, false))).append("\n public static interface ") + .append(simpleNameOfGeneratedInterfaceMatcher).append("BuildSyntaxicSugar") + .append(fullGeneric).append(" extends org.hamcrest.Matcher<") .append(fullyWithGeneric).append( "> {\n") .append(addPrefix(" ",