当前位置: 首页>>代码示例>>Java>>正文


Java JBlock._switch方法代码示例

本文整理汇总了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);

	}
 
开发者ID:l3ug1m,项目名称:thrift-java-compiler,代码行数:22,代码来源:StructCodeGeneratorHelper.java

示例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);
	}
 
开发者ID:l3ug1m,项目名称:thrift-java-compiler,代码行数:18,代码来源:StructCodeGeneratorHelper.java

示例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;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:32,代码来源:DynamicPropertiesRule.java

示例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;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:30,代码来源:DynamicPropertiesRule.java

示例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)));
}
 
开发者ID:nport,项目名称:jemma.ah.zigbee.zcl.compiler,代码行数:50,代码来源:ZclGenerator.java


注:本文中的com.sun.codemodel.JBlock._switch方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。