Search in sources :

Example 1 with JSwitch

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

the class AbstractKeyEventHandler method process.

@Override
public void process(Element element, HasKeyEventCallbackMethods holder) throws Exception {
    String methodName = element.getSimpleName().toString();
    ExecutableElement executableElement = (ExecutableElement) element;
    TypeMirror returnType = executableElement.getReturnType();
    boolean returnMethodResult = returnType.getKind() != TypeKind.VOID;
    JSwitch switchBody = getSwitchBody(holder);
    int[] keyCodes = annotationHelper.extractKeyCode(element);
    for (int keyCode : keyCodes) {
        String keyCodeFieldName = annotationHelper.getFieldNameForKeyCode(keyCode);
        JBlock switchCaseBody = switchBody._case(getClasses().KEY_EVENT.staticRef(keyCodeFieldName)).body();
        JInvocation methodCall = invoke(methodName);
        if (returnMethodResult) {
            switchCaseBody._return(methodCall);
        } else {
            switchCaseBody.add(methodCall);
            switchCaseBody._return(TRUE);
        }
        passParametersToMethodCall(element, holder, methodCall);
    }
}
Also used : JSwitch(com.helger.jcodemodel.JSwitch) TypeMirror(javax.lang.model.type.TypeMirror) ExecutableElement(javax.lang.model.element.ExecutableElement) JBlock(com.helger.jcodemodel.JBlock) JInvocation(com.helger.jcodemodel.JInvocation)

Aggregations

JBlock (com.helger.jcodemodel.JBlock)1 JInvocation (com.helger.jcodemodel.JInvocation)1 JSwitch (com.helger.jcodemodel.JSwitch)1 ExecutableElement (javax.lang.model.element.ExecutableElement)1 TypeMirror (javax.lang.model.type.TypeMirror)1