use of com.helger.jcodemodel.IJExpression in project androidannotations by androidannotations.
the class ActivityIntentBuilder method addFragmentConstructor.
private JFieldVar addFragmentConstructor(AbstractJClass fragmentClass, String fieldName) {
JFieldVar fragmentField = holder.getIntentBuilderClass().field(PRIVATE, fragmentClass, fieldName);
IJExpression generatedClass = holder.getGeneratedClass().dotclass();
JMethod constructor = holder.getIntentBuilderClass().constructor(JMod.PUBLIC);
JVar constructorFragmentParam = constructor.param(fragmentClass, "fragment");
JBlock constructorBody = constructor.body();
constructorBody.invoke("super").arg(constructorFragmentParam.invoke("getActivity")).arg(generatedClass);
constructorBody.assign(fragmentField, constructorFragmentParam);
return fragmentField;
}
use of com.helger.jcodemodel.IJExpression in project androidannotations by androidannotations.
the class OptionsItemHandler method process.
@Override
public void process(Element element, HasOptionsMenu holder) {
String methodName = element.getSimpleName().toString();
ExecutableElement executableElement = (ExecutableElement) element;
List<? extends VariableElement> parameters = executableElement.getParameters();
TypeMirror returnType = executableElement.getReturnType();
boolean returnMethodResult = returnType.getKind() != TypeKind.VOID;
boolean hasItemParameter = parameters.size() == 1;
List<JFieldRef> idsRefs = annotationHelper.extractAnnotationFieldRefs(element, IRClass.Res.ID, true);
JBlock block = holder.getOnOptionsItemSelectedMiddleBlock();
IJExpression ifExpr = holder.getOnOptionsItemSelectedItemId().eq(idsRefs.get(0));
for (int i = 1; i < idsRefs.size(); i++) {
ifExpr = ifExpr.cor(holder.getOnOptionsItemSelectedItemId().eq(idsRefs.get(i)));
}
JBlock itemIfBody = block._if(ifExpr)._then();
JInvocation methodCall = invoke(methodName);
if (returnMethodResult) {
itemIfBody._return(methodCall);
} else {
itemIfBody.add(methodCall);
itemIfBody._return(TRUE);
}
if (hasItemParameter) {
methodCall.arg(holder.getOnOptionsItemSelectedItem());
}
}
use of com.helger.jcodemodel.IJExpression in project androidannotations by androidannotations.
the class PageScrolledHandler 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 positionOffsetParameterPosition = -1;
int positionOffsetPixelsParameterPosition = -1;
int viewPagerParameterPosition = -1;
int numberOfIntParameters = 0;
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())) {
if (numberOfIntParameters == 0 && positionOffsetParameterPosition == -1) {
positionParameterPosition = i;
} else {
positionOffsetPixelsParameterPosition = i;
}
numberOfIntParameters++;
} else if (parameterType.getKind() == TypeKind.FLOAT || CanonicalNameConstants.FLOAT.equals(parameterType.toString())) {
positionOffsetParameterPosition = i;
} else {
if (isViewPagerParameter(parameterType)) {
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.getPageScrolledBody();
IJExpression activityRef = holder.getGeneratedClass().staticRef("this");
JInvocation pageScrollCall = methodBody.invoke(activityRef, methodName);
for (int i = 0; i < parameters.size(); i++) {
if (i == positionParameterPosition) {
JVar positionParam = pageChangeHolder.getPageScrolledPositionParam();
pageScrollCall.arg(positionParam);
} else if (i == positionOffsetParameterPosition) {
JVar pageScrolledPositionOffsetParam = pageChangeHolder.getPageScrolledPositionOffsetParam();
pageScrollCall.arg(pageScrolledPositionOffsetParam);
} else if (i == positionOffsetPixelsParameterPosition) {
JVar pageScrolledPositionOffsetPixelsParam = pageChangeHolder.getPageScrolledPositionOffsetPixelsParam();
pageScrollCall.arg(pageScrolledPositionOffsetPixelsParam);
} else if (i == viewPagerParameterPosition) {
JVar viewParameter = pageChangeHolder.getViewPagerVariable();
pageScrollCall.arg(viewParameter);
}
}
}
}
use of com.helger.jcodemodel.IJExpression in project androidannotations by androidannotations.
the class IntentBuilder method createContextConstructor.
private void createContextConstructor() {
IJExpression generatedClass = holder.getGeneratedClass().dotclass();
JMethod constructor = holder.getIntentBuilderClass().constructor(JMod.PUBLIC);
JVar constructorContextParam = constructor.param(getClasses().CONTEXT, "context");
constructor.body().invoke("super").arg(constructorContextParam).arg(generatedClass);
}
use of com.helger.jcodemodel.IJExpression 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();
}
Aggregations