use of com.helger.jcodemodel.AbstractJClass in project adt4j by sviperll.
the class ValueClassConfiguration method wrapValue.
public IJExpression wrapValue(AbstractJType usedWrappedClassType, IJExpression valueExpression) {
AbstractJClass wrapperClass = customization.wrapperClass();
if (wrapperClass == null)
return valueExpression;
else {
JInvocation invocation1 = JExpr._new(usedWrappedClassType);
invocation1.arg(valueExpression);
return invocation1;
}
}
use of com.helger.jcodemodel.AbstractJClass in project adt4j by sviperll.
the class ValueClassConfiguration method getUpdatersConfiguration.
public GenerationResult<Map<String, FieldConfiguration>> getUpdatersConfiguration(JDefinedClass valueClass, Types types) {
GenerationProcess generation = new GenerationProcess();
AbstractJClass usedValueClassType = Source.narrowType(valueClass, valueClass.typeParams());
Map<String, FieldConfiguration> updatersMap = new TreeMap<>();
FieldReader reader = new FieldReader(updatersMap);
VisitorDefinition.VisitorUsage narrowed = visitorDefinition.narrowed(usedValueClassType, visitorDefinition.getResultTypeParameter(), types._RuntimeException);
for (MethodUsage interfaceMethod : narrowed.methods()) {
for (VariableDeclaration param : interfaceMethod.params()) {
generation.processGenerationResult(reader.readUpdater(interfaceMethod, param, param.type().declarable(), false));
}
VariableDeclaration param = interfaceMethod.varParam();
if (param != null) {
generation.processGenerationResult(reader.readUpdater(interfaceMethod, param, param.type().declarable(), true));
}
}
return generation.createGenerationResult(updatersMap);
}
use of com.helger.jcodemodel.AbstractJClass in project adt4j by sviperll.
the class Source method getNullability.
public static GenerationResult<Boolean> getNullability(AbstractJType type, String name, Collection<? extends JAnnotationUse> annotations) {
boolean hasNonnull = false;
boolean hasNullable = false;
for (JAnnotationUse annotationUse : annotations) {
AbstractJClass annotationClass = annotationUse.getAnnotationClass();
if (!annotationClass.isError()) {
String annotationClassName = annotationClass.fullName();
if (annotationClassName != null) {
if (annotationClassName.equals("javax.annotation.Nonnull")) {
hasNonnull = true;
}
if (annotationClassName.equals("javax.annotation.Nullable")) {
hasNullable = true;
}
}
}
}
if (hasNonnull && hasNullable)
return new GenerationResult<>(false, Collections.singletonList(MessageFormat.format("Parameter {0} is declared as both @Nullable and @Nonnull", name)));
if (!type.isReference() && hasNullable)
return new GenerationResult<>(false, Collections.singletonList(MessageFormat.format("Parameter {0} is non-reference, but declared as @Nullable", name)));
return new GenerationResult<>(hasNullable, Collections.<String>emptyList());
}
use of com.helger.jcodemodel.AbstractJClass in project RoboBinding by RoboBinding.
the class AbstractPresentationModelObjectClassGen method defineTryToCreateProperty.
/*
@Override
public SimpleProperty tryToCreateProperty(String name) {
if(name.equals(PROP1)) {
PropertyDescriptor descriptor = createPropertyDescriptor(String.class, name, true, true);
AbstractGetSet<?> getSet = new AbstractGetSet<String>(descriptor) {
@Override
public String getValue() {
return presentationModel.getProp1();
}
@Override
public void setValue(String newValue) {
presentationModel.setProp1(newValue);
}
};
return new SimpleProperty(this, descriptor, getSet);
}
if(name.equals(PROP2)) {
PropertyDescriptor descriptor = createPropertyDescriptor(Integer.class, name, true, true);
AbstractGetSet<?> getSet = new AbstractGetSet<Integer>(descriptor) {
@Override
public Integer getValue() {
return presentationModel.getProp2();
}
@Override
public void setValue(Integer newValue) {
presentationModel.setProp2(newValue);
}
};
return new SimpleProperty(this, descriptor, getSet);
}
return null;
}
*/
public void defineTryToCreateProperty() {
try {
JMethod method = declarePublicMethodOverride("tryToCreateProperty", SimpleProperty.class);
JVar nameParam = method.param(String.class, "name");
JBlock body = method.body();
for (PropertyInfo propertyInfo : presentationModelInfo.properties()) {
JConditional conditional = body._if(nameParam.invoke("equals").arg(propertyInfo.name()));
JBlock conditionalBody = conditional._then();
//create PropertyDescriptor.
AbstractJClass propertyClass = codeModel.ref(propertyInfo.typeName());
JInvocation createPropertyDescriptor = JExpr.invoke("createPropertyDescriptor").arg(propertyClass.dotclass()).arg(nameParam).arg(JExpr.lit(propertyInfo.isReadable())).arg(JExpr.lit(propertyInfo.isWritable()));
JVar descriptorVar = conditionalBody.decl(propertyDescriptorClass, "descriptor", createPropertyDescriptor);
//create AbstractGetSet.
//JClass narrowedGetSet = getSetClass.narrow(codeModel.ref(propertyInfo.typeName()));
AbstractJClass narrowedGetSet = getSetClass.narrow(propertyClass);
JDefinedClass anonymousGetSet = codeModel.anonymousClass(narrowedGetSet);
if (propertyInfo.isReadable()) {
JMethod getter = declarePublicMethodOverride(anonymousGetSet, "getValue", propertyClass);
getter.body()._return(presentationModelFieldWithoutThis.invoke(propertyInfo.getter()));
}
if (propertyInfo.isWritable()) {
JMethod setter = declarePublicMethodOverride(anonymousGetSet, "setValue", Void.TYPE);
JVar newValueParam = setter.param(propertyClass, "newValue");
setter.body().add(presentationModelFieldWithoutThis.invoke(propertyInfo.setter()).arg(newValueParam));
}
JVar getSetVar = conditionalBody.decl(wildcardGetSetClass, "getSet", JExpr._new(anonymousGetSet).arg(descriptorVar));
//return SimpleProperty.
conditionalBody._return(JExpr._new(simplePropertyClass).arg(JExpr._this()).arg(descriptorVar).arg(getSetVar));
}
body._return(JExpr._null());
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of com.helger.jcodemodel.AbstractJClass 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());
}
Aggregations