Search in sources :

Example 16 with JFieldVar

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

the class FragmentArgHandler method createBuilderInjectMethod.

public void createBuilderInjectMethod(EFragmentHolder holder, Element element, List<ArgHelper> argHelpers) {
    JDefinedClass builderClass = holder.getBuilderClass();
    JFieldRef builderArgsField = holder.getBuilderArgsField();
    JMethod builderMethod = builderClass.method(PUBLIC, holder.narrow(builderClass), element.getSimpleName().toString());
    String docComment = getProcessingEnvironment().getElementUtils().getDocComment(element);
    codeModelHelper.addTrimmedDocComment(builderMethod, docComment);
    for (ArgHelper argHelper : argHelpers) {
        String fieldName = argHelper.param.getSimpleName().toString();
        TypeMirror actualType = codeModelHelper.getActualTypeOfEnclosingElementOfInjectedElement(holder, argHelper.param);
        BundleHelper bundleHelper = new BundleHelper(getEnvironment(), actualType);
        JFieldVar argKeyStaticField = getOrCreateStaticArgField(holder, argHelper.argKey, fieldName);
        AbstractJClass paramClass = codeModelHelper.typeMirrorToJClass(actualType);
        JVar arg = builderMethod.param(paramClass, fieldName);
        builderMethod.body().add(bundleHelper.getExpressionToSaveFromField(builderArgsField, argKeyStaticField, arg));
        builderMethod.javadoc().addParam(fieldName).append("value for this Fragment argument");
    }
    builderMethod.javadoc().addReturn().append("the FragmentBuilder to chain calls");
    builderMethod.body()._return(_this());
}
Also used : JFieldRef(com.helger.jcodemodel.JFieldRef) JDefinedClass(com.helger.jcodemodel.JDefinedClass) TypeMirror(javax.lang.model.type.TypeMirror) JFieldVar(com.helger.jcodemodel.JFieldVar) AbstractJClass(com.helger.jcodemodel.AbstractJClass) JMethod(com.helger.jcodemodel.JMethod) BundleHelper(org.androidannotations.helper.BundleHelper) JVar(com.helger.jcodemodel.JVar)

Example 17 with JFieldVar

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

the class ReceiverActionHandler method process.

@Override
public void process(Element element, EReceiverHolder holder) throws Exception {
    ExecutableElement executableElement = (ExecutableElement) element;
    String methodName = element.getSimpleName().toString();
    ReceiverAction annotation = element.getAnnotation(ReceiverAction.class);
    String[] dataSchemes = annotation.dataSchemes();
    String[] actions = annotation.actions();
    JFieldVar actionKeyField = createStaticField(holder, "actions", methodName, actions);
    JFieldVar dataSchemesField = createStaticField(holder, "dataSchemes", methodName, dataSchemes);
    addActionInOnReceive(holder, executableElement, methodName, actionKeyField, dataSchemesField);
}
Also used : ReceiverAction(org.androidannotations.annotations.ReceiverAction) JFieldVar(com.helger.jcodemodel.JFieldVar) ExecutableElement(javax.lang.model.element.ExecutableElement)

Example 18 with JFieldVar

use of com.helger.jcodemodel.JFieldVar 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 19 with JFieldVar

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

the class ServiceActionHandler method process.

@Override
public void process(Element element, EIntentServiceHolder holder) throws Exception {
    ExecutableElement executableElement = (ExecutableElement) element;
    String methodName = element.getSimpleName().toString();
    ServiceAction annotation = element.getAnnotation(ServiceAction.class);
    String extraKey = annotation.value();
    if (extraKey.isEmpty()) {
        extraKey = methodName;
    }
    JFieldVar actionKeyField = createStaticActionField(holder, extraKey, methodName);
    addActionInOnHandleIntent(holder, executableElement, methodName, actionKeyField);
    addActionToIntentBuilder(holder, executableElement, methodName, actionKeyField);
}
Also used : JFieldVar(com.helger.jcodemodel.JFieldVar) ExecutableElement(javax.lang.model.element.ExecutableElement) ServiceAction(org.androidannotations.annotations.ServiceAction)

Example 20 with JFieldVar

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

the class ActivityIntentBuilder method addFragmentConstructor.

private JFieldVar addFragmentConstructor(AbstractJClass fragmentClass, String fieldName) {
    JFieldVar fragmentField = holder.getIntentBuilderClass().field(PRIVATE, fragmentClass, fieldName);
    IJExpression generatedClass = holder.getGeneratedClass().dotclass();
    JMethod constructor = holder.getIntentBuilderClass().constructor(JMod.PUBLIC);
    JVar constructorFragmentParam = constructor.param(fragmentClass, "fragment");
    JBlock constructorBody = constructor.body();
    constructorBody.invoke("super").arg(constructorFragmentParam.invoke("getActivity")).arg(generatedClass);
    constructorBody.assign(fragmentField, constructorFragmentParam);
    return fragmentField;
}
Also used : JFieldVar(com.helger.jcodemodel.JFieldVar) IJExpression(com.helger.jcodemodel.IJExpression) JBlock(com.helger.jcodemodel.JBlock) JMethod(com.helger.jcodemodel.JMethod) JVar(com.helger.jcodemodel.JVar)

Aggregations

JFieldVar (com.helger.jcodemodel.JFieldVar)34 AbstractJClass (com.helger.jcodemodel.AbstractJClass)13 JVar (com.helger.jcodemodel.JVar)12 JBlock (com.helger.jcodemodel.JBlock)11 JMethod (com.helger.jcodemodel.JMethod)10 IJExpression (com.helger.jcodemodel.IJExpression)7 JDefinedClass (com.helger.jcodemodel.JDefinedClass)5 JInvocation (com.helger.jcodemodel.JInvocation)5 TypeMirror (javax.lang.model.type.TypeMirror)5 BundleHelper (org.androidannotations.helper.BundleHelper)4 ExecutableElement (javax.lang.model.element.ExecutableElement)3 JFieldRef (com.helger.jcodemodel.JFieldRef)2 JTypeVar (com.helger.jcodemodel.JTypeVar)2 VariableElement (javax.lang.model.element.VariableElement)2 DeclaredType (javax.lang.model.type.DeclaredType)2 IntentBuilder (org.androidannotations.internal.core.helper.IntentBuilder)2 Caching (com.github.sviperll.adt4j.Caching)1 VariableDeclaration (com.github.sviperll.adt4j.model.config.VariableDeclaration)1 VisitorDefinition (com.github.sviperll.adt4j.model.config.VisitorDefinition)1 MethodUsage (com.github.sviperll.adt4j.model.config.VisitorDefinition.MethodUsage)1