@Test void normalizeType() { Assertions.assertAll( () -> assertEquals("java.util.Set<java.util.Map.Entry<K,V>>", GeciReflectionTools.getGenericTypeName(Map.class.getDeclaredMethod("entrySet").getGenericReturnType())), () -> assertEquals("java.util.Map.Entry", GeciReflectionTools.getGenericTypeName(java.util.Map.Entry.class)), () -> assertEquals("java.util.Map.Entry<String,Integer>[]", GeciReflectionTools.getGenericTypeName(this.getClass().getDeclaredMethod("m1").getGenericReturnType())), () -> assertEquals("java.util.Map.Entry<? extends String,? super Integer>[]", GeciReflectionTools.getGenericTypeName(this.getClass().getDeclaredMethod("m2").getGenericReturnType())) ); }
public static String getGenericTypeName(Type t) { final String normalizedName; if (t instanceof ParameterizedType) { normalizedName = getGenericParametrizedTypeName((ParameterizedType) t); } else if (t instanceof Class<?>) { normalizedName = removeJavaLang(((Class) t).getCanonicalName()); } else if (t instanceof WildcardType) { normalizedName = getGenericWildcardTypeName((WildcardType) t); } else if (t instanceof GenericArrayType) { var at = (GenericArrayType) t; normalizedName = getGenericTypeName(at.getGenericComponentType()) + "[]"; } else if (t instanceof TypeVariable) { normalizedName = t.getTypeName(); } else { throw new GeciException( "Type is something not handled. It is '%s' for the type '%s'", t.getClass(), t.getTypeName()); } return normalizedName; }
GeciReflectionTools { public static String getGenericTypeName(Type t) { final String normalizedName; if (t instanceof ParameterizedType) { normalizedName = getGenericParametrizedTypeName((ParameterizedType) t); } else if (t instanceof Class<?>) { normalizedName = removeJavaLang(((Class) t).getCanonicalName()); } else if (t instanceof WildcardType) { normalizedName = getGenericWildcardTypeName((WildcardType) t); } else if (t instanceof GenericArrayType) { var at = (GenericArrayType) t; normalizedName = getGenericTypeName(at.getGenericComponentType()) + "[]"; } else if (t instanceof TypeVariable) { normalizedName = t.getTypeName(); } else { throw new GeciException( "Type is something not handled. It is '%s' for the type '%s'", t.getClass(), t.getTypeName()); } return normalizedName; } }
GeciReflectionTools { public static String getGenericTypeName(Type t) { final String normalizedName; if (t instanceof ParameterizedType) { normalizedName = getGenericParametrizedTypeName((ParameterizedType) t); } else if (t instanceof Class<?>) { normalizedName = removeJavaLang(((Class) t).getCanonicalName()); } else if (t instanceof WildcardType) { normalizedName = getGenericWildcardTypeName((WildcardType) t); } else if (t instanceof GenericArrayType) { var at = (GenericArrayType) t; normalizedName = getGenericTypeName(at.getGenericComponentType()) + "[]"; } else if (t instanceof TypeVariable) { normalizedName = t.getTypeName(); } else { throw new GeciException( "Type is something not handled. It is '%s' for the type '%s'", t.getClass(), t.getTypeName()); } return normalizedName; }  }
GeciReflectionTools { public static String getGenericTypeName(Type t) { final String normalizedName; if (t instanceof ParameterizedType) { normalizedName = getGenericParametrizedTypeName((ParameterizedType) t); } else if (t instanceof Class<?>) { normalizedName = removeJavaLang(((Class) t).getCanonicalName()); } else if (t instanceof WildcardType) { normalizedName = getGenericWildcardTypeName((WildcardType) t); } else if (t instanceof GenericArrayType) { var at = (GenericArrayType) t; normalizedName = getGenericTypeName(at.getGenericComponentType()) + "[]"; } else if (t instanceof TypeVariable) { normalizedName = t.getTypeName(); } else { throw new GeciException( "Type is something not handled. It is '%s' for the type '%s'", t.getClass(), t.getTypeName()); } return normalizedName; }  static CompoundParams getParameters(AnnotatedElement element, String generatorMnemonic); static Invoker invoke(String methodName); static String modifiersString(Method method); static String modifiersStringNoAccess(Method method); static String typeAsString(Member member); static String normalizeTypeName(String s); static String normalizeTypeName(String s, Class<?> klass); static String getGenericTypeName(Type t); static String getSimpleGenericClassName(Class<?> t); static String getLocalGenericClassName(Class<?> t); static Field[] getDeclaredFieldsSorted(Class<?> klass); static Field[] getAllFieldsSorted(Class<?> klass); static Method[] getDeclaredMethodsSorted(Class<?> klass); static Method[] getMethodsSorted(Class<?> klass); static Method[] getAllMethodsSorted(final Class<?> klass); static Class[] getAllClassesSorted(Class<?> klass); static Class[] getDeclaredClassesSorted(Class<?> klass); static Class[] getClassesSorted(Class<?> klass); static Method getMethod(Class<?> klass, String methodName, Class<?>... classes); static Field getField(Class<?> klass, String fieldName); static Class<?> classForName(String className); static String unmask(int modifiers); static int mask(String masks, int dfault); }
GeciReflectionTools { public static String getGenericTypeName(Type t) { final String normalizedName; if (t instanceof ParameterizedType) { normalizedName = getGenericParametrizedTypeName((ParameterizedType) t); } else if (t instanceof Class<?>) { normalizedName = removeJavaLang(((Class) t).getCanonicalName()); } else if (t instanceof WildcardType) { normalizedName = getGenericWildcardTypeName((WildcardType) t); } else if (t instanceof GenericArrayType) { var at = (GenericArrayType) t; normalizedName = getGenericTypeName(at.getGenericComponentType()) + "[]"; } else if (t instanceof TypeVariable) { normalizedName = t.getTypeName(); } else { throw new GeciException( "Type is something not handled. It is '%s' for the type '%s'", t.getClass(), t.getTypeName()); } return normalizedName; }  static CompoundParams getParameters(AnnotatedElement element, String generatorMnemonic); static Invoker invoke(String methodName); static String modifiersString(Method method); static String modifiersStringNoAccess(Method method); static String typeAsString(Member member); static String normalizeTypeName(String s); static String normalizeTypeName(String s, Class<?> klass); static String getGenericTypeName(Type t); static String getSimpleGenericClassName(Class<?> t); static String getLocalGenericClassName(Class<?> t); static Field[] getDeclaredFieldsSorted(Class<?> klass); static Field[] getAllFieldsSorted(Class<?> klass); static Method[] getDeclaredMethodsSorted(Class<?> klass); static Method[] getMethodsSorted(Class<?> klass); static Method[] getAllMethodsSorted(final Class<?> klass); static Class[] getAllClassesSorted(Class<?> klass); static Class[] getDeclaredClassesSorted(Class<?> klass); static Class[] getClassesSorted(Class<?> klass); static Method getMethod(Class<?> klass, String methodName, Class<?>... classes); static Field getField(Class<?> klass, String fieldName); static Class<?> classForName(String className); static String unmask(int modifiers); static int mask(String masks, int dfault); static final int PACKAGE; }