Search in sources :

Example 1 with AnnotationHelper

use of org.androidannotations.helper.AnnotationHelper in project androidannotations by androidannotations.

the class EActivityHolder method setOnRetainNonConfigurationInstance.

private void setOnRetainNonConfigurationInstance() throws JClassAlreadyExistsException {
    AnnotationHelper annotationHelper = new AnnotationHelper(getEnvironment());
    TypeElement fragmentActivityTypeElement = annotationHelper.typeElementFromQualifiedName(CanonicalNameConstants.FRAGMENT_ACTIVITY);
    TypeElement typeElement = annotationHelper.typeElementFromQualifiedName(generatedClass._extends().fullName());
    String onRetainNonConfigurationInstanceName = "onRetainNonConfigurationInstance";
    if (fragmentActivityTypeElement != null && annotationHelper.isSubtype(typeElement.asType(), fragmentActivityTypeElement.asType())) {
        onRetainNonConfigurationInstanceName = "onRetainCustomNonConfigurationInstance";
    }
    NonConfigurationHolder ncHolder = getNonConfigurationHolder();
    JDefinedClass ncHolderClass = ncHolder.getGeneratedClass();
    JMethod onRetainNonConfigurationInstanceMethod = generatedClass.method(PUBLIC, ncHolderClass, onRetainNonConfigurationInstanceName);
    onRetainNonConfigurationInstanceMethod.annotate(Override.class);
    JBlock methodBody = onRetainNonConfigurationInstanceMethod.body();
    onRetainNonConfigurationInstance = methodBody.decl(ncHolderClass, "nonConfigurationInstanceState_", _new(ncHolderClass));
    IJExpression superCall = _super().invoke(onRetainNonConfigurationInstanceMethod);
    methodBody.assign(onRetainNonConfigurationInstance.ref(ncHolder.getSuperNonConfigurationInstanceField()), superCall);
    onRetainNonConfigurationInstanceBindBlock = methodBody.blockSimple();
    methodBody._return(onRetainNonConfigurationInstance);
}
Also used : JDefinedClass(com.helger.jcodemodel.JDefinedClass) AnnotationHelper(org.androidannotations.helper.AnnotationHelper) TypeElement(javax.lang.model.element.TypeElement) JBlock(com.helger.jcodemodel.JBlock) IJExpression(com.helger.jcodemodel.IJExpression) JMethod(com.helger.jcodemodel.JMethod)

Example 2 with AnnotationHelper

use of org.androidannotations.helper.AnnotationHelper 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)

Aggregations

JBlock (com.helger.jcodemodel.JBlock)2 JDefinedClass (com.helger.jcodemodel.JDefinedClass)2 TypeElement (javax.lang.model.element.TypeElement)2 AnnotationHelper (org.androidannotations.helper.AnnotationHelper)2 IJExpression (com.helger.jcodemodel.IJExpression)1 JFieldVar (com.helger.jcodemodel.JFieldVar)1 JMethod (com.helger.jcodemodel.JMethod)1 JVar (com.helger.jcodemodel.JVar)1