Search in sources :

Example 21 with JFieldVar

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

the class PresentationModelObjectClassGen method defineFields.

/**
	 * Note: not private in order to improve performance.
	 * 
	 * final PresentationModelType presentationModel;
	 */
@Override
public void defineFields() {
    JFieldVar var = definedClass.field(JMod.FINAL, presentationModelClass, "presentationModel");
    presentationModelField = JExpr.refthis(var.name());
    presentationModelFieldWithoutThis = JExpr.ref(var.name());
}
Also used : JFieldVar(com.helger.jcodemodel.JFieldVar)

Example 22 with JFieldVar

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

the class EActivityHolder method setGetLastNonConfigurationInstance.

private void setGetLastNonConfigurationInstance() throws JClassAlreadyExistsException {
    AnnotationHelper annotationHelper = new AnnotationHelper(getEnvironment());
    TypeElement fragmentActivityTypeElement = annotationHelper.typeElementFromQualifiedName(CanonicalNameConstants.FRAGMENT_ACTIVITY);
    TypeElement typeElement = annotationHelper.typeElementFromQualifiedName(generatedClass._extends().fullName());
    String getLastNonConfigurationInstanceName = "getLastNonConfigurationInstance";
    if (fragmentActivityTypeElement != null && annotationHelper.isSubtype(typeElement.asType(), fragmentActivityTypeElement.asType())) {
        getLastNonConfigurationInstanceName = "getLastCustomNonConfigurationInstance";
    }
    NonConfigurationHolder ncHolder = getNonConfigurationHolder();
    JDefinedClass ncHolderClass = ncHolder.getGeneratedClass();
    JFieldVar superNonConfigurationInstanceField = ncHolder.getSuperNonConfigurationInstanceField();
    getLastNonConfigurationInstance = generatedClass.method(PUBLIC, Object.class, getLastNonConfigurationInstanceName);
    getLastNonConfigurationInstance.annotate(Override.class);
    JBlock body = getLastNonConfigurationInstance.body();
    JVar nonConfigurationInstance = body.decl(ncHolderClass, "nonConfigurationInstance", cast(ncHolderClass, _super().invoke(getLastNonConfigurationInstance)));
    body._if(nonConfigurationInstance.eq(_null()))._then()._return(_null());
    body._return(nonConfigurationInstance.ref(superNonConfigurationInstanceField));
}
Also used : JDefinedClass(com.helger.jcodemodel.JDefinedClass) JFieldVar(com.helger.jcodemodel.JFieldVar) AnnotationHelper(org.androidannotations.helper.AnnotationHelper) TypeElement(javax.lang.model.element.TypeElement) JBlock(com.helger.jcodemodel.JBlock) JVar(com.helger.jcodemodel.JVar)

Example 23 with JFieldVar

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

the class RoboGuiceHandler method process.

@Override
public void process(Element element, EActivityHolder holder) {
    RoboGuiceHolder roboGuiceHolder = holder.getPluginHolder(new RoboGuiceHolder(holder));
    holder.getGeneratedClass()._implements(getJClass(RoboGuiceClasses.ROBO_CONTEXT));
    JFieldVar scope = roboGuiceHolder.getScopeField();
    JFieldVar scopedObjects = roboGuiceHolder.getScopedObjectsField();
    JFieldVar eventManager = roboGuiceHolder.getEventManagerField();
    roboGuiceHolder.getContentViewListenerField();
    listenerFields(element, holder);
    beforeCreateMethod(holder, scope, scopedObjects, eventManager);
    onRestartMethod(holder, eventManager);
    onStartMethod(holder, eventManager);
    onResumeMethod(holder, eventManager);
    onPauseMethod(holder, eventManager);
    onNewIntentMethod(holder, eventManager);
    onStopMethod(holder, eventManager);
    onDestroyMethod(holder, eventManager);
    onConfigurationChangedMethod(holder, roboGuiceHolder, eventManager);
    onContentChangedMethod(roboGuiceHolder, scope, eventManager);
    onActivityResultMethod(holder, eventManager);
    getScopedObjectMap(holder, scopedObjects);
}
Also used : JFieldVar(com.helger.jcodemodel.JFieldVar) RoboGuiceHolder(org.androidannotations.roboguice.holder.RoboGuiceHolder)

Example 24 with JFieldVar

use of com.helger.jcodemodel.JFieldVar in project adt4j by sviperll.

the class FinalValueClassModel method buildCaseClass.

private JDefinedClass buildCaseClass(String interfaceMethodName, Serialization serialization) throws JClassAlreadyExistsException {
    JDefinedClass caseClass = environment.buildValueClassInnerClass(JMod.PRIVATE | JMod.STATIC, Source.capitalize(interfaceMethodName) + "Case" + environment.acceptingInterfaceName(), EClassType.CLASS);
    for (JTypeVar visitorTypeParameter : environment.getValueTypeParameters()) {
        JTypeVar typeParameter = caseClass.generify(visitorTypeParameter.name());
        typeParameter.boundLike(visitorTypeParameter);
    }
    AbstractJClass usedAcceptingInterfaceType = environment.acceptingInterfaceType(caseClass.typeParams());
    AbstractJClass usedValueClassType = environment.wrappedValueClassType(caseClass.typeParams());
    VisitorDefinition.VisitorUsage usedVisitor = environment.visitor(usedValueClassType, usedValueClassType, types._RuntimeException);
    MethodUsage interfaceMethod = usedVisitor.findMethod(interfaceMethodName);
    if (interfaceMethod == null)
        throw new IllegalStateException("Method with given name not found: " + interfaceMethodName);
    JTypeVar[] methodArguments = new JTypeVar[interfaceMethod.typeParams().length];
    for (int i = 0; i < methodArguments.length; i++) {
        JTypeVar visitorMethodTypeParameter = interfaceMethod.typeParams()[i];
        JTypeVar typeParameter = caseClass.generify(visitorMethodTypeParameter.name());
        typeParameter.boundLike(visitorMethodTypeParameter);
        methodArguments[i] = typeParameter;
    }
    MethodUsage usedInterfaceMethod = interfaceMethod.narrow(methodArguments);
    caseClass._implements(usedAcceptingInterfaceType);
    if (serialization.isSerializable()) {
        caseClass._implements(types._Serializable);
        caseClass.field(JMod.PRIVATE | JMod.FINAL | JMod.STATIC, types._long, "serialVersionUID", JExpr.lit(serialization.serialVersionUIDForGeneratedCode()));
    }
    JMethod constructor = caseClass.constructor(JMod.NONE);
    for (VariableDeclaration param : usedInterfaceMethod.params()) {
        AbstractJType paramType = param.type().declarable();
        JFieldVar field = caseClass.field(JMod.PRIVATE | JMod.FINAL, paramType, param.name());
        JVar argument = constructor.param(paramType, param.name());
        constructor.body().assign(JExpr._this().ref(field), argument);
    }
    VariableDeclaration param = usedInterfaceMethod.varParam();
    if (param != null) {
        AbstractJType paramType = param.type().elementType().declarable();
        JFieldVar field = caseClass.field(JMod.PRIVATE | JMod.FINAL, paramType.array(), param.name());
        JVar argument = constructor.varParam(paramType, param.name());
        constructor.body().assign(JExpr._this().ref(field), argument);
    }
    JMethod acceptMethod = declareAcceptMethod(caseClass, usedValueClassType);
    JInvocation invocation = JExpr.invoke(acceptMethod.params().get(0), usedInterfaceMethod.name());
    for (AbstractJClass argument : methodArguments) {
        invocation.narrow(argument);
    }
    for (VariableDeclaration param1 : usedInterfaceMethod.params()) {
        invocation.arg(JExpr._this().ref(param1.name()));
    }
    VariableDeclaration param1 = usedInterfaceMethod.varParam();
    if (param1 != null) {
        invocation.arg(JExpr._this().ref(param1.name()));
    }
    acceptMethod.body()._return(invocation);
    return caseClass;
}
Also used : VisitorDefinition(com.github.sviperll.adt4j.model.config.VisitorDefinition) JDefinedClass(com.helger.jcodemodel.JDefinedClass) AbstractJType(com.helger.jcodemodel.AbstractJType) AbstractJClass(com.helger.jcodemodel.AbstractJClass) JInvocation(com.helger.jcodemodel.JInvocation) JTypeVar(com.helger.jcodemodel.JTypeVar) JFieldVar(com.helger.jcodemodel.JFieldVar) VariableDeclaration(com.github.sviperll.adt4j.model.config.VariableDeclaration) MethodUsage(com.github.sviperll.adt4j.model.config.VisitorDefinition.MethodUsage) JMethod(com.helger.jcodemodel.JMethod) JVar(com.helger.jcodemodel.JVar)

Example 25 with JFieldVar

use of com.helger.jcodemodel.JFieldVar in project adt4j by sviperll.

the class FinalValueClassModel method createMethodBuilder.

MethodBuilder createMethodBuilder(Serialization serialization) {
    if (isError)
        return new MethodBuilder(null, null);
    else {
        JFieldVar acceptorField = buildAcceptorField();
        Map<String, JDefinedClass> caseClasses;
        try {
            caseClasses = buildCaseClasses(serialization);
        } catch (JClassAlreadyExistsException ex) {
            throw new RuntimeException("Unexpected exception :)", ex);
        }
        Caching hashCode = environment.hashCodeCaching();
        if (!hashCode.enabled())
            return new MethodBuilder(caseClasses, acceptorField);
        else {
            JFieldVar hashCodeField = buildHashCodeCachedValueField(serialization);
            return new MethodBuilder(caseClasses, acceptorField, hashCodeField);
        }
    }
}
Also used : JClassAlreadyExistsException(com.helger.jcodemodel.JClassAlreadyExistsException) Caching(com.github.sviperll.adt4j.Caching) JFieldVar(com.helger.jcodemodel.JFieldVar) JDefinedClass(com.helger.jcodemodel.JDefinedClass)

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