use of com.helger.jcodemodel.JInvocation in project androidannotations by androidannotations.
the class RestHandler method setResponseErrorHandler.
private void setResponseErrorHandler(Element element, RestHolder holder) {
DeclaredType responseErrorHandler = annotationHelper.extractAnnotationClassParameter(element, getTarget(), "responseErrorHandler");
if (responseErrorHandler != null) {
JInvocation errorHandler = codeModelHelper.newBeanOrEBean(responseErrorHandler, holder.getInitContextParam());
holder.getInit().body().add(invoke(holder.getRestTemplateField(), "setErrorHandler").arg(errorHandler));
}
}
use of com.helger.jcodemodel.JInvocation in project androidannotations by androidannotations.
the class IntentBuilder method addPutExtraMethod.
private JMethod addPutExtraMethod(Element element, List<IntentExtra> intentExtras) {
String docComment = elementUtils.getDocComment(element);
JMethod method = holder.getIntentBuilderClass().method(PUBLIC, holder.getIntentBuilderClass(), element.getSimpleName().toString());
method.javadoc().addReturn().append("the IntentBuilder to chain calls");
codeModelHelper.addTrimmedDocComment(method, docComment);
int paramCount = intentExtras.size();
for (int i = 0; i < paramCount; i++) {
IntentExtra intentExtra = intentExtras.get(i);
method.javadoc().addParam(intentExtra.parameterName).append("the value for this extra");
AbstractJClass parameterClass = codeModelHelper.typeMirrorToJClass(intentExtra.type);
JVar extraParameterVar = method.param(parameterClass, intentExtra.parameterName);
JInvocation superCall = getSuperPutExtraInvocation(intentExtra.type, extraParameterVar, intentExtra.keyField);
if (i + 1 == paramCount) {
method.body()._return(superCall);
} else {
method.body().add(superCall);
}
}
return method;
}
use of com.helger.jcodemodel.JInvocation in project androidannotations by androidannotations.
the class ReceiverActionHandler method addActionInOnReceive.
private void addActionInOnReceive(EReceiverHolder holder, ExecutableElement executableElement, String methodName, JFieldVar actionsField, JFieldVar dataSchemesField) {
String actionsInvoke = getInvocationName(actionsField);
IJExpression filterCondition = actionsField.invoke(actionsInvoke).arg(holder.getOnReceiveIntentAction());
if (dataSchemesField != null) {
String dataSchemesInvoke = getInvocationName(dataSchemesField);
filterCondition = filterCondition.cand(dataSchemesField.invoke(dataSchemesInvoke).arg(holder.getOnReceiveIntentDataScheme()));
}
JBlock callActionBlock = holder.getOnReceiveBody()._if(filterCondition)._then();
IJExpression receiverRef = holder.getGeneratedClass().staticRef("this");
JInvocation callActionInvocation = receiverRef.invoke(methodName);
JVar intent = holder.getOnReceiveIntent();
JVar extras = null;
List<? extends VariableElement> methodParameters = executableElement.getParameters();
for (VariableElement param : methodParameters) {
AbstractJClass extraParamClass = codeModelHelper.typeMirrorToJClass(param.asType());
if (extraParamClass.equals(getClasses().CONTEXT)) {
callActionInvocation.arg(holder.getOnReceiveContext());
} else if (extraParamClass.equals(getClasses().INTENT) && param.getAnnotation(ReceiverAction.Extra.class) == null) {
callActionInvocation.arg(intent);
} else if (param.getAnnotation(ReceiverAction.Extra.class) != null) {
if (extras == null) {
extras = callActionBlock.decl(getClasses().BUNDLE, "extras_", JOp.cond(//
intent.invoke("getExtras").ne(_null()), intent.invoke("getExtras"), _new(getClasses().BUNDLE)));
}
callActionInvocation.arg(extraHandler.getExtraValue(param, extras, callActionBlock, holder));
}
}
callActionBlock.add(callActionInvocation);
callActionBlock._return();
}
use of com.helger.jcodemodel.JInvocation in project androidannotations by androidannotations.
the class ReceiverActionHandler method createStaticField.
private JFieldVar createStaticField(EReceiverHolder holder, String prefix, String methodName, String[] values) {
String staticFieldName = CaseHelper.camelCaseToUpperSnakeCase(prefix, methodName, null);
if (values == null || values.length == 0) {
return null;
} else if (values.length == 1) {
return holder.getGeneratedClass().field(PUBLIC | STATIC | FINAL, getClasses().STRING, staticFieldName, lit(values[0]));
}
JInvocation asListInvoke = getClasses().ARRAYS.staticInvoke("asList");
for (String scheme : values) {
asListInvoke.arg(scheme);
}
AbstractJClass listOfStrings = getClasses().LIST.narrow(getClasses().STRING);
return holder.getGeneratedClass().field(PUBLIC | STATIC | FINAL, listOfStrings, staticFieldName, asListInvoke);
}
use of com.helger.jcodemodel.JInvocation in project androidannotations by androidannotations.
the class SeekBarProgressChangeHandler method process.
@Override
public void process(Element element, EComponentWithViewSupportHolder holder) throws Exception {
String methodName = element.getSimpleName().toString();
ExecutableElement executableElement = (ExecutableElement) element;
List<? extends VariableElement> parameters = executableElement.getParameters();
int seekBarViewParameterPosition = -1;
int progressParameterPosition = -1;
int fromUserParameterPosition = -1;
for (int i = 0; i < parameters.size(); i++) {
VariableElement parameter = parameters.get(i);
TypeMirror parameterType = parameter.asType();
if (CanonicalNameConstants.SEEKBAR.equals(parameterType.toString())) {
seekBarViewParameterPosition = i;
} else if (parameterType.getKind() == TypeKind.INT || CanonicalNameConstants.INTEGER.equals(parameterType.toString())) {
progressParameterPosition = i;
} else if (parameterType.getKind() == TypeKind.BOOLEAN || CanonicalNameConstants.BOOLEAN.equals(parameterType.toString())) {
fromUserParameterPosition = i;
}
}
List<JFieldRef> idsRefs = annotationHelper.extractAnnotationFieldRefs(element, IRClass.Res.ID, true);
for (JFieldRef idRef : idsRefs) {
OnSeekBarChangeListenerHolder onSeekBarChangeListenerHolder = holder.getOnSeekBarChangeListenerHolder(idRef);
JBlock methodBody = onSeekBarChangeListenerHolder.getOnProgressChangedBody();
IJExpression activityRef = holder.getGeneratedClass().staticRef("this");
JInvocation textChangeCall = methodBody.invoke(activityRef, methodName);
for (int i = 0; i < parameters.size(); i++) {
if (i == seekBarViewParameterPosition) {
JVar seekBarViewParameter = onSeekBarChangeListenerHolder.getOnProgressChangedSeekBarParam();
textChangeCall.arg(seekBarViewParameter);
} else if (i == progressParameterPosition) {
JVar progressParameter = onSeekBarChangeListenerHolder.getOnProgressChangedProgressParam();
textChangeCall.arg(progressParameter);
} else if (i == fromUserParameterPosition) {
JVar fromUserParameter = onSeekBarChangeListenerHolder.getOnProgressChangedFromUserParam();
textChangeCall.arg(fromUserParameter);
}
}
}
}
Aggregations