Search in sources :

Example 91 with AbstractJClass

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

the class AbstractViewListenerHandler method assignListeners.

@Override
protected final void assignListeners(EComponentWithViewSupportHolder holder, List<JFieldRef> idsRefs, JDefinedClass listenerAnonymousClass) {
    for (JFieldRef idRef : idsRefs) {
        AbstractJClass listenerTargetClass = getListenerTargetClass(holder);
        FoundViewHolder foundViewHolder = holder.getFoundViewHolder(idRef, listenerTargetClass);
        foundViewHolder.getIfNotNullBlock().invoke(foundViewHolder.getOrCastRef(listenerTargetClass), getSetterName()).arg(_new(listenerAnonymousClass));
    }
}
Also used : JFieldRef(com.helger.jcodemodel.JFieldRef) FoundViewHolder(org.androidannotations.holder.FoundViewHolder) AbstractJClass(com.helger.jcodemodel.AbstractJClass)

Example 92 with AbstractJClass

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

the class ExtraParameterHandler method getExtraValue.

public IJExpression getExtraValue(VariableElement parameter, JVar extras, JBlock block, JMethod annotatedMethod, JDefinedClass generatedClass) {
    String parameterName = parameter.getSimpleName().toString();
    AbstractJClass parameterClass = codeModelHelper.typeMirrorToJClass(parameter.asType());
    String extraKey = getAnnotationValue(parameter);
    if (extraKey == null || extraKey.isEmpty()) {
        extraKey = parameterName;
    }
    BundleHelper bundleHelper = new BundleHelper(getEnvironment(), parameter.asType());
    IJExpression restoreMethodCall = bundleHelper.getExpressionToRestoreFromBundle(parameterClass, extras, getStaticExtraField(generatedClass, extraKey), annotatedMethod);
    return block.decl(parameterClass, parameterName, restoreMethodCall);
}
Also used : IJExpression(com.helger.jcodemodel.IJExpression) AbstractJClass(com.helger.jcodemodel.AbstractJClass) BundleHelper(org.androidannotations.helper.BundleHelper)

Example 93 with AbstractJClass

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

the class EViewHolder method createConstructorAndBuilder.

private void createConstructorAndBuilder() {
    List<ExecutableElement> constructors = new ArrayList<>();
    for (Element e : annotatedElement.getEnclosedElements()) {
        if (e.getKind() == CONSTRUCTOR) {
            constructors.add((ExecutableElement) e);
        }
    }
    for (ExecutableElement userConstructor : constructors) {
        JMethod copyConstructor = generatedClass.constructor(PUBLIC);
        JMethod staticHelper = generatedClass.method(PUBLIC | STATIC, generatedClass._extends(), "build");
        codeModelHelper.generify(staticHelper, getAnnotatedElement());
        JBlock body = copyConstructor.body();
        JInvocation superCall = body.invoke("super");
        AbstractJClass narrowedGeneratedClass = narrow(generatedClass);
        JInvocation newInvocation = JExpr._new(narrowedGeneratedClass);
        for (VariableElement param : userConstructor.getParameters()) {
            String paramName = param.getSimpleName().toString();
            AbstractJClass paramType = codeModelHelper.typeMirrorToJClass(param.asType());
            copyConstructor.param(paramType, paramName);
            staticHelper.param(paramType, paramName);
            superCall.arg(JExpr.ref(paramName));
            newInvocation.arg(JExpr.ref(paramName));
        }
        JVar newCall = staticHelper.body().decl(narrowedGeneratedClass, "instance", newInvocation);
        staticHelper.body().invoke(newCall, getOnFinishInflate());
        staticHelper.body()._return(newCall);
        body.invoke(getInit());
    }
}
Also used : ExecutableElement(javax.lang.model.element.ExecutableElement) ExecutableElement(javax.lang.model.element.ExecutableElement) VariableElement(javax.lang.model.element.VariableElement) Element(javax.lang.model.element.Element) TypeElement(javax.lang.model.element.TypeElement) ArrayList(java.util.ArrayList) 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 94 with AbstractJClass

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

the class EFragmentHolder method setFragmentBuilder.

private void setFragmentBuilder() throws JClassAlreadyExistsException {
    fragmentBuilderClass = generatedClass._class(PUBLIC | STATIC, "FragmentBuilder" + generationSuffix());
    narrowBuilderClass = narrow(fragmentBuilderClass);
    codeModelHelper.generify(fragmentBuilderClass, annotatedElement);
    AbstractJClass superClass = getJClass(org.androidannotations.api.builder.FragmentBuilder.class);
    superClass = superClass.narrow(narrowBuilderClass, getAnnotatedClass());
    fragmentBuilderClass._extends(superClass);
    fragmentArgumentsBuilderField = ref("args");
    setFragmentBuilderBuild();
    setFragmentBuilderCreate();
}
Also used : AbstractJClass(com.helger.jcodemodel.AbstractJClass)

Example 95 with AbstractJClass

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

the class EFragmentHolder method setFragmentBuilderBuild.

private void setFragmentBuilderBuild() {
    JMethod method = fragmentBuilderClass.method(PUBLIC, generatedClass._extends(), "build");
    method.annotate(Override.class);
    JBlock body = method.body();
    AbstractJClass result = narrow(generatedClass);
    JVar fragment = body.decl(result, "fragment_", _new(result));
    body.invoke(fragment, "setArguments").arg(fragmentArgumentsBuilderField);
    body._return(fragment);
}
Also used : JBlock(com.helger.jcodemodel.JBlock) AbstractJClass(com.helger.jcodemodel.AbstractJClass) JMethod(com.helger.jcodemodel.JMethod) JVar(com.helger.jcodemodel.JVar)

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