Skip to content

Commit

Permalink
[#2] Added more testcases and restructed TypeUtils class.
Browse files Browse the repository at this point in the history
Grouped methods in non static embedded classes.
  • Loading branch information
tobiasstamann committed Jul 3, 2017
1 parent a0fcda8 commit b2b1a73
Show file tree
Hide file tree
Showing 12 changed files with 618 additions and 311 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public boolean checkForMatchingCharacteristic(Element element, Class[] toCheckFo


for (int i = 0; i < executableElement.getParameters().size(); i++) {
if (!executableElement.getParameters().get(i).asType().equals(TypeUtils.getTypeUtils(tools).getTypeMirror(toCheckFor[i]))) {
if (!executableElement.getParameters().get(i).asType().equals(TypeUtils.getTypeUtils(tools).TYPE_RETRIEVAL.getTypeMirror(toCheckFor[i]))) {
return false;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public boolean checkForMatchingCharacteristic(Element element, String[] toCheckF

for (int i = 0; i < executableElement.getParameters().size(); i++) {

TypeMirror parameterTypeMirror = TypeUtils.getTypeUtils(tools).getTypeMirror(toCheckFor[i]);
TypeMirror parameterTypeMirror = TypeUtils.getTypeUtils(tools).TYPE_RETRIEVAL.getTypeMirror(toCheckFor[i]);
if (parameterTypeMirror == null) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public boolean checkForMatchingCharacteristic(Element element, Class toCheckFor)
// cast to executable element for further checks
TypeUtils typeUtils = TypeUtils.getTypeUtils(tools);

return typeUtils.isErasedTypeEqual(element.asType(), typeUtils.getTypeMirror(toCheckFor));
return typeUtils.TYPE_COMPARISON.isErasedTypeEqual(element.asType(), typeUtils.TYPE_RETRIEVAL.getTypeMirror(toCheckFor));

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import de.holisticon.annotationprocessortoolkit.internal.FrameworkToolWrapper;
import de.holisticon.annotationprocessortoolkit.tools.ElementUtils;
import de.holisticon.annotationprocessortoolkit.tools.TypeUtils;

import javax.lang.model.element.ElementKind;
import javax.lang.model.element.ExecutableElement;
Expand Down Expand Up @@ -72,7 +73,7 @@ public FluentExecutableElementValidator hasVoidReturnType() {

boolean nextResult = this.currentValidationResult;

if (ElementUtils.CheckKindOfElement.isMethod(element) && !typeUtils.checkTypeKind().isVoid(element.getReturnType())) {
if (ElementUtils.CheckKindOfElement.isMethod(element) && !TypeUtils.CheckTypeKind.INSTANCE.isVoid(element.getReturnType())) {

// validation failed - output message
messagerUtils.printMessage(element, getMessageLevel(), getCustomOrDefaultMessage("Method must have void return type"));
Expand All @@ -94,7 +95,7 @@ public FluentExecutableElementValidator hasNonVoidReturnType() {

boolean nextResult = this.currentValidationResult;

if (ElementUtils.CheckKindOfElement.isMethod(element) && typeUtils.checkTypeKind().isVoid(element.getReturnType())) {
if (ElementUtils.CheckKindOfElement.isMethod(element) && TypeUtils.CheckTypeKind.INSTANCE.isVoid(element.getReturnType())) {

// validation failed - output message
messagerUtils.printMessage(element, getMessageLevel(), getCustomOrDefaultMessage("Method must have non void return type"));
Expand All @@ -117,7 +118,7 @@ public FluentExecutableElementValidator hasReturnType(Class type) {

if (ElementUtils.CheckKindOfElement.isMethod(element) && hasNonVoidReturnType().getValidationResult()) {

if (type == null || !typeUtils.getTypes().isAssignable(element.getReturnType(), typeUtils.getTypeMirror(type))) {
if (type == null || !typeUtils.getTypes().isAssignable(element.getReturnType(), typeUtils.TYPE_RETRIEVAL.getTypeMirror(type))) {

// validation failed - output message
messagerUtils.printMessage(element, getMessageLevel(), getCustomOrDefaultMessage("Methods return type must be assignable to type ${0}", type.getSimpleName()));
Expand Down Expand Up @@ -182,7 +183,7 @@ public FluentExecutableElementValidator hasParameters(Class... parameterTypes) {
nextResult = isErrorLevel() ? false : nextResult;
} else {
for (int i = 0; i < element.getParameters().size(); i++) {
if (!element.getParameters().get(i).asType().equals(typeUtils.getTypeMirror(parameterTypes[i]))) {
if (!element.getParameters().get(i).asType().equals(typeUtils.TYPE_RETRIEVAL.getTypeMirror(parameterTypes[i]))) {
triggerMismatchingParameterError(parameterTypes);
nextResult = isErrorLevel() ? false : nextResult;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ private FluentTypeElementValidator(FluentTypeElementValidator previousFluentType
* @return an immutable FluentExecutableElementValidator instance
*/
public FluentTypeElementValidator isAssignableTo(Class type) {
return type != null ? isAssignableTo(typeUtils.getTypeElement(type)) : new FluentTypeElementValidator(this, false);
return type != null ? isAssignableTo(typeUtils.TYPE_RETRIEVAL.getTypeElement(type)) : new FluentTypeElementValidator(this, false);
}

/**
Expand All @@ -58,7 +58,7 @@ public FluentTypeElementValidator isAssignableTo(TypeElement typeElementToCheck)
public FluentTypeElementValidator isAssignableTo(TypeMirror typeMirror) {
boolean check = this.currentValidationResult;

if (typeMirror == null || !typeUtils.isAssignableTo(element, typeMirror)) {
if (typeMirror == null || !typeUtils.TYPE_COMPARISON.isAssignableTo(element, typeMirror)) {
messagerUtils.printMessage(element, getMessageLevel(), getCustomOrDefaultMessage("type must be assignable to ${0}", typeMirror));
check = isErrorLevel() ? false : check;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ protected void testCase(TypeElement element) {
List<? extends Element> result = createFluentElementFilter(element.getEnclosedElements())
.applyFilter(Filter.ELEMENT_KIND_FILTER).filterByOneOf(ElementKind.FIELD)
.getResult();
MatcherAssert.assertThat(result, Matchers.hasSize(7));
MatcherAssert.assertThat(result, Matchers.hasSize(8));


result = createFluentElementFilter(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ protected void testCase(TypeElement element) {
.applyFilter(Filter.ELEMENT_KIND_FILTER).filterByOneOf(ElementKind.FIELD)
.getResult();

MatcherAssert.assertThat(results, Matchers.hasSize(7));
MatcherAssert.assertThat(results, Matchers.hasSize(8));

for (Element resultElement : results) {
MatcherAssert.assertThat(resultElement.getKind(), Matchers.is(ElementKind.FIELD));
Expand Down Expand Up @@ -144,7 +144,7 @@ protected void testCase(TypeElement element) {
.applyFilter(Filter.ELEMENT_KIND_FILTER).invert().filterByOneOf(ElementKind.FIELD)
.getResult();

MatcherAssert.assertThat(results, Matchers.hasSize(element.getEnclosedElements().size() - 7));
MatcherAssert.assertThat(results, Matchers.hasSize(element.getEnclosedElements().size() - 8));

for (Element resultElement : results) {
MatcherAssert.assertThat(resultElement.getKind(), Matchers.not(ElementKind.FIELD));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ protected void testCase(TypeElement element) {
MatcherAssert.assertThat(getFluentMethodValidator(testElement).hasReturnType(String.class).getValidationResult(), Matchers.is(false));


getTypeUtils().getTypeElement(AbstractAnnotationProcessorTestBaseClass.AbstractTestAnnotationProcessorClass.class);
getTypeUtils().TYPE_RETRIEVAL.getTypeElement(AbstractAnnotationProcessorTestBaseClass.AbstractTestAnnotationProcessorClass.class);

}
},
Expand Down
Loading

0 comments on commit b2b1a73

Please sign in to comment.