Search in sources :

Example 16 with JMethod

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

the class KeyEventCallbackMethodsDelegate method createOnKeyDownMethod.

private void createOnKeyDownMethod() {
    JMethod method = getGeneratedClass().method(PUBLIC, codeModel().BOOLEAN, "onKeyDown");
    method.annotate(Override.class);
    JVar keyCode = method.param(codeModel().INT, "keyCode");
    onKeyDownKeyEventParam = method.param(getClasses().KEY_EVENT, "keyEvent");
    JBlock methodBody = method.body();
    onKeyDownSwitchBody = methodBody._switch(keyCode);
    methodBody._return(_super().invoke(method).arg(keyCode).arg(onKeyDownKeyEventParam));
}
Also used : JBlock(com.helger.jcodemodel.JBlock) JMethod(com.helger.jcodemodel.JMethod) JVar(com.helger.jcodemodel.JVar)

Example 17 with JMethod

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

the class APTCodeModelHelper method implementMethod.

public JMethod implementMethod(GeneratedClassHolder holder, List<ExecutableElement> methods, String methodName, String returnType, boolean finalParams, String... parameterTypes) {
    // First get the ExecutableElement method object from the util function.
    ExecutableElement method = getMethod(methods, methodName, returnType, parameterTypes);
    JMethod jmethod = null;
    if (method != null) {
        // Get the return type or VOID if none.
        AbstractJType jcReturnType = returnType.equals(TypeKind.VOID.toString()) ? environment.getCodeModel().VOID : environment.getJClass(returnType);
        // Create the implementation and annotate it with the Override
        // annotation.
        jmethod = holder.getGeneratedClass().method(JMod.PUBLIC, jcReturnType, method.getSimpleName().toString());
        jmethod.annotate(Override.class);
        // Create the parameters.
        int paramMods = finalParams ? JMod.FINAL : JMod.NONE;
        for (int i = 0; i < method.getParameters().size(); i++) {
            VariableElement param = method.getParameters().get(i);
            jmethod.param(paramMods, environment.getJClass(parameterTypes[i]), param.getSimpleName().toString());
        }
    }
    return jmethod;
}
Also used : ExecutableElement(javax.lang.model.element.ExecutableElement) AbstractJType(com.helger.jcodemodel.AbstractJType) VariableElement(javax.lang.model.element.VariableElement) JMethod(com.helger.jcodemodel.JMethod)

Example 18 with JMethod

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

the class EActivityHolder method setContentViewMethod.

private JMethod setContentViewMethod(AbstractJType[] paramTypes, String[] paramNames) {
    JMethod method = generatedClass.method(JMod.PUBLIC, getCodeModel().VOID, "setContentView");
    method.annotate(Override.class);
    List<JVar> params = new ArrayList<>();
    for (int i = 0; i < paramTypes.length; i++) {
        JVar param = method.param(paramTypes[i], paramNames[i]);
        params.add(param);
    }
    JBlock body = method.body();
    JInvocation superCall = body.invoke(JExpr._super(), method);
    for (JVar arg : params) {
        superCall.arg(arg);
    }
    viewNotifierHelper.invokeViewChanged(body);
    return method;
}
Also used : ArrayList(java.util.ArrayList) JBlock(com.helger.jcodemodel.JBlock) JInvocation(com.helger.jcodemodel.JInvocation) JMethod(com.helger.jcodemodel.JMethod) JVar(com.helger.jcodemodel.JVar)

Example 19 with JMethod

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

the class EActivityHolder method setOnResume.

private void setOnResume() {
    JMethod method = generatedClass.method(JMod.PUBLIC, getCodeModel().VOID, "onResume");
    method.annotate(Override.class);
    JBlock body = method.body();
    onResumeBeforeSuperBlock = body.blockSimple();
    body.invoke(_super(), method);
    onResumeAfterSuperBlock = body.blockSimple();
}
Also used : JBlock(com.helger.jcodemodel.JBlock) JMethod(com.helger.jcodemodel.JMethod)

Example 20 with JMethod

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

the class EActivityHolder method setOnConfigurationChanged.

private void setOnConfigurationChanged() {
    JMethod method = generatedClass.method(JMod.PUBLIC, getCodeModel().VOID, "onConfigurationChanged");
    method.annotate(Override.class);
    AbstractJClass configurationClass = getClasses().CONFIGURATION;
    onConfigurationChangedNewConfigParam = method.param(configurationClass, "newConfig");
    JBlock body = method.body();
    onConfigurationChangedBeforeSuperBlock = body.blockSimple();
    body.invoke(_super(), method).arg(onConfigurationChangedNewConfigParam);
    onConfigurationChangedAfterSuperBlock = body.blockSimple();
}
Also used : JBlock(com.helger.jcodemodel.JBlock) AbstractJClass(com.helger.jcodemodel.AbstractJClass) 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