Showing 4 of 31 files from the diff.
Other files ignored by Codecov

@@ -19,6 +19,9 @@
Loading
19 19
 */
20 20
package ch.powerunit.extensions.matchers.provideprocessor;
21 21
22 +
import static ch.powerunit.extensions.matchers.common.CommonUtils.addPrefix;
23 +
import static java.util.Arrays.asList;
24 +
import static java.util.Collections.unmodifiableList;
22 25
import static java.util.stream.Collectors.joining;
23 26
import static java.util.stream.Collectors.toList;
24 27
import static java.util.stream.Collectors.toMap;
@@ -29,6 +32,7 @@
Loading
29 32
import java.util.List;
30 33
import java.util.Optional;
31 34
import java.util.Set;
35 +
import java.util.stream.Stream;
32 36
33 37
import javax.annotation.processing.AbstractProcessor;
34 38
import javax.annotation.processing.ProcessingEnvironment;
@@ -44,6 +48,7 @@
Loading
44 48
import ch.powerunit.extensions.matchers.common.CommonUtils;
45 49
import ch.powerunit.extensions.matchers.common.FactoryHelper;
46 50
import ch.powerunit.extensions.matchers.common.FileObjectHelper;
51 +
import ch.powerunit.extensions.matchers.common.RessourceLoaderHelper;
47 52
48 53
/**
49 54
 * @author borettim
@@ -62,6 +67,10 @@
Loading
62 67
63 68
	private List<Element> allSourceElements = new ArrayList<>();
64 69
70 +
	private static final List<String> POSTPROCESSOR_FORMAT = unmodifiableList(asList(addPrefix("  ",
71 +
			RessourceLoaderHelper.loadRessource(ProvidesMatchersAnnotatedElementMirror.class, "PostProcessor.txt"))
72 +
					.split("\n")));
73 +
65 74
	@Override
66 75
	public synchronized void init(ProcessingEnvironment processingEnv) {
67 76
		super.init(processingEnv);
@@ -106,7 +115,7 @@
Loading
106 115
				jfo -> new PrintWriter(jfo.openWriter()),
107 116
				wjfo -> FactoryHelper.generateFactoryClass(wjfo, ProvidesMatchersAnnotationsProcessor.class,
108 117
						factory.replaceAll("\\.[^.]+$", ""), factory.replaceAll("^([^.]+\\.)*", ""),
109 -
						() -> factories.stream()),
118 +
						() -> Stream.concat(factories.stream(), POSTPROCESSOR_FORMAT.stream())),
110 119
				e -> processingEnv.getMessager().printMessage(Kind.ERROR,
111 120
						"Unable to create the file containing the target class `" + factory + "`, because of "
112 121
								+ e.getMessage()));

@@ -31,7 +31,8 @@
Loading
31 31
	default long getCompatibility() {
32 32
		// 0x01 : withSameValue also provides a version to ignore fields
33 33
		// 0x02 : withSameValue also use a list of parent to detect cycle
34 -
		return 0x03;
34 +
		// 0x04 : withSameValue also support a post processor
35 +
		return 0x07;
35 36
	}
36 37
37 38
	default String getMethodNameDSLWithSameValue() {
@@ -53,6 +54,10 @@
Loading
53 54
	default boolean supportCycleDetectionV1() {
54 55
		return (getCompatibility() & 0x02) == 0x02;
55 56
	}
57 +
	
58 +
	default boolean supportSameValueWithParentPostPrecessor() {
59 +
		return (getCompatibility() & 0x04) == 0x04;
60 +
	}
56 61
57 62
	static Matchable of(String fullName, String methodName, String interfaceName, boolean hasWithSameValue,
58 63
			long compatibility) {

@@ -56,6 +56,9 @@
Loading
56 56
	private static final String MATCHER_FORMAT = RessourceLoaderHelper
57 57
			.loadRessource(ProvidesMatchersAnnotatedElementMirror.class, "Matchers.txt");
58 58
59 +
	private static final String POSTPROCESSOR_FORMAT = addPrefix("  ",
60 +
			RessourceLoaderHelper.loadRessource(ProvidesMatchersAnnotatedElementMirror.class, "PostProcessor.txt"));
61 +
59 62
	private static final ListJoining<DSLMethod> JOIN_DSL_METHOD = ListJoining
60 63
			.joinWithMapperAndDelimiter(m -> addPrefix("  ", m.asStaticImplementation()), "\n");
61 64
@@ -65,9 +68,9 @@
Loading
65 68
66 69
	public ProvidesMatchersAnnotatedElementMirror(TypeElement typeElement, RoundMirror roundMirror) {
67 70
		super(typeElement, roundMirror);
68 -
		List<Supplier<Collection<DSLMethod>>> tmp = new ArrayList<>(
69 -
				Arrays.asList(asCollection(this::generateDefaultDSLStarter),
70 -
						asCollection(this::generateDefaultForChainingDSLStarter)));
71 +
		List<Supplier<Collection<DSLMethod>>> tmp = new ArrayList<>(Arrays.asList(
72 +
				asCollection(this::generateDefaultDSLStarter), asCollection(this::generateDefaultForChainingDSLStarter),
73 +
				asCollection(this::generateMatcherClassMethod)));
71 74
		if (hasSuperClass()) {
72 75
			tmp.add(asCollection(this::generateParentDSLStarter));
73 76
			tmp.add(() -> ProvidesMatchersWithSameValueHelper.generateParentValueDSLStarter(this));
@@ -96,7 +99,8 @@
Loading
96 99
							getFullyQualifiedNameOfClassAnnotated(),
97 100
							generateGeneratedAnnotation(ProvidesMatchersAnnotationsProcessor.class, comments()),
98 101
							getSimpleNameOfGeneratedClass(), generateMatchers(), generatePublicInterface(),
99 -
							generatePrivateImplementation(), JOIN_DSL_METHOD.asString(tmp), generateMetadata());
102 +
							generatePrivateImplementation(), JOIN_DSL_METHOD.asString(tmp), POSTPROCESSOR_FORMAT,
103 +
							generateMetadata());
100 104
					output.flush();
101 105
					return tmp;
102 106
				}, e -> traceErrorAndDump(this, e, te));
@@ -177,4 +181,13 @@
Loading
177 181
		}).orElse(null);
178 182
	}
179 183
184 +
	public DSLMethod generateMatcherClassMethod() {
185 +
		return of(getFullGenericParent()+" Class<" + getFullyQualifiedNameOfGeneratedClass() + "."
186 +
				+ getSimpleNameOfGeneratedInterfaceMatcherWithGenericParent() + "> "
187 +
				+ getMethodShortClassName() + "MatcherClass").withoutArgument()
188 +
						.withImplementation("return (Class)" + getSimpleNameOfGeneratedInterfaceMatcher() + ".class;")
189 +
						.withJavadoc(
190 +
								"/**\n * Helper method to retrieve the Class of the matcher interface.\n * @return the class.\n */\n");
191 +
	}
192 +
180 193
}

@@ -1,11 +1,11 @@
Loading
1 1
package ch.powerunit.extensions.matchers.provideprocessor.helper;
2 2
3 3
import static ch.powerunit.extensions.matchers.common.CommonUtils.addPrefix;
4 -
import static ch.powerunit.extensions.matchers.provideprocessor.dsl.DSLMethod.of;
5 4
import static java.lang.String.format;
6 5
import static java.util.Arrays.asList;
7 6
import static java.util.Arrays.stream;
8 7
import static java.util.Collections.emptyList;
8 +
import static java.util.Optional.of;
9 9
import static java.util.stream.Collectors.joining;
10 10
11 11
import java.util.Collection;
@@ -20,6 +20,7 @@
Loading
20 20
import ch.powerunit.extensions.matchers.provideprocessor.Matchable;
21 21
import ch.powerunit.extensions.matchers.provideprocessor.ProvidesMatchersAnnotatedElementMirror;
22 22
import ch.powerunit.extensions.matchers.provideprocessor.dsl.DSLMethod;
23 +
import ch.powerunit.extensions.matchers.provideprocessor.dsl.lang.DSLMethodArgument;
23 24
import ch.powerunit.extensions.matchers.provideprocessor.fields.AbstractFieldDescription;
24 25
25 26
public final class ProvidesMatchersWithSameValueHelper {
@@ -33,35 +34,46 @@
Loading
33 34
34 35
	private static final String JAVADOC_IGNORE = "ignoredFields fields name that must be ignored.";
35 36
37 +
	private static final String JAVADOC_POSTPROCESSOR = "postProcessor Function to be applied to modify, if necessary, the matchers.";
38 +
36 39
	private static final String JAVADOC_OTHER_IGNORE = JAVADOC_OTHER + "\n" + JAVADOC_IGNORE;
37 40
38 -
	private static final String JAVADOC_OTHER_PREVIOUS_IGNORE = JAVADOC_OTHER + "\n" + JAVDOC_PREVIOUS + "\n"
39 -
			+ JAVADOC_IGNORE;
41 +
	private static final String JAVADOC_OTHER_IGNORE_POSTPROCESSOR = JAVADOC_OTHER + "\n" + JAVADOC_IGNORE + "\n"
42 +
			+ JAVADOC_POSTPROCESSOR;
43 +
44 +
	private static final String JAVADOC_OTHER_PREVIOUS_IGNORE_POST = JAVADOC_OTHER + "\n" + JAVDOC_PREVIOUS + "\n"
45 +
			+ JAVADOC_IGNORE + "\n" + JAVADOC_POSTPROCESSOR;
40 46
41 47
	private ProvidesMatchersWithSameValueHelper() {
42 48
	}
43 49
44 50
	private static DSLMethod generateWithSameValueWithParentMatcherIgnoreAndCycle(
45 51
			ProvidesMatchersAnnotatedElementMirror target, boolean hasSuper) {
46 -
		return of(generateHasSameValueDeclaration(target))
52 +
		return generateHasSameValueDeclaration(target)
47 53
				.addOneArgument(target.getFullyQualifiedNameOfClassAnnotatedWithProvideMatcherWithGeneric(), "other")
48 54
				.addOneArgument("java.util.Set<java.lang.Object>", "previous")
55 +
				.addOneArgument(
56 +
						"java.util.function.BiFunction<org.hamcrest.Matcher<?>,java.lang.Object,org.hamcrest.Matcher<?>>",
57 +
						"postProcessor")
49 58
				.addOneArgument("String...", "ignoredFields")
50 59
				.withImplementation(asList(format(HAS_SAME_VALUE_IGNORE_CYCLE,
51 60
						target.getSimpleNameOfGeneratedInterfaceMatcherWithGenericNoParent(),
52 61
						target.getSimpleNameOfGeneratedImplementationMatcherWithGenericNoParent(),
53 -
						generateParentMatcher(target, hasSuper), copyFields(target)).split("\n")))
54 -
				.withJavadoc(target.generateDefaultJavaDocWithoutDSLStarter(Optional.of(JAVADOC_OTHER_PREVIOUS_IGNORE),
62 +
						generateParentMatcher(target, hasSuper), copyFields(target),
63 +
						target.getSimpleNameOfGeneratedInterfaceMatcher()).split("\n")))
64 +
				.withJavadoc(target.generateDefaultJavaDocWithoutDSLStarter(of(JAVADOC_OTHER_PREVIOUS_IGNORE_POST),
55 65
						"the DSL matcher", false));
56 66
	}
57 67
58 68
	private static String generateParentMatcher(ProvidesMatchersAnnotatedElementMirror target, boolean hasSuper) {
59 -
		return hasSuper
60 -
				? (target.getParentMirror()
61 -
						.map(p -> p.getWithSameValue(false) + "(other" + (p.supportIgnore() ? ",ignoredFields" : "")
62 -
								+ ")")
63 -
						.orElse("org.hamcrest.Matchers.anything()"))
64 -
				: "";
69 +
		return hasSuper ? (target.getParentMirror()
70 +
				.map(p -> "(" + p.getFullyQualifiedNameOfGeneratedClass() + "."
71 +
						+ p.getSimpleNameOfGeneratedInterfaceMatcher()
72 +
						+ ")java.util.Objects.requireNonNull(postProcessor,\"postProcessor can't be null\").apply("
73 +
						+ p.getWithSameValue(false) + "(other"
74 +
						+ (p.supportSameValueWithParentPostPrecessor() ? ",postProcessor" : "")
75 +
						+ (p.supportIgnore() ? ",ignoredFields" : "") + "),other)")
76 +
				.orElse("org.hamcrest.Matchers.anything()")) : "";
65 77
	}
66 78
67 79
	private static String copyFields(ProvidesMatchersAnnotatedElementMirror target) {
@@ -69,29 +81,43 @@
Loading
69 81
	}
70 82
71 83
	private static String copyField(AbstractFieldDescription f) {
72 -
		String args = f.getTargetAsMatchable().filter(Matchable::supportCycleDetectionV1)
73 -
				.map(x -> ",nPrevious,localIgnored").orElse(",localIgnored");
84 +
		String args = f
85 +
				.getTargetAsMatchable().filter(Matchable::supportCycleDetectionV1).map(x -> ",nPrevious"
86 +
						+ (x.supportSameValueWithParentPostPrecessor() ? ",postProcessor" : "") + ",localIgnored")
87 +
				.orElse(",localIgnored");
74 88
		return format(
75 89
				"if(!ignored.contains(\"%1$s\")) {\n  String localIgnored[] = ignored.stream().filter(s->s.startsWith(\"%1$s.\")).map(s->s.replaceFirst(\"%1$s\\\\.\",\"\")).toArray(String[]::new);\n%2$s\n}",
76 90
				f.getFieldName(), addPrefix("  ", f.getFieldCopy("m", "other", args)));
77 91
	}
78 92
79 -
	private static DSLMethod generateWithSameValueWithParentMatcherIgnore(
93 +
	private static DSLMethod generateWithSameValueWithParentMatcherIgnoreAndPostProcessor(
80 94
			ProvidesMatchersAnnotatedElementMirror target) {
81 -
		return of(generateHasSameValueDeclaration(target))
95 +
		return generateHasSameValueDeclaration(target)
82 96
				.addOneArgument(target.getFullyQualifiedNameOfClassAnnotatedWithProvideMatcherWithGeneric(), "other")
97 +
				.addOneArgument(
98 +
						"java.util.function.BiFunction<org.hamcrest.Matcher<?>,java.lang.Object,org.hamcrest.Matcher<?>>",
99 +
						"postProcessor")
83 100
				.addOneArgument("String...", "ignoredFields")
84 -
				.withImplementation(generateReturnOther(target, "ignoredFields"))
85 -
				.withJavadoc(target.generateDefaultJavaDocWithoutDSLStarter(Optional.of(JAVADOC_OTHER_IGNORE),
101 +
				.withImplementation(generateReturnOther(target, "postProcessor,ignoredFields"))
102 +
				.withJavadoc(target.generateDefaultJavaDocWithoutDSLStarter(of(JAVADOC_OTHER_IGNORE_POSTPROCESSOR),
86 103
						"the DSL matcher", false));
87 104
	}
88 105
106 +
	private static DSLMethod generateWithSameValueWithParentMatcherIgnore(
107 +
			ProvidesMatchersAnnotatedElementMirror target) {
108 +
		return generateHasSameValueDeclaration(target)
109 +
				.addOneArgument(target.getFullyQualifiedNameOfClassAnnotatedWithProvideMatcherWithGeneric(), "other")
110 +
				.addOneArgument("String...", "ignoredFields")
111 +
				.withImplementation(generateReturnOther(target, "(m,o)->m,ignoredFields")).withJavadoc(target
112 +
						.generateDefaultJavaDocWithoutDSLStarter(of(JAVADOC_OTHER_IGNORE), "the DSL matcher", false));
113 +
	}
114 +
89 115
	private static DSLMethod generateWithSameValueWithParentMatcherAndNoIgnore(
90 116
			ProvidesMatchersAnnotatedElementMirror target) {
91 -
		return of(generateHasSameValueDeclaration(target))
117 +
		return generateHasSameValueDeclaration(target)
92 118
				.withOneArgument(target.getFullyQualifiedNameOfClassAnnotatedWithProvideMatcherWithGeneric(), "other")
93 -
				.withImplementation(generateReturnOther(target, "new String[]{}")).withJavadoc(target
94 -
						.generateDefaultJavaDocWithoutDSLStarter(Optional.of(JAVADOC_OTHER), "the DSL matcher", false));
119 +
				.withImplementation(generateReturnOther(target, "(m,o)->m,new String[]{}")).withJavadoc(
120 +
						target.generateDefaultJavaDocWithoutDSLStarter(of(JAVADOC_OTHER), "the DSL matcher", false));
95 121
	}
96 122
97 123
	private static String generateReturnOther(ProvidesMatchersAnnotatedElementMirror target, String complement) {
@@ -99,10 +125,11 @@
Loading
99 125
				target.getMethodNameDSLWithSameValue(), complement);
100 126
	}
101 127
102 -
	private static String generateHasSameValueDeclaration(ProvidesMatchersAnnotatedElementMirror target) {
103 -
		return format("%1$s %2$s.%3$s %4$s", target.getFullGeneric(), target.getFullyQualifiedNameOfGeneratedClass(),
104 -
				target.getSimpleNameOfGeneratedInterfaceMatcherWithGenericNoParent(),
105 -
				target.getMethodNameDSLWithSameValue());
128 +
	private static DSLMethodArgument generateHasSameValueDeclaration(ProvidesMatchersAnnotatedElementMirror target) {
129 +
		return DSLMethod.of(
130 +
				format("%1$s %2$s.%3$s %4$s", target.getFullGeneric(), target.getFullyQualifiedNameOfGeneratedClass(),
131 +
						target.getSimpleNameOfGeneratedInterfaceMatcherWithGenericNoParent(),
132 +
						target.getMethodNameDSLWithSameValue()));
106 133
	}
107 134
108 135
	private static boolean isWeakAllowed(ProvidesMatchersAnnotatedElementMirror target) {
@@ -122,12 +149,14 @@
Loading
122 149
	public static Collection<DSLMethod> generateParentValueDSLStarter(ProvidesMatchersAnnotatedElementMirror target) {
123 150
		return target.getParentMirror()
124 151
				.map(parentMirror -> asList(generateWithSameValueWithParentMatcherIgnoreAndCycle(target, true),
152 +
						generateWithSameValueWithParentMatcherIgnoreAndPostProcessor(target),
125 153
						generateWithSameValueWithParentMatcherIgnore(target),
126 154
						generateWithSameValueWithParentMatcherAndNoIgnore(target)))
127 155
				.orElseGet(() -> {
128 156
					if (isWeakAllowed(target)) {
129 157
						logWeak(target);
130 158
						return asList(generateWithSameValueWithParentMatcherIgnoreAndCycle(target, true),
159 +
								generateWithSameValueWithParentMatcherIgnoreAndPostProcessor(target),
131 160
								generateWithSameValueWithParentMatcherIgnore(target),
132 161
								generateWithSameValueWithParentMatcherAndNoIgnore(target));
133 162
					} else {
@@ -138,6 +167,7 @@
Loading
138 167
139 168
	public static Collection<DSLMethod> generateNoParentValueDSLStarter(ProvidesMatchersAnnotatedElementMirror target) {
140 169
		return asList(generateWithSameValueWithParentMatcherIgnoreAndCycle(target, false),
170 +
				generateWithSameValueWithParentMatcherIgnoreAndPostProcessor(target),
141 171
				generateWithSameValueWithParentMatcherIgnore(target),
142 172
				generateWithSameValueWithParentMatcherAndNoIgnore(target));
143 173
	}
Files Coverage
src/main/java/ch/powerunit/extensions/matchers 99.27%
Project Totals (81 files) 99.27%
2301.3
openjdk10=
TRAVIS_OS_NAME=linux
linuxopenjdk10
2301.1
TRAVIS_OS_NAME=linux
oraclejdk9=
linuxoraclejdk9
2301.2
TRAVIS_OS_NAME=linux
openjdk8=
linuxopenjdk8

No yaml found.

Create your codecov.yml to customize your Codecov experience

Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading