Refine search
fieldType = fieldType.unboxify(); if (fieldType.fullName().equals(String.class.getName())) { return JExpr.lit(node.asText()); } else if (fieldType.fullName().equals(int.class.getName())) { return JExpr.lit(Integer.parseInt(node.asText())); } else if (fieldType.fullName().equals(BigInteger.class.getName())) { return JExpr._new(fieldType).arg(JExpr.lit(node.asText())); } else if (fieldType.fullName().equals(double.class.getName())) { return JExpr.lit(Double.parseDouble(node.asText())); } else if (fieldType.fullName().equals(BigDecimal.class.getName())) { return JExpr._new(fieldType).arg(JExpr.lit(node.asText())); } else if (fieldType.fullName().equals(boolean.class.getName())) { return JExpr.lit(Boolean.parseBoolean(node.asText())); } else if (fieldType.fullName().equals(DateTime.class.getName()) || fieldType.fullName().equals(Date.class.getName())) { long millisecs = parseDateToMillisecs(node.asText()); } else if (fieldType.fullName().equals(LocalDate.class.getName()) || fieldType.fullName().equals(LocalTime.class.getName())) { } else if (fieldType.fullName().equals(long.class.getName())) { return JExpr.lit(Long.parseLong(node.asText())); } else if (fieldType.fullName().equals(float.class.getName())) {
body._if(otherObject.eq(JExpr._this()))._then()._return(JExpr.TRUE); body._if(otherObject._instanceof(jclass).eq(JExpr.FALSE))._then()._return(JExpr.FALSE); JVar rhsVar = body.decl(jclass, "rhs").init(JExpr.cast(jclass, otherObject)); JExpression result = JExpr.lit(true); if (!jclass._extends().fullName().equals(Object.class.getName())) { result = result.cand(JExpr._super().invoke("equals").arg(rhsVar)); JExpression fieldEquals; if (fieldVar.type().isPrimitive()) { if ("double".equals(fieldVar.type().name())) { JClass doubleClass = jclass.owner().ref(Double.class); fieldEquals = doubleClass.staticInvoke("doubleToLongBits").arg(thisFieldRef).eq( doubleClass.staticInvoke("doubleToLongBits").arg(otherFieldRef)); } else if ("float".equals(fieldVar.type().name())) { JClass floatClass = jclass.owner().ref(Float.class); fieldEquals = floatClass.staticInvoke("floatToIntBits").arg(thisFieldRef).eq( floatClass.staticInvoke("floatToIntBits").arg(otherFieldRef)); fieldEquals = thisFieldRef.eq(otherFieldRef); } else if (fieldVar.type().isArray()) { if (!fieldVar.type().elementType().isPrimitive()) { throw new UnsupportedOperationException("Only primitive arrays are supported");
private JFieldVar addQuickLookupMap(JDefinedClass _enum, JType backingType) { JClass lookupType = _enum.owner().ref(Map.class).narrow(backingType.boxify(), _enum); JFieldVar lookupMap = _enum.field(JMod.PRIVATE | JMod.STATIC | JMod.FINAL, lookupType, "CONSTANTS"); JClass lookupImplType = _enum.owner().ref(HashMap.class).narrow(backingType.boxify(), _enum); lookupMap.init(JExpr._new(lookupImplType)); JForEach forEach = _enum.init().forEach(_enum, "c", JExpr.invoke("values")); JInvocation put = forEach.body().invoke(lookupMap, "put"); put.arg(forEach.var().ref("value")); put.arg(forEach.var()); return lookupMap; }
private static JDefinedClass definedClassOrNullFromType(JType type) { if (type == null || type.isPrimitive()) { return null; } JClass fieldClass = type.boxify(); JPackage jPackage = fieldClass._package(); return jPackage._getClass(fieldClass.name()); }
@Override public void propertyField(JFieldVar field, JDefinedClass clazz, String propertyName, JsonNode propertyNode) { field.annotate(JsonProperty.class).param("value", propertyName); if (field.type().erasure().equals(field.type().owner().ref(Set.class))) { field.annotate(JsonDeserialize.class).param("as", LinkedHashSet.class); } if (propertyNode.has("javaJsonView")) { field.annotate(JsonView.class).param( "value", field.type().owner().ref(propertyNode.get("javaJsonView").asText())); } }
JClass stringBuilderClass = jclass.owner().ref(StringBuilder.class); JVar sb = body.decl(stringBuilderClass, "sb", JExpr._new(stringBuilderClass)); body.add(sb .invoke("append").arg(jclass.dotclass().invoke("getName")) .invoke("append").arg(JExpr.lit('@')) .invoke("append").arg( jclass.owner().ref(Integer.class).staticInvoke("toHexString").arg( jclass.owner().ref(System.class).staticInvoke("identityHashCode").arg(JExpr._this()))) .invoke("append").arg(JExpr.lit('['))); if (!jclass._extends().fullName().equals(Object.class.getName())) { JVar baseLength = body.decl(jclass.owner().INT, "baseLength", sb.invoke("length")); JVar superString = body.decl(jclass.owner().ref(String.class), "superString", JExpr._super().invoke("toString")); body.add(sb.invoke("append").arg(JExpr.lit('='))); if (fieldVar.type().isPrimitive()) { body.add(sb.invoke("append").arg(JExpr.refthis(fieldVar.name()))); } else if (fieldVar.type().isArray()) { if (!fieldVar.type().elementType().isPrimitive()) { throw new UnsupportedOperationException("Only primitive arrays are supported");
JVar result = body.decl(jclass.owner().INT, "result", JExpr.lit(1)); JFieldRef fieldRef = JExpr.refthis(fieldVar.name()); if (fieldVar.type().isPrimitive()) { if ("long".equals(fieldVar.type().name())) { fieldHash = JExpr.cast(jclass.owner().INT, fieldRef.xor(fieldRef.shrz(JExpr.lit(32)))); } else if ("boolean".equals(fieldVar.type().name())) { fieldHash = JOp.cond(fieldRef, JExpr.lit(1), JExpr.lit(0)); } else if ("int".equals(fieldVar.type().name())) { fieldHash = fieldRef; } else if ("double".equals(fieldVar.type().name())) { JClass doubleClass = jclass.owner().ref(Double.class); JExpression longField = doubleClass.staticInvoke("doubleToLongBits").arg(fieldRef); fieldHash = JExpr.cast(jclass.owner().INT, longField.xor(longField.shrz(JExpr.lit(32)))); } else if ("float".equals(fieldVar.type().name())) { fieldHash = jclass.owner().ref(Float.class).staticInvoke("floatToIntBits").arg(fieldRef); } else { fieldHash = JExpr.cast(jclass.owner().INT, fieldRef); } else if (fieldVar.type().isArray()) { if (!fieldVar.type().elementType().isPrimitive()) { throw new UnsupportedOperationException("Only primitive arrays are supported"); body.assign(result, result.mul(JExpr.lit(31)).plus(fieldHash));
public void generateToString() { JMethod toString1 = cls().method(JMod.PUBLIC, cm.ref("java.lang.String"), "toString"); toString1.body()._return(ref("this").invoke("toString").arg(lit(""))); JMethod toString2 = cls().method(JMod.PUBLIC, cm.ref("java.lang.String"), "toString"); toString2.param(String.class, "indent"); toString2.body().decl(cm.ref("java.lang.String"), "rc", lit("")); for (int i = 0; i < amqpFields.size(); i++) { Attribute attr = amqpFields.get(i); if ( attr.attribute.type().isArray() ) { JBlock block = toString2.body()._if(_this().ref(attr.attribute).ne(_null()))._then().block(); block._if(ref("rc").invoke("length").ne(lit(0)))._then().assignPlus(ref("rc"), lit(",\n")); block.assignPlus(ref("rc"), ref("indent").plus(lit(" " + attr.attribute.name() + ":").plus(cm.ref("java.util.Arrays").staticInvoke("toString").arg(_this().ref(attr.attribute))))); } else { JExpression value = _this().ref(attr.attribute); if ( generator.getMapping().get(attr.type) == null ) { value = value.invoke("toString").arg(ref("indent").plus(lit(" "))); } JBlock block = toString2.body()._if(_this().ref(attr.attribute).ne(_null()))._then().block(); block._if(ref("rc").invoke("length").ne(lit(0)))._then().assignPlus(ref("rc"), lit(",\n")); block.assignPlus(ref("rc"), ref("indent").plus(lit(" " + attr.attribute.name() + ":").plus(value))); } } toString2.body()._if(ref("rc").invoke("length").ne(lit(0)))._then(). assign(ref("rc"), lit(", {\n").plus(ref("rc").plus(lit("}")))); toString2.body()._return(lit("[" + toJavaClassName(type.getName())).plus(ref("rc")).plus(lit("]"))); }
JClass setGenericType = ((JClass) fieldType).getTypeParameters().get(0); JClass setImplClass = fieldType.owner().ref(LinkedHashSet.class); setImplClass = setImplClass.narrow(setGenericType); JInvocation newSetImpl = JExpr._new(setImplClass); JInvocation invokeAsList = fieldType.owner().ref(Arrays.class).staticInvoke("asList"); for (JsonNode defaultValue : node) { invokeAsList.arg(getDefaultValue(setGenericType, defaultValue)); newSetImpl.arg(invokeAsList); } else if (!ruleFactory.getGenerationConfig().isInitializeCollections()) { return JExpr._null();
public void addConstructorFromParcel(JDefinedClass jclass) { JMethod ctorFromParcel = jclass.constructor(JMod.PROTECTED); JVar in = ctorFromParcel.param(jclass.owner().directClass("android.os.Parcel"), "in"); if (extendsParcelable(jclass)) { ctorFromParcel.body().directStatement("super(in);"); } for (JFieldVar f : jclass.fields().values()) { if( (f.mods().getValue() & JMod.STATIC) == JMod.STATIC ) { continue; } if (f.type().erasure().name().equals("List")) { ctorFromParcel.body() .invoke(in, "readList") .arg(JExpr._this().ref(f)) .arg(JExpr.direct(getListType(f.type()) + ".class.getClassLoader()")); } else { ctorFromParcel.body().assign( JExpr._this().ref(f), JExpr.cast( f.type(), in.invoke("readValue").arg(JExpr.direct(f.type().erasure().name() + ".class.getClassLoader()")) ) ); } } }
public JavaType getResponseBeanJavaType(){ JCodeModel cm = _responseBean.getJavaType().getType().getType().owner(); if(_asyncOpType.equals(AsyncOperationType.CALLBACK)){ JClass future = cm.ref(java.util.concurrent.Future.class).narrow(cm.ref(Object.class).wildcard()); return new JavaSimpleType(new JAXBTypeAndAnnotation(future)); }else if(_asyncOpType.equals(AsyncOperationType.POLLING)){ JClass polling = cm.ref(javax.xml.ws.Response.class).narrow(_responseBean.getJavaType().getType().getType().boxify()); return new JavaSimpleType(new JAXBTypeAndAnnotation(polling)); } return null; }
private JInvocation illegalArgumentInvocation(JDefinedClass jclass, String propertyName, JType propertyType, JVar valueVar) { return _new(jclass.owner()._ref(IllegalArgumentException.class)) .arg(lit("property \"" + propertyName + "\" is of type \"" + propertyType.fullName() + "\", but got ") .plus(valueVar.invoke("getClass").invoke("toString"))); }
private void addFieldWrite(Attribute attribute, JBlock body) { if ( attribute.attribute.type().isArray() ) { body.staticInvoke(cm.ref("AMQPArray"), "write").arg(_this().ref(attribute.attribute.name())).arg(ref("out")); } else if ( generator.getMapping().get(attribute.type) != null ) { body.staticInvoke(cm.ref(generator.getPrimitiveJavaClass().get(attribute.type)), "write").arg(_this().ref(attribute.attribute.name())).arg(ref("out")); } else { JConditional conditional = body ._if(ref(attribute.attribute.name()).ne(_null())); conditional._then() .invoke(ref(attribute.attribute.name()), "write").arg(ref("out")); conditional._else().invoke(ref("out"), "writeByte").arg(generator.registry().cls().staticRef("NULL_FORMAT_CODE")); } }
private List<Partitioner> createClassInstances(int actualPartitions) throws SchemaChangeException { // set up partitioning function final LogicalExpression expr = config.getExpr(); final ClassGenerator<Partitioner> cg = context.getClassProducer().createGenerator(Partitioner.TEMPLATE_DEFINITION).getRoot(); ClassGenerator<Partitioner> cgInner = cg.getInnerGenerator("OutgoingRecordBatch"); final LogicalExpression materializedExpr = context.getClassProducer().materialize(expr, incoming); // generate code to copy from an incoming value vector to the destination partition's outgoing value vector JExpression bucket = JExpr.direct("bucket"); // generate evaluate expression to determine the hash ClassGenerator.HoldingContainer exprHolder = cg.addExpr(materializedExpr); cg.getEvalBlock().decl(JType.parse(cg.getModel(), "int"), "bucket", exprHolder.getValue().mod(JExpr.lit(outGoingBatchCount))); cg.getEvalBlock()._return(cg.getModel().ref(Math.class).staticInvoke("abs").arg(bucket)); CopyUtil.generateCopies(cgInner, incoming, incoming.getSchema().getSelectionVectorMode() == SelectionVectorMode.FOUR_BYTE); // compile and setup generated code List<Partitioner> subPartitioners = cg.getCodeGenerator().getImplementationClass(actualPartitions); return subPartitioners; }
private void addSetProperty(JDefinedClass jclass, JBlock callSite, String propertyName, JType propertyType, JVar valueVar, JsonNode node) { JMethod propertySetter = jclass.getMethod(getSetterName(propertyName, node), new JType[] { propertyType }); JConditional isInstance = callSite._if(valueVar._instanceof(propertyType.boxify().erasure())); isInstance._then() .invoke(propertySetter).arg(cast(propertyType.boxify(), valueVar)); isInstance._else() ._throw(illegalArgumentInvocation(jclass, propertyName, propertyType, valueVar)); }
private void addFieldRead(Attribute attribute, JBlock body) { if ( attribute.attribute.type().isArray() ) { body.assign(attribute.attribute, cast(attribute.attribute.type(), cm.ref("AMQPArray").staticInvoke("read").arg(ref("in")))); } else if ( generator.getMapping().get(attribute.type) != null ) { body.assign(attribute.attribute, cm.ref(generator.getPrimitiveJavaClass().get(attribute.type)).staticInvoke("read").arg(ref("in"))); } else if ( generator.getProvides().contains(attribute.type) ) { } else { //body.assign(attribute.attribute, cast(attribute.attribute.type(), cm.ref(generator.getMarshaller() + ".TypeReader").staticInvoke("read").arg(ref("in")))); body.assign(attribute.attribute, cast(attribute.attribute.type(), cm.ref(generator.getMarshaller() + ".TypeReader").staticInvoke("read").arg(ref("in")))); } }
private JMethod addWithIfNotNullMethod(JDefinedClass builderClass, FieldOutline field, JMethod unconditionalWithMethod) { if (field.getRawType().isPrimitive()) return null; String fieldName = field.getPropertyInfo().getName(true); JMethod method = builderClass.method(JMod.PUBLIC, builderClass, "with" + fieldName + "IfNotNull"); JVar param = generateMethodParameter(method, field); JBlock block = method.body(); JConditional conditional = block._if(param.eq(JExpr._null())); conditional._then()._return(JExpr.direct("this")); conditional._else()._return(JExpr.invoke(unconditionalWithMethod).arg(param)); return method; }
private JFieldVar addAdditionalPropertiesField(JDefinedClass jclass, JType propertyType) { JClass propertiesMapType = jclass.owner().ref(Map.class); propertiesMapType = propertiesMapType.narrow(jclass.owner().ref(String.class), propertyType.boxify()); JClass propertiesMapImplType = jclass.owner().ref(HashMap.class); propertiesMapImplType = propertiesMapImplType.narrow(jclass.owner().ref(String.class), propertyType.boxify()); JFieldVar field = jclass.field(JMod.PRIVATE, propertiesMapType, "additionalProperties"); ruleFactory.getAnnotator().additionalPropertiesField(field, jclass, "additionalProperties"); field.init(JExpr._new(propertiesMapImplType)); return field; }
public void callSuperMethod(JMethod superMethod, EBeanHolder holder, JBlock callBlock) { JExpression activitySuper = holder.generatedClass.staticRef("super"); JInvocation superCall = JExpr.invoke(activitySuper, superMethod); for (JVar param : superMethod.params()) { superCall.arg(param); } JType returnType = superMethod.type(); if (returnType.fullName().equals("void")) { callBlock.add(superCall); } else { callBlock._return(superCall); } }