use of com.helger.jcodemodel.JConditional 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.JConditional in project adt4j by sviperll.
the class EqualsMethod method appendNonnullObject.
private void appendNonnullObject(IJExpression value1, IJExpression value2, boolean isLast) {
JInvocation invocation = value1.invoke("equals");
invocation.arg(value2);
if (isLast) {
body._return(invocation);
} else {
JConditional _if = body._if(invocation.not());
_if._then()._return(JExpr.FALSE);
}
}
use of com.helger.jcodemodel.JConditional in project adt4j by sviperll.
the class EqualsMethod method appendNullableValueAndReturn.
void appendNullableValueAndReturn(AbstractJType type, IJExpression value1, IJExpression value2) {
if (!type.isReference()) {
throw new AssertionError("appendNullableValue called for non-reference type");
} else {
JConditional _if = body._if(value1.eq(JExpr._null()));
_if._then()._return(value2.eq(JExpr._null()));
EqualsMethod innerBody = new EqualsMethod(types, _if._else(), nameSource, floatCustomization);
innerBody.appendNotNullValueAndReturn(type, value1, value2);
}
}
Aggregations