use of com.helger.jcodemodel.JBlock in project RoboBinding by RoboBinding.
the class ViewBindingObjectClassGen method defineSimpleOneWayPropertyClasses.
/**
* private static class ImageAlphaAttribute implements OneWayPropertyViewAttribute<ImageView, Integer> {
* @Override
* public void updateView(ImageView view, Integer newValue) {
* view.setImageAlpha(newValue);
* }
* }
*/
public void defineSimpleOneWayPropertyClasses() {
for (SimpleOneWayPropertyInfo propInfo : simpleOneWayPropertyInfoList) {
JDefinedClass definedBindingAttributeClass = propInfo.defineBindingClass(new ClassDefinitionCallback() {
@Override
public JDefinedClass define(String typeName) {
try {
return definedClass._class(JMod.PUBLIC | JMod.STATIC, typeName);
} catch (JClassAlreadyExistsException e) {
throw new RuntimeException("Class '" + typeName + "' already exists", e);
}
}
});
AbstractJClass propertyClass = codeModel.ref(propInfo.propertyType());
AbstractJClass oneWayPropertyInterface = codeModel.ref(OneWayPropertyViewAttribute.class).narrow(viewClass, propertyClass);
definedBindingAttributeClass._implements(oneWayPropertyInterface);
JMethod method = definedBindingAttributeClass.method(JMod.PUBLIC, codeModel.VOID, "updateView");
method.annotate(Override.class);
JVar viewParam = method.param(viewClass, "view");
JVar newValueParam = method.param(propertyClass, "newValue");
JBlock body = method.body();
body.invoke(viewParam, propInfo.propertySetter()).arg(newValueParam);
}
}
use of com.helger.jcodemodel.JBlock in project androidannotations by androidannotations.
the class InjectHelper method processMethod.
private void processMethod(Element element, T holder) {
ExecutableElement executableElement = (ExecutableElement) element;
VariableElement param = executableElement.getParameters().get(0);
String methodName = executableElement.getSimpleName().toString();
JBlock block = createBlock(holder, true);
AbstractJClass type = codeModelHelper.typeMirrorToJClass(param.asType());
JVar fieldRef = block.decl(type, param.getSimpleName().toString(), getDefault(param.asType()));
handler.assignValue(block, fieldRef, holder, element, param);
block.add(JExpr.invoke(methodName).arg(fieldRef));
}
use of com.helger.jcodemodel.JBlock in project androidannotations by androidannotations.
the class EActivityHolder method setContentViewMethod.
private JMethod setContentViewMethod(AbstractJType[] paramTypes, String[] paramNames) {
JMethod method = generatedClass.method(JMod.PUBLIC, getCodeModel().VOID, "setContentView");
method.annotate(Override.class);
List<JVar> params = new ArrayList<>();
for (int i = 0; i < paramTypes.length; i++) {
JVar param = method.param(paramTypes[i], paramNames[i]);
params.add(param);
}
JBlock body = method.body();
JInvocation superCall = body.invoke(JExpr._super(), method);
for (JVar arg : params) {
superCall.arg(arg);
}
viewNotifierHelper.invokeViewChanged(body);
return method;
}
use of com.helger.jcodemodel.JBlock in project androidannotations by androidannotations.
the class EActivityHolder method setOnStart.
// CHECKSTYLE:OFF
private void setOnStart() {
JMethod method = generatedClass.method(JMod.PUBLIC, getCodeModel().VOID, "onStart");
method.annotate(Override.class);
JBlock body = method.body();
onStartBeforeSuperBlock = body.blockSimple();
body.invoke(_super(), method);
onStartAfterSuperBlock = body.blockSimple();
}
use of com.helger.jcodemodel.JBlock in project androidannotations by androidannotations.
the class EActivityHolder method setOnRetainNonConfigurationInstance.
private void setOnRetainNonConfigurationInstance() throws JClassAlreadyExistsException {
AnnotationHelper annotationHelper = new AnnotationHelper(getEnvironment());
TypeElement fragmentActivityTypeElement = getFragmentActivity(annotationHelper);
TypeElement typeElement = annotationHelper.typeElementFromQualifiedName(generatedClass._extends().fullName());
String onRetainNonConfigurationInstanceName = "onRetainNonConfigurationInstance";
if (fragmentActivityTypeElement != null && annotationHelper.isSubtype(typeElement.asType(), fragmentActivityTypeElement.asType())) {
onRetainNonConfigurationInstanceName = "onRetainCustomNonConfigurationInstance";
}
NonConfigurationHolder ncHolder = getNonConfigurationHolder();
JDefinedClass ncHolderClass = ncHolder.getGeneratedClass();
JMethod onRetainNonConfigurationInstanceMethod = generatedClass.method(PUBLIC, ncHolderClass, onRetainNonConfigurationInstanceName);
onRetainNonConfigurationInstanceMethod.annotate(Override.class);
JBlock methodBody = onRetainNonConfigurationInstanceMethod.body();
onRetainNonConfigurationInstance = methodBody.decl(ncHolderClass, "nonConfigurationInstanceState_", _new(ncHolderClass));
IJExpression superCall = _super().invoke(onRetainNonConfigurationInstanceMethod);
methodBody.assign(onRetainNonConfigurationInstance.ref(ncHolder.getSuperNonConfigurationInstanceField()), superCall);
onRetainNonConfigurationInstanceBindBlock = methodBody.blockSimple();
methodBody._return(onRetainNonConfigurationInstance);
}
Aggregations