use of com.helger.jcodemodel.AbstractJClass in project androidannotations by androidannotations.
the class RestAnnotationHelper method resolveResponseClass.
/**
* Resolve the expected class for the input type according to the following
* rules :
* <ul>
* <li>The type is a primitive : Directly return the JClass as usual</li>
* <li>The type is NOT a generics : Directly return the JClass as usual</li>
* <li>The type is a generics and enclosing type is a class C<T> :
* Generate a subclass of C<T> and return it</li>
* <li>The type is a generics and enclosing type is an interface I<T>
* : Looking the inheritance tree, then</li>
* <ol>
* <li>One of the parent is a {@link java.util.Map Map} : Generate a
* subclass of {@link LinkedHashMap}<T> one and return it</li>
* <li>One of the parent is a {@link Set} : Generate a subclass of
* {@link TreeSet}<T> one and return it</li>
* <li>One of the parent is a {@link java.util.Collection Collection} :
* Generate a subclass of {@link ArrayList}<T> one and return it</li>
* <li>Return {@link Object} definition</li>
* </ol>
* </ul>
*
*/
private AbstractJClass resolveResponseClass(TypeMirror expectedType, RestHolder holder, boolean useTypeReference) {
// is a class or an interface
if (expectedType.getKind() == TypeKind.DECLARED) {
DeclaredType declaredType = (DeclaredType) expectedType;
List<? extends TypeMirror> typeArguments = declaredType.getTypeArguments();
// is NOT a generics, return directly
if (typeArguments.isEmpty()) {
return codeModelHelper.typeMirrorToJClass(declaredType);
}
// is a generics, must generate a new super class
TypeElement declaredElement = (TypeElement) declaredType.asElement();
if (useTypeReference && getElementUtils().getTypeElement(RestSpringClasses.PARAMETERIZED_TYPE_REFERENCE) != null) {
return codeModelHelper.typeMirrorToJClass(declaredType);
}
AbstractJClass baseClass = codeModelHelper.typeMirrorToJClass(declaredType).erasure();
AbstractJClass decoratedExpectedClass = retrieveDecoratedResponseClass(declaredType, declaredElement, holder);
if (decoratedExpectedClass == null) {
decoratedExpectedClass = baseClass;
}
return decoratedExpectedClass;
} else if (expectedType.getKind() == TypeKind.ARRAY) {
ArrayType arrayType = (ArrayType) expectedType;
TypeMirror componentType = arrayType.getComponentType();
return resolveResponseClass(componentType, holder, false).array();
}
// is not a class nor an interface, return directly
return codeModelHelper.typeMirrorToJClass(expectedType);
}
use of com.helger.jcodemodel.AbstractJClass in project androidannotations by androidannotations.
the class RestAnnotationHelper method plainName.
protected String plainName(AbstractJClass jClass) {
String plainName = jClass.erasure().name();
List<? extends AbstractJClass> typeParameters = jClass.getTypeParameters();
if (typeParameters.size() > 0) {
plainName += "_";
for (AbstractJClass typeParameter : typeParameters) {
plainName += plainName(typeParameter);
}
}
return plainName;
}
use of com.helger.jcodemodel.AbstractJClass in project androidannotations by androidannotations.
the class RestHolder method setAvailableCookiesField.
private void setAvailableCookiesField() {
AbstractJClass stringClass = getClasses().STRING;
AbstractJClass mapClass = getClasses().HASH_MAP.narrow(stringClass, stringClass);
availableCookiesField = getGeneratedClass().field(JMod.PRIVATE, mapClass, "availableCookies");
getInit().body().assign(availableCookiesField, _new(mapClass));
}
use of com.helger.jcodemodel.AbstractJClass in project androidannotations by androidannotations.
the class AbstractRestMethodWithParameterHandler method getRequestEntity.
@Override
protected IJExpression getRequestEntity(ExecutableElement element, RestHolder holder, JBlock methodBody, SortedMap<String, JVar> params) {
JVar httpHeaders = restAnnotationHelper.declareHttpHeaders(element, holder, methodBody);
JVar entitySentToServer = restAnnotationHelper.getEntitySentToServer(element, params);
if (entitySentToServer == null) {
Map<String, String> parameters = restAnnotationHelper.extractFieldAndPartParameters(element);
if (parameters != null) {
AbstractJClass hashMapClass = getJClass(RestSpringClasses.LINKED_MULTI_VALUE_MAP).narrow(String.class, Object.class);
entitySentToServer = methodBody.decl(hashMapClass, "parameters", JExpr._new(hashMapClass));
for (Map.Entry<String, String> parameter : parameters.entrySet()) {
methodBody.add(entitySentToServer.invoke("add").arg(JExpr.lit(parameter.getKey())).arg(params.get(parameter.getValue())));
}
}
}
return restAnnotationHelper.declareHttpEntity(methodBody, entitySentToServer, httpHeaders);
}
use of com.helger.jcodemodel.AbstractJClass in project androidannotations by androidannotations.
the class RoboGuiceHandler method listenerFields.
private void listenerFields(Element element, EActivityHolder holder) {
List<TypeMirror> listenerTypeMirrors = extractListenerTypeMirrors(element);
int i = 1;
for (TypeMirror listenerTypeMirror : listenerTypeMirrors) {
AbstractJClass listenerClass = codeModelHelper.typeMirrorToJClass(listenerTypeMirror);
JFieldVar listener = holder.getGeneratedClass().field(JMod.PRIVATE, listenerClass, "listener" + i + generationSuffix());
codeModelHelper.addSuppressWarnings(listener, "unused");
listener.annotate(getJClass(RoboGuiceClasses.INJECT));
i++;
}
}
Aggregations