use of com.helger.jcodemodel.JMethod in project RoboBinding by RoboBinding.
the class AbstractPresentationModelObjectClassGen method defineTryToCreateDataSetProperty.
/*
@Override
public DataSetProperty tryToCreateDataSetProperty(String name) {
if(name.equals(DATA_SET_PROP)) {
PropertyDescriptor descriptor = createDataSetPropertyDescriptor(List.class, name);
AbstractGetSet<?> getSet = new AbstractGetSet<List<String>>(descriptor) {
@Override
public List<String> getValue() {
return presentationModel.getDataSetProp();
}
};
RefreshableItemPresentationModelFactory factory = new RefreshableItemPresentationModelFactory() {
@Override
public RefreshableItemPresentationModel create(int itemViewType) {
return new StringItemPresentationModel_IPM(new StringItemPresentationModel());
}
};
return new DataSetProperty(this, descriptor, new ListDataSet(factory, getSet));
}
if(name.equals(DATA_SET_PROP_WITH_FACTORY_METHOD)) {
PropertyDescriptor descriptor = createDataSetPropertyDescriptor(List.class, name);
AbstractGetSet<?> getSet = new AbstractGetSet<List<String>>(descriptor) {
@Override
public List<String> getValue() {
return presentationModel.getDataSetPropWithFactoryMethod();
}
};
RefreshableItemPresentationModelFactory factory = new RefreshableItemPresentationModelFactory() {
@Override
public RefreshableItemPresentationModel create(int itemViewType) {
return new StringItemPresentationModel_IPM(presentationModel.newStringItemPresentationModel());
}
};
return new DataSetProperty(this, descriptor, new ListDataSet(factory, getSet));
}
if(name.equals(DATA_SET_PROP_WITH_VIEW_TYPE_SELECTOR)) {
PropertyDescriptor descriptor = createDataSetPropertyDescriptor(List.class, name);
AbstractGetSet<?> getSet = new AbstractGetSet<List<String>>(descriptor) {
@Override
public List<String> getValue() {
return presentationModel.getDataSetPropWithViewTypeSelector();
}
};
RefreshableItemPresentationModelFactory factory = new RefreshableItemPresentationModelFactory() {
@Override
public RefreshableItemPresentationModel create(int itemViewType) {
return new StringItemPresentationModelPOC_IPM(new StringItemPresentationModelPOC());
}
};
ViewTypeSelectable viewTypeSelector = new ViewTypeSelectable() {
@Override
@SuppressWarnings({ "rawtypes", "unchecked" })
public int selectViewType(ViewTypeSelectionContext context) {
return presentationModel.selectViewTypeWithParameter(context);
}
};
return new DataSetProperty(this, descriptor, new ListDataSet(factory, getSet), viewTypeSelector);
}
if(name.equals(DATA_SET_PROP_WITH_FACTORY_METHOD_AND_VIEW_TYPE_SELECTOR)) {
PropertyDescriptor descriptor = createDataSetPropertyDescriptor(List.class, name);
AbstractGetSet<?> getSet = new AbstractGetSet<List<String>>(descriptor) {
@Override
public List<String> getValue() {
return presentationModel.getDataSetPropWithViewTypeSelector();
}
};
RefreshableItemPresentationModelFactory factory = new RefreshableItemPresentationModelFactory() {
@Override
public RefreshableItemPresentationModel create(int itemViewType) {
return new StringItemPresentationModelPOC_IPM(
presentationModel.createStringItemPresentationModelWithParameter(itemViewType));
}
};
ViewTypeSelectable viewTypeSelector = new ViewTypeSelectable() {
@Override
@SuppressWarnings({ "rawtypes", "unchecked" })
public int selectViewType(ViewTypeSelectionContext context) {
return presentationModel.selectViewTypeWithParameter(context);
}
};
return new DataSetProperty(this, descriptor, new ListDataSet(factory, getSet), viewTypeSelector, PreInitializingViews.DEFAULT);
}
return null;
}
*/
public void defineTryToCreateDataSetProperty() {
JMethod method = declarePublicMethodOverride("tryToCreateDataSetProperty", DataSetProperty.class);
JVar nameParam = method.param(String.class, "name");
JBlock body = method.body();
for (DataSetPropertyInfo propertyInfo : presentationModelInfo.dataSetProperties()) {
JConditional conditional = body._if(nameParam.invoke("equals").arg(propertyInfo.name()));
JBlock conditionalBody = conditional._then();
//create createDataSetPropertyDescriptor.
AbstractJClass propertyClass = codeModel.ref(propertyInfo.type());
JInvocation createDataSetPropertyDescriptor = JExpr.invoke("createDataSetPropertyDescriptor").arg(propertyClass.dotclass()).arg(nameParam);
JVar descriptorVar = conditionalBody.decl(propertyDescriptorClass, "descriptor", createDataSetPropertyDescriptor);
//create AbstractGetSet.
AbstractJClass narrowedGetSet = getSetClass.narrow(codeModel.ref(propertyInfo.type()));
JDefinedClass anonymousGetSet = codeModel.anonymousClass(narrowedGetSet);
JMethod getter = declarePublicMethodOverride(anonymousGetSet, "getValue", propertyClass);
getter.body()._return(presentationModelFieldWithoutThis.invoke(propertyInfo.getter()));
JVar getSetVar = conditionalBody.decl(wildcardGetSetClass, "getSet", JExpr._new(anonymousGetSet).arg(descriptorVar));
//JVar getSetVar = conditionalBody.decl(getSetClass, "getSet",
// JExpr._new(anonymousGetSet.narrow(propertyClass)).arg(descriptorVar));
//create RefreshableItemPresentationModelFactory.
JDefinedClass anonymousFactory = codeModel.anonymousClass(RefreshableItemPresentationModelFactory.class);
JMethod create = declarePublicMethodOverride(anonymousFactory, "create", RefreshableItemPresentationModel.class);
JVar itemViewTypeParam = create.param(int.class, "itemViewType");
AbstractJClass itemPresentationModelObjectClass = codeModel.ref(propertyInfo.itemPresentationModelObjectTypeName());
JInvocation newItemPresentationModelObject = JExpr._new(itemPresentationModelObjectClass);
if (propertyInfo.isCreatedByFactoryMethodWithArg()) {
newItemPresentationModelObject.arg(presentationModelFieldWithoutThis.invoke(propertyInfo.factoryMethod()).arg(itemViewTypeParam));
} else if (propertyInfo.isCreatedByFactoryMethodWithoutArg()) {
newItemPresentationModelObject.arg(presentationModelFieldWithoutThis.invoke(propertyInfo.factoryMethod()));
} else {
newItemPresentationModelObject.arg(JExpr._new(codeModel.ref(propertyInfo.itemPresentationModelTypeName())));
}
create.body()._return(newItemPresentationModelObject);
JVar factoryVar = conditionalBody.decl(refreshableItemPresentationModelFactoryClass, "factory", JExpr._new(anonymousFactory));
//new DataSetProperty(this, descriptor, new ListDataSet(factory, getSet));
JInvocation newDataSetProperty = JExpr._new(dataSetPropertyClass).arg(JExpr._this()).arg(descriptorVar).arg(JExpr._new(codeModel.ref(propertyInfo.dataSetImplementationType())).arg(factoryVar).arg(getSetVar));
//create viewTypeSelector.
if (propertyInfo.hasViewTypeSelector()) {
JDefinedClass anonymousViewTypeSelector = codeModel.anonymousClass(ViewTypeSelectable.class);
JMethod selectViewType = declarePublicMethodOverride(anonymousViewTypeSelector, "selectViewType", int.class);
selectViewType.annotate(codeModel.ref(SuppressWarnings.class)).paramArray("value", "rawtypes", "unchecked");
JVar contextParam = selectViewType.param(ViewTypeSelectionContext.class, "context");
JInvocation userSelectViewTypeCall;
if (propertyInfo.viewTypeSelectorAcceptsArg()) {
userSelectViewTypeCall = presentationModelFieldWithoutThis.invoke(propertyInfo.viewTypeSelector()).arg(contextParam);
} else {
userSelectViewTypeCall = presentationModelFieldWithoutThis.invoke(propertyInfo.viewTypeSelector());
}
selectViewType.body()._return(userSelectViewTypeCall);
JVar viewTypeSelectorVar = conditionalBody.decl(viewTypeSelectableClass, "viewTypeSelector", JExpr._new(anonymousViewTypeSelector));
newDataSetProperty.arg(viewTypeSelectorVar);
}
newDataSetProperty.arg(JExpr.enumConstantRef(preInitializingViewsClass, propertyInfo.preInitializingViews().name()));
//return DataSetProperty.
conditionalBody._return(newDataSetProperty);
}
body._return(JExpr._null());
}
use of com.helger.jcodemodel.JMethod in project RoboBinding by RoboBinding.
the class ItemPresentationModelObjectClassGen method defineConstructor.
/**
* public StringItemPresentationModel_IPM(StringItemPresentationModel itemPresentationModel) {
* super(itemPresentationModel);
* this.itemPresentationModel = itemPresentationModel;
* }
*
*/
@Override
public void defineConstructor() {
/*
public class StringItemPresentationModel_IPM extends AbstractItemPresentationModelObject {
*/
definedClass._extends(AbstractItemPresentationModelObject.class);
JMethod constructor = definedClass.constructor(JMod.PUBLIC);
AbstractJType itemPresentationModelClass = codeModel.ref(presentationModelInfo.getPresentationModelTypeName());
JVar itemPresentationModelParam = constructor.param(itemPresentationModelClass, "itemPresentationModel");
JBlock block = constructor.body();
JInvocation superInvocation = JExpr.invoke("super").arg(itemPresentationModelParam);
block.add(superInvocation);
block.assign(presentationModelField, itemPresentationModelParam);
}
use of com.helger.jcodemodel.JMethod in project RoboBinding by RoboBinding.
the class PresentationModelObjectClassGen method defineConstructor.
/**
* public PresentationModelType_PM(PresentationModelType presentationModel) {
* super(presentationModel);
* this.presentationModel = presentationModel;
* }
*
*/
@Override
public void defineConstructor() {
/*
public class PresentationModelType_PM extends AbstractPresentationModelObject {
*/
definedClass._extends(AbstractPresentationModelObject.class);
JMethod constructor = definedClass.constructor(JMod.PUBLIC);
JVar presentationModelParam = constructor.param(presentationModelClass, "presentationModel");
JBlock block = constructor.body();
JInvocation superInvocation = JExpr.invoke("super").arg(presentationModelParam);
block.add(superInvocation);
block.assign(presentationModelField, presentationModelParam);
}
use of com.helger.jcodemodel.JMethod in project RoboBinding by RoboBinding.
the class ViewBindingObjectClassGen method defineConstructor.
/**
*
public MyCustomViewBinding$$VB(MyCustomViewBinding customViewBinding) {
this.customViewBinding = customViewBinding;
}
*
*/
public void defineConstructor() {
JMethod constructor = definedClass.constructor(JMod.PUBLIC);
JVar customViewBindingParam = constructor.param(customViewBindingClass, "customViewBinding");
JBlock block = constructor.body();
block.assign(customViewBindingField, customViewBindingParam);
}
use of com.helger.jcodemodel.JMethod in project RoboBinding by RoboBinding.
the class ViewBindingObjectClassGen method defineMapBindingAttributesMethod.
/**
*
@Override
public void mapBindingAttributes(BindingAttributeMappings<ImageView> mappings) {
mappings.mapOneWayProperty(ImageAlphaAttribute.class, "imageAlpha");
mappings.mapOneWayProperty(MaxWidthAttribute.class, "maxWidth");
mappings.mapOneWayProperty(MaxHeightAttribute.class, "maxHeight");
customViewBinding.mapBindingAttributes(mappings);
}
*
*/
public void defineMapBindingAttributesMethod() {
JMethod method = definedClass.method(JMod.PUBLIC, codeModel.VOID, "mapBindingAttributes");
method.annotate(Override.class);
AbstractJClass bindingAttributeMappingsType = codeModel.ref(BindingAttributeMappings.class).narrow(viewClass);
JVar mappingsParam = method.param(bindingAttributeMappingsType, "mappings");
JBlock body = method.body();
for (SimpleOneWayPropertyInfo info : simpleOneWayPropertyInfoList) {
body.invoke(mappingsParam, "mapOneWayProperty").arg(info.getBindingClass().dotclass()).arg(info.propertyName());
}
body.invoke(customViewBindingFieldWithoutThis, "mapBindingAttributes").arg(mappingsParam);
}
Aggregations