use of com.helger.jcodemodel.JMethod 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.JMethod in project RoboBinding by RoboBinding.
the class AbstractPresentationModelObjectClassGen method defineEventMethods.
/*
@Override
public Set<MethodDescriptor> eventMethods() {
return Sets.newHashSet(
createMethodDescriptor(ON_CLICK),
createMethodDescriptor(ON_CLICK_WITH_EVENT, AbstractViewEvent.class));
}
*/
public void defineEventMethods() {
JMethod method = declarePublicMethodOverride("eventMethods", setClassWithMethodDescriptor);
JInvocation invocation = codeModel.ref(Sets.class).staticInvoke("newHashSet");
for (EventMethodInfo eventMethod : presentationModelInfo.eventMethods()) {
JInvocation getMethodInvocation = JExpr.invoke("createMethodDescriptor").arg(eventMethod.name());
if (eventMethod.hasEventArg()) {
getMethodInvocation.arg(codeModel.ref(eventMethod.eventArgType()).dotclass());
}
invocation.arg(getMethodInvocation);
}
method.body()._return(invocation);
}
use of com.helger.jcodemodel.JMethod in project RoboBinding by RoboBinding.
the class AbstractPresentationModelObjectClassGen method declarePublicMethodOverride.
private static JMethod declarePublicMethodOverride(JDefinedClass definedClass, String methodName, Class<?> returnType) {
JMethod method = definedClass.method(JMod.PUBLIC, returnType, methodName);
method.annotate(Override.class);
return method;
}
use of com.helger.jcodemodel.JMethod in project RoboBinding by RoboBinding.
the class AbstractPresentationModelObjectClassGen method definePropertyDependencies.
/*
@Override
public Map<String, Set<String>> propertyDependencies() {
Map<String, Set<String>> dependencies = Maps.newHashMap();
dependencies.put(PROP1, Sets.newHashSet(PROP2));
return dependencies;
}
*/
public void definePropertyDependencies() {
JMethod method = declarePublicMethodOverride("propertyDependencies", mapClassWithStringAndStringSet);
JBlock body = method.body();
JVar dependenciesVar = body.decl(mapClassWithStringAndStringSet, "dependencies", codeModel.ref(Maps.class).staticInvoke("newHashMap"));
for (PropertyDependencyInfo propertyDependencyInfo : presentationModelInfo.propertyDependencies()) {
body.add(dependenciesVar.invoke("put").arg(propertyDependencyInfo.property()).arg(newHashSetInvocation(propertyDependencyInfo.dependentProperties())));
}
body._return(dependenciesVar);
}
use of com.helger.jcodemodel.JMethod in project RoboBinding by RoboBinding.
the class AbstractPresentationModelObjectClassGen method declarePublicMethodOverride.
private static JMethod declarePublicMethodOverride(JDefinedClass definedClass, String methodName, AbstractJClass returnType) {
JMethod method = definedClass.method(JMod.PUBLIC, returnType, methodName);
method.annotate(Override.class);
return method;
}
Aggregations