Search in sources :

Example 66 with AbstractJClass

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

the class InjectHelper method processParam.

private void processParam(Element element, T holder) {
    ExecutableElement method = (ExecutableElement) element.getEnclosingElement();
    List<? extends VariableElement> parameters = method.getParameters();
    List<ParamHelper> parameterList = methodParameterMap.get(method);
    JBlock targetBlock = methodBlockMap.get(method);
    int paramCount = parameters.size();
    if (parameterList == null) {
        parameterList = new ArrayList<>();
        methodParameterMap.put(method, parameterList);
    }
    if (targetBlock == null) {
        targetBlock = createBlock(holder, true);
        methodBlockMap.put(method, targetBlock);
    }
    for (int paramIndex = 0; paramIndex < paramCount; paramIndex++) {
        VariableElement param = parameters.get(paramIndex);
        if (param.equals(element)) {
            AbstractJClass type = codeModelHelper.typeMirrorToJClass(param.asType());
            JVar fieldRef = targetBlock.decl(type, param.getSimpleName().toString(), getDefault(param.asType()));
            handler.assignValue(targetBlock, fieldRef, holder, param, param);
            parameterList.add(new ParamHelper(fieldRef, paramIndex, param));
        }
    }
    if (parameterList.size() == paramCount) {
        String methodName = method.getSimpleName().toString();
        Collections.sort(parameterList);
        JInvocation invocation = JExpr.invoke(methodName);
        for (ParamHelper parameter : parameterList) {
            invocation.arg(parameter.beanInstance);
        }
        targetBlock.add(invocation);
        if (handler instanceof MethodInjectionHandler.AfterAllParametersInjectedHandler<?>) {
            ((MethodInjectionHandler.AfterAllParametersInjectedHandler<T>) handler).afterAllParametersInjected(holder, method, parameterList);
        }
        methodParameterMap.remove(method);
    }
}
Also used : ExecutableElement(javax.lang.model.element.ExecutableElement) AbstractJClass(com.helger.jcodemodel.AbstractJClass) JInvocation(com.helger.jcodemodel.JInvocation) VariableElement(javax.lang.model.element.VariableElement) JBlock(com.helger.jcodemodel.JBlock) JVar(com.helger.jcodemodel.JVar)

Example 67 with AbstractJClass

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

the class EComponentWithViewSupportHolder method setOnViewChanged.

protected void setOnViewChanged() {
    getGeneratedClass()._implements(OnViewChangedListener.class);
    onViewChanged = getGeneratedClass().method(PUBLIC, getCodeModel().VOID, "onViewChanged");
    onViewChanged.annotate(Override.class);
    onViewChangedBody = onViewChanged.body();
    onViewChangedBodyBeforeInjectionBlock = onViewChangedBody.blockVirtual();
    onViewChangedBodyViewHolderBlock = onViewChangedBody.blockVirtual();
    onViewChangedBodyInjectionBlock = onViewChangedBody.blockVirtual();
    onViewChangedBodyAfterInjectionBlock = onViewChangedBody.blockVirtual();
    onViewChangedHasViewsParam = onViewChanged.param(HasViews.class, "hasViews");
    AbstractJClass notifierClass = getJClass(OnViewChangedNotifier.class);
    getInitBodyInjectionBlock().staticInvoke(notifierClass, "registerOnViewChangedListener").arg(_this());
}
Also used : AbstractJClass(com.helger.jcodemodel.AbstractJClass) HasViews(org.androidannotations.api.view.HasViews)

Example 68 with AbstractJClass

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

the class EComponentWithViewSupportHolder method createOnSeekBarChangeListenerHolder.

private OnSeekBarChangeListenerHolder createOnSeekBarChangeListenerHolder(JFieldRef idRef) {
    JDefinedClass onSeekbarChangeListenerClass = getCodeModel().anonymousClass(getClasses().ON_SEEKBAR_CHANGE_LISTENER);
    AbstractJClass viewClass = getClasses().SEEKBAR;
    FoundViewHolder foundViewHolder = getFoundViewHolder(idRef, viewClass);
    foundViewHolder.getIfNotNullBlock().invoke(foundViewHolder.getRef(), "setOnSeekBarChangeListener").arg(_new(onSeekbarChangeListenerClass));
    return new OnSeekBarChangeListenerHolder(this, onSeekbarChangeListenerClass);
}
Also used : JDefinedClass(com.helger.jcodemodel.JDefinedClass) AbstractJClass(com.helger.jcodemodel.AbstractJClass)

Example 69 with AbstractJClass

use of com.helger.jcodemodel.AbstractJClass 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)

Example 70 with AbstractJClass

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

the class EActivityHolder method setInit.

@Override
protected void setInit() {
    init = generatedClass.method(PRIVATE, getCodeModel().VOID, "init" + generationSuffix());
    AbstractJClass bundleClass = getClasses().BUNDLE;
    initSavedInstanceParam = init.param(bundleClass, "savedInstanceState");
    getOnCreate();
}
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