use of com.helger.jcodemodel.JVar in project androidannotations by androidannotations.
the class ExtraHandler method assignValue.
@Override
public void assignValue(JBlock targetBlock, IJAssignmentTarget fieldRef, EActivityHolder holder, Element element, Element param) {
String fieldName = element.getSimpleName().toString();
String extraKey = extractExtraKey(element, fieldName);
TypeMirror actualType = codeModelHelper.getActualTypeOfEnclosingElementOfInjectedElement(holder, param);
BundleHelper bundleHelper = new BundleHelper(getEnvironment(), actualType);
JFieldVar extraKeyStaticField = getOrCreateStaticExtraField(holder, extraKey, fieldName);
if (element.getKind() != ElementKind.PARAMETER) {
holder.getIntentBuilder().getPutExtraMethod(element, new IntentBuilder.IntentExtra(param.asType(), fieldName, extraKeyStaticField));
}
AbstractJClass elementClass = codeModelHelper.typeMirrorToJClass(param.asType());
JMethod injectExtrasMethod = holder.getInjectExtrasMethod();
JVar extras = holder.getInjectExtras();
IJExpression restoreMethodCall = bundleHelper.getExpressionToRestoreFromBundle(elementClass, extras, extraKeyStaticField, injectExtrasMethod);
JBlock ifContainsKey = targetBlock._if(JExpr.invoke(extras, "containsKey").arg(extraKeyStaticField))._then();
ifContainsKey.assign(fieldRef, restoreMethodCall);
}
use of com.helger.jcodemodel.JVar in project androidannotations by androidannotations.
the class AfterTextChangeHandler 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 editableParameterPosition = -1;
int viewParameterPosition = -1;
TypeMirror viewParameterType = null;
for (int i = 0; i < parameters.size(); i++) {
VariableElement parameter = parameters.get(i);
TypeMirror parameterType = parameter.asType();
if (CanonicalNameConstants.EDITABLE.equals(parameterType.toString())) {
editableParameterPosition = 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.getAfterTextChangedBody();
IJExpression activityRef = holder.getGeneratedClass().staticRef("this");
JInvocation textChangeCall = methodBody.invoke(activityRef, methodName);
for (int i = 0; i < parameters.size(); i++) {
if (i == editableParameterPosition) {
JVar afterTextChangeEditableParam = textWatcherHolder.getAfterTextChangedEditableParam();
textChangeCall.arg(afterTextChangeEditableParam);
} else if (i == viewParameterPosition) {
JVar viewParameter = textWatcherHolder.getTextViewVariable();
textChangeCall.arg(viewParameter);
}
}
}
}
use of com.helger.jcodemodel.JVar in project androidannotations by androidannotations.
the class PreferencesDelegate method setAddPreferencesFromResourceBlock.
private void setAddPreferencesFromResourceBlock() {
JMethod method = getGeneratedClass().method(PUBLIC, codeModel().VOID, "addPreferencesFromResource");
method.annotate(Override.class);
JVar preferencesResIdParam = method.param(int.class, "preferencesResId");
method.body().invoke(JExpr._super(), "addPreferencesFromResource").arg(preferencesResIdParam);
addPreferencesFromResourceInjectionBlock = method.body().blockVirtual();
addPreferencesFromResourceAfterInjectionBlock = method.body().blockVirtual();
}
use of com.helger.jcodemodel.JVar in project androidannotations by androidannotations.
the class SharedPrefHolder method createEditorConstructor.
private void createEditorConstructor() {
editorConstructor = editorClass.constructor(JMod.NONE);
AbstractJClass sharedPreferencesClass = getJClass("android.content.SharedPreferences");
JVar sharedPreferencesParam = editorConstructor.param(sharedPreferencesClass, "sharedPreferences");
editorConstructor.body().invoke("super").arg(sharedPreferencesParam);
}
use of com.helger.jcodemodel.JVar in project androidannotations by androidannotations.
the class ViewInstanceStateDelegate method setSaveStateMethod.
private void setSaveStateMethod() {
JMethod method = getGeneratedClass().method(PUBLIC, getClasses().PARCELABLE, "onSaveInstanceState");
method.annotate(Override.class);
JMethod saveStateMethod = getGeneratedClass().method(PRIVATE, codeModel().VOID, "saveInstanceState");
saveStateBundleParam = saveStateMethod.param(getClasses().BUNDLE, "bundle");
saveStateMethodBody = saveStateMethod.body();
JBlock methodBody = method.body();
JVar onSaveSuperInstanceState = methodBody.decl(getClasses().PARCELABLE, "instanceState", _super().invoke("onSaveInstanceState"));
JVar bundleParam = methodBody.decl(getClasses().BUNDLE, "bundle" + generationSuffix(), _new(getClasses().BUNDLE));
methodBody.invoke(bundleParam, "putParcelable").arg(getInstanceStateKey()).arg(onSaveSuperInstanceState);
methodBody.invoke(saveStateMethod).arg(bundleParam);
methodBody._return(bundleParam);
}
Aggregations