use of com.bluelinelabs.logansquare.typeconverters.TypeConverter in project LoganSquare by bluelinelabs.
the class JsonFieldProcessor method ensureTypeConverterClassValid.
private boolean ensureTypeConverterClassValid(TypeMirror typeConverterClassMirror, Elements elements, Types types) {
TypeElement typeConverterElement = elements.getTypeElement(typeConverterClassMirror.toString());
if (typeConverterElement != null) {
boolean isTypeConverterType = false;
TypeElement element = typeConverterElement;
while (!isTypeConverterType && element != null) {
for (TypeMirror iface : element.getInterfaces()) {
if (types.erasure(iface).toString().equals(TypeConverter.class.getCanonicalName())) {
isTypeConverterType = true;
}
}
TypeMirror superClassMirror = element.getSuperclass();
if (superClassMirror != null) {
superClassMirror = types.erasure(superClassMirror);
element = elements.getTypeElement(superClassMirror.toString());
} else {
element = null;
}
}
if (!isTypeConverterType) {
error(element, "TypeConverter elements must implement the TypeConverter interface or extend from one of the convenience helpers (ie StringBasedTypeConverter or DateTypeConverter).");
return false;
}
boolean constructorIsDeclared = false;
boolean hasAccessibleConstructor = false;
List<? extends Element> enclosedElements = typeConverterElement.getEnclosedElements();
for (Element enclosedElement : enclosedElements) {
ElementKind enclosedElementKind = enclosedElement.getKind();
if (enclosedElementKind == ElementKind.CONSTRUCTOR) {
constructorIsDeclared = true;
if (!enclosedElement.getModifiers().contains(Modifier.PRIVATE)) {
ExecutableElement executableElement = (ExecutableElement) enclosedElement;
if (executableElement.getParameters().size() == 0) {
hasAccessibleConstructor = true;
}
}
}
}
if (constructorIsDeclared && !hasAccessibleConstructor) {
error(element, "TypeConverter classes must have a non-private zero argument constructor.");
return false;
}
}
return true;
}
Aggregations