Search in sources :

Example 1 with SerializationIndex

use of org.eclipse.che.dto.shared.SerializationIndex in project che by eclipse.

the class DtoImplClientTemplate method emitDeserializeFieldForMethodCompact.

private void emitDeserializeFieldForMethodCompact(Method method, final StringBuilder builder) {
    final String fieldName = getFieldNameFromGetterName(method.getName());
    final String fieldNameIn = fieldName + "In";
    final String fieldNameOut = fieldName + "Out";
    final String baseIndentation = "        ";
    SerializationIndex serializationIndex = Preconditions.checkNotNull(method.getAnnotation(SerializationIndex.class));
    int index = serializationIndex.value() - 1;
    builder.append("\n");
    builder.append("      if (").append(index).append(" < json.size()) {\n");
    List<Type> expandedTypes = expandType(method.getGenericReturnType());
    builder.append("        JSONValue ").append(fieldNameIn).append(" = json.get(").append(index).append(");\n");
    emitDeserializerImpl(expandedTypes, 0, builder, fieldNameIn, fieldNameOut, baseIndentation);
    builder.append("        dto.").append(getSetterName(fieldName)).append("(").append(fieldNameOut).append(");\n");
    builder.append("      }\n");
}
Also used : SerializationIndex(org.eclipse.che.dto.shared.SerializationIndex) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type)

Example 2 with SerializationIndex

use of org.eclipse.che.dto.shared.SerializationIndex in project che by eclipse.

the class DtoImpl method calcDtoMethods.

private Method[] calcDtoMethods() {
    if (!compactJson) {
        return dtoInterface.getMethods();
    }
    Map<Integer, Method> methodsMap = new HashMap<>();
    int maxIndex = 0;
    for (Method method : dtoInterface.getMethods()) {
        SerializationIndex serializationIndex = method.getAnnotation(SerializationIndex.class);
        Preconditions.checkNotNull(serializationIndex, "Serialization index is not specified for %s in %s", method.getName(), dtoInterface.getSimpleName());
        // "53" is the number of bits in JS integer.
        // This restriction will allow to add simple bit-field
        // "serialization-skipping-list" in the future.
        int index = serializationIndex.value();
        Preconditions.checkState(index > 0 && index <= 53, "Serialization index out of range [1..53] for %s in %s", method.getName(), dtoInterface.getSimpleName());
        Preconditions.checkState(!methodsMap.containsKey(index), "Duplicate serialization index for %s in %s", method.getName(), dtoInterface.getSimpleName());
        maxIndex = Math.max(index, maxIndex);
        methodsMap.put(index, method);
    }
    Method[] result = new Method[maxIndex];
    for (int index = 0; index < maxIndex; index++) {
        result[index] = methodsMap.get(index + 1);
    }
    return result;
}
Also used : SerializationIndex(org.eclipse.che.dto.shared.SerializationIndex) HashMap(java.util.HashMap) Method(java.lang.reflect.Method)

Aggregations

SerializationIndex (org.eclipse.che.dto.shared.SerializationIndex)2 Method (java.lang.reflect.Method)1 ParameterizedType (java.lang.reflect.ParameterizedType)1 Type (java.lang.reflect.Type)1 HashMap (java.util.HashMap)1