Search in sources :

Example 46 with JMethod

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

the class EActivityHolder method setFindSupportFragmentByTag.

@Override
protected void setFindSupportFragmentByTag() {
    JMethod method = generatedClass.method(PRIVATE, getClasses().SUPPORT_V4_FRAGMENT, "findSupportFragmentByTag");
    JVar tagParam = method.param(getClasses().STRING, "tag");
    JBlock body = method.body();
    body._return(invoke("getSupportFragmentManager").invoke("findFragmentByTag").arg(tagParam));
    findSupportFragmentByTag = method;
}
Also used : JBlock(com.helger.jcodemodel.JBlock) JMethod(com.helger.jcodemodel.JMethod) JVar(com.helger.jcodemodel.JVar)

Example 47 with JMethod

use of com.helger.jcodemodel.JMethod 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 48 with JMethod

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

the class EApplicationHolder method createSingleton.

private void createSingleton() {
    AbstractJClass annotatedComponent = generatedClass._extends();
    staticInstanceField = generatedClass.field(PRIVATE | STATIC, annotatedComponent, "INSTANCE" + generationSuffix());
    // Static singleton getter and setter
    JMethod getInstance = generatedClass.method(PUBLIC | STATIC, annotatedComponent, GET_APPLICATION_INSTANCE);
    getInstance.body()._return(staticInstanceField);
    JMethod setInstance = generatedClass.method(PUBLIC | STATIC, getCodeModel().VOID, "setForTesting");
    setInstance.javadoc().append("Visible for testing purposes");
    JVar applicationParam = setInstance.param(annotatedComponent, "application");
    setInstance.body().assign(staticInstanceField, applicationParam);
}
Also used : AbstractJClass(com.helger.jcodemodel.AbstractJClass) JMethod(com.helger.jcodemodel.JMethod) JVar(com.helger.jcodemodel.JVar)

Example 49 with JMethod

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

the class RestHolder method implementGetCookie.

private void implementGetCookie(List<ExecutableElement> methods) {
    JMethod getCookieMethod = codeModelHelper.implementMethod(this, methods, "getCookie", STRING, STRING);
    if (getCookieMethod != null) {
        JInvocation cookieValue = JExpr.invoke(getAvailableCookiesField(), "get").arg(getCookieMethod.params().get(0));
        getCookieMethod.body()._return(cookieValue);
    }
}
Also used : JInvocation(com.helger.jcodemodel.JInvocation) JMethod(com.helger.jcodemodel.JMethod)

Example 50 with JMethod

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

the class RestHolder method implementSetErrorHandler.

private void implementSetErrorHandler(List<ExecutableElement> methods) {
    JMethod setErrorHandlerMethod = codeModelHelper.implementMethod(this, methods, "setRestErrorHandler", TypeKind.VOID.toString(), RestErrorHandler.class.getName());
    if (setErrorHandlerMethod != null) {
        setRestErrorHandlerField();
        setErrorHandlerMethod.body().assign(_this().ref(getRestErrorHandlerField()), setErrorHandlerMethod.params().get(0));
    }
}
Also used : RestErrorHandler(org.androidannotations.rest.spring.api.RestErrorHandler) JMethod(com.helger.jcodemodel.JMethod)

Aggregations

JMethod (com.helger.jcodemodel.JMethod)122 JBlock (com.helger.jcodemodel.JBlock)73 JVar (com.helger.jcodemodel.JVar)56 AbstractJClass (com.helger.jcodemodel.AbstractJClass)36 JInvocation (com.helger.jcodemodel.JInvocation)26 JDefinedClass (com.helger.jcodemodel.JDefinedClass)20 IJExpression (com.helger.jcodemodel.IJExpression)15 ExecutableElement (javax.lang.model.element.ExecutableElement)13 JFieldVar (com.helger.jcodemodel.JFieldVar)10 JConditional (com.helger.jcodemodel.JConditional)8 JTryBlock (com.helger.jcodemodel.JTryBlock)7 JTypeVar (com.helger.jcodemodel.JTypeVar)7 TypeMirror (javax.lang.model.type.TypeMirror)7 VariableElement (javax.lang.model.element.VariableElement)6 JFieldRef (com.helger.jcodemodel.JFieldRef)5 JPrimitiveType (com.helger.jcodemodel.JPrimitiveType)5 ArrayList (java.util.ArrayList)5 VisitorDefinition (com.github.sviperll.adt4j.model.config.VisitorDefinition)4 GenerationProcess (com.github.sviperll.adt4j.model.util.GenerationProcess)4 AbstractJType (com.helger.jcodemodel.AbstractJType)4