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)); }
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)); 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);
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; }
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; }
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; }
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()")) ) ); } } }
body._if(otherObject._instanceof(jclass).eq(JExpr.FALSE))._then()._return(JExpr.FALSE); JVar rhsVar = body.decl(jclass, "rhs").init(JExpr.cast(jclass, otherObject));
JExpression as(JExpression rhs, TypeMirror targetType) { return JExpr.cast(toJtype.visit(targetType, null), rhs.invoke("get")); } JClass sourceType() {
m.directClass(BooleanObjectInspector.class.getCanonicalName()), "castOI", JExpr._null()); jc._else().assign(castedOI, JExpr.cast(m.directClass(BooleanObjectInspector.class.getCanonicalName()), returnOI)); m.directClass(ByteObjectInspector.class.getCanonicalName()), "castOI", JExpr._null()); jc._else().assign(castedOI, JExpr.cast(m.directClass(ByteObjectInspector.class.getCanonicalName()), returnOI)); m.directClass(ShortObjectInspector.class.getCanonicalName()), "castOI", JExpr._null()); jc._else().assign(castedOI, JExpr.cast(m.directClass(ShortObjectInspector.class.getCanonicalName()), returnOI)); m.directClass(IntObjectInspector.class.getCanonicalName()), "castOI", JExpr._null()); jc._else().assign(castedOI, JExpr.cast(m.directClass(IntObjectInspector.class.getCanonicalName()), returnOI)); m.directClass(LongObjectInspector.class.getCanonicalName()), "castOI", JExpr._null()); jc._else().assign(castedOI, JExpr.cast(m.directClass(LongObjectInspector.class.getCanonicalName()), returnOI)); m.directClass(FloatObjectInspector.class.getCanonicalName()), "castOI", JExpr._null()); jc._else().assign(castedOI, JExpr.cast(m.directClass(FloatObjectInspector.class.getCanonicalName()), returnOI)); m.directClass(DoubleObjectInspector.class.getCanonicalName()), "castOI", JExpr._null()); jc._else().assign(castedOI, JExpr.cast(m.directClass(DoubleObjectInspector.class.getCanonicalName()), returnOI)); m.directClass(HiveVarcharObjectInspector.class.getCanonicalName()), "castOI", JExpr._null());
public void doFindViewById(JBlock afterViewsBody, String id, JFieldVar field, JVar contentViewVar) { JFieldRef rId = ref.r().staticRef("id").ref(id); JInvocation findViewById = JExpr.invoke(contentViewVar, "findViewById").arg(rId); JExpression findViewByIdCasted = JExpr.cast(field.type(), findViewById); afterViewsBody.assign(field, findViewByIdCasted); }
/** * Case from {@link #exposedType} to {@link #implType} if necessary. */ protected final JExpression castToImplType( JExpression exp ) { if(implType==exposedType) return exp; else return JExpr.cast(implType,exp); }
/** * Case from {@link #exposedType} to {@link #implType} if necessary. */ protected final JExpression castToImplType( JExpression exp ) { if(implType==exposedType) return exp; else return JExpr.cast(implType,exp); }
/** * Case from {@link #exposedType} to {@link #implType} if necessary. */ protected final JExpression castToImplType( JExpression exp ) { if(implType==exposedType) return exp; else return JExpr.cast(implType,exp); }
@Override public void process(Element element, JCodeModel codeModel, EBeanHolder holder) { String fieldName = element.getSimpleName().toString(); TypeMirror elementType = element.asType(); JInvocation getApplication = holder.initActivityRef.invoke("getApplication"); String applicationTypeQualifiedName = elementType.toString(); if (APPLICATION.equals(applicationTypeQualifiedName)) { holder.initIfActivityBody.assign(ref(fieldName), getApplication); } else { holder.initIfActivityBody.assign(ref(fieldName), cast(holder.refClass(applicationTypeQualifiedName), getApplication)); } }
private JAssignment assignVisitClone( final JAssignmentTarget valueCopy, final JExpression value, JType type) { return (JAssignment) valueCopy.assign(JExpr.cast(type, value.invoke("visitClone").arg( clonedObjects))); }
@Override public void process(Element element, JCodeModel codeModel, EBeanHolder holder) { String fieldName = element.getSimpleName().toString(); TypeMirror uiFieldTypeMirror = element.asType(); String typeQualifiedName = uiFieldTypeMirror.toString(); JFieldRef idRef = annotationHelper.extractOneAnnotationFieldRef(holder, element, Res.ID, true); JBlock methodBody = holder.afterSetContentView.body(); methodBody.assign(ref(fieldName), cast(holder.refClass(typeQualifiedName), invoke("findViewById").arg(idRef))); }
@Override protected JExpression unwrap(JExpression source) { final JType type = getTypeRef().getTarget().toType(outline.parent(), Aspect.EXPOSED); return JExpr.cast(type, super.unwrap(source)); }
@Override protected JExpression unwrap(JExpression source) { return codeModel.ref(JAXBElementUtils.class).staticInvoke("getValue") .arg( JExpr.cast(codeModel.ref(JAXBElement.class).narrow( type.toType(outline.parent(), Aspect.EXPOSED) .boxify()), source)); }
private void createSetter(TypeInfo declaringClass, String methodBaseName, String fieldName, JClass javaType, JClass fieldType) { String methodName = setterName(methodBaseName); JMethod imethod = declaringClass.interfaceClass.method(JMod.NONE, void.class, methodName); imethod.param(javaType, fieldName); JMethod method = declaringClass.implClass.method(JMod.PUBLIC, void.class, methodName); JExpression param = method.param(javaType, fieldName); if (fieldType != javaType) { param = JExpr.cast(fieldType, param); } method.body().assign(JExpr._this().ref(fieldName), param); }
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)); }