本文整理汇总了Java中com.sun.codemodel.JBlock._switch方法的典型用法代码示例。如果您正苦于以下问题:Java JBlock._switch方法的具体用法?Java JBlock._switch怎么用?Java JBlock._switch使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.sun.codemodel.JBlock
的用法示例。
在下文中一共展示了JBlock._switch方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createMethodFieldSetFieldValue
import com.sun.codemodel.JBlock; //导入方法依赖的package包/类
private void createMethodFieldSetFieldValue(JDefinedClass _class, Map<String, JType> fields) {
JMethod method = _class.method(JMod.PUBLIC, Void.TYPE, "setFieldValue");
JClass refEnumFields = codeModel.ref(_class.fullName() + DOT_FIELD);
JVar param = method.param(refEnumFields, "field");
JVar param2 = method.param(codeModel.ref(Object.class), "value");
JBlock body = method.body();
JSwitch _switch = body._switch(param);
for (Map.Entry<String, JType> entry : fields.entrySet()) {
JBlock bodyCase = _switch._case(JExpr.ref(entry.getKey().toUpperCase())).body();
JConditional _if = bodyCase._if(param2.eq(JExpr._null()));
String capitalizeName = JavaGeneratorUtil.getCapitalizeString(entry.getKey());
_if._then().invoke("unset" + capitalizeName);
_if._else().invoke("set" + capitalizeName).arg(JExpr.cast(getTypeGetMethodByName(_class, capitalizeName), param2));
bodyCase._break();
}
// JInvocation _newException = JExpr._new(codeModel.ref(IllegalStateException.class));
// _switch._default().body()._throw(_newException);
}
示例2: createMethodFielGetFieldValue
import com.sun.codemodel.JBlock; //导入方法依赖的package包/类
private void createMethodFielGetFieldValue(JDefinedClass _class, Map<String, JType> fields) {
JMethod method = _class.method(JMod.PUBLIC, codeModel.ref(Object.class), "getFieldValue");
JClass refEnumFields = codeModel.ref(_class.fullName() + DOT_FIELD);
JVar param = method.param(refEnumFields, "field");
JBlock body = method.body();
JSwitch _switch = body._switch(param);
for (Map.Entry<String, JType> entry : fields.entrySet()) {
_switch._case(JExpr.ref(entry.getKey().toUpperCase())).body()._return(JExpr.invoke("get" + JavaGeneratorUtil.getCapitalizeString(entry.getKey())));
}
JInvocation _newException = JExpr._new(codeModel.ref(IllegalStateException.class));
// _switch._default().body()._throw(_newException);
body._throw(_newException);
}
示例3: addInternalGetMethodJava7
import com.sun.codemodel.JBlock; //导入方法依赖的package包/类
private JMethod addInternalGetMethodJava7(JDefinedClass jclass, JsonNode propertiesNode) {
JMethod method = jclass.method(PROTECTED, jclass.owner()._ref(Object.class), DEFINED_GETTER_NAME);
JVar nameParam = method.param(String.class, "name");
JVar notFoundParam = method.param(jclass.owner()._ref(Object.class), "notFoundValue");
JBlock body = method.body();
JSwitch propertySwitch = body._switch(nameParam);
if (propertiesNode != null) {
for (Iterator<Map.Entry<String, JsonNode>> properties = propertiesNode.fields(); properties.hasNext();) {
Map.Entry<String, JsonNode> property = properties.next();
String propertyName = property.getKey();
JsonNode node = property.getValue();
String fieldName = ruleFactory.getNameHelper().getPropertyName(propertyName, node);
JType propertyType = jclass.fields().get(fieldName).type();
addGetPropertyCase(jclass, propertySwitch, propertyName, propertyType, node);
}
}
JClass extendsType = jclass._extends();
if (extendsType != null && extendsType instanceof JDefinedClass) {
JDefinedClass parentClass = (JDefinedClass) extendsType;
JMethod parentMethod = parentClass.getMethod(DEFINED_GETTER_NAME,
new JType[] { parentClass.owner()._ref(String.class), parentClass.owner()._ref(Object.class) });
propertySwitch._default().body()
._return(_super().invoke(parentMethod).arg(nameParam).arg(notFoundParam));
} else {
propertySwitch._default().body()
._return(notFoundParam);
}
return method;
}
示例4: addInternalSetMethodJava7
import com.sun.codemodel.JBlock; //导入方法依赖的package包/类
private JMethod addInternalSetMethodJava7(JDefinedClass jclass, JsonNode propertiesNode) {
JMethod method = jclass.method(PROTECTED, jclass.owner().BOOLEAN, DEFINED_SETTER_NAME);
JVar nameParam = method.param(String.class, "name");
JVar valueParam = method.param(Object.class, "value");
JBlock body = method.body();
JSwitch propertySwitch = body._switch(nameParam);
if (propertiesNode != null) {
for (Iterator<Map.Entry<String, JsonNode>> properties = propertiesNode.fields(); properties.hasNext();) {
Map.Entry<String, JsonNode> property = properties.next();
String propertyName = property.getKey();
JsonNode node = property.getValue();
String fieldName = ruleFactory.getNameHelper().getPropertyName(propertyName, node);
JType propertyType = jclass.fields().get(fieldName).type();
addSetPropertyCase(jclass, propertySwitch, propertyName, propertyType, valueParam, node);
}
}
JBlock defaultBlock = propertySwitch._default().body();
JClass extendsType = jclass._extends();
if (extendsType != null && extendsType instanceof JDefinedClass) {
JDefinedClass parentClass = (JDefinedClass) extendsType;
JMethod parentMethod = parentClass.getMethod(DEFINED_SETTER_NAME,
new JType[] { parentClass.owner()._ref(String.class), parentClass.owner()._ref(Object.class) });
defaultBlock._return(_super().invoke(parentMethod).arg(nameParam).arg(valueParam));
} else {
defaultBlock._return(FALSE);
}
return method;
}
示例5: generateReadAttributeResponseGetSize
import com.sun.codemodel.JBlock; //导入方法依赖的package包/类
private void generateReadAttributeResponseGetSize(JCodeModel jModel, JPackage jPackage, JDefinedClass jClusterClass,
ZclClusterDescriptor zclClusterDescriptor, boolean isServer) throws Exception {
Vector zclAttributeDescriptors = null;
if (isServer)
zclAttributeDescriptors = zclClusterDescriptor.getZclClientAttributesDescriptors();
else
zclAttributeDescriptors = zclClusterDescriptor.getZclServerAttributesDescriptors();
if (zclAttributeDescriptors.size() == 0)
return;
JClass jZCLClass = jModel.ref(ZCL.class);
JMethod jReadAttibuteMethod = jClusterClass.method(JMod.PROTECTED, int.class, "readAttributeResponseGetSize");
JVar jAttrIdVar = jReadAttibuteMethod.param(int.class, "attrId");
jReadAttibuteMethod._throws(ServiceClusterException.class);
jReadAttibuteMethod._throws(ZclValidationException.class);
JBlock jBlock = jReadAttibuteMethod.body();
JClass interfaceClass = getClusterConnectionClass(zclClusterDescriptor, !isServer);
if (interfaceClass == null) {
return;
}
JSwitch jSwitch = jBlock._switch(jAttrIdVar);
JBlock jCaseBody = null;
for (int i = 0; i < zclAttributeDescriptors.size(); i++) {
ZclAttributeDescr zclAttributeDescriptor = (ZclAttributeDescr) zclAttributeDescriptors.get(i);
logDebug(zclClusterDescriptor.getName() + ":" + zclAttributeDescriptor.getName() + ": generating get size");
jCaseBody = jSwitch._case(JExpr.lit(zclAttributeDescriptor.getId())).body();
JType type = jTypeForZbTypename(jModel, jClusterClass.getPackage(), zclAttributeDescriptor.getTypeName(),
zclAttributeDescriptor);
JClass jClassZigBeeType = getZclDataTypeJClass(jModel, jClusterClass.getPackage(), jClusterClass,
zclAttributeDescriptor.getTypeName(), zclAttributeDescriptor);
JExpression nullValue = jNullValue4ZigBeeTypeName(jModel, zclAttributeDescriptor.getTypeName());
jCaseBody._return(jClassZigBeeType.staticInvoke("zclSize").arg(nullValue));
}
jSwitch._default().body()._throw(JExpr._new(jModel.ref(UnsupportedClusterAttributeException.class)));
}