Search in sources :

Example 21 with Type

use of java.lang.reflect.Type in project che by eclipse.

the class DtoImplClientTemplate method emitDeepCopyForGetters.

private void emitDeepCopyForGetters(List<Type> expandedTypes, int depth, StringBuilder builder, String origin, Method getter, String i) {
    String getterName = getter.getName();
    String fieldName = getJavaFieldName(getterName);
    String fieldNameIn = fieldName + "In";
    String fieldNameOut = fieldName + "Out";
    Type type = expandedTypes.get(depth);
    Class<?> rawClass = getRawClass(type);
    String rawTypeName = getImplName(type, false);
    if (isList(rawClass) || isMap(rawClass)) {
        builder.append(i).append(rawTypeName).append(" ").append(fieldNameIn).append(" = ").append(origin).append(".").append(getterName).append("();\n");
        builder.append(i).append("if (").append(fieldNameIn).append(" != null) {\n");
        builder.append(i).append("  ").append(rawTypeName).append(" ").append(fieldNameOut).append(" = new ").append(getImplName(type, true)).append("();\n");
        emitDeepCopyCollections(expandedTypes, depth, builder, fieldNameIn, fieldNameOut, i);
        builder.append(i).append("  ").append("this.").append(fieldName).append(" = ").append(fieldNameOut).append(";\n");
        builder.append(i).append("}\n");
    } else if (getEnclosingTemplate().isDtoInterface(rawClass)) {
        builder.append(i).append(rawTypeName).append(" ").append(fieldNameIn).append(" = ").append(origin).append(".").append(getterName).append("();\n");
        builder.append(i).append("this.").append(fieldName).append(" = ");
        emitCheckNullAndCopyDto(rawClass, fieldNameIn, builder);
        builder.append(";\n");
    } else if (isAny(rawClass)) {
        builder.append(i).append("this.").append(fieldName).append(" = ");
        appendNaiveCopyJsonExpression(origin + "." + getterName + "()", builder).append(";\n");
    } else {
        builder.append(i).append("this.").append(fieldName).append(" = ").append(origin).append(".").append(getterName).append("();\n");
    }
}
Also used : ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type)

Example 22 with Type

use of java.lang.reflect.Type in project che by eclipse.

the class DtoImplClientTemplate method emitDeserializeFieldForMethod.

private void emitDeserializeFieldForMethod(Method getter, StringBuilder builder) {
    final String fieldName = getFieldNameFromGetterName(getter.getName());
    final String fieldNameIn = fieldName + "In";
    final String fieldNameOut = fieldName + "Out";
    final String baseIndentation = "        ";
    final String jsonFieldName = getJsonFieldName(getter);
    final String jsonFieldNameLiteral = quoteStringLiteral(jsonFieldName);
    builder.append("\n");
    builder.append("      if (json.containsKey(").append(jsonFieldNameLiteral).append(")) {\n");
    List<Type> expandedTypes = expandType(getter.getGenericReturnType());
    builder.append("        JSONValue ").append(fieldNameIn).append(" = json.get(").append(jsonFieldNameLiteral).append(");\n");
    emitDeserializerImpl(expandedTypes, 0, builder, fieldNameIn, fieldNameOut, baseIndentation);
    builder.append("        dto.").append(getSetterName(fieldName)).append("(").append(fieldNameOut).append(");\n");
    builder.append("      }\n");
    Type type = expandedTypes.get(0);
    Class<?> aClass = getRawClass(type);
    if (Boolean.class.equals(aClass)) {
        builder.append("     else {\n");
        builder.append("        dto.").append(getSetterName(fieldName)).append("(").append("false").append(");\n");
        builder.append("     }\n");
    }
}
Also used : ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type)

Example 23 with Type

use of java.lang.reflect.Type in project che by eclipse.

the class DtoImplServerTemplate method emitDeepCopyCollections.

private void emitDeepCopyCollections(List<Type> expandedTypes, int depth, StringBuilder builder, String varIn, String varOut, String i) {
    Type type = expandedTypes.get(depth);
    String childVarIn = varIn + "_";
    String childVarOut = varOut + "_";
    String entryVar = "entry" + depth;
    Class<?> rawClass = getRawClass(type);
    Class<?> childRawType = getRawClass(expandedTypes.get(depth + 1));
    final String childTypeName = getImplName(expandedTypes.get(depth + 1), false);
    if (isList(rawClass)) {
        builder.append(i).append("  for (").append(childTypeName).append(" ").append(childVarIn).append(" : ").append(varIn).append(") {\n");
    } else if (isMap(rawClass)) {
        builder.append(i).append("  for (java.util.Map.Entry<String, ").append(childTypeName).append("> ").append(entryVar).append(" : ").append(varIn).append(".entrySet()) {\n");
        builder.append(i).append("    ").append(childTypeName).append(" ").append(childVarIn).append(" = ").append(entryVar).append(".getValue();\n");
    }
    if (isList(childRawType) || isMap(childRawType)) {
        builder.append(i).append("    if (").append(childVarIn).append(" != null) {\n");
        builder.append(i).append("      ").append(childTypeName).append(" ").append(childVarOut).append(" = new ").append(getImplName(expandedTypes.get(depth + 1), true)).append("();\n");
        emitDeepCopyCollections(expandedTypes, depth + 1, builder, childVarIn, childVarOut, i + "    ");
        builder.append(i).append("      ").append(varOut);
        if (isList(rawClass)) {
            builder.append(".add(");
        } else {
            builder.append(".put(").append(entryVar).append(".getKey(), ");
        }
        builder.append(childVarOut);
        builder.append(");\n");
        builder.append(i).append("    ").append("}\n");
    } else {
        builder.append(i).append("      ").append(varOut);
        if (isList(rawClass)) {
            builder.append(".add(");
        } else {
            builder.append(".put(").append(entryVar).append(".getKey(), ");
        }
        if (getEnclosingTemplate().isDtoInterface(childRawType)) {
            emitCheckNullAndCopyDto(childRawType, childVarIn, builder);
        } else {
            builder.append(childVarIn);
        }
        builder.append(");\n");
    }
    builder.append(i).append("  }\n");
}
Also used : ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type)

Example 24 with Type

use of java.lang.reflect.Type in project che by eclipse.

the class DtoImplServerTemplate method emitDeepCopyForGetters.

private void emitDeepCopyForGetters(List<Type> expandedTypes, int depth, StringBuilder builder, String origin, Method getter, String i) {
    String getterName = getter.getName();
    String fieldName = getJavaFieldName(getterName);
    String fieldNameIn = fieldName + "In";
    String fieldNameOut = fieldName + "Out";
    Type type = expandedTypes.get(depth);
    Class<?> rawClass = getRawClass(type);
    String rawTypeName = getImplName(type, false);
    if (isList(rawClass) || isMap(rawClass)) {
        builder.append(i).append(rawTypeName).append(" ").append(fieldNameIn).append(" = ").append(origin).append(".").append(getterName).append("();\n");
        builder.append(i).append("if (").append(fieldNameIn).append(" != null) {\n");
        builder.append(i).append("  ").append(rawTypeName).append(" ").append(fieldNameOut).append(" = new ").append(getImplName(type, true)).append("();\n");
        emitDeepCopyCollections(expandedTypes, depth, builder, fieldNameIn, fieldNameOut, i);
        builder.append(i).append("  ").append("this.").append(fieldName).append(" = ").append(fieldNameOut).append(";\n");
        builder.append(i).append("}\n");
    } else if (isAny(rawClass)) {
        builder.append(i).append("this.").append(fieldName).append(" = ");
        appendNaiveCopyJsonExpression(origin + "." + getterName + "()", builder).append(";\n");
    } else if (getEnclosingTemplate().isDtoInterface(rawClass)) {
        builder.append(i).append(rawTypeName).append(" ").append(fieldNameIn).append(" = ").append(origin).append(".").append(getterName).append("();\n");
        builder.append(i).append("this.").append(fieldName).append(" = ");
        emitCheckNullAndCopyDto(rawClass, fieldNameIn, builder);
        builder.append(";\n");
    } else {
        builder.append(i).append("this.").append(fieldName).append(" = ").append(origin).append(".").append(getterName).append("();\n");
    }
}
Also used : ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type)

Example 25 with Type

use of java.lang.reflect.Type in project cucumber-jvm by cucumber.

the class ParameterInfo method fromMethod.

public static List<ParameterInfo> fromMethod(Method method) {
    List<ParameterInfo> result = new ArrayList<ParameterInfo>();
    Type[] genericParameterTypes = method.getGenericParameterTypes();
    Annotation[][] annotations = method.getParameterAnnotations();
    for (int i = 0; i < genericParameterTypes.length; i++) {
        String format = null;
        String delimiter = DEFAULT_DELIMITER;
        boolean transposed = false;
        Transformer<?> transformer = null;
        for (Annotation annotation : annotations[i]) {
            if (annotation instanceof Format) {
                format = ((Format) annotation).value();
            } else if (isAnnotatedWith(annotation, Format.class)) {
                format = getAnnotationForAnnotation(annotation, Format.class).value();
            }
            if (annotation instanceof Delimiter) {
                delimiter = ((Delimiter) annotation).value();
            } else if (isAnnotatedWith(annotation, Delimiter.class)) {
                delimiter = getAnnotationForAnnotation(annotation, Delimiter.class).value();
            }
            if (annotation instanceof Transpose) {
                transposed = ((Transpose) annotation).value();
            }
            if (annotation instanceof Transform) {
                transformer = getTransformer(annotation);
            } else if (isAnnotatedWith(annotation, Transform.class)) {
                transformer = getTransformer(getAnnotationForAnnotation(annotation, Transform.class));
            }
        }
        result.add(new ParameterInfo(genericParameterTypes[i], format, delimiter, transposed, transformer));
    }
    return result;
}
Also used : Delimiter(cucumber.api.Delimiter) ArrayList(java.util.ArrayList) Transpose(cucumber.api.Transpose) Annotation(java.lang.annotation.Annotation) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) Format(cucumber.api.Format) Transform(cucumber.api.Transform)

Aggregations

Type (java.lang.reflect.Type)6477 ParameterizedType (java.lang.reflect.ParameterizedType)1798 ProgressRequestBody (io.kubernetes.client.ProgressRequestBody)722 ProgressResponseBody (io.kubernetes.client.ProgressResponseBody)722 GenericArrayType (java.lang.reflect.GenericArrayType)711 WildcardType (java.lang.reflect.WildcardType)580 Test (org.junit.Test)513 ArrayList (java.util.ArrayList)429 Method (java.lang.reflect.Method)424 TypeVariable (java.lang.reflect.TypeVariable)350 List (java.util.List)342 Map (java.util.Map)296 Gson (com.google.gson.Gson)230 V1Status (io.kubernetes.client.models.V1Status)228 V1Status (io.kubernetes.client.openapi.models.V1Status)224 HashMap (java.util.HashMap)211 Field (java.lang.reflect.Field)170 Annotation (java.lang.annotation.Annotation)161 IOException (java.io.IOException)146 Collection (java.util.Collection)116