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


Java JBlock._throw方法代码示例

本文整理汇总了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;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:23,代码来源:DynamicPropertiesRule.java

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

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

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

示例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));
}
 
开发者ID:ops4j,项目名称:org.ops4j.ramler,代码行数:12,代码来源:EnumGenerator.java


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