本文整理汇总了Java中com.sun.codemodel.JSwitch类的典型用法代码示例。如果您正苦于以下问题:Java JSwitch类的具体用法?Java JSwitch怎么用?Java JSwitch使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
JSwitch类属于com.sun.codemodel包,在下文中一共展示了JSwitch类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: createMethodFieldIsSet
import com.sun.codemodel.JSwitch; //导入依赖的package包/类
private void createMethodFieldIsSet(JDefinedClass _class, Map<String, JType> fields) {
JMethod method = _class.method(JMod.PUBLIC, codeModel.BOOLEAN, "isSet");
JClass refEnumFields = codeModel.ref(_class.fullName() + DOT_FIELD);
JVar param = method.param(refEnumFields, "field");
method.body()._if(param.eq(JExpr._null()))._then()._throw(JExpr._new(codeModel.ref(IllegalStateException.class)));
JSwitch _switch = method.body()._switch(param);
for (Map.Entry<String, JType> entry : fields.entrySet()) {
JBlock bodyCase = _switch._case(JExpr.ref(entry.getKey().toUpperCase())).body();
String capitalizeName = JavaGeneratorUtil.getCapitalizeString(entry.getKey());
bodyCase._return(JExpr.invoke("isSet" + capitalizeName));
}
JInvocation _newException = JExpr._new(codeModel.ref(IllegalStateException.class));
method.body()._throw(_newException);
}
开发者ID:l3ug1m,项目名称:thrift-java-compiler,代码行数:19,代码来源:StructCodeGeneratorHelper.java
示例2: createMethodFieldSetFieldValue
import com.sun.codemodel.JSwitch; //导入依赖的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
示例3: createMethodFielGetFieldValue
import com.sun.codemodel.JSwitch; //导入依赖的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
示例4: addInternalGetMethodJava7
import com.sun.codemodel.JSwitch; //导入依赖的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
示例5: addInternalSetMethodJava7
import com.sun.codemodel.JSwitch; //导入依赖的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
示例6: createStateActionMethod
import com.sun.codemodel.JSwitch; //导入依赖的package包/类
private JMethod createStateActionMethod(State s){
JMethod method = clazz.method(JMod.PRIVATE, actionsEnum,
"getState"+stateIndex.get(s)+"Action");
JVar lookahead = method.param(f.getNodeInterface().narrow(nodes.getVisitorInterface()), "lookahead");
JSwitch sw = method.body()._switch(symbolGen.castTo(JExpr.invoke(lookahead, "symbol")));
List<JExpression> expected = new ArrayList<JExpression>();
//add a case statement for each valid lookahead symbol
for(String symbol : nodes.getAllSymbols()){
Action a = table.getAction(s, symbol);
if(a != null){
JEnumConstant actionConst = this.defineAction(a);
sw._case(symbolGen.getRef(symbol)).body()._return(actionConst);
expected.add(symbolGen.getSymbolObj(symbol));
}
}
//the default case should return error action
sw._default().body()._return(actionsEnum.enumConstant("ERROR"));
JArray array = JExpr.newArray(f.getSymbolInterface());
for(JExpression exp : expected){
array.add(exp);
}
expectedStateSwitch._case(JExpr.lit(stateIndex.get(s)))
.body()._return(array);
return method;
}
开发者ID:tbepler,项目名称:LRPaGe,代码行数:29,代码来源:ParsingEngineGenerator.java
示例7: addGetPropertyCase
import com.sun.codemodel.JSwitch; //导入依赖的package包/类
private void addGetPropertyCase(JDefinedClass jclass, JSwitch propertySwitch, String propertyName, JType propertyType, JsonNode node) {
JMethod propertyGetter = jclass.getMethod(getGetterName(propertyName, propertyType, node), new JType[] {});
propertySwitch._case(lit(propertyName)).body()
._return(invoke(propertyGetter));
}
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:6,代码来源:DynamicPropertiesRule.java
示例8: addSetPropertyCase
import com.sun.codemodel.JSwitch; //导入依赖的package包/类
private void addSetPropertyCase(JDefinedClass jclass, JSwitch setterSwitch, String propertyName, JType propertyType, JVar valueVar, JsonNode node) {
JBlock setterBody = setterSwitch._case(lit(propertyName)).body();
addSetProperty(jclass, setterBody, propertyName, propertyType, valueVar, node);
setterBody._return(TRUE);
}
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:6,代码来源:DynamicPropertiesRule.java
示例9: introduceUserCodeBlock
import com.sun.codemodel.JSwitch; //导入依赖的package包/类
private void introduceUserCodeBlock(JDefinedClass jc, JCodeModel jm,
ConcreticisedMethod block,
JSwitch methodSwitch,
JVar _ca2, JVar _ca1,
Map<String, JMethod> virtualMethods) {
JMethod vmethhandler = jc.method(JMod.PUBLIC,
jm.VOID,
block.getRefMeth().getArguments().get(0).getIdentificator());
vmethhandler._throws(AVEInternaException.class);
vmethhandler.javadoc().add("Virtual method handler for " + block.getMethodName() + " method.");
vmethhandler.javadoc().addThrows(AVEInternaException.class).
add("Throws when message has an invalid instance.");
allMethods.put(UCB_DECLPREFIX + block.getMethodName(), methodsEnum.enumConstant(UCB_DECLPREFIX + block.getMethodName()));
JBlock userBlockSwitch = methodSwitch._case(JExpr.ref(UCB_DECLPREFIX + block.getMethodName())).body();
JArray mthNames = JExpr.newArray(jm.ref(String.class));
int argId = 0;
for (Argument arg : block.getRefMeth().getArguments()) {
String defaultV = arg.getDefaultValue();
userBlockSwitch.add(_ca2.invoke("add").arg(
JExpr._new(jm.ref(Node.class))
.arg(arg.getIdentificator())
.arg(arg.getType())
.arg(defaultV == null ? "" : defaultV)
.arg(JExpr.lit(arg.isFixed()))));
mthNames.add(JExpr.lit(arg.getIdentificator()));
vmethargs.put(block.getMethodName() + argId, vmethhandler.param(Message.class, arg.getIdentificator()));
argId++;
}
userBlockSwitch.add(_ca1.invoke("add").arg(jm.ref(Arrays.class)
.staticInvoke("asList").arg(mthNames)));
userBlockSwitch._break();
virtualMethods.put(block.getMethodName(), vmethhandler);
}
开发者ID:vlarin,项目名称:visualakka,代码行数:43,代码来源:DefaultGenerator.java
示例10: _switch
import com.sun.codemodel.JSwitch; //导入依赖的package包/类
@Override
public JSwitch _switch(JExpression test) {
return block._switch(test);
}
开发者ID:kompics,项目名称:kola,代码行数:5,代码来源:JBlockParent.java
示例11: SwitchLabelAdapter
import com.sun.codemodel.JSwitch; //导入依赖的package包/类
SwitchLabelAdapter(JSwitch _switch, ResolutionContext context) {
this.context = context;
this._switch = _switch;
}
开发者ID:kompics,项目名称:kola,代码行数:5,代码来源:SwitchLabelAdapter.java
示例12: generateReadAttributeResponseGetSize
import com.sun.codemodel.JSwitch; //导入依赖的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
示例13: _switch
import com.sun.codemodel.JSwitch; //导入依赖的package包/类
public JSwitch _switch(JExpression test);
开发者ID:kompics,项目名称:kola,代码行数:2,代码来源:StatementAdapter.java
注:本文中的com.sun.codemodel.JSwitch类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论