/** * Returns the element type of the given metaclass under the following conditions: * <ul> * <li>toType is a collection type * <li>toType has a single type parameter * <li>toType's type parameter is not a wildcard * <li>toType's type parameter is a non-abstract (concrete) type * <li>toType's type parameter is not java.lang.Object * </ul> * * @param toType * The type to check for a known concrete collection element type. * @return The concrete element type meeting all above-mentioned criteria, or null if one or more * of the criteria fails. */ public static MetaClass getConcreteCollectionElementType(final MetaClass toType) { if (toType.isAssignableTo(Collection.class)) { return getConcreteElementType(toType); } return null; }
public static MetaMethod findGetterMethod(final MetaClass cls, final String key) { MetaMethod metaMethod = _findGetterMethod("get", cls, key); if (metaMethod != null) return metaMethod; metaMethod = _findGetterMethod("is", cls, key); return metaMethod; }
public static void ensureMarshallerFieldCreated(final ClassStructureBuilder<?> classStructureBuilder, final MetaClass marshallerForType, final MetaClass type, final BlockBuilder<?> initMethod) { ensureMarshallerFieldCreated(classStructureBuilder, marshallerForType, type, initMethod, null); }
public Statement maybeAddAssumedTypes(BlockBuilder<?> blockBuilder, String varName, Mapping mapping, Statement statement) { final MetaClass elementType = MarshallingGenUtil.getConcreteCollectionElementType(mapping.getType()); final MetaClass mapKeyType = MarshallingGenUtil.getConcreteMapKeyType(mapping.getType()); final MetaClass mapValueType = MarshallingGenUtil.getConcreteMapValueType(mapping.getType()); boolean assumedMapTypesSet = false; if (elementType != null) { blockBuilder.append(Stmt.loadVariable("a1").invoke("setAssumedElementType", elementType.getFullyQualifiedName())); } else if (mapKeyType != null && mapValueType != null) { blockBuilder.append(Stmt.loadVariable("a1").invoke("setAssumedMapKeyType", mapKeyType.getFullyQualifiedName())); blockBuilder.append(Stmt.loadVariable("a1") .invoke("setAssumedMapValueType", mapValueType.getFullyQualifiedName())); assumedMapTypesSet = true; } if (varName != null) { blockBuilder.append(Stmt.declareFinalVariable(varName, mapping.getTargetType(), statement)); } else { blockBuilder.append(statement); } if (assumedMapTypesSet) { blockBuilder.append(Stmt.loadVariable("a1").invoke("resetAssumedTypes")); } return (varName != null) ? Stmt.loadVariable(varName) : statement; }
public static Statement demarshal(final MetaClass type, final Statement statement, final String accepts) { Statement demarshallingStatement = null; if (PrimitiveTypeMarshaller.canHandle(type, accepts)) { demarshallingStatement = PrimitiveTypeMarshaller.demarshal(type, statement); } else { if (!type.equals(MetaClassFactory.get(void.class))) { if (type.isAssignableTo(Map.class)) { demarshallingStatement = Stmt.invokeStatic(MarshallingWrapper.class, "fromJSON", statement, type.asBoxed().asClass(), MarshallingGenUtil.getConcreteMapKeyType(type.asBoxed()), MarshallingGenUtil.getConcreteMapValueType(type.asBoxed())); } else { demarshallingStatement = Stmt.invokeStatic(MarshallingWrapper.class, "fromJSON", statement, type.asBoxed().asClass(), MarshallingGenUtil.getConcreteElementType(type.asBoxed())); } } else { demarshallingStatement = Stmt.invokeStatic(MarshallingWrapper.class, "fromJSON", statement); } } return demarshallingStatement; }
marshallerVarName = getVarName(MetaClassFactory.get(Object.class)); MarshallingGenUtil.ensureMarshallerFieldCreated(classBuilder, toMap, MetaClassFactory.get(Object.class), initMethod); marshallerVarName = getVarName(toMap); MarshallingGenUtil.ensureMarshallerFieldCreated(classBuilder, null, toMap, initMethod); .parameters(arrayType, MarshallingSession.class).body(); MarshallingGenUtil.ensureMarshallerFieldCreated(classBuilder, null, MetaClassFactory.get(Object.class), initMethod); .append(Stmt.loadVariable("sb").invoke("append", ",")).finish()) .append(Stmt.loadVariable("sb").invoke("append", dim == 1 ? Stmt.loadVariable(MarshallingGenUtil.getVarName(MetaClassFactory.get(Object.class))) .invoke("marshall", Stmt.loadVariable("a0", Stmt.loadVariable("i")),
public static String getVarName(final MetaClass clazz) { return clazz.isArray() ? getArrayVarName(clazz.getOuterComponentType().getFullyQualifiedName()) + "_D" + GenUtil.getArrayDimensions(clazz) : getVarName(clazz.asBoxed().getFullyQualifiedName()); }
public static void ensureMarshallerFieldCreated(final ClassStructureBuilder<?> classStructureBuilder, final MetaClass marshallerForType, final MetaClass type, final BlockBuilder<?> initMethod, final Statement marshallerCreationCallback) { final String fieldName = MarshallingGenUtil.getVarName(type); if (classStructureBuilder.getClassDefinition().getField(fieldName) == null) { final Statement marshallerLookup = createMarshallerLookup(marshallerForType, type, marshallerCreationCallback); if (initMethod == null) { classStructureBuilder.privateField(fieldName, parameterizedAs(Marshaller.class, typeParametersOf(type.getErased().asBoxed()))) .initializesWith(marshallerLookup).finish(); } else { classStructureBuilder.privateField(fieldName, parameterizedAs(Marshaller.class, typeParametersOf(type.getErased().asBoxed()))) .initializesWith(Stmt.load(null)).finish(); initMethod.append( If.isNull(Stmt.loadVariable(fieldName)).append( Stmt.loadVariable(fieldName).assignValue(marshallerLookup)).finish()); } } }
MetaClass elementType = MarshallingGenUtil.getConcreteCollectionElementType(field.getType()); if (elementType == null) { throw new UnsupportedOperationException(
/** * Returns the element type of the given metaclass under the following conditions: * <ul> * <li>toType has a single type parameter * <li>toType's type parameter is not a wildcard * <li>toType's type parameter is a non-abstract (concrete) type * <li>toType's type parameter is not java.lang.Object * </ul> * * @param toType * The type to check for a known concrete collection element type. * @return The concrete element type meeting all above-mentioned criteria, or null if one or more * of the criteria fails. */ public static MetaClass getConcreteElementType(final MetaClass toType) { return getConcreteTypeParameter(toType, 0, 1); }
final MetaMethod getterMethod = MarshallingGenUtil.findGetterMethod(toMap, field.getName());
public Statement maybeAddAssumedTypes(BlockBuilder<?> blockBuilder, String varName, Mapping mapping, Statement statement) { final MetaClass elementType = MarshallingGenUtil.getConcreteCollectionElementType(mapping.getType()); final MetaClass mapKeyType = MarshallingGenUtil.getConcreteMapKeyType(mapping.getType()); final MetaClass mapValueType = MarshallingGenUtil.getConcreteMapValueType(mapping.getType()); boolean assumedMapTypesSet = false; if (elementType != null) { blockBuilder.append(Stmt.loadVariable("a1").invoke("setAssumedElementType", elementType.getFullyQualifiedName())); } else if (mapKeyType != null && mapValueType != null) { blockBuilder.append(Stmt.loadVariable("a1").invoke("setAssumedMapKeyType", mapKeyType.getFullyQualifiedName())); blockBuilder.append(Stmt.loadVariable("a1") .invoke("setAssumedMapValueType", mapValueType.getFullyQualifiedName())); assumedMapTypesSet = true; } if (varName != null) { blockBuilder.append(Stmt.declareFinalVariable(varName, mapping.getTargetType(), statement)); } else { blockBuilder.append(statement); } if (assumedMapTypesSet) { blockBuilder.append(Stmt.loadVariable("a1").invoke("resetAssumedTypes")); } return (varName != null) ? Stmt.loadVariable(varName) : statement; }
marshallerVarName = getVarName(MetaClassFactory.get(Object.class)); MarshallingGenUtil.ensureMarshallerFieldCreated(classBuilder, toMap, MetaClassFactory.get(Object.class), initMethod); marshallerVarName = getVarName(toMap); MarshallingGenUtil.ensureMarshallerFieldCreated(classBuilder, null, toMap, initMethod); .parameters(arrayType, MarshallingSession.class).body(); MarshallingGenUtil.ensureMarshallerFieldCreated(classBuilder, null, MetaClassFactory.get(Object.class), initMethod); .append(Stmt.loadVariable("sb").invoke("append", ",")).finish()) .append(Stmt.loadVariable("sb").invoke("append", dim == 1 ? Stmt.loadVariable(MarshallingGenUtil.getVarName(MetaClassFactory.get(Object.class))) .invoke("marshall", Stmt.loadVariable("a0", Stmt.loadVariable("i")),
public static String getVarName(final MetaClass clazz) { return clazz.isArray() ? getArrayVarName(clazz.getOuterComponentType().getFullyQualifiedName()) + "_D" + GenUtil.getArrayDimensions(clazz) : getVarName(clazz.asBoxed().getFullyQualifiedName()); }
public static void ensureMarshallerFieldCreated(final ClassStructureBuilder<?> classStructureBuilder, final MetaClass marshallerForType, final MetaClass type, final BlockBuilder<?> initMethod, final Statement marshallerCreationCallback) { final String fieldName = MarshallingGenUtil.getVarName(type); if (classStructureBuilder.getClassDefinition().getField(fieldName) == null) { final Statement marshallerLookup = createMarshallerLookup(marshallerForType, type, marshallerCreationCallback); if (initMethod == null) { classStructureBuilder.privateField(fieldName, parameterizedAs(Marshaller.class, typeParametersOf(type.getErased().asBoxed()))) .initializesWith(marshallerLookup).finish(); } else { classStructureBuilder.privateField(fieldName, parameterizedAs(Marshaller.class, typeParametersOf(type.getErased().asBoxed()))) .initializesWith(Stmt.load(null)).finish(); initMethod.append( If.isNull(Stmt.loadVariable(fieldName)).append( Stmt.loadVariable(fieldName).assignValue(marshallerLookup)).finish()); } } }
MetaClass elementType = MarshallingGenUtil.getConcreteCollectionElementType(field.getType()); if (elementType == null) { throw new UnsupportedOperationException(
/** * Returns the element type of the given metaclass under the following conditions: * <ul> * <li>toType has a single type parameter * <li>toType's type parameter is not a wildcard * <li>toType's type parameter is a non-abstract (concrete) type * <li>toType's type parameter is not java.lang.Object * </ul> * * @param toType * The type to check for a known concrete collection element type. * @return The concrete element type meeting all above-mentioned criteria, or null if one or more * of the criteria fails. */ public static MetaClass getConcreteElementType(final MetaClass toType) { return getConcreteTypeParameter(toType, 0, 1); }
final MetaMethod getterMethod = MarshallingGenUtil.findGetterMethod(toMap, field.getName());
MarshallingGenUtil.ensureMarshallerFieldCreated(classStructureBuilder, toMap, type, lazyInitMethod, deferred); constructorParameters[parmIndex] = Stmt.loadVariable(MarshallingGenUtil.getVarName(type)).invoke("demarshall", extractJSONObjectProperty(mapping.getKey(), EJObject.class), Stmt.loadVariable("a1")); MarshallingGenUtil.ensureMarshallerFieldCreated(classStructureBuilder, toMap, type, lazyInitMethod); constructorParameters[parmIndex] = context.getArrayMarshallerCallback() .demarshall(type, extractJSONObjectProperty(mapping.getKey(), EJObject.class)); MarshallingGenUtil.ensureMarshallerFieldCreated(classStructureBuilder, toMap, type, lazyInitMethod); if (context.canMarshal(type.getFullyQualifiedName())) { Statement s = maybeAddAssumedTypes(builder, MarshallingGenUtil.ensureMarshallerFieldCreated(classStructureBuilder, toMap, memberMapping.getType() .asBoxed(), lazyInitMethod, deferred); MarshallingGenUtil.ensureMarshallerFieldCreated(classStructureBuilder, toMap, memberMapping.getType() .asBoxed(), lazyInitMethod); MarshallingGenUtil.ensureMarshallerFieldCreated(classStructureBuilder, toMap, memberMapping.getType() .asBoxed(), lazyInitMethod); val = fieldDemarshall(memberMapping, MetaClassFactory.get(EJObject.class), loadVariable("objVal"));
/** * Returns the element type of the given metaclass under the following conditions: * <ul> * <li>toType is a collection type * <li>toType has a single type parameter * <li>toType's type parameter is not a wildcard * <li>toType's type parameter is a non-abstract (concrete) type * <li>toType's type parameter is not java.lang.Object * </ul> * * @param toType * The type to check for a known concrete collection element type. * @return The concrete element type meeting all above-mentioned criteria, or null if one or more * of the criteria fails. */ public static MetaClass getConcreteCollectionElementType(final MetaClass toType) { if (toType.isAssignableTo(Collection.class)) { return getConcreteElementType(toType); } return null; }