本文整理汇总了Java中com.sun.codemodel.JExpression.plus方法的典型用法代码示例。如果您正苦于以下问题:Java JExpression.plus方法的具体用法?Java JExpression.plus怎么用?Java JExpression.plus使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.sun.codemodel.JExpression
的用法示例。
在下文中一共展示了JExpression.plus方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addFactoryMethod
import com.sun.codemodel.JExpression; //导入方法依赖的package包/类
private void addFactoryMethod(JDefinedClass _enum, JType backingType) {
JFieldVar quickLookupMap = addQuickLookupMap(_enum, backingType);
JMethod fromValue = _enum.method(JMod.PUBLIC | JMod.STATIC, _enum, "fromValue");
JVar valueParam = fromValue.param(backingType, "value");
JBlock body = fromValue.body();
JVar constant = body.decl(_enum, "constant");
constant.init(quickLookupMap.invoke("get").arg(valueParam));
JConditional _if = body._if(constant.eq(JExpr._null()));
JInvocation illegalArgumentException = JExpr._new(_enum.owner().ref(IllegalArgumentException.class));
JExpression expr = valueParam;
// if string no need to add ""
if(!isString(backingType)){
expr = expr.plus(JExpr.lit(""));
}
illegalArgumentException.arg(expr);
_if._then()._throw(illegalArgumentException);
_if._else()._return(constant);
ruleFactory.getAnnotator().enumCreatorMethod(fromValue);
}
示例2: binaryOp_int_int
import com.sun.codemodel.JExpression; //导入方法依赖的package包/类
JExpression binaryOp_int_int(Expression.BinaryOp op,
JExpression left, JExpression right)
{
switch(op.op) {
case ADD: return left.plus(right);
case SUB: return left.minus(right);
case MUL: return left.mul(right);
case DIV:
JExpression fl_right =
JExpr.cast(convertTypeToJClass_p(null, TypeFloat.I), right);
return left.div(fl_right);
case FLOORDIV:
return left.div(right);
case EQ: return left.eq(right);
case NE: return left.ne(right);
case LT: return left.lt(right);
case GT: return left.gt(right);
case LE: return left.lte(right);
case GE: return left.gte(right);
default:
return null; // handle upstream
}
}
示例3: addToString
import com.sun.codemodel.JExpression; //导入方法依赖的package包/类
private void addToString(JDefinedClass _enum, JFieldVar valueField) {
JMethod toString = _enum.method(JMod.PUBLIC, String.class, "toString");
JBlock body = toString.body();
JExpression toReturn = JExpr._this().ref(valueField);
if(!isString(valueField.type())){
toReturn = toReturn.plus(JExpr.lit(""));
}
body._return(toReturn);
toString.annotate(Override.class);
}