Skip to content

Commit

Permalink
split
Browse files Browse the repository at this point in the history
  • Loading branch information
boretti committed Apr 22, 2018
1 parent acfe729 commit 162b5e5
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 46 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/**
* 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 <http://www.gnu.org/licenses/>.
*/
package ch.powerunit.extensions.matchers.provideprocessor;

import java.util.Optional;

import javax.lang.model.element.TypeElement;

public abstract class ProvidesMatchersAnnotatedElementGeneralMirror
extends ProvidesMatchersAnnotatedElementGenericMirror {

protected final TypeElement typeElementForClassAnnotatedWithProvideMatcher;
protected final String methodShortClassName;
protected final Optional<String> fullyQualifiedNameOfSuperClassOfClassAnnotatedWithProvideMatcher;
protected final RoundMirror roundMirror;

public ProvidesMatchersAnnotatedElementGeneralMirror(TypeElement typeElement, RoundMirror roundMirror) {
super(typeElement, roundMirror);
this.roundMirror = roundMirror;
this.typeElementForClassAnnotatedWithProvideMatcher = typeElement;
this.methodShortClassName = simpleNameOfClassAnnotatedWithProvideMatcher.substring(0, 1).toLowerCase()
+ simpleNameOfClassAnnotatedWithProvideMatcher.substring(1);
if (!roundMirror.getProcessingEnv().getElementUtils().getTypeElement("java.lang.Object").asType()
.equals(typeElement.getSuperclass())) {
this.fullyQualifiedNameOfSuperClassOfClassAnnotatedWithProvideMatcher = Optional
.ofNullable(typeElement.getSuperclass().toString());
} else {
this.fullyQualifiedNameOfSuperClassOfClassAnnotatedWithProvideMatcher = Optional.empty();
}

}

public String getDefaultReturnMethod() {
return simpleNameOfClassAnnotatedWithProvideMatcher + "Matcher" + getGenericParent();
}

public TypeElement getTypeElementForClassAnnotatedWithProvideMatcher() {
return typeElementForClassAnnotatedWithProvideMatcher;
}

public String getMethodShortClassName() {
return methodShortClassName;
}

public String getSimpleNameOfGeneratedImplementationMatcher() {
return simpleNameOfClassAnnotatedWithProvideMatcher + "MatcherImpl";
}

public String getSimpleNameOfGeneratedImplementationMatcherWithGenericNoParent() {
return getSimpleNameOfGeneratedImplementationMatcher() + getGenericNoParent();
}

public String getSimpleNameOfGeneratedImplementationMatcherWithGenericParent() {
return getSimpleNameOfGeneratedImplementationMatcher() + getGenericParent();
}

public RoundMirror getRoundMirror() {
return roundMirror;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
import ch.powerunit.extensions.matchers.provideprocessor.fields.IgoreFieldDescription;

public abstract class ProvidesMatchersAnnotatedElementMatcherMirror
extends ProvidesMatchersAnnotatedElementGenericMirror {
extends ProvidesMatchersAnnotatedElementGeneralMirror {

private static final String PRIVATE_IMPLEMENTATION_END = "\n\n @Override\n public _PARENT end() {\n return _parentBuilder;\n }\n\n\n";

Expand All @@ -54,13 +54,9 @@ 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 * <p>\n * <i>This method, when used more than once, just add more matcher to the list.</i>\n * @param otherMatcher the matcher on the object itself.\n * @return the DSL to continue\n */\n";

public static final String DEFAULT_FEATUREMATCHER_FORCONVERTER = "\n private static <_TARGET,_SOURCE> org.hamcrest.Matcher<_SOURCE> asFeatureMatcher(String msg,java.util.function.Function<_SOURCE,_TARGET> converter,org.hamcrest.Matcher<? super _TARGET> matcher) {\n return new org.hamcrest.FeatureMatcher<_SOURCE,_TARGET>(matcher, msg, msg) {\n protected _TARGET featureValueOf(_SOURCE actual) {\n return converter.apply(actual);\n }};\n }\n\n";
private static final String DEFAULT_FEATUREMATCHER_FORCONVERTER = "\n private static <_TARGET,_SOURCE> org.hamcrest.Matcher<_SOURCE> asFeatureMatcher(String msg,java.util.function.Function<_SOURCE,_TARGET> converter,org.hamcrest.Matcher<? super _TARGET> matcher) {\n return new org.hamcrest.FeatureMatcher<_SOURCE,_TARGET>(matcher, msg, msg) {\n protected _TARGET featureValueOf(_SOURCE actual) {\n return converter.apply(actual);\n }};\n }\n\n";

protected final TypeElement typeElementForClassAnnotatedWithProvideMatcher;
protected final String methodShortClassName;
protected final Optional<String> fullyQualifiedNameOfSuperClassOfClassAnnotatedWithProvideMatcher;
protected final List<AbstractFieldDescription> fields;
protected final RoundMirror roundMirror;

private List<AbstractFieldDescription> generateFields(TypeElement typeElement,
ProvidesMatchersSubElementVisitor providesMatchersSubElementVisitor) {
Expand All @@ -78,18 +74,6 @@ private List<AbstractFieldDescription> generateFields(TypeElement typeElement,

public ProvidesMatchersAnnotatedElementMatcherMirror(TypeElement typeElement, RoundMirror roundMirror) {
super(typeElement, roundMirror);
this.roundMirror = roundMirror;
this.typeElementForClassAnnotatedWithProvideMatcher = typeElement;
this.methodShortClassName = simpleNameOfClassAnnotatedWithProvideMatcher.substring(0, 1).toLowerCase()
+ simpleNameOfClassAnnotatedWithProvideMatcher.substring(1);
if (!roundMirror.getProcessingEnv().getElementUtils().getTypeElement("java.lang.Object").asType()
.equals(typeElement.getSuperclass())) {
this.fullyQualifiedNameOfSuperClassOfClassAnnotatedWithProvideMatcher = Optional
.ofNullable(typeElement.getSuperclass().toString());
} else {
this.fullyQualifiedNameOfSuperClassOfClassAnnotatedWithProvideMatcher = Optional.empty();
}

this.fields = generateFields(typeElement, new ProvidesMatchersSubElementVisitor(roundMirror));
}

Expand Down Expand Up @@ -275,32 +259,4 @@ private String generatePrivateImplementationForAndWith() {
getFullyQualifiedNameOfClassAnnotatedWithProvideMatcherWithGeneric());
}

public String getDefaultReturnMethod() {
return simpleNameOfClassAnnotatedWithProvideMatcher + "Matcher" + getGenericParent();
}

public TypeElement getTypeElementForClassAnnotatedWithProvideMatcher() {
return typeElementForClassAnnotatedWithProvideMatcher;
}

public String getMethodShortClassName() {
return methodShortClassName;
}

public String getSimpleNameOfGeneratedImplementationMatcher() {
return simpleNameOfClassAnnotatedWithProvideMatcher + "MatcherImpl";
}

public String getSimpleNameOfGeneratedImplementationMatcherWithGenericNoParent() {
return getSimpleNameOfGeneratedImplementationMatcher() + getGenericNoParent();
}

public String getSimpleNameOfGeneratedImplementationMatcherWithGenericParent() {
return getSimpleNameOfGeneratedImplementationMatcher() + getGenericParent();
}

public RoundMirror getRoundMirror() {
return roundMirror;
}

}

0 comments on commit 162b5e5

Please sign in to comment.