本文整理汇总了Java中com.sun.codemodel.JBlock._throw方法的典型用法代码示例。如果您正苦于以下问题:Java JBlock._throw方法的具体用法?Java JBlock._throw怎么用?Java JBlock._throw使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.sun.codemodel.JBlock
的用法示例。
在下文中一共展示了JBlock._throw方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addPublicGetMethod
import com.sun.codemodel.JBlock; //导入方法依赖的package包/类
private JMethod addPublicGetMethod(JDefinedClass jclass, JMethod internalGetMethod, JFieldRef notFoundValue) {
JMethod method = jclass.method(PUBLIC, jclass.owner()._ref(Object.class), GETTER_NAME);
JTypeVar returnType = method.generify("T");
method.type(returnType);
Models.suppressWarnings(method, "unchecked");
JVar nameParam = method.param(String.class, "name");
JBlock body = method.body();
JVar valueVar = body.decl(jclass.owner()._ref(Object.class), "value",
invoke(internalGetMethod).arg(nameParam).arg(notFoundValue));
JConditional found = method.body()._if(notFoundValue.ne(valueVar));
found._then()._return(cast(returnType, valueVar));
JBlock notFound = found._else();
JMethod getAdditionalProperties = jclass.getMethod("getAdditionalProperties", new JType[] {});
if (getAdditionalProperties != null) {
notFound._return(cast(returnType, invoke(getAdditionalProperties).invoke("get").arg(nameParam)));
} else {
notFound._throw(illegalArgumentInvocation(jclass, nameParam));
}
return method;
}
示例2: addPublicSetMethod
import com.sun.codemodel.JBlock; //导入方法依赖的package包/类
private JMethod addPublicSetMethod(JDefinedClass jclass, JMethod internalSetMethod) {
JMethod method = jclass.method(PUBLIC, jclass.owner().VOID, SETTER_NAME);
JVar nameParam = method.param(String.class, "name");
JVar valueParam = method.param(Object.class, "value");
JBlock body = method.body();
JBlock notFound = body._if(JOp.not(invoke(internalSetMethod).arg(nameParam).arg(valueParam)))._then();
// if we have additional properties, then put value.
JMethod getAdditionalProperties = jclass.getMethod("getAdditionalProperties", new JType[] {});
if (getAdditionalProperties != null) {
JType additionalPropertiesType = ((JClass) (getAdditionalProperties.type())).getTypeParameters().get(1);
notFound.add(invoke(getAdditionalProperties).invoke("put").arg(nameParam)
.arg(cast(additionalPropertiesType, valueParam)));
}
// else throw exception.
else {
notFound._throw(illegalArgumentInvocation(jclass, nameParam));
}
return method;
}
示例3: addPublicWithMethod
import com.sun.codemodel.JBlock; //导入方法依赖的package包/类
private JMethod addPublicWithMethod(JDefinedClass jclass, JMethod internalSetMethod) {
JMethod method = jclass.method(PUBLIC, jclass, BUILDER_NAME);
JVar nameParam = method.param(String.class, "name");
JVar valueParam = method.param(Object.class, "value");
JBlock body = method.body();
JBlock notFound = body._if(JOp.not(invoke(internalSetMethod).arg(nameParam).arg(valueParam)))._then();
// if we have additional properties, then put value.
JMethod getAdditionalProperties = jclass.getMethod("getAdditionalProperties", new JType[] {});
if (getAdditionalProperties != null) {
JType additionalPropertiesType = ((JClass) (getAdditionalProperties.type())).getTypeParameters().get(1);
notFound.add(invoke(getAdditionalProperties).invoke("put").arg(nameParam)
.arg(cast(additionalPropertiesType, valueParam)));
}
// else throw exception.
else {
notFound._throw(illegalArgumentInvocation(jclass, nameParam));
}
body._return(_this());
return method;
}
示例4: 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);
}
示例5: generateEnumFromStringMethod
import com.sun.codemodel.JBlock; //导入方法依赖的package包/类
private void generateEnumFromStringMethod(JDefinedClass klass, JFieldVar valueField) {
JMethod converter = klass.method(JMod.PUBLIC | JMod.STATIC, klass, "fromString");
JVar param = converter.param(String.class, VALUE);
JBlock body = converter.body();
JForEach forEach = body.forEach(klass, "v", klass.staticInvoke("values"));
JBlock loopBlock = forEach.body();
loopBlock._if(forEach.var().ref(valueField).invoke("equals").arg(param))._then()
._return(forEach.var());
body._throw(JExpr._new(codeModel._ref(IllegalArgumentException.class)).arg(param));
}