Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/**
* Powerunit - A JDK1.8 test framework
* Copyright (C) 2014 Mathieu Boretti.
*
* This file is part of Powerunit
*
* Powerunit is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Powerunit is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Powerunit. If not, see .
*/
package ch.powerunit.extensions.matchers.provideprocessor;
import static ch.powerunit.extensions.matchers.common.CommonUtils.addPrefix;
import static java.util.stream.Collectors.joining;
import java.util.Arrays;
import java.util.Optional;
import javax.lang.model.element.TypeElement;
import ch.powerunit.extensions.matchers.provideprocessor.fields.AbstractFieldDescription;
public abstract class ProvidesMatchersAnnotatedElementMatcherMirror
extends ProvidesMatchersAnnotatedElementFieldMatcherMirror {
private static final String PRIVATE_IMPLEMENTATION_END = "\n\n @Override\n public _PARENT end() {\n return _parentBuilder;\n }\n\n\n";
private static final String NEXTMATCHERS_DESCRIBETO = " for(org.hamcrest.Matcher nMatcher : nextMatchers) {\n description.appendText(\"[object itself \").appendDescriptionOf(nMatcher).appendText(\"]\\n\");\n }\n }\n";
private static final String PARENT_DESCRIBETO = " description.appendText(\"[\").appendDescriptionOf(_parent).appendText(\"]\\n\");\n";
private static final String PARENT_VALIDATION = " if(!_parent.matches(actual)) {\n mismatchDescription.appendText(\"[\"); _parent.describeMismatch(actual,mismatchDescription); mismatchDescription.appendText(\"]\\n\");\n result=false;\n }\n";
private static final String NEXTMATCHERS_VALIDATION = " for(org.hamcrest.Matcher nMatcher : nextMatchers) {\n if(!nMatcher.matches(actual)) {\n mismatchDescription.appendText(\"[object itself \"); nMatcher.describeMismatch(actual,mismatchDescription); mismatchDescription.appendText(\"]\\n\");\n result=false;\n }\n }\n return result;\n }\n\n";
private static final String JAVADOC_ANDWITHAS = " /**\n * Add a matcher on the object itself and not on a specific field, but convert the object before passing it to the matcher.\n *
\n * This method, when used more than once, just add more matcher to the list.\n * @param converter the function to convert the object.\n * @param otherMatcher the matcher on the converter object itself.\n * @param <_TARGETOBJECT> the type of the target object\n * @return the DSL to continue\n */\n";
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() {
return new StringBuilder().append(generateMainBuildPublicInterface())
.append(generateMainParentPublicInterface()).append(generateExposedPublicInterface()).toString();
}
private String generateExposedPublicInterface() {
return new StringBuilder(addPrefix(" ",
generateDefaultJavaDoc(Optional.empty(), Optional.empty(), Optional.empty(), true, true))).append("\n")
.append(" public static interface ").append(simpleNameOfGeneratedInterfaceMatcher)
.append(getFullGenericParent()).append(" extends org.hamcrest.Matcher<")
.append(getFullyQualifiedNameOfClassAnnotatedWithProvideMatcherWithGeneric()).append(">,")
.append(simpleNameOfGeneratedInterfaceMatcher).append("BuildSyntaxicSugar ").append(generic)
.append(",").append(simpleNameOfGeneratedInterfaceMatcher).append("EndSyntaxicSugar ")
.append(getGenericParent()).append(" {\n")
.append(fields.stream().map(AbstractFieldDescription::getDslInterface)
.map(s -> addPrefix(" ", s)).collect(joining("\n")))
.append("\n\n").append(generateAsPublicInterface()).append(" }\n").toString();
}
private String generateAsPublicInterface() {
String fully = getFullyQualifiedNameOfClassAnnotatedWithProvideMatcherWithGeneric();
String otherMatcher = "org.hamcrest.Matcher super " + fully + "> otherMatcher";
String interfaceWithGeneric = getSimpleNameOfGeneratedInterfaceMatcherWithGenericParent();
StringBuilder sb = new StringBuilder(JAVADOC_ANDWITH).append(" ").append(interfaceWithGeneric)
.append(" andWith(").append(otherMatcher).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 super _TARGETOBJECT> otherMatcher) {\n return andWith(asFeatureMatcher(\"