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 04fbe23 commit 06a3339
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ public abstract class ProvidesMatchersAnnotatedElementMatcherMirror
protected final TypeElement typeElementForClassAnnotatedWithProvideMatcher;
protected final String methodShortClassName;
protected final Optional<String> fullyQualifiedNameOfSuperClassOfClassAnnotatedWithProvideMatcher;
protected final String simpleNameOfGeneratedImplementationMatcher;
protected final List<AbstractFieldDescription> fields;
protected final RoundMirror roundMirror;

Expand All @@ -82,17 +81,16 @@ public ProvidesMatchersAnnotatedElementMatcherMirror(TypeElement typeElement, Ro
super(typeElement, roundMirror);
this.roundMirror = roundMirror;
this.typeElementForClassAnnotatedWithProvideMatcher = typeElement;
ProcessingEnvironment processingEnv = roundMirror.getProcessingEnv();
this.methodShortClassName = simpleNameOfClassAnnotatedWithProvideMatcher.substring(0, 1).toLowerCase()
+ simpleNameOfClassAnnotatedWithProvideMatcher.substring(1);
if (!processingEnv.getElementUtils().getTypeElement("java.lang.Object").asType()
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.simpleNameOfGeneratedImplementationMatcher = simpleNameOfClassAnnotatedWithProvideMatcher + "MatcherImpl";

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

Expand Down Expand Up @@ -212,8 +210,8 @@ private String generateMainBuildPublicInterface() {
}

public String generatePrivateImplementationConstructor(String argument, String... body) {
return String.format(" public %1$s(%2$s) {\n%3$s }", simpleNameOfGeneratedImplementationMatcher, argument,
Arrays.stream(body).map(l -> " " + l).collect(joining("\n")));
return String.format(" public %1$s(%2$s) {\n%3$s }", getSimpleNameOfGeneratedImplementationMatcher(),
argument, Arrays.stream(body).map(l -> " " + l).collect(joining("\n")));
}

protected String generatePrivateImplementation() {
Expand All @@ -231,7 +229,7 @@ protected String generatePrivateImplementation() {
"this._parentBuilder=parentBuilder;")
+ "\n\n");
return new StringBuilder(" /* package protected */ static class ")
.append(simpleNameOfGeneratedImplementationMatcher).append(getFullGenericParent())
.append(getSimpleNameOfGeneratedImplementationMatcher()).append(getFullGenericParent())
.append(" extends org.hamcrest.TypeSafeDiagnosingMatcher<")
.append(getFullyQualifiedNameOfClassAnnotatedWithProvideMatcherWithGeneric()).append("> implements ")
.append(getSimpleNameOfGeneratedInterfaceMatcherWithGenericParent() + " {\n ")
Expand Down Expand Up @@ -291,6 +289,14 @@ public String getMethodShortClassName() {
return methodShortClassName;
}

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

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

public RoundMirror getRoundMirror() {
return roundMirror;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,15 +116,15 @@ public Collection<DSLMethod> generateDSLStarter() {
public String getDefaultStarterBody(boolean withParentBuilder) {
if (withParentBuilder) {
return fullyQualifiedNameOfSuperClassOfClassAnnotatedWithProvideMatcher.isPresent()
? ("return new " + simpleNameOfGeneratedImplementationMatcher + getGenericParent()
? ("return new " + getSimpleNameOfGeneratedImplementationMatcher() + getGenericParent()
+ "(org.hamcrest.Matchers.anything(),parentBuilder);")
: ("return new " + simpleNameOfGeneratedImplementationMatcher + getGenericParent()
: ("return new " + getSimpleNameOfGeneratedImplementationMatcher() + getGenericParent()
+ "(parentBuilder);");
} else {
return fullyQualifiedNameOfSuperClassOfClassAnnotatedWithProvideMatcher.isPresent()
? ("return new " + simpleNameOfGeneratedImplementationMatcher + getGenericNoParent()
? ("return new " + getSimpleNameOfGeneratedImplementationMatcherWithGenericNoParent()
+ "(org.hamcrest.Matchers.anything());")
: ("return new " + simpleNameOfGeneratedImplementationMatcher + getGenericNoParent() + "();");
: ("return new " + getSimpleNameOfGeneratedImplementationMatcherWithGenericNoParent() + "();");
}
}

Expand Down Expand Up @@ -175,7 +175,7 @@ public DSLMethod generateNoParentValueDSLStarter() {
false);
List<String> lines = new ArrayList<>();
lines.add(getSimpleNameOfGeneratedInterfaceMatcherWithGenericNoParent() + " m=new "
+ simpleNameOfGeneratedImplementationMatcher + getGenericNoParent() + "();");
+ getSimpleNameOfGeneratedImplementationMatcherWithGenericNoParent() + "();");
lines.addAll(fields.stream().map(f -> " " + f.getFieldCopy("m", "other") + ";").collect(toList()));
lines.add("return m;");
return new DSLMethod(javadoc,
Expand All @@ -201,7 +201,7 @@ public DSLMethod generateParentValueDSLStarter() {
false);
List<String> lines = new ArrayList<>();
lines.add(getSimpleNameOfGeneratedInterfaceMatcherWithGenericNoParent() + " m=new "
+ simpleNameOfGeneratedImplementationMatcher + getGenericNoParent() + "(" + argumentForParentBuilder
+ getSimpleNameOfGeneratedImplementationMatcherWithGenericNoParent() + "(" + argumentForParentBuilder
+ ");");
lines.addAll(fields.stream().map(f -> " " + f.getFieldCopy("m", "other") + ";").collect(toList()));
lines.add("return m;");
Expand All @@ -221,8 +221,8 @@ public DSLMethod generateParentInSameRoundWithChaningDSLStarter() {
+ parentMirror.simpleNameOfGeneratedInterfaceMatcher + genericForChaining + " "
+ methodShortClassName + "WithParent",
new String[] {
simpleNameOfGeneratedImplementationMatcher + getGenericNoParent() + " m=new "
+ simpleNameOfGeneratedImplementationMatcher + getGenericNoParent()
getSimpleNameOfGeneratedImplementationMatcherWithGenericNoParent() + " m=new "
+ getSimpleNameOfGeneratedImplementationMatcherWithGenericNoParent()
+ "(org.hamcrest.Matchers.anything());",
parentMirror.getFullyQualifiedNameOfGeneratedClass() + "."
+ parentMirror.simpleNameOfGeneratedInterfaceMatcher + " tmp = "
Expand Down

0 comments on commit 06a3339

Please sign in to comment.