Search in sources :

Example 41 with AbstractJClass

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);
}
Also used : AbstractJClass(com.helger.jcodemodel.AbstractJClass) Map(java.util.Map) SortedMap(java.util.SortedMap) JVar(com.helger.jcodemodel.JVar)

Example 42 with AbstractJClass

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++;
    }
}
Also used : TypeMirror(javax.lang.model.type.TypeMirror) JFieldVar(com.helger.jcodemodel.JFieldVar) AbstractJClass(com.helger.jcodemodel.AbstractJClass)

Example 43 with AbstractJClass

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

the class RoboGuiceHolder method getCurrentConfig.

public JVar getCurrentConfig() {
    if (currentConfig == null) {
        AbstractJClass configurationClass = environment().getClasses().CONFIGURATION;
        JBlock onConfigurationChangedBeforeSuperBlock = holder().getOnConfigurationChangedBeforeSuperBlock();
        currentConfig = onConfigurationChangedBeforeSuperBlock.decl(configurationClass, "currentConfig", JExpr.invoke("getResources").invoke("getConfiguration"));
        onConfigurationChangedBeforeSuperBlock.bracesRequired(false).indentRequired(false);
    }
    return currentConfig;
}
Also used : JBlock(com.helger.jcodemodel.JBlock) AbstractJClass(com.helger.jcodemodel.AbstractJClass)

Example 44 with AbstractJClass

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

the class IntentBuilder method addPutExtraMethod.

private JMethod addPutExtraMethod(Element element, List<IntentExtra> intentExtras) {
    String docComment = elementUtils.getDocComment(element);
    JMethod method = holder.getIntentBuilderClass().method(PUBLIC, holder.getIntentBuilderClass(), element.getSimpleName().toString());
    method.javadoc().addReturn().append("the IntentBuilder to chain calls");
    codeModelHelper.addTrimmedDocComment(method, docComment);
    int paramCount = intentExtras.size();
    for (int i = 0; i < paramCount; i++) {
        IntentExtra intentExtra = intentExtras.get(i);
        method.javadoc().addParam(intentExtra.parameterName).append("the value for this extra");
        AbstractJClass parameterClass = codeModelHelper.typeMirrorToJClass(intentExtra.type);
        JVar extraParameterVar = method.param(parameterClass, intentExtra.parameterName);
        JInvocation superCall = getSuperPutExtraInvocation(intentExtra.type, extraParameterVar, intentExtra.keyField);
        if (i + 1 == paramCount) {
            method.body()._return(superCall);
        } else {
            method.body().add(superCall);
        }
    }
    return method;
}
Also used : AbstractJClass(com.helger.jcodemodel.AbstractJClass) JInvocation(com.helger.jcodemodel.JInvocation) JMethod(com.helger.jcodemodel.JMethod) JVar(com.helger.jcodemodel.JVar)

Example 45 with AbstractJClass

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

the class AnnotationArrayParamExtractor method visitEnumConstant.

@Override
public Void visitEnumConstant(VariableElement c, JAnnotationArrayMember p) {
    AbstractJClass annotationClass = helper.typeMirrorToJClass(c.asType());
    JEnumConstantRef ref = JExpr.enumConstantRef(annotationClass, c.getSimpleName().toString());
    p.param(ref);
    return null;
}
Also used : AbstractJClass(com.helger.jcodemodel.AbstractJClass) JEnumConstantRef(com.helger.jcodemodel.JEnumConstantRef)

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