Search in sources :

Example 16 with AbstractJClass

use of com.helger.jcodemodel.AbstractJClass in project androidannotations by androidannotations.

the class RestMethodHandler method addMethodParams.

protected SortedMap<String, JVar> addMethodParams(ExecutableElement executableElement, RestHolder restHolder, JMethod method) {
    List<? extends VariableElement> params = executableElement.getParameters();
    SortedMap<String, JVar> methodParams = new TreeMap<>();
    for (VariableElement parameter : params) {
        String paramName = parameter.getSimpleName().toString();
        String paramType = parameter.asType().toString();
        JVar param;
        if (parameter.asType().getKind().isPrimitive()) {
            param = method.param(getCodeModel().parseType(paramType), paramName);
        } else {
            AbstractJClass parameterClass = codeModelHelper.typeMirrorToJClass(parameter.asType());
            param = method.param(parameterClass, paramName);
        }
        methodParams.put(paramName, param);
    }
    return methodParams;
}
Also used : AbstractJClass(com.helger.jcodemodel.AbstractJClass) VariableElement(javax.lang.model.element.VariableElement) TreeMap(java.util.TreeMap) JVar(com.helger.jcodemodel.JVar)

Example 17 with AbstractJClass

use of com.helger.jcodemodel.AbstractJClass in project androidannotations by androidannotations.

the class RestServiceHandler method assignValue.

@Override
public void assignValue(JBlock targetBlock, IJAssignmentTarget fieldRef, EComponentHolder holder, Element element, Element param) {
    TypeMirror fieldTypeMirror = param.asType();
    TypeMirror erasedFieldTypeMirror = getProcessingEnvironment().getTypeUtils().erasure(fieldTypeMirror);
    String interfaceName = erasedFieldTypeMirror.toString();
    String generatedClassName = interfaceName + classSuffix();
    AbstractJClass clazz = codeModelHelper.narrowGeneratedClass(getJClass(generatedClassName), fieldTypeMirror);
    targetBlock.add(fieldRef.assign(JExpr._new(clazz).arg(holder.getContextRef())));
}
Also used : TypeMirror(javax.lang.model.type.TypeMirror) AbstractJClass(com.helger.jcodemodel.AbstractJClass)

Example 18 with AbstractJClass

use of com.helger.jcodemodel.AbstractJClass in project androidannotations by androidannotations.

the class RestAnnotationHelper method retrieveResponseClass.

public AbstractJClass retrieveResponseClass(TypeMirror returnType, RestHolder holder) {
    String returnTypeString = returnType.toString();
    AbstractJClass responseClass;
    if (returnTypeString.startsWith(RESPONSE_ENTITY)) {
        DeclaredType declaredReturnType = (DeclaredType) returnType;
        if (declaredReturnType.getTypeArguments().size() > 0) {
            responseClass = resolveResponseClass(declaredReturnType.getTypeArguments().get(0), holder, false);
        } else {
            responseClass = getEnvironment().getJClass(RESPONSE_ENTITY);
        }
    } else {
        responseClass = resolveResponseClass(returnType, holder, true);
    }
    return responseClass;
}
Also used : AbstractJClass(com.helger.jcodemodel.AbstractJClass) DeclaredType(javax.lang.model.type.DeclaredType)

Example 19 with AbstractJClass

use of com.helger.jcodemodel.AbstractJClass in project androidannotations by androidannotations.

the class RestAnnotationHelper method getResponseClass.

public IJExpression getResponseClass(Element element, RestHolder holder) {
    ExecutableElement executableElement = (ExecutableElement) element;
    IJExpression responseClassExpr = nullCastedToNarrowedClass(holder);
    TypeMirror returnType = executableElement.getReturnType();
    if (returnType.getKind() != TypeKind.VOID) {
        if (getElementUtils().getTypeElement(RestSpringClasses.PARAMETERIZED_TYPE_REFERENCE) != null) {
            if (returnType.toString().startsWith(RestSpringClasses.RESPONSE_ENTITY)) {
                List<? extends TypeMirror> typeArguments = ((DeclaredType) returnType).getTypeArguments();
                if (!typeArguments.isEmpty()) {
                    returnType = typeArguments.get(0);
                }
            }
            if (checkIfParameterizedTypeReferenceShouldBeUsed(returnType)) {
                return createParameterizedTypeReferenceAnonymousSubclassInstance(returnType);
            }
        }
        AbstractJClass responseClass = retrieveResponseClass(returnType, holder);
        if (responseClass != null) {
            responseClassExpr = responseClass.dotclass();
        }
    }
    return responseClassExpr;
}
Also used : TypeMirror(javax.lang.model.type.TypeMirror) ExecutableElement(javax.lang.model.element.ExecutableElement) IJExpression(com.helger.jcodemodel.IJExpression) AbstractJClass(com.helger.jcodemodel.AbstractJClass) DeclaredType(javax.lang.model.type.DeclaredType)

Example 20 with AbstractJClass

use of com.helger.jcodemodel.AbstractJClass in project androidannotations by androidannotations.

the class OrmLiteHolder method setDatabaseHelperRef.

private JFieldVar setDatabaseHelperRef(TypeMirror databaseHelperTypeMirror) {
    AbstractJClass databaseHelperClass = getJClass(databaseHelperTypeMirror.toString());
    String fieldName = CaseHelper.lowerCaseFirst(databaseHelperClass.name()) + ModelConstants.generationSuffix();
    JFieldVar databaseHelperRef = getGeneratedClass().field(PRIVATE, databaseHelperClass, fieldName);
    databaseHelperRefs.put(databaseHelperTypeMirror, databaseHelperRef);
    IJExpression dbHelperClass = databaseHelperClass.dotclass();
    //
    holder().getInitBodyInjectionBlock().assign(//
    databaseHelperRef, getJClass(OrmLiteClasses.OPEN_HELPER_MANAGER).staticInvoke("getHelper").arg(holder().getContextRef()).arg(dbHelperClass));
    return databaseHelperRef;
}
Also used : JFieldVar(com.helger.jcodemodel.JFieldVar) IJExpression(com.helger.jcodemodel.IJExpression) AbstractJClass(com.helger.jcodemodel.AbstractJClass)

Aggregations

AbstractJClass (com.helger.jcodemodel.AbstractJClass)125 JVar (com.helger.jcodemodel.JVar)48 JMethod (com.helger.jcodemodel.JMethod)36 JBlock (com.helger.jcodemodel.JBlock)35 JInvocation (com.helger.jcodemodel.JInvocation)31 TypeMirror (javax.lang.model.type.TypeMirror)24 IJExpression (com.helger.jcodemodel.IJExpression)23 JDefinedClass (com.helger.jcodemodel.JDefinedClass)19 VariableElement (javax.lang.model.element.VariableElement)14 JFieldVar (com.helger.jcodemodel.JFieldVar)13 GenerationProcess (com.github.sviperll.adt4j.model.util.GenerationProcess)9 ExecutableElement (javax.lang.model.element.ExecutableElement)9 JAnnotationUse (com.helger.jcodemodel.JAnnotationUse)8 JConditional (com.helger.jcodemodel.JConditional)8 JTypeVar (com.helger.jcodemodel.JTypeVar)8 DeclaredType (javax.lang.model.type.DeclaredType)8 VisitorDefinition (com.github.sviperll.adt4j.model.config.VisitorDefinition)6 JFieldRef (com.helger.jcodemodel.JFieldRef)6 ArrayList (java.util.ArrayList)6 BundleHelper (org.androidannotations.helper.BundleHelper)6