Search in sources :

Example 31 with JFieldVar

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

the class OrmLiteDaoHandler method assignValue.

@Override
public void assignValue(JBlock targetBlock, IJAssignmentTarget fieldRef, EComponentHolder holder, Element element, Element param) {
    OrmLiteHolder ormLiteHolder = holder.getPluginHolder(new OrmLiteHolder(holder));
    AbstractJClass modelClass = getJClass(ormLiteHelper.getEntityType(param).toString());
    AbstractJClass idClass = getJClass(ormLiteHelper.getEntityIdType(param).toString());
    IJExpression modelClassDotClass = modelClass.dotclass();
    AbstractJClass daoClass = getJClass(OrmLiteClasses.DAO).narrow(modelClass, idClass);
    AbstractJClass daoImplClass = codeModelHelper.typeMirrorToJClass(param.asType());
    TypeMirror databaseHelperTypeMirror = annotationHelper.extractAnnotationParameter(element, "helper");
    JFieldVar databaseHelperRef = ormLiteHolder.getDatabaseHelperRef(databaseHelperTypeMirror);
    IJExpression injectExpr = databaseHelperRef.invoke("getDao").arg(modelClassDotClass);
    if (elementExtendsRuntimeExceptionDao(param)) {
        injectExpr = _new(daoImplClass).arg(cast(daoClass, injectExpr));
    }
    JTryBlock tryBlock = targetBlock._try();
    tryBlock.body().add(fieldRef.assign(injectExpr));
    JCatchBlock catchBlock = tryBlock._catch(getClasses().SQL_EXCEPTION);
    JVar exception = catchBlock.param("e");
    String fieldName = param.getSimpleName().toString();
    //
    catchBlock.body().staticInvoke(getClasses().LOG, //
    "e").arg(//
    logTagForClassHolder(holder)).arg(//
    "Could not create DAO " + fieldName).arg(exception);
}
Also used : TypeMirror(javax.lang.model.type.TypeMirror) JFieldVar(com.helger.jcodemodel.JFieldVar) OrmLiteHolder(org.androidannotations.ormlite.holder.OrmLiteHolder) IJExpression(com.helger.jcodemodel.IJExpression) AbstractJClass(com.helger.jcodemodel.AbstractJClass) JTryBlock(com.helger.jcodemodel.JTryBlock) JCatchBlock(com.helger.jcodemodel.JCatchBlock) JVar(com.helger.jcodemodel.JVar)

Example 32 with JFieldVar

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

the class ReceiverHandler method process.

@Override
public void process(Element element, HasReceiverRegistration holder) throws Exception {
    String methodName = element.getSimpleName().toString();
    String receiverName = methodName + "Receiver" + generationSuffix();
    Receiver annotation = element.getAnnotation(Receiver.class);
    String[] actions = annotation.actions();
    String[] dataSchemes = annotation.dataSchemes();
    Receiver.RegisterAt registerAt = annotation.registerAt();
    boolean local = annotation.local();
    JFieldVar intentFilterField = holder.getIntentFilterField(new IntentFilterData(actions, dataSchemes, registerAt));
    JFieldVar receiverField = createReceiverField(holder, receiverName, methodName, (ExecutableElement) element);
    registerAndUnregisterReceiver(holder, registerAt, intentFilterField, receiverField, local);
}
Also used : IntentFilterData(org.androidannotations.holder.ReceiverRegistrationDelegate.IntentFilterData) JFieldVar(com.helger.jcodemodel.JFieldVar) Receiver(org.androidannotations.annotations.Receiver)

Example 33 with JFieldVar

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

the class ServiceActionHandler method addActionToIntentBuilder.

private void addActionToIntentBuilder(EIntentServiceHolder holder, ExecutableElement executableElement, String methodName, JFieldVar actionKeyField) {
    JMethod method = holder.getIntentBuilderClass().method(PUBLIC, holder.getIntentBuilderClass(), methodName);
    JBlock body = method.body();
    String docComment = getProcessingEnvironment().getElementUtils().getDocComment(executableElement);
    codeModelHelper.addTrimmedDocComment(method, docComment);
    method.javadoc().addReturn().append("the IntentBuilder to chain calls");
    // setAction
    body.invoke("action").arg(actionKeyField);
    for (VariableElement param : executableElement.getParameters()) {
        String paramName = param.getSimpleName().toString();
        AbstractJClass parameterClass = codeModelHelper.typeMirrorToJClass(param.asType());
        JFieldVar paramVar = getStaticExtraField(holder, paramName);
        JVar methodParam = method.param(parameterClass, paramName);
        JInvocation putExtraInvocation = holder.getIntentBuilder().getSuperPutExtraInvocation(param.asType(), methodParam, paramVar);
        body.add(putExtraInvocation);
    }
    body._return(JExpr._this());
}
Also used : JFieldVar(com.helger.jcodemodel.JFieldVar) JBlock(com.helger.jcodemodel.JBlock) 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)

Example 34 with JFieldVar

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

the class ServiceActionHandler method getStaticExtraField.

private JFieldVar getStaticExtraField(EIntentServiceHolder holder, String extraName) {
    String staticFieldName = CaseHelper.camelCaseToUpperSnakeCase(null, extraName, "Extra");
    JFieldVar staticExtraField = holder.getGeneratedClass().fields().get(staticFieldName);
    if (staticExtraField == null) {
        staticExtraField = holder.getGeneratedClass().field(PUBLIC | STATIC | FINAL, getClasses().STRING, staticFieldName, lit(extraName));
    }
    return staticExtraField;
}
Also used : JFieldVar(com.helger.jcodemodel.JFieldVar)

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