Search in sources :

Example 76 with JBlock

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

the class EComponentHolder method setPowerManagerRef.

private void setPowerManagerRef() {
    JBlock methodBody = getInitBodyInjectionBlock();
    JFieldRef serviceRef = getClasses().CONTEXT.staticRef("POWER_SERVICE");
    powerManagerRef = getGeneratedClass().field(PRIVATE, getClasses().POWER_MANAGER, "powerManager" + generationSuffix());
    methodBody.assign(powerManagerRef, cast(getClasses().POWER_MANAGER, getContextRef().invoke("getSystemService").arg(serviceRef)));
}
Also used : JFieldRef(com.helger.jcodemodel.JFieldRef) JBlock(com.helger.jcodemodel.JBlock)

Example 77 with JBlock

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

the class EComponentWithViewSupportHolder method createFoundViewAndIfNotNullBlock.

protected FoundViewHolder createFoundViewAndIfNotNullBlock(JFieldRef idRef, AbstractJClass viewClass, IJAssignmentTarget fieldRef) {
    IJExpression findViewExpression = findViewById(idRef);
    JBlock block = getOnViewChangedBodyBeforeInjectionBlock();
    if (viewClass == null) {
        viewClass = getClasses().VIEW;
    } else if (viewClass != getClasses().VIEW) {
        findViewExpression = cast(viewClass, findViewExpression);
    }
    IJAssignmentTarget foundView = fieldRef;
    if (foundView == null) {
        JVar view = block.decl(viewClass, "view_" + idRef.name(), findViewExpression);
        if (viewClass.isParameterized()) {
            codeModelHelper.addSuppressWarnings(view, "unchecked");
        }
        foundView = view;
    } else {
        block.add(foundView.assign(findViewExpression));
    }
    return new FoundViewHolder(this, viewClass, foundView, getOnViewChangedBodyViewHolderBlock());
}
Also used : IJExpression(com.helger.jcodemodel.IJExpression) JBlock(com.helger.jcodemodel.JBlock) IJAssignmentTarget(com.helger.jcodemodel.IJAssignmentTarget) JVar(com.helger.jcodemodel.JVar)

Example 78 with JBlock

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

the class EComponentWithViewSupportHolder method setFindNativeFragmentByTag.

protected void setFindNativeFragmentByTag() {
    findNativeFragmentByTag = getGeneratedClass().method(PRIVATE, getClasses().FRAGMENT, "findNativeFragmentByTag");
    JVar tagParam = findNativeFragmentByTag.param(getClasses().STRING, "tag");
    JBlock body = findNativeFragmentByTag.body();
    body._if(getContextRef()._instanceof(getClasses().ACTIVITY).not())._then()._return(_null());
    JVar activityVar = body.decl(getClasses().ACTIVITY, "activity_", cast(getClasses().ACTIVITY, getContextRef()));
    body._return(activityVar.invoke("getFragmentManager").invoke("findFragmentByTag").arg(tagParam));
}
Also used : JBlock(com.helger.jcodemodel.JBlock) JVar(com.helger.jcodemodel.JVar)

Example 79 with JBlock

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

the class EComponentWithViewSupportHolder method setFindSupportFragmentById.

protected void setFindSupportFragmentById() {
    findSupportFragmentById = getGeneratedClass().method(PRIVATE, getClasses().SUPPORT_V4_FRAGMENT, "findSupportFragmentById");
    JVar idParam = findSupportFragmentById.param(getCodeModel().INT, "id");
    JBlock body = findSupportFragmentById.body();
    body._if(getContextRef()._instanceof(getClasses().FRAGMENT_ACTIVITY).not())._then()._return(_null());
    JVar activityVar = body.decl(getClasses().FRAGMENT_ACTIVITY, "activity_", cast(getClasses().FRAGMENT_ACTIVITY, getContextRef()));
    body._return(activityVar.invoke("getSupportFragmentManager").invoke("findFragmentById").arg(idParam));
}
Also used : JBlock(com.helger.jcodemodel.JBlock) JVar(com.helger.jcodemodel.JVar)

Example 80 with JBlock

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

the class EComponentWithViewSupportHolder method createPageChangeHolder.

private PageChangeHolder createPageChangeHolder(JFieldRef idRef, TypeMirror viewParameterType, boolean hasAddOnPageChangeListenerMethod) {
    JDefinedClass onPageChangeListenerClass = getCodeModel().anonymousClass(getClasses().PAGE_CHANGE_LISTENER);
    AbstractJClass viewClass = getClasses().VIEW_PAGER;
    if (viewParameterType != null) {
        viewClass = getJClass(viewParameterType.toString());
    }
    JBlock onViewChangedBody = getOnViewChangedBodyInjectionBlock().blockSimple();
    JVar viewVariable = onViewChangedBody.decl(FINAL, viewClass, "view", cast(viewClass, findViewById(idRef)));
    JBlock block = onViewChangedBody._if(viewVariable.ne(JExpr._null()))._then();
    if (hasAddOnPageChangeListenerMethod) {
        block.invoke(viewVariable, "addOnPageChangeListener").arg(_new(onPageChangeListenerClass));
    } else {
        block.invoke(viewVariable, "setOnPageChangeListener").arg(_new(onPageChangeListenerClass));
    }
    return new PageChangeHolder(this, viewVariable, onPageChangeListenerClass);
}
Also used : JDefinedClass(com.helger.jcodemodel.JDefinedClass) JBlock(com.helger.jcodemodel.JBlock) AbstractJClass(com.helger.jcodemodel.AbstractJClass) JVar(com.helger.jcodemodel.JVar)

Aggregations

JBlock (com.helger.jcodemodel.JBlock)148 JVar (com.helger.jcodemodel.JVar)81 JMethod (com.helger.jcodemodel.JMethod)73 JInvocation (com.helger.jcodemodel.JInvocation)37 AbstractJClass (com.helger.jcodemodel.AbstractJClass)35 IJExpression (com.helger.jcodemodel.IJExpression)31 ExecutableElement (javax.lang.model.element.ExecutableElement)25 JFieldRef (com.helger.jcodemodel.JFieldRef)19 JDefinedClass (com.helger.jcodemodel.JDefinedClass)15 VariableElement (javax.lang.model.element.VariableElement)15 TypeMirror (javax.lang.model.type.TypeMirror)13 JFieldVar (com.helger.jcodemodel.JFieldVar)11 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 TextWatcherHolder (org.androidannotations.holder.TextWatcherHolder)3 AbstractJType (com.helger.jcodemodel.AbstractJType)2 IJAssignmentTarget (com.helger.jcodemodel.IJAssignmentTarget)2