Search in sources :

Example 46 with AbstractJClass

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

the class AnnotationArrayParamExtractor method visitType.

@Override
public Void visitType(TypeMirror t, JAnnotationArrayMember p) {
    AbstractJClass annotationClass = helper.typeMirrorToJClass(t);
    p.param(annotationClass);
    return null;
}
Also used : AbstractJClass(com.helger.jcodemodel.AbstractJClass)

Example 47 with AbstractJClass

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

the class ReceiverActionHandler method addActionInOnReceive.

private void addActionInOnReceive(EReceiverHolder holder, ExecutableElement executableElement, String methodName, JFieldVar actionsField, JFieldVar dataSchemesField) {
    String actionsInvoke = getInvocationName(actionsField);
    IJExpression filterCondition = actionsField.invoke(actionsInvoke).arg(holder.getOnReceiveIntentAction());
    if (dataSchemesField != null) {
        String dataSchemesInvoke = getInvocationName(dataSchemesField);
        filterCondition = filterCondition.cand(dataSchemesField.invoke(dataSchemesInvoke).arg(holder.getOnReceiveIntentDataScheme()));
    }
    JBlock callActionBlock = holder.getOnReceiveBody()._if(filterCondition)._then();
    IJExpression receiverRef = holder.getGeneratedClass().staticRef("this");
    JInvocation callActionInvocation = receiverRef.invoke(methodName);
    JVar intent = holder.getOnReceiveIntent();
    JVar extras = null;
    List<? extends VariableElement> methodParameters = executableElement.getParameters();
    for (VariableElement param : methodParameters) {
        AbstractJClass extraParamClass = codeModelHelper.typeMirrorToJClass(param.asType());
        if (extraParamClass.equals(getClasses().CONTEXT)) {
            callActionInvocation.arg(holder.getOnReceiveContext());
        } else if (extraParamClass.equals(getClasses().INTENT) && param.getAnnotation(ReceiverAction.Extra.class) == null) {
            callActionInvocation.arg(intent);
        } else if (param.getAnnotation(ReceiverAction.Extra.class) != null) {
            if (extras == null) {
                extras = callActionBlock.decl(getClasses().BUNDLE, "extras_", JOp.cond(//
                intent.invoke("getExtras").ne(_null()), intent.invoke("getExtras"), _new(getClasses().BUNDLE)));
            }
            callActionInvocation.arg(extraHandler.getExtraValue(param, extras, callActionBlock, holder));
        }
    }
    callActionBlock.add(callActionInvocation);
    callActionBlock._return();
}
Also used : IJExpression(com.helger.jcodemodel.IJExpression) JBlock(com.helger.jcodemodel.JBlock) AbstractJClass(com.helger.jcodemodel.AbstractJClass) JInvocation(com.helger.jcodemodel.JInvocation) VariableElement(javax.lang.model.element.VariableElement) JVar(com.helger.jcodemodel.JVar)

Example 48 with AbstractJClass

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

the class ReceiverActionHandler method createStaticField.

private JFieldVar createStaticField(EReceiverHolder holder, String prefix, String methodName, String[] values) {
    String staticFieldName = CaseHelper.camelCaseToUpperSnakeCase(prefix, methodName, null);
    if (values == null || values.length == 0) {
        return null;
    } else if (values.length == 1) {
        return holder.getGeneratedClass().field(PUBLIC | STATIC | FINAL, getClasses().STRING, staticFieldName, lit(values[0]));
    }
    JInvocation asListInvoke = getClasses().ARRAYS.staticInvoke("asList");
    for (String scheme : values) {
        asListInvoke.arg(scheme);
    }
    AbstractJClass listOfStrings = getClasses().LIST.narrow(getClasses().STRING);
    return holder.getGeneratedClass().field(PUBLIC | STATIC | FINAL, listOfStrings, staticFieldName, asListInvoke);
}
Also used : AbstractJClass(com.helger.jcodemodel.AbstractJClass) JInvocation(com.helger.jcodemodel.JInvocation)

Example 49 with AbstractJClass

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

the class ServiceActionHandler method addActionInOnHandleIntent.

private void addActionInOnHandleIntent(EIntentServiceHolder holder, ExecutableElement executableElement, String methodName, JFieldVar actionKeyField) {
    JMethod onHandleIntentMethod = holder.getOnHandleIntentMethod();
    // If action match, call the method
    JInvocation actionCondition = actionKeyField.invoke("equals").arg(holder.getOnHandleIntentIntentAction());
    JBlock callActionBlock = holder.getOnHandleIntentBody()._if(actionCondition)._then();
    JInvocation callActionInvocation = JExpr._super().invoke(methodName);
    // For each method params, we get back value from extras and put it
    // in super calls
    List<? extends VariableElement> methodParameters = executableElement.getParameters();
    if (methodParameters.size() > 0) {
        // Extras
        JVar intent = holder.getOnHandleIntentIntent();
        JVar extras = callActionBlock.decl(getClasses().BUNDLE, "extras");
        extras.init(intent.invoke("getExtras"));
        callActionBlock = callActionBlock._if(extras.ne(_null()))._then();
        // Extras params
        for (VariableElement param : methodParameters) {
            String paramName = param.getSimpleName().toString();
            String extraParamName = paramName + "Extra";
            JFieldVar paramVar = getStaticExtraField(holder, paramName);
            AbstractJClass extraParamClass = codeModelHelper.typeMirrorToJClass(param.asType());
            BundleHelper bundleHelper = new BundleHelper(getEnvironment(), param.asType());
            IJExpression getExtraExpression = bundleHelper.getExpressionToRestoreFromBundle(extraParamClass, extras, paramVar, onHandleIntentMethod);
            JVar extraField = callActionBlock.decl(extraParamClass, extraParamName, getExtraExpression);
            callActionInvocation.arg(extraField);
        }
    }
    callActionBlock.add(callActionInvocation);
    callActionBlock._return();
}
Also used : JFieldVar(com.helger.jcodemodel.JFieldVar) JBlock(com.helger.jcodemodel.JBlock) IJExpression(com.helger.jcodemodel.IJExpression) AbstractJClass(com.helger.jcodemodel.AbstractJClass) JInvocation(com.helger.jcodemodel.JInvocation) VariableElement(javax.lang.model.element.VariableElement) JMethod(com.helger.jcodemodel.JMethod) JVar(com.helger.jcodemodel.JVar) BundleHelper(org.androidannotations.helper.BundleHelper)

Example 50 with AbstractJClass

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

the class ProcessHolder method refClass.

public AbstractJClass refClass(String fullyQualifiedClassName) {
    int arrayCounter = 0;
    while (fullyQualifiedClassName.endsWith("[]")) {
        arrayCounter++;
        fullyQualifiedClassName = fullyQualifiedClassName.substring(0, fullyQualifiedClassName.length() - 2);
    }
    AbstractJClass refClass = loadedClasses.get(fullyQualifiedClassName);
    if (refClass == null) {
        refClass = codeModel.directClass(fullyQualifiedClassName);
        loadedClasses.put(fullyQualifiedClassName, refClass);
    }
    for (int i = 0; i < arrayCounter; i++) {
        refClass = refClass.array();
    }
    return refClass;
}
Also used : 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