Skip to content

Commit

Permalink
quality
Browse files Browse the repository at this point in the history
  • Loading branch information
boretti committed Apr 22, 2018
1 parent 8fa7df3 commit 426033b
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public String getSeeValue() {

public String getParam() {
String param = element.getParameters().stream()
.map((ve) -> ve.asType().toString() + " " + ve.getSimpleName().toString()).collect(joining(","));
.map(ve -> ve.asType().toString() + " " + ve.getSimpleName().toString()).collect(joining(","));
return element.isVarArgs() ? param.replaceAll(VAR_ARG_REGEX, "...") : param;
}

Expand All @@ -96,7 +96,7 @@ private String getGeneric() {
if (!element.getTypeParameters().isEmpty()) {
return new StringBuilder("<")
.append(element.getTypeParameters().stream()
.map((ve) -> ve.getSimpleName().toString()
.map(ve -> ve.getSimpleName().toString()
+ (ve.getBounds().isEmpty() ? ""
: (" extends " + ve.getBounds().stream().map(Object::toString)
.collect(joining("&")))))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import java.util.Optional;
import java.util.function.Supplier;

import javax.lang.model.element.Element;
import javax.lang.model.element.TypeElement;
import javax.tools.Diagnostic.Kind;

Expand Down Expand Up @@ -70,10 +71,11 @@ public ProvidesMatchersAnnotatedElementMirror(TypeElement typeElement, RoundMirr
}

public Collection<DSLMethod> process() {
RoundMirror rm = roundMirror;
Element te = typeElementForClassAnnotatedWithProvideMatcher;
Collection<DSLMethod> results = new ArrayList<>();
FileObjectHelper.processFileWithIOException(
() -> roundMirror.getProcessingEnv().getFiler().createSourceFile(
getFullyQualifiedNameOfGeneratedClass(), typeElementForClassAnnotatedWithProvideMatcher),
() -> rm.getProcessingEnv().getFiler().createSourceFile(getFullyQualifiedNameOfGeneratedClass(), te),
jfo -> new PrintWriter(jfo.openWriter()), wjfo -> {
wjfo.println("package " + getPackageNameOfGeneratedClass() + ";");
wjfo.println();
Expand All @@ -96,10 +98,8 @@ public Collection<DSLMethod> process() {
tmp.stream().map(m -> addPrefix(" ", m.asStaticImplementation())).forEach(wjfo::println);
wjfo.println("}");
results.addAll(tmp);
} ,
e -> roundMirror.getProcessingEnv().getMessager().printMessage(Kind.ERROR,
"Unable to create the file containing the target class because of " + e,
typeElementForClassAnnotatedWithProvideMatcher));
} , e -> rm.getProcessingEnv().getMessager().printMessage(Kind.ERROR,
"Unable to create the file containing the target class because of " + e, te));
return results;
}

Expand Down Expand Up @@ -154,16 +154,17 @@ public DSLMethod generateDefaultForChainingDSLStarter() {

public DSLMethod generateParentDSLStarter() {
String mscn = methodShortClassName;
String fqngc = getFullyQualifiedNameOfGeneratedClass();
return new DSLMethod(
generateDefaultJavaDoc(Optional.empty(), Optional.of("matcherOnParent the matcher on the parent data."),
Optional.of("the DSL matcher"), true, false),
fullGeneric + " " + getFullyQualifiedNameOfGeneratedClass() + "."
+ getSimpleNameOfGeneratedInterfaceMatcherWithGenericNoParent() + " " + mscn + "With",
fullGeneric + " " + fqngc + "." + getSimpleNameOfGeneratedInterfaceMatcherWithGenericNoParent() + " "
+ mscn + "With",
new String[] {
"org.hamcrest.Matcher<? super "
+ fullyQualifiedNameOfSuperClassOfClassAnnotatedWithProvideMatcher.get() + ">",
"matcherOnParent" },
"return " + getFullyQualifiedNameOfGeneratedClass() + "." + mscn + "With(matcherOnParent);");
"matcherOnParent" },
"return " + fqngc + "." + mscn + "With(matcherOnParent);");
}

public DSLMethod generatParentValueDSLStarter(String argumentForParentBuilder) {
Expand Down Expand Up @@ -204,16 +205,14 @@ public DSLMethod generateParentValueDSLStarter() {
public DSLMethod generateParentInSameRoundWithChaningDSLStarter() {
String implGenericNoParent = getSimpleNameOfGeneratedImplementationMatcherWithGenericNoParent();
ProvidesMatchersAnnotatedElementMirror parentMirror = getParentMirror();
String pmfqngc = parentMirror.getFullyQualifiedNameOfGeneratedClass();
return new DSLMethod(
generateDefaultJavaDoc(Optional.empty(), Optional.empty(), Optional.of("the DSL matcher"), true, false),
fullGeneric + " " + parentMirror.getFullyQualifiedNameOfGeneratedClass() + "."
+ parentMirror.simpleNameOfGeneratedInterfaceMatcher + genericForChaining + " "
+ methodShortClassName + "WithParent",
fullGeneric + " " + pmfqngc + "." + parentMirror.simpleNameOfGeneratedInterfaceMatcher
+ genericForChaining + " " + methodShortClassName + "WithParent",
new String[] {
implGenericNoParent + " m=new " + implGenericNoParent + "(org.hamcrest.Matchers.anything());",
parentMirror.getFullyQualifiedNameOfGeneratedClass() + "."
+ parentMirror.simpleNameOfGeneratedInterfaceMatcher + " tmp = "
+ parentMirror.getFullyQualifiedNameOfGeneratedClass() + "."
pmfqngc + "." + parentMirror.simpleNameOfGeneratedInterfaceMatcher + " tmp = " + pmfqngc + "."
+ parentMirror.methodShortClassName + "WithParent(m);",
"m._parent = new SuperClassMatcher(tmp);", "return tmp;" });
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,30 +58,31 @@ public List<FieldDSLMethod> getFieldDslMethodForIterableAndComparable() {
}

public List<FieldDSLMethod> getDslForIterableWithGeneric() {
String tgeneric = this.generic;
return Arrays.asList(
getDslMethodBuilder().withDeclaration("Contains", this.generic + "... elements")
getDslMethodBuilder().withDeclaration("Contains", tgeneric + "... elements")
.withJavaDoc("that the iterable contains the received elements", "elements the elements",
MATCHERS + "#contains(java.lang.Object[])")
.havingDefault(MATCHERS + ".contains(elements)"),
.havingDefault(MATCHERS + ".contains(elements)"),
getDslMethodBuilder()
.withDeclaration("Contains", "org.hamcrest.Matcher<" + this.generic + ">... matchersOnElements")
.withDeclaration("Contains", "org.hamcrest.Matcher<" + tgeneric + ">... matchersOnElements")
.withJavaDoc("that the iterable contains the received elements, using matchers",
DEFAULT_JAVADOC_MATCHER_ON_ELEMENTS, MATCHERS + "#contains(org.hamcrest.Matcher[])")
.havingDefault(MATCHERS + ".contains(matchersOnElements)"),
getDslMethodBuilder().withDeclaration("ContainsInAnyOrder", this.generic + "... elements")
getDslMethodBuilder().withDeclaration("ContainsInAnyOrder", tgeneric + "... elements")
.withJavaDoc("that the iterable contains the received elements in any order",
"elements the elements", MATCHERS + "#containsInAnyOrder(java.lang.Object[])")
.havingDefault(MATCHERS + ".containsInAnyOrder(elements)"),
getDslMethodBuilder()
.withDeclaration("ContainsInAnyOrder",
"org.hamcrest.Matcher<" + this.generic + ">... matchersOnElements")
"org.hamcrest.Matcher<" + tgeneric + ">... matchersOnElements")
.withJavaDoc("that the iterable contains the received elements, using matchers in any order",
DEFAULT_JAVADOC_MATCHER_ON_ELEMENTS,
MATCHERS + "#containsInAnyOrder(org.hamcrest.Matcher[])")
.havingDefault(MATCHERS + ".containsInAnyOrder(matchersOnElements)"),
getDslMethodBuilder()
.withDeclaration("Contains",
"java.util.List<org.hamcrest.Matcher<? super " + this.generic + ">> matchersOnElements")
"java.util.List<org.hamcrest.Matcher<? super " + tgeneric + ">> matchersOnElements")
.withJavaDoc("that the iterable contains the received elements, using list of matcher",
DEFAULT_JAVADOC_MATCHER_ON_ELEMENTS, MATCHERS + "#contains(java.util.List)")
.havingDefault(MATCHERS + ".contains(matchersOnElements)"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,13 @@ public SupplierFieldDescription(ProvidesMatchersAnnotatedElementData containingE

@Override
protected Collection<FieldDSLMethod> getSpecificFieldDslMethodFor() {
String tgeneric = this.generic;
return Collections.singleton(getDslMethodBuilder()
.withDeclaration("SupplierResult", "org.hamcrest.Matcher<? super " + this.generic + "> matcherOnResult")
.withDeclaration("SupplierResult", "org.hamcrest.Matcher<? super " + tgeneric + "> matcherOnResult")
.withJavaDoc(
" Validate that the result of the supplier is accepted by another matcher (the result of the execution must be stable)",
"matcherOnResult a Matcher on result of the supplier execution")
.havingDefault("asFeatureMatcher(\"with supplier result\",(java.util.function.Supplier<" + this.generic
.havingDefault("asFeatureMatcher(\"with supplier result\",(java.util.function.Supplier<" + tgeneric
+ "> s) -> s.get(),matcherOnResult)"));
}

Expand Down

0 comments on commit 426033b

Please sign in to comment.