use of com.helger.jcodemodel.JVar in project androidannotations by androidannotations.
the class EditorActionHandler method processParameters.
@Override
protected void processParameters(EComponentWithViewSupportHolder holder, JMethod listenerMethod, JInvocation call, List<? extends VariableElement> userParameters) {
JVar textView = listenerMethod.param(getClasses().TEXT_VIEW, "textView");
JVar actionId = listenerMethod.param(getCodeModel().INT, "actionId");
JVar event = listenerMethod.param(getClasses().KEY_EVENT, "event");
for (VariableElement param : userParameters) {
String paramClassQualifiedName = param.asType().toString();
if (isTypeOrSubclass(CanonicalNameConstants.TEXT_VIEW, param)) {
call.arg(castArgumentIfNecessary(holder, CanonicalNameConstants.TEXT_VIEW, textView, param));
} else if (paramClassQualifiedName.equals(CanonicalNameConstants.INTEGER) || paramClassQualifiedName.equals(getCodeModel().INT.fullName())) {
call.arg(actionId);
} else if (paramClassQualifiedName.equals(CanonicalNameConstants.KEY_EVENT)) {
call.arg(event);
}
}
}
use of com.helger.jcodemodel.JVar in project androidannotations by androidannotations.
the class FragmentArgHandler method createBuilderInjectMethod.
public void createBuilderInjectMethod(EFragmentHolder holder, Element element, List<ArgHelper> argHelpers) {
JDefinedClass builderClass = holder.getBuilderClass();
JFieldRef builderArgsField = holder.getBuilderArgsField();
JMethod builderMethod = builderClass.method(PUBLIC, holder.narrow(builderClass), element.getSimpleName().toString());
String docComment = getProcessingEnvironment().getElementUtils().getDocComment(element);
codeModelHelper.addTrimmedDocComment(builderMethod, docComment);
for (ArgHelper argHelper : argHelpers) {
String fieldName = argHelper.param.getSimpleName().toString();
TypeMirror actualType = codeModelHelper.getActualTypeOfEnclosingElementOfInjectedElement(holder, argHelper.param);
BundleHelper bundleHelper = new BundleHelper(getEnvironment(), actualType);
JFieldVar argKeyStaticField = getOrCreateStaticArgField(holder, argHelper.argKey, fieldName);
AbstractJClass paramClass = codeModelHelper.typeMirrorToJClass(actualType);
JVar arg = builderMethod.param(paramClass, fieldName);
builderMethod.body().add(bundleHelper.getExpressionToSaveFromField(builderArgsField, argKeyStaticField, arg));
builderMethod.javadoc().addParam(fieldName).append("value for this Fragment argument");
}
builderMethod.javadoc().addReturn().append("the FragmentBuilder to chain calls");
builderMethod.body()._return(_this());
}
use of com.helger.jcodemodel.JVar in project androidannotations by androidannotations.
the class FragmentArgHandler method assignValue.
@Override
public void assignValue(JBlock targetBlock, IJAssignmentTarget fieldRef, EFragmentHolder holder, Element element, Element param) {
String fieldName = element.getSimpleName().toString();
String argKey = extractArgKey(element, fieldName);
if (element.getKind() != ElementKind.PARAMETER) {
createBuilderInjectionMethod(holder, element, new ArgHelper(param, argKey));
}
TypeMirror actualType = codeModelHelper.getActualTypeOfEnclosingElementOfInjectedElement(holder, param);
AbstractJClass elementClass = codeModelHelper.typeMirrorToJClass(actualType);
BundleHelper bundleHelper = new BundleHelper(getEnvironment(), actualType);
JVar bundle = holder.getInjectBundleArgs();
JMethod injectExtrasMethod = holder.getInjectArgsMethod();
JFieldVar extraKeyStaticField = getOrCreateStaticArgField(holder, argKey, fieldName);
IJExpression restoreMethodCall = bundleHelper.getExpressionToRestoreFromBundle(elementClass, bundle, extraKeyStaticField, injectExtrasMethod);
JConditional conditional = targetBlock._if(JExpr.invoke(bundle, "containsKey").arg(extraKeyStaticField));
conditional._then().add(fieldRef.assign(restoreMethodCall));
}
use of com.helger.jcodemodel.JVar in project androidannotations by androidannotations.
the class CheckedChangeHandler method processParameters.
@Override
protected void processParameters(EComponentWithViewSupportHolder holder, JMethod listenerMethod, JInvocation call, List<? extends VariableElement> parameters) {
JVar btnParam = listenerMethod.param(getClasses().COMPOUND_BUTTON, "buttonView");
JVar isCheckedParam = listenerMethod.param(getCodeModel().BOOLEAN, "isChecked");
for (VariableElement parameter : parameters) {
String parameterType = parameter.asType().toString();
if (isTypeOrSubclass(CanonicalNameConstants.COMPOUND_BUTTON, parameter)) {
call.arg(castArgumentIfNecessary(holder, CanonicalNameConstants.COMPOUND_BUTTON, btnParam, parameter));
} else if (parameterType.equals(CanonicalNameConstants.BOOLEAN) || parameter.asType().getKind() == TypeKind.BOOLEAN) {
call.arg(isCheckedParam);
}
}
}
use of com.helger.jcodemodel.JVar in project androidannotations by androidannotations.
the class AbstractSeekBarTouchHandler method process.
@Override
public void process(Element element, EComponentWithViewSupportHolder holder) throws Exception {
String methodName = element.getSimpleName().toString();
List<JFieldRef> idsRefs = annotationHelper.extractAnnotationFieldRefs(element, IRClass.Res.ID, true);
for (JFieldRef idRef : idsRefs) {
OnSeekBarChangeListenerHolder onSeekBarChangeListenerHolder = holder.getOnSeekBarChangeListenerHolder(idRef);
JBlock methodBody = getMethodBodyToCall(onSeekBarChangeListenerHolder);
IJExpression activityRef = holder.getGeneratedClass().staticRef("this");
JInvocation textChangeCall = methodBody.invoke(activityRef, methodName);
ExecutableElement executableElement = (ExecutableElement) element;
List<? extends VariableElement> parameters = executableElement.getParameters();
if (parameters.size() == 1) {
JVar progressParameter = getMethodParamToPass(onSeekBarChangeListenerHolder);
textChangeCall.arg(progressParameter);
}
}
}
Aggregations