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 06a3339 commit 5342d90
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ public String getSeeValue() {
return result;
}

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

private String convertParameterForSee(VariableElement ve) {
Element e = processingEnv.getTypeUtils().asElement(ve.asType());
if (e == null || ve.asType().getKind() == TypeKind.TYPEVAR) {
Expand All @@ -87,29 +93,23 @@ private String getJavadoc() {
}

private String getGeneric() {
return new StringBuilder("<")
.append(element.getTypeParameters()
.stream().map(
(ve) -> ve.getSimpleName().toString()
+ (ve.getBounds().isEmpty() ? ""
: (" extends " + ve.getBounds().stream().map(Object::toString)
.collect(joining("&")))))
.collect(joining(",")))
.append("> ").toString();
if (!element.getTypeParameters().isEmpty()) {
return new StringBuilder("<")
.append(element.getTypeParameters().stream()
.map((ve) -> ve.getSimpleName().toString()
+ (ve.getBounds().isEmpty() ? ""
: (" extends " + ve.getBounds().stream().map(Object::toString)
.collect(joining("&")))))
.collect(joining(",")))
.append("> ").toString();
} else {
return "";
}
}

private String getDeclaration() {
StringBuilder sb = new StringBuilder();
if (!element.getTypeParameters().isEmpty()) {
sb.append(getGeneric());
}
sb.append(element.getReturnType().toString()).append(" ").append(element.getSimpleName().toString())
.append("(");
String param = element.getParameters().stream()
.map((ve) -> ve.asType().toString() + " " + ve.getSimpleName().toString()).collect(joining(","));
sb.append(element.isVarArgs() ? param.replaceAll(VAR_ARG_REGEX, "...") : param);
sb.append(")");
return sb.toString();
return String.format("%1$s%2$s %3$s(%4$s)", getGeneric(), element.getReturnType(), element.getSimpleName(),
getParam());
}

public String generateFactory() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import java.util.List;
import java.util.Optional;

import javax.annotation.processing.ProcessingEnvironment;
import javax.lang.model.element.TypeElement;

import ch.powerunit.extensions.matchers.provideprocessor.fields.AbstractFieldDescription;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,23 +169,27 @@ public DSLMethod generateParentDSLStarter() {
+ "With(matcherOnParent);");
}

public DSLMethod generateNoParentValueDSLStarter() {
public DSLMethod generatParentValueDSLStarter(String argumentForParentBuilder) {
String genericNoParent = getSimpleNameOfGeneratedInterfaceMatcherWithGenericNoParent();
String javadoc = generateDefaultJavaDoc(Optional.empty(),
Optional.of("other the other object to be used as a reference."), Optional.of("the DSL matcher"), true,
false);
List<String> lines = new ArrayList<>();
lines.add(getSimpleNameOfGeneratedInterfaceMatcherWithGenericNoParent() + " m=new "
+ getSimpleNameOfGeneratedImplementationMatcherWithGenericNoParent() + "();");
lines.add(genericNoParent + " m=new " + getSimpleNameOfGeneratedImplementationMatcherWithGenericNoParent() + "("
+ argumentForParentBuilder + ");");
lines.addAll(fields.stream().map(f -> " " + f.getFieldCopy("m", "other") + ";").collect(toList()));
lines.add("return m;");
return new DSLMethod(javadoc,
fullGeneric + " " + getFullyQualifiedNameOfGeneratedClass() + "."
+ getSimpleNameOfGeneratedInterfaceMatcherWithGenericNoParent() + " " + methodShortClassName
+ "WithSameValue",
fullGeneric + " " + getFullyQualifiedNameOfGeneratedClass() + "." + genericNoParent + " "
+ methodShortClassName + "WithSameValue",
new String[] { getFullyQualifiedNameOfClassAnnotatedWithProvideMatcherWithGeneric(), "other" },
lines.toArray(new String[0]));
}

public DSLMethod generateNoParentValueDSLStarter() {
return generatParentValueDSLStarter("");
}

public ProvidesMatchersAnnotatedElementMirror getParentMirror() {
return roundMirror.getByName(((TypeElement) roundMirror.getProcessingEnv().getTypeUtils()
.asElement(typeElementForClassAnnotatedWithProvideMatcher.getSuperclass())).getQualifiedName()
Expand All @@ -196,21 +200,7 @@ public DSLMethod generateParentValueDSLStarter() {
ProvidesMatchersAnnotatedElementMirror parentMirror = getParentMirror();
String argumentForParentBuilder = parentMirror.getFullyQualifiedNameOfGeneratedClass() + "."
+ parentMirror.methodShortClassName + "WithSameValue(other)";
String javadoc = generateDefaultJavaDoc(Optional.empty(),
Optional.of("other the other object to be used as a reference."), Optional.of("the DSL matcher"), true,
false);
List<String> lines = new ArrayList<>();
lines.add(getSimpleNameOfGeneratedInterfaceMatcherWithGenericNoParent() + " m=new "
+ getSimpleNameOfGeneratedImplementationMatcherWithGenericNoParent() + "(" + argumentForParentBuilder
+ ");");
lines.addAll(fields.stream().map(f -> " " + f.getFieldCopy("m", "other") + ";").collect(toList()));
lines.add("return m;");
return new DSLMethod(javadoc,
fullGeneric + " " + getFullyQualifiedNameOfGeneratedClass() + "."
+ getSimpleNameOfGeneratedInterfaceMatcherWithGenericNoParent() + " " + methodShortClassName
+ "WithSameValue",
new String[] { getFullyQualifiedNameOfClassAnnotatedWithProvideMatcherWithGeneric(), "other" },
lines.toArray(new String[0]));
return generatParentValueDSLStarter(argumentForParentBuilder);
}

public DSLMethod generateParentInSameRoundWithChaningDSLStarter() {
Expand Down

0 comments on commit 5342d90

Please sign in to comment.