Search in sources :

Example 56 with JInvocation

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

the class RestHandler method setRequestFactory.

private void setRequestFactory(Element element, RestHolder holder) {
    DeclaredType requestFactoryType = annotationHelper.extractAnnotationClassParameter(element, getTarget(), "requestFactory");
    if (requestFactoryType != null) {
        JInvocation requestFactory = codeModelHelper.newBeanOrEBean(requestFactoryType, holder.getInitContextParam());
        holder.getInit().body().add(invoke(holder.getRestTemplateField(), "setRequestFactory").arg(requestFactory));
    }
}
Also used : JInvocation(com.helger.jcodemodel.JInvocation) DeclaredType(javax.lang.model.type.DeclaredType)

Example 57 with JInvocation

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

the class RestHandler method setInterceptors.

private void setInterceptors(Element element, RestHolder holder) {
    List<DeclaredType> interceptors = annotationHelper.extractAnnotationClassArrayParameter(element, getTarget(), "interceptors");
    if (interceptors != null) {
        AbstractJClass listClass = getJClass(ARRAYLIST);
        AbstractJClass clientInterceptorClass = getJClass(CLIENT_HTTP_REQUEST_INTERCEPTOR);
        listClass = listClass.narrow(clientInterceptorClass);
        JFieldVar restTemplateField = holder.getRestTemplateField();
        JBlock init = holder.getInit().body();
        init.add(invoke(restTemplateField, "setInterceptors").arg(_new(listClass)));
        for (DeclaredType interceptorType : interceptors) {
            JInvocation newInterceptor = codeModelHelper.newBeanOrEBean(interceptorType, holder.getInitContextParam());
            init.add(invoke(restTemplateField, "getInterceptors").invoke("add").arg(newInterceptor));
        }
    }
}
Also used : JFieldVar(com.helger.jcodemodel.JFieldVar) JBlock(com.helger.jcodemodel.JBlock) AbstractJClass(com.helger.jcodemodel.AbstractJClass) JInvocation(com.helger.jcodemodel.JInvocation) DeclaredType(javax.lang.model.type.DeclaredType)

Example 58 with JInvocation

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

the class RestHolder method implementSetBasicAuth.

private void implementSetBasicAuth(List<ExecutableElement> methods) {
    JMethod setAuthMethod = codeModelHelper.implementMethod(this, methods, "setHttpBasicAuth", TypeKind.VOID.toString(), STRING, STRING);
    if (setAuthMethod != null) {
        AbstractJClass basicAuthClass = getJClass(HTTP_BASIC_AUTHENTICATION);
        JInvocation basicAuthentication = JExpr._new(basicAuthClass).arg(setAuthMethod.params().get(0)).arg(setAuthMethod.params().get(1));
        setAuthMethod.body().assign(_this().ref(getAuthenticationField()), basicAuthentication);
    }
}
Also used : AbstractJClass(com.helger.jcodemodel.AbstractJClass) JInvocation(com.helger.jcodemodel.JInvocation) JMethod(com.helger.jcodemodel.JMethod)

Example 59 with JInvocation

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

the class RestHolder method implementGetHeader.

private void implementGetHeader(List<ExecutableElement> methods) {
    JMethod getHeaderMethod = codeModelHelper.implementMethod(this, methods, "getHeader", STRING, STRING);
    if (getHeaderMethod != null) {
        JInvocation headerValue = JExpr.invoke(getAvailableHeadersField(), "get").arg(getHeaderMethod.params().get(0));
        getHeaderMethod.body()._return(headerValue);
    }
}
Also used : JInvocation(com.helger.jcodemodel.JInvocation) JMethod(com.helger.jcodemodel.JMethod)

Example 60 with JInvocation

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

the class SharedPrefHandler method createFieldMethod.

private IJExpression createFieldMethod(SharedPrefHolder holder, ExecutableElement method, Class<? extends Annotation> annotationClass, Class<? extends AbstractPrefField<?>> prefFieldClass, Object defaultValue, Res resType, String fieldHelperMethodName) {
    Annotation annotation = method.getAnnotation(annotationClass);
    IJExpression defaultValueExpr;
    Object value = null;
    if (annotation != null) {
        value = annotationHelper.extractAnnotationParameter(method, annotationClass.getName(), "value");
    }
    if (annotation != null && method.getAnnotation(DefaultStringSet.class) == null) {
        defaultValueExpr = codeModelHelper.litObject(value);
    } else if (method.getAnnotation(DefaultRes.class) != null) {
        defaultValueExpr = extractResValue(holder, method, resType);
        annotationClass = DefaultRes.class;
    } else if (method.getAnnotation(DefaultStringSet.class) != null) {
        if (value != null) {
            Set<String> arrayValues = new HashSet<>(Arrays.asList((String[]) value));
            value = arrayValues;
            if (arrayValues.isEmpty()) {
                defaultValueExpr = newEmptyStringHashSet();
            } else {
                JInvocation arrayAsList = getClasses().ARRAYS.staticInvoke("asList");
                for (String arrayValue : arrayValues) {
                    arrayAsList.arg(lit(arrayValue));
                }
                defaultValueExpr = JExpr._new(getClasses().HASH_SET.narrow(getClasses().STRING)).arg(arrayAsList);
            }
        } else {
            defaultValueExpr = newEmptyStringHashSet();
        }
        annotationClass = DefaultStringSet.class;
    } else {
        defaultValueExpr = defaultValue != null ? codeModelHelper.litObject(defaultValue) : newEmptyStringHashSet();
        annotationClass = null;
    }
    Integer keyResId = ResId.DEFAULT_VALUE;
    if (annotationClass != null) {
        keyResId = annotationHelper.extractAnnotationParameter(method, annotationClass.getName(), "keyRes");
    }
    IJExpression keyExpression;
    String fieldName = method.getSimpleName().toString();
    if (keyResId == ResId.DEFAULT_VALUE) {
        keyExpression = lit(fieldName);
    } else {
        IRInnerClass idClass = getEnvironment().getRClass().get(IRClass.Res.STRING);
        JFieldRef idRef = idClass.getIdStaticRef(keyResId, getEnvironment());
        keyExpression = holder.getEditorContextField().invoke("getString").arg(idRef);
    }
    String docComment = getProcessingEnvironment().getElementUtils().getDocComment(method);
    String defaultValueStr = value == null ? null : value.toString();
    if (defaultValueStr == null) {
        defaultValueStr = defaultValue == null ? null : defaultValue.toString();
    }
    holder.createFieldMethod(prefFieldClass, keyExpression, fieldName, fieldHelperMethodName, defaultValueExpr, docComment, defaultValueStr);
    return keyExpression;
}
Also used : DefaultStringSet(org.androidannotations.annotations.sharedpreferences.DefaultStringSet) JFieldRef(com.helger.jcodemodel.JFieldRef) IJExpression(com.helger.jcodemodel.IJExpression) DefaultRes(org.androidannotations.annotations.sharedpreferences.DefaultRes) JInvocation(com.helger.jcodemodel.JInvocation) DefaultString(org.androidannotations.annotations.sharedpreferences.DefaultString) Annotation(java.lang.annotation.Annotation) HashSet(java.util.HashSet) IRInnerClass(org.androidannotations.rclass.IRInnerClass)

Aggregations

JInvocation (com.helger.jcodemodel.JInvocation)71 JVar (com.helger.jcodemodel.JVar)38 JBlock (com.helger.jcodemodel.JBlock)37 AbstractJClass (com.helger.jcodemodel.AbstractJClass)31 IJExpression (com.helger.jcodemodel.IJExpression)27 JMethod (com.helger.jcodemodel.JMethod)26 ExecutableElement (javax.lang.model.element.ExecutableElement)20 VariableElement (javax.lang.model.element.VariableElement)16 JFieldRef (com.helger.jcodemodel.JFieldRef)14 TypeMirror (javax.lang.model.type.TypeMirror)14 JConditional (com.helger.jcodemodel.JConditional)11 JDefinedClass (com.helger.jcodemodel.JDefinedClass)9 AbstractJType (com.helger.jcodemodel.AbstractJType)5 JFieldVar (com.helger.jcodemodel.JFieldVar)5 JTryBlock (com.helger.jcodemodel.JTryBlock)5 ArrayList (java.util.ArrayList)4 DeclaredType (javax.lang.model.type.DeclaredType)4 JCatchBlock (com.helger.jcodemodel.JCatchBlock)3 PageChangeHolder (org.androidannotations.holder.PageChangeHolder)3 TextWatcherHolder (org.androidannotations.holder.TextWatcherHolder)3