use of com.helger.jcodemodel.IJExpression in project androidannotations by androidannotations.
the class TextChangeHandler 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 startParameterPosition = -1;
int countParameterPosition = -1;
int beforeParameterPosition = -1;
int charSequenceParameterPosition = -1;
int viewParameterPosition = -1;
TypeMirror viewParameterType = null;
for (int i = 0; i < parameters.size(); i++) {
VariableElement parameter = parameters.get(i);
String parameterName = parameter.toString();
TypeMirror parameterType = parameter.asType();
if (CanonicalNameConstants.CHAR_SEQUENCE.equals(parameterType.toString())) {
charSequenceParameterPosition = i;
} else if (parameterType.getKind() == TypeKind.INT || CanonicalNameConstants.INTEGER.equals(parameterType.toString())) {
if ("start".equals(parameterName)) {
startParameterPosition = i;
} else if ("count".equals(parameterName)) {
countParameterPosition = i;
} else if ("before".equals(parameterName)) {
beforeParameterPosition = i;
}
} else {
TypeMirror textViewType = annotationHelper.typeElementFromQualifiedName(CanonicalNameConstants.TEXT_VIEW).asType();
if (annotationHelper.isSubtype(parameterType, textViewType)) {
viewParameterPosition = i;
viewParameterType = parameterType;
}
}
}
List<JFieldRef> idsRefs = annotationHelper.extractAnnotationFieldRefs(element, IRClass.Res.ID, true);
for (JFieldRef idRef : idsRefs) {
TextWatcherHolder textWatcherHolder = holder.getTextWatcherHolder(idRef, viewParameterType);
JBlock methodBody = textWatcherHolder.getOnTextChangedBody();
IJExpression activityRef = holder.getGeneratedClass().staticRef("this");
JInvocation textChangeCall = methodBody.invoke(activityRef, methodName);
for (int i = 0; i < parameters.size(); i++) {
if (i == startParameterPosition) {
JVar startParameter = textWatcherHolder.getOnTextChangedStartParam();
textChangeCall.arg(startParameter);
} else if (i == countParameterPosition) {
JVar countParameter = textWatcherHolder.getOnTextChangedCountParam();
textChangeCall.arg(countParameter);
} else if (i == beforeParameterPosition) {
JVar beforeParameter = textWatcherHolder.getOnTextChangedBeforeParam();
textChangeCall.arg(beforeParameter);
} else if (i == charSequenceParameterPosition) {
JVar charSequenceParam = textWatcherHolder.getOnTextChangedCharSequenceParam();
textChangeCall.arg(charSequenceParam);
} else if (i == viewParameterPosition) {
JVar viewParameter = textWatcherHolder.getTextViewVariable();
textChangeCall.arg(viewParameter);
}
}
}
}
use of com.helger.jcodemodel.IJExpression in project androidannotations by androidannotations.
the class PageScrollStateChangedHandler method process.
@Override
public void process(Element element, EComponentWithViewSupportHolder holder) {
String methodName = element.getSimpleName().toString();
ExecutableElement executableElement = (ExecutableElement) element;
List<? extends VariableElement> parameters = executableElement.getParameters();
int stateParameterPosition = -1;
int viewPagerParameterPosition = -1;
TypeMirror viewPagerParameterType = null;
for (int i = 0; i < parameters.size(); i++) {
VariableElement parameter = parameters.get(i);
TypeMirror parameterType = parameter.asType();
if (parameterType.getKind() == TypeKind.INT || CanonicalNameConstants.INTEGER.equals(parameterType.toString())) {
stateParameterPosition = i;
} else {
TypeMirror viewPagerType = annotationHelper.typeElementFromQualifiedName(CanonicalNameConstants.VIEW_PAGER).asType();
if (annotationHelper.isSubtype(parameterType, viewPagerType)) {
viewPagerParameterPosition = i;
viewPagerParameterType = parameterType;
}
}
}
List<JFieldRef> idsRefs = annotationHelper.extractAnnotationFieldRefs(element, IRClass.Res.ID, true);
for (JFieldRef idRef : idsRefs) {
PageChangeHolder pageChangeHolder = holder.getPageChangeHolder(idRef, viewPagerParameterType, hasAddOnPageChangeListenerMethod());
JBlock methodBody = pageChangeHolder.getPageScrollStateChangedBody();
IJExpression thisRef = holder.getGeneratedClass().staticRef("this");
JInvocation methodCall = methodBody.invoke(thisRef, methodName);
for (int i = 0; i < parameters.size(); i++) {
if (i == stateParameterPosition) {
JVar stateParam = pageChangeHolder.getPageScrollStateChangedStateParam();
methodCall.arg(stateParam);
} else if (i == viewPagerParameterPosition) {
JVar viewParameter = pageChangeHolder.getViewPagerVariable();
methodCall.arg(viewParameter);
}
}
}
}
use of com.helger.jcodemodel.IJExpression in project androidannotations by androidannotations.
the class PageSelectedHandler 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 positionParameterPosition = -1;
int viewPagerParameterPosition = -1;
TypeMirror viewPagerParameterType = null;
for (int i = 0; i < parameters.size(); i++) {
VariableElement parameter = parameters.get(i);
TypeMirror parameterType = parameter.asType();
if (parameterType.getKind() == TypeKind.INT || CanonicalNameConstants.INTEGER.equals(parameterType.toString())) {
positionParameterPosition = i;
} else {
TypeMirror viewPagerType = annotationHelper.typeElementFromQualifiedName(CanonicalNameConstants.VIEW_PAGER).asType();
if (annotationHelper.isSubtype(parameterType, viewPagerType)) {
viewPagerParameterPosition = i;
viewPagerParameterType = parameterType;
}
}
}
List<JFieldRef> idsRefs = annotationHelper.extractAnnotationFieldRefs(element, IRClass.Res.ID, true);
for (JFieldRef idRef : idsRefs) {
PageChangeHolder pageChangeHolder = holder.getPageChangeHolder(idRef, viewPagerParameterType, hasAddOnPageChangeListenerMethod());
JBlock methodBody = pageChangeHolder.getPageSelectedBody();
IJExpression thisRef = holder.getGeneratedClass().staticRef("this");
JInvocation methodCall = methodBody.invoke(thisRef, methodName);
for (int i = 0; i < parameters.size(); i++) {
if (i == positionParameterPosition) {
JVar stateParam = pageChangeHolder.getPageSelectedPositionParam();
methodCall.arg(stateParam);
} else if (i == viewPagerParameterPosition) {
JVar viewParameter = pageChangeHolder.getViewPagerVariable();
methodCall.arg(viewParameter);
}
}
}
}
use of com.helger.jcodemodel.IJExpression in project androidannotations by androidannotations.
the class IntentBuilder method getSuperPutExtraInvocation.
public JInvocation getSuperPutExtraInvocation(TypeMirror elementType, JVar extraParam, JFieldVar extraKeyField) {
IJExpression extraParameterArg = extraParam;
// Cast to Parcelable, wrap with Parcels.wrap or cast Serializable if needed
if (elementType.getKind() == TypeKind.DECLARED) {
Elements elementUtils = environment.getProcessingEnvironment().getElementUtils();
TypeMirror parcelableType = elementUtils.getTypeElement(PARCELABLE).asType();
if (typeUtils.isSubtype(elementType, parcelableType)) {
TypeMirror serializableType = elementUtils.getTypeElement(SERIALIZABLE).asType();
if (typeUtils.isSubtype(elementType, serializableType)) {
extraParameterArg = cast(environment.getClasses().PARCELABLE, extraParameterArg);
}
} else if (!BundleHelper.METHOD_SUFFIX_BY_TYPE_NAME.containsKey(elementType.toString()) && parcelerHelper.isParcelType(elementType)) {
extraParameterArg = environment.getJClass(CanonicalNameConstants.PARCELS_UTILITY_CLASS).staticInvoke("wrap").arg(extraParameterArg);
} else {
TypeMirror stringType = elementUtils.getTypeElement(STRING).asType();
if (!typeUtils.isSubtype(elementType, stringType)) {
extraParameterArg = cast(environment.getClasses().SERIALIZABLE, extraParameterArg);
}
}
}
return _super().invoke("extra").arg(extraKeyField).arg(extraParameterArg);
}
use of com.helger.jcodemodel.IJExpression in project androidannotations by androidannotations.
the class ReceiverHandler method createReceiverField.
private JFieldVar createReceiverField(HasReceiverRegistration holder, String receiverName, String methodName, ExecutableElement executableElement) {
JDefinedClass anonymousReceiverClass = getCodeModel().anonymousClass(getClasses().BROADCAST_RECEIVER);
JMethod onReceiveMethod = anonymousReceiverClass.method(PUBLIC, getCodeModel().VOID, "onReceive");
JVar contextVar = onReceiveMethod.param(getClasses().CONTEXT, "context");
JVar intentVar = onReceiveMethod.param(getClasses().INTENT, "intent");
JBlock body = onReceiveMethod.body();
IJExpression receiverRef = holder.getGeneratedClass().staticRef("this");
JInvocation methodCall = receiverRef.invoke(methodName);
JVar extras = null;
List<? extends VariableElement> methodParameters = executableElement.getParameters();
for (VariableElement param : methodParameters) {
AbstractJClass extraParamClass = codeModelHelper.typeMirrorToJClass(param.asType());
if (extraParamClass.equals(getClasses().CONTEXT)) {
methodCall.arg(contextVar);
} else if (extraParamClass.equals(getClasses().INTENT) && param.getAnnotation(Receiver.Extra.class) == null) {
methodCall.arg(intentVar);
} else if (param.getAnnotation(Receiver.Extra.class) != null) {
if (extras == null) {
extras = body.decl(getClasses().BUNDLE, "extras_", JOp.cond(intentVar.invoke("getExtras").ne(_null()), intentVar.invoke("getExtras"), _new(getClasses().BUNDLE)));
}
methodCall.arg(extraHandler.getExtraValue(param, extras, body, onReceiveMethod, anonymousReceiverClass));
}
}
body.add(methodCall);
IJExpression receiverInit = _new(anonymousReceiverClass);
return holder.getGeneratedClass().field(PRIVATE | FINAL, getClasses().BROADCAST_RECEIVER, receiverName, receiverInit);
}
Aggregations