public final JExpression plus(JExpression right) { return JOp.plus(this, right); }
public final JExpression plus(JExpression right) { return JOp.plus(this, right); }
public final JExpression plus(JExpression right) { return JOp.plus(this, right); }
public final JExpression plus(JExpression right) { return JOp.plus(this, right); }
public final JExpression plus(JExpression right) { return JOp.plus(this, right); }
public JExpression countLength(final JCodeModel codeModel, final JExpression value) { final JClass unicodeUtil = codeModel.ref(UnicodeUtil.class); return JOp.plus( unicodeUtil.staticInvoke("countLength").arg(value.invoke("getNamespaceURI")), unicodeUtil.staticInvoke("countLength").arg(value.invoke("getLocalPart"))); }
@Override protected void generateMethod(final ClassRepresentation clazz, final List<JFieldVar> excludeFields, final boolean hasSuperClassFields) { final JDefinedClass implClass = clazz.getClassOutline().implClass; final JMethod method = implClass.method(JMod.PUBLIC, String.class, OPERATION); method.annotate(Override.class); JExpression invocation = null; if (hasSuperClassFields) { invocation = JExpr._super().invoke(OPERATION); } final List<JFieldVar> clonedList = new ArrayList<JFieldVar>(); final Collection<JFieldVar> fields = implClass.fields().values(); if (fields != null && !fields.isEmpty()) { clonedList.addAll(implClass.fields().values()); final JFieldVar last = Iterables.getLast(clonedList); for (final JFieldVar field : clonedList) { if (excludeFields == null || !excludeFields.contains(field)) { final String lastChar = field.name().equals(last.name()) ? ") " : "), "; if (invocation != null) { invocation = JOp.plus(invocation, JExpr.lit("(" + field.name() + " = ")).plus(JExpr.ref(field.name())).plus(JExpr.lit(lastChar)); } else { invocation = JExpr.lit("(" + field.name() + " = ").plus(JExpr.ref(field.name())).plus(JExpr.lit(lastChar)); } } } } final JExpression returnValue = invocation == null ? JExpr.lit("") : invocation; method.body()._return(returnValue); }
/** * Override the getMessage class on an exception to make sure the * status code is displayed * @param $exception */ protected void overrideMessageOnException(JDefinedClass $exception) { JClass $responseClass = codeModel.ref(Response.class); // Create a new version of getMessage, adding on the reason phrase // if it is a standard message JMethod $getMessage = $exception.method(JMod.PUBLIC, String.class, "getMessage"); $getMessage.javadoc().append("Workaround for JAX_RS_SPEC-312"); JBlock $body = $getMessage.body(); JVar $response = $body.decl($responseClass, "response", JExpr.invoke("getResponse")); JClass $statusClass = codeModel.ref(Response.Status.class); JVar $status = $body.decl( $statusClass, "status", $statusClass.staticInvoke("fromStatusCode") .arg($response.invoke("getStatus"))); JConditional $if = $body._if(JOp.ne($status, JExpr._null())); $if._then()._return( JOp.plus($response.invoke("getStatus"), JOp.plus(JExpr.lit(" "),$status.invoke("getReasonPhrase")))); $if._else()._return( codeModel.ref(Integer.class).staticInvoke("toString") .arg( $response.invoke("getStatus"))); }
private void appendHashCode(final JCodeModel codeModel, final JBlock block, final JVar hash, final JType type, final JExpression value, final JExpression isValueSet) { if (type.isArray()) { final JConditional _if = block._if(JExpr._null().eq(value)); _if._then().assign(hash, JOp.mul(JExpr.lit(31), hash)); final JForLoop _for = _if._else()._for(); final JVar i = _for.init(codeModel.INT, "i", JExpr.lit(0)); _for.test(JOp.lt(i, value.ref("length"))); _for.update(JOp.incr(i)); final JVar valueComponent = _for.body().decl(type.elementType(), "valueComponent", value.component(i)); _for.body().assign( hash, JOp.plus( JOp.mul(JExpr.lit(31), hash), valueHashCode(codeModel, type.elementType(), valueComponent, JOp.eq(JExpr._null(), valueComponent)))); } else { block.assign( hash, JOp.plus(JOp.mul(JExpr.lit(31), hash), valueHashCode(codeModel, type, value, isValueSet))); } }
valueOf.body()._throw(JExpr._new(exceptionClass).arg(JOp.plus(JExpr.lit("Invalid name: "), nameVar)));
codeModel.ref(String.class), "subindent", JOp.plus(indent, JExpr.lit('\t'))); final JVar buffer = toStringIndented.param(JMod.FINAL, StringBuffer.class, "buffer");