Search in sources :

Example 36 with JBlock

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

the class EBeanHolder method setConstructors.

private void setConstructors() {
    constructor = generatedClass.constructor(PRIVATE);
    JVar constructorContextParam = constructor.param(getClasses().CONTEXT, "context");
    JBlock constructorBody = constructor.body();
    List<ExecutableElement> constructors = ElementFilter.constructorsIn(annotatedElement.getEnclosedElements());
    ExecutableElement superConstructor = constructors.get(0);
    if (superConstructor.getParameters().size() == 1) {
        constructorBody.invoke("super").arg(constructorContextParam);
    }
    constructorBody.assign(getContextField(), constructorContextParam);
    overloadedConstructor = generatedClass.constructor(PRIVATE);
    JVar overloadedConstructorContextParam = overloadedConstructor.param(getClasses().CONTEXT, "context");
    JVar overloadedConstructorRootFragmentParam = overloadedConstructor.param(getClasses().OBJECT, "rootFragment");
    JBlock overloadedConstructorBody = overloadedConstructor.body();
    if (superConstructor.getParameters().size() == 1) {
        overloadedConstructorBody.invokeSuper().arg(constructorContextParam);
    }
    overloadedConstructorBody.assign(getContextField(), overloadedConstructorContextParam);
    overloadedConstructorBody.assign(getRootFragmentField(), overloadedConstructorRootFragmentParam);
}
Also used : ExecutableElement(javax.lang.model.element.ExecutableElement) JBlock(com.helger.jcodemodel.JBlock) JVar(com.helger.jcodemodel.JVar)

Example 37 with JBlock

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

the class EBeanHolder method createOverloadedFactoryMethod.

private void createOverloadedFactoryMethod(EBean.Scope scope) {
    AbstractJClass narrowedGeneratedClass = codeModelHelper.narrowGeneratedClass(generatedClass, annotatedElement.asType());
    JMethod factoryMethod = generatedClass.method(PUBLIC | STATIC, narrowedGeneratedClass, GET_INSTANCE_METHOD_NAME);
    codeModelHelper.generify(factoryMethod, annotatedElement);
    JVar factoryMethodContextParam = factoryMethod.param(getClasses().CONTEXT, "context");
    JVar factoryMethodRootFragmentParam = factoryMethod.param(getClasses().OBJECT, "rootFragment");
    JBlock factoryMethodBody = factoryMethod.body();
    if (scope == EBean.Scope.Fragment) {
        requestInstanceFromBeanHolder(factoryMethodRootFragmentParam, factoryMethodContextParam, factoryMethodBody);
    }
    factoryMethodBody._return(_new(narrowedGeneratedClass).arg(factoryMethodContextParam).arg(factoryMethodRootFragmentParam));
}
Also used : JBlock(com.helger.jcodemodel.JBlock) AbstractJClass(com.helger.jcodemodel.AbstractJClass) JMethod(com.helger.jcodemodel.JMethod) JVar(com.helger.jcodemodel.JVar)

Example 38 with JBlock

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

the class RestHandler method setConverters.

private void setConverters(Element element, RestHolder holder) {
    List<DeclaredType> converters = annotationHelper.extractAnnotationClassArrayParameter(element, getTarget(), "converters");
    JFieldVar restTemplateField = holder.getRestTemplateField();
    JBlock init = holder.getInit().body();
    init.add(invoke(restTemplateField, "getMessageConverters").invoke("clear"));
    for (DeclaredType converterType : converters) {
        JInvocation newConverter = codeModelHelper.newBeanOrEBean(converterType, holder.getInitContextParam());
        init.add(invoke(restTemplateField, "getMessageConverters").invoke("add").arg(newConverter));
    }
}
Also used : JFieldVar(com.helger.jcodemodel.JFieldVar) JBlock(com.helger.jcodemodel.JBlock) JInvocation(com.helger.jcodemodel.JInvocation) DeclaredType(javax.lang.model.type.DeclaredType)

Example 39 with JBlock

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

the class RoboGuiceHandler method onDestroyMethod.

private void onDestroyMethod(EActivityHolder holder, JFieldVar eventManager) {
    JBlock onDestroyBlock = new JBlock().bracesRequired(false).indentRequired(false);
    JTryBlock tryBlock = onDestroyBlock._try();
    fireEvent(eventManager, tryBlock.body(), getJClass(RoboGuiceClasses.ON_DESTROY_EVENT));
    JBlock finallyBody = tryBlock._finally();
    JTryBlock tryInFinally = finallyBody._try();
    tryInFinally.body().add(getJClass(RoboGuiceClasses.ROBO_GUICE).staticInvoke("destroyInjector").arg(_this()));
    tryInFinally._finally().invoke(_super(), "onDestroy");
    JMethod onDestroy = holder.getOnDestroy();
    codeModelHelper.replaceSuperCall(onDestroy, onDestroyBlock);
}
Also used : JBlock(com.helger.jcodemodel.JBlock) JTryBlock(com.helger.jcodemodel.JTryBlock) JMethod(com.helger.jcodemodel.JMethod)

Example 40 with JBlock

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

the class RoboGuiceHandler method onResumeMethod.

private void onResumeMethod(EActivityHolder holder, JFieldVar eventManager) {
    JBlock onResumeAfterSuperBlock = holder.getOnResumeAfterSuperBlock();
    fireEvent(eventManager, onResumeAfterSuperBlock, getJClass(RoboGuiceClasses.ON_RESUME_EVENT));
}
Also used : JBlock(com.helger.jcodemodel.JBlock)

Aggregations

JBlock (com.helger.jcodemodel.JBlock)155 JVar (com.helger.jcodemodel.JVar)86 JMethod (com.helger.jcodemodel.JMethod)75 AbstractJClass (com.helger.jcodemodel.AbstractJClass)40 JInvocation (com.helger.jcodemodel.JInvocation)38 IJExpression (com.helger.jcodemodel.IJExpression)31 ExecutableElement (javax.lang.model.element.ExecutableElement)26 JFieldRef (com.helger.jcodemodel.JFieldRef)19 JDefinedClass (com.helger.jcodemodel.JDefinedClass)15 VariableElement (javax.lang.model.element.VariableElement)15 JFieldVar (com.helger.jcodemodel.JFieldVar)13 TypeMirror (javax.lang.model.type.TypeMirror)13 JConditional (com.helger.jcodemodel.JConditional)10 JTryBlock (com.helger.jcodemodel.JTryBlock)9 JCatchBlock (com.helger.jcodemodel.JCatchBlock)4 TypeElement (javax.lang.model.element.TypeElement)3 PageChangeHolder (org.androidannotations.holder.PageChangeHolder)3 AbstractJType (com.helger.jcodemodel.AbstractJType)2 IJAssignmentTarget (com.helger.jcodemodel.IJAssignmentTarget)2 IJStatement (com.helger.jcodemodel.IJStatement)2