use of com.helger.jcodemodel.AbstractJClass in project androidannotations by androidannotations.
the class ViewNotifierHelper method replacePreviousNotifier.
public JVar replacePreviousNotifier(JBlock block) {
AbstractJClass notifierClass = holder.getEnvironment().getJClass(OnViewChangedNotifier.class);
if (notifier == null) {
notifier = holder.getGeneratedClass().field(PRIVATE | FINAL, notifierClass, "onViewChangedNotifier" + generationSuffix(), _new(notifierClass));
holder.getGeneratedClass()._implements(HasViews.class);
}
return block.decl(notifierClass, "previousNotifier", notifierClass.staticInvoke("replaceNotifier").arg(notifier));
}
use of com.helger.jcodemodel.AbstractJClass in project androidannotations by androidannotations.
the class InstanceStateHandler method process.
@Override
public void process(Element element, HasInstanceState holder) {
AbstractJClass elementClass = codeModelHelper.typeMirrorToJClass(element.asType());
String fieldName = element.getSimpleName().toString();
JBlock saveStateBody = holder.getSaveStateMethodBody();
JVar saveStateBundleParam = holder.getSaveStateBundleParam();
JMethod restoreStateMethod = holder.getRestoreStateMethod();
JBlock restoreStateBody = holder.getRestoreStateMethodBody();
JVar restoreStateBundleParam = holder.getRestoreStateBundleParam();
TypeMirror type = codeModelHelper.getActualType(element, holder);
BundleHelper bundleHelper = new BundleHelper(getEnvironment(), type);
JFieldRef ref = ref(fieldName);
saveStateBody.add(bundleHelper.getExpressionToSaveFromField(saveStateBundleParam, JExpr.lit(fieldName), ref));
IJExpression restoreMethodCall = bundleHelper.getExpressionToRestoreFromBundle(elementClass, restoreStateBundleParam, JExpr.lit(fieldName), restoreStateMethod);
restoreStateBody.assign(ref, restoreMethodCall);
}
use of com.helger.jcodemodel.AbstractJClass in project androidannotations by androidannotations.
the class ItemClickHandler method processParameters.
@Override
protected void processParameters(EComponentWithViewSupportHolder holder, JMethod listenerMethod, JInvocation call, List<? extends VariableElement> parameters) {
boolean hasItemParameter = parameters.size() == 1;
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");
if (hasItemParameter) {
VariableElement parameter = parameters.get(0);
TypeMirror parameterType = parameter.asType();
if (parameterType.getKind() == TypeKind.INT) {
call.arg(onItemClickPositionParam);
} else {
AbstractJClass parameterClass = codeModelHelper.typeMirrorToJClass(parameterType);
call.arg(cast(parameterClass, invoke(onItemClickParentParam, "getAdapter").invoke("getItem").arg(onItemClickPositionParam)));
if (parameterClass.isParameterized()) {
codeModelHelper.addSuppressWarnings(listenerMethod, "unchecked");
}
}
}
}
use of com.helger.jcodemodel.AbstractJClass in project androidannotations by androidannotations.
the class ItemLongClickHandler method processParameters.
@Override
protected void processParameters(EComponentWithViewSupportHolder holder, JMethod listenerMethod, JInvocation call, List<? extends VariableElement> parameters) {
boolean hasItemParameter = parameters.size() == 1;
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");
if (hasItemParameter) {
VariableElement parameter = parameters.get(0);
TypeMirror parameterType = parameter.asType();
if (parameterType.getKind() == TypeKind.INT) {
call.arg(onItemClickPositionParam);
} else {
AbstractJClass parameterClass = codeModelHelper.typeMirrorToJClass(parameterType);
call.arg(cast(parameterClass, invoke(onItemClickParentParam, "getAdapter").invoke("getItem").arg(onItemClickPositionParam)));
if (parameterClass.isParameterized()) {
codeModelHelper.addSuppressWarnings(listenerMethod, "unchecked");
}
}
}
}
use of com.helger.jcodemodel.AbstractJClass in project androidannotations by androidannotations.
the class ActivityIntentBuilder method overrideStartForResultMethod.
private void overrideStartForResultMethod() {
AbstractJClass postActivityStarterClass = environment.getJClass(PostActivityStarter.class);
JMethod method = holder.getIntentBuilderClass().method(PUBLIC, postActivityStarterClass, "startForResult");
method.annotate(Override.class);
JVar requestCode = method.param(environment.getCodeModel().INT, "requestCode");
JBlock body = method.body();
JConditional condition = null;
if (fragmentSupportField != null) {
condition = body._if(fragmentSupportField.ne(JExpr._null()));
//
condition._then().invoke(fragmentSupportField, "startActivityForResult").arg(intentField).arg(requestCode);
}
if (fragmentField != null) {
if (condition == null) {
condition = body._if(fragmentField.ne(JExpr._null()));
} else {
condition = condition._elseif(fragmentField.ne(JExpr._null()));
}
JBlock fragmentStartForResultInvocationBlock;
if (hasActivityOptionsInFragment() && shouldGuardActivityOptions()) {
fragmentStartForResultInvocationBlock = createCallWithIfGuard(requestCode, condition._then(), fragmentField);
} else {
fragmentStartForResultInvocationBlock = condition._then();
}
JInvocation invocation = //
fragmentStartForResultInvocationBlock.invoke(fragmentField, "startActivityForResult").arg(intentField).arg(requestCode);
if (hasActivityOptionsInFragment()) {
invocation.arg(optionsField);
}
}
JBlock activityStartInvocationBlock = null;
if (condition != null) {
activityStartInvocationBlock = condition._else();
} else {
activityStartInvocationBlock = method.body();
}
JConditional activityCondition = activityStartInvocationBlock._if(contextField._instanceof(getClasses().ACTIVITY));
JBlock thenBlock = activityCondition._then();
JVar activityVar = thenBlock.decl(getClasses().ACTIVITY, "activity", JExpr.cast(getClasses().ACTIVITY, contextField));
if (hasActivityCompatInClasspath() && hasActivityOptionsInActivityCompat()) {
//
thenBlock.staticInvoke(getClasses().ACTIVITY_COMPAT, "startActivityForResult").arg(activityVar).arg(intentField).arg(requestCode).arg(optionsField);
} else if (hasActivityOptionsInFragment()) {
JBlock startForResultInvocationBlock;
if (shouldGuardActivityOptions()) {
startForResultInvocationBlock = createCallWithIfGuard(requestCode, thenBlock, activityVar);
} else {
startForResultInvocationBlock = thenBlock;
}
//
startForResultInvocationBlock.invoke(activityVar, "startActivityForResult").arg(intentField).arg(requestCode).arg(optionsField);
} else {
thenBlock.invoke(activityVar, "startActivityForResult").arg(intentField).arg(requestCode);
}
if (hasActivityOptionsInFragment()) {
JBlock startInvocationBlock;
if (shouldGuardActivityOptions()) {
startInvocationBlock = createCallWithIfGuard(null, activityCondition._else(), contextField);
} else {
startInvocationBlock = activityCondition._else();
}
startInvocationBlock.invoke(contextField, "startActivity").arg(intentField).arg(optionsField);
} else {
activityCondition._else().invoke(contextField, "startActivity").arg(intentField);
}
body._return(_new(postActivityStarterClass).arg(contextField));
}
Aggregations