use of com.helger.jcodemodel.JVar in project androidannotations by androidannotations.
the class ViewInstanceStateDelegate method setRestoreStateMethod.
private void setRestoreStateMethod() {
restoreStateMethod = getGeneratedClass().method(PUBLIC, codeModel().VOID, "onRestoreInstanceState");
restoreStateMethod.annotate(Override.class);
JVar state = restoreStateMethod.param(getClasses().PARCELABLE, "state");
JBlock body = restoreStateMethod.body();
restoreStateBundleParam = body.decl(getClasses().BUNDLE, "bundle" + generationSuffix(), cast(getClasses().BUNDLE, state));
JVar instanceState = body.decl(getClasses().PARCELABLE, "instanceState", restoreStateBundleParam.invoke("getParcelable").arg(getInstanceStateKey()));
restoreStateMethodBody = body.blockSimple();
body.invoke(_super(), "onRestoreInstanceState").arg(instanceState);
}
use of com.helger.jcodemodel.JVar 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));
}
use of com.helger.jcodemodel.JVar in project androidannotations by androidannotations.
the class KeyEventCallbackMethodsDelegate method createOnKeyMultipleMethod.
private void createOnKeyMultipleMethod() {
JMethod method = getGeneratedClass().method(PUBLIC, codeModel().BOOLEAN, "onKeyMultiple");
method.annotate(Override.class);
JVar keyCode = method.param(codeModel().INT, "keyCode");
onKeyMultipleCountParam = method.param(codeModel().INT, "count");
onKeyMultipleKeyEventParam = method.param(getClasses().KEY_EVENT, "keyEvent");
JBlock methodBody = method.body();
onKeyMultipleSwitchBody = methodBody._switch(keyCode);
methodBody._return(_super().invoke(method).arg(keyCode).arg(onKeyMultipleCountParam).arg(onKeyDownKeyEventParam));
}
use of com.helger.jcodemodel.JVar in project androidannotations by androidannotations.
the class RestMethodHandler method surroundWithRestTryCatch.
/**
* Adds the try/catch around the rest execution code.
*
* If an exception is caught, it will first check if the handler is set. If the
* handler is set, it will call the handler and return null (or nothing if
* void). If the handler isn't set, it will re-throw the exception so that it
* behaves as it did previous to this feature.
*/
private JBlock surroundWithRestTryCatch(RestHolder holder, JBlock block, boolean methodReturnVoid) {
if (holder.getRestErrorHandlerField() != null) {
JBlock newBlock = new JBlock().bracesRequired(false).indentRequired(false);
JTryBlock tryBlock = newBlock._try();
codeModelHelper.copy(block, tryBlock.body());
JCatchBlock jCatch = tryBlock._catch(getJClass(NESTED_RUNTIME_EXCEPTION));
JBlock catchBlock = jCatch.body();
JConditional conditional = catchBlock._if(JOp.ne(holder.getRestErrorHandlerField(), JExpr._null()));
JVar exceptionParam = jCatch.param("e");
JBlock thenBlock = conditional._then();
// call the handler method if it was set.
thenBlock.add(holder.getRestErrorHandlerField().invoke("onRestClientExceptionThrown").arg(exceptionParam));
// return null if exception was caught and handled.
if (!methodReturnVoid) {
thenBlock._return(JExpr._null());
}
// re-throw the exception if handler wasn't set.
conditional._else()._throw(exceptionParam);
return newBlock;
}
return block;
}
use of com.helger.jcodemodel.JVar in project androidannotations by androidannotations.
the class RestMethodHandler method addMethodParams.
protected SortedMap<String, JVar> addMethodParams(ExecutableElement executableElement, RestHolder restHolder, JMethod method) {
List<? extends VariableElement> params = executableElement.getParameters();
SortedMap<String, JVar> methodParams = new TreeMap<>();
for (VariableElement parameter : params) {
String paramName = parameter.getSimpleName().toString();
String paramType = parameter.asType().toString();
JVar param;
if (parameter.asType().getKind().isPrimitive()) {
param = method.param(getCodeModel().parseType(paramType), paramName);
} else {
AbstractJClass parameterClass = codeModelHelper.typeMirrorToJClass(parameter.asType());
param = method.param(parameterClass, paramName);
}
methodParams.put(paramName, param);
}
return methodParams;
}
Aggregations