use of com.helger.jcodemodel.IJExpression in project androidannotations by androidannotations.
the class ItemSelectHandler method processParameters.
@Override
protected void processParameters(EComponentWithViewSupportHolder holder, JMethod listenerMethod, JInvocation itemSelectedCall, List<? extends VariableElement> parameters) {
AbstractJClass narrowAdapterViewClass = getClasses().ADAPTER_VIEW.narrow(getCodeModel().wildcard());
JVar onItemClickParentParam = listenerMethod.param(narrowAdapterViewClass, "parent");
listenerMethod.param(getClasses().VIEW, "view");
JVar onItemClickPositionParam = listenerMethod.param(getCodeModel().INT, "position");
listenerMethod.param(getCodeModel().LONG, "id");
itemSelectedCall.arg(JExpr.TRUE);
boolean hasItemParameter = parameters.size() == 2;
boolean secondParameterIsInt = false;
String secondParameterQualifiedName = null;
if (hasItemParameter) {
VariableElement secondParameter = parameters.get(1);
TypeMirror secondParameterType = secondParameter.asType();
secondParameterQualifiedName = secondParameterType.toString();
secondParameterIsInt = secondParameterType.getKind() == TypeKind.INT;
}
if (hasItemParameter) {
if (secondParameterIsInt) {
itemSelectedCall.arg(onItemClickPositionParam);
} else {
itemSelectedCall.arg(JExpr.cast(getJClass(secondParameterQualifiedName), invoke(onItemClickParentParam, "getAdapter").invoke("getItem").arg(onItemClickPositionParam)));
}
}
onNothingSelectedMethod.param(narrowAdapterViewClass, "parent");
IJExpression activityRef = holder.getGeneratedClass().staticRef("this");
JInvocation nothingSelectedCall = invoke(activityRef, getMethodName());
onNothingSelectedMethod.body().add(nothingSelectedCall);
nothingSelectedCall.arg(JExpr.FALSE);
if (hasItemParameter) {
if (secondParameterIsInt) {
nothingSelectedCall.arg(lit(-1));
} else {
nothingSelectedCall.arg(_null());
}
}
}
use of com.helger.jcodemodel.IJExpression in project androidannotations by androidannotations.
the class ViewNotifierHelper method implementHasViewsInHolder.
private void implementHasViewsInHolder() {
holder.getGeneratedClass()._implements(HasViews.class);
JCodeModel codeModel = environment.getCodeModel();
JDirectClass genericType = codeModel.directClass("T");
JMethod findViewById = holder.getGeneratedClass().method(PUBLIC, genericType, "internalFindViewById");
findViewById.generify("T", environment.getClasses().VIEW);
findViewById.annotate(Override.class);
JVar idParam = findViewById.param(codeModel.INT, "id");
IJExpression findViewByIdExpression = holder.getFindViewByIdExpression(idParam);
findViewById.body()._return(JExpr.cast(genericType, findViewByIdExpression));
}
use of com.helger.jcodemodel.IJExpression 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.IJExpression in project androidannotations by androidannotations.
the class AbstractListenerHandler method process.
@Override
public void process(Element element, T holder) {
methodName = element.getSimpleName().toString();
ExecutableElement executableElement = (ExecutableElement) element;
List<? extends VariableElement> parameters = executableElement.getParameters();
TypeMirror returnType = executableElement.getReturnType();
List<JFieldRef> idsRefs = annotationHelper.extractAnnotationFieldRefs(element, getResourceType(), true);
JDefinedClass listenerAnonymousClass = getCodeModel().anonymousClass(getListenerClass(holder));
JMethod listenerMethod = createListenerMethod(listenerAnonymousClass);
listenerMethod.annotate(Override.class);
JBlock listenerMethodBody = listenerMethod.body();
IJExpression activityRef = holder.getGeneratedClass().staticRef("this");
JInvocation call = invoke(activityRef, methodName);
makeCall(listenerMethodBody, call, returnType);
processParameters(holder, listenerMethod, call, parameters);
assignListeners(holder, idsRefs, listenerAnonymousClass);
}
use of com.helger.jcodemodel.IJExpression 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