/** * Returns the simple name of a class. * * <p> * Similar to {@link Class#getSimpleName()}, but includes the simple name of an enclosing or declaring class. * * @param c The class to get the simple name on. * @return The simple name of a class. */ public static String getSimpleName(Class<?> c) { if (c.isLocalClass()) return getSimpleName(c.getEnclosingClass()) + '.' + c.getSimpleName(); if (c.isMemberClass()) return getSimpleName(c.getDeclaringClass()) + '.' + c.getSimpleName(); return c.getSimpleName(); }
/** * Returns the simple name of a class. * * <p> * Similar to {@link Class#getSimpleName()}, but includes the simple name of an enclosing or declaring class. * * @param c The class to get the simple name on. * @return The simple name of a class. */ public static String getSimpleName(Class<?> c) { if (c.isLocalClass()) return getSimpleName(c.getEnclosingClass()) + '.' + c.getSimpleName(); if (c.isMemberClass()) return getSimpleName(c.getDeclaringClass()) + '.' + c.getSimpleName(); return c.getSimpleName(); }
/** * Returns the simple name of a class. * * <p> * Similar to {@link Class#getSimpleName()}, but includes the simple name of an enclosing or declaring class. * * @param c The class to get the simple name on. * @return The simple name of a class. */ public static String getSimpleName(Class<?> c) { if (c.isLocalClass()) return getSimpleName(c.getEnclosingClass()) + '.' + c.getSimpleName(); if (c.isMemberClass()) return getSimpleName(c.getDeclaringClass()) + '.' + c.getSimpleName(); return c.getSimpleName(); }
/** * Returns the simple name of a class. * * <p> * Similar to {@link Class#getSimpleName()}, but includes the simple name of an enclosing or declaring class. * * @param t The class to get the simple name on. * @return The simple name of a class. */ public static String getSimpleName(Type t) { if (t instanceof Class) return getSimpleName((Class<?>)t); if (t instanceof ParameterizedType) { StringBuilder sb = new StringBuilder(); ParameterizedType pt = (ParameterizedType)t; sb.append(getSimpleName(pt.getRawType())); sb.append("<"); boolean first = true; for (Type t2 : pt.getActualTypeArguments()) { if (! first) sb.append(','); first = false; sb.append(getSimpleName(t2)); } sb.append(">"); return sb.toString(); } return null; }
/** * Returns the simple name of a class. * * <p> * Similar to {@link Class#getSimpleName()}, but includes the simple name of an enclosing or declaring class. * * @param t The class to get the simple name on. * @return The simple name of a class. */ public static String getSimpleName(Type t) { if (t instanceof Class) return getSimpleName((Class<?>)t); if (t instanceof ParameterizedType) { StringBuilder sb = new StringBuilder(); ParameterizedType pt = (ParameterizedType)t; sb.append(getSimpleName(pt.getRawType())); sb.append("<"); boolean first = true; for (Type t2 : pt.getActualTypeArguments()) { if (! first) sb.append(','); first = false; sb.append(getSimpleName(t2)); } sb.append(">"); return sb.toString(); } return null; }
/** * Returns the simple name of a class. * * <p> * Similar to {@link Class#getSimpleName()}, but includes the simple name of an enclosing or declaring class. * * @param t The class to get the simple name on. * @return The simple name of a class. */ public static String getSimpleName(Type t) { if (t instanceof Class) return getSimpleName((Class<?>)t); if (t instanceof ParameterizedType) { StringBuilder sb = new StringBuilder(); ParameterizedType pt = (ParameterizedType)t; sb.append(getSimpleName(pt.getRawType())); sb.append("<"); boolean first = true; for (Type t2 : pt.getActualTypeArguments()) { if (! first) sb.append(','); first = false; sb.append(getSimpleName(t2)); } sb.append(">"); return sb.toString(); } return null; }
/** * Given a Java method, returns the arguments signature. * * @param m The Java method. * @param full Whether fully-qualified names should be used for arguments. * @return The arguments signature for the specified method. */ public static String getMethodArgsSignature(Method m, boolean full) { StringBuilder sb = new StringBuilder(); Class<?>[] pt = m.getParameterTypes(); if (pt.length == 0) return ""; sb.append('('); for (int i = 0; i < pt.length; i++) { if (i > 0) sb.append(','); sb.append(full ? ClassUtils.getReadableClassName(pt[i]) : ClassUtils.getSimpleName(pt[i])); } sb.append(')'); return sb.toString(); } }
/** * Given a Java method, returns the arguments signature. * * @param m The Java method. * @param full Whether fully-qualified names should be used for arguments. * @return The arguments signature for the specified method. */ public static String getMethodArgsSignature(Method m, boolean full) { StringBuilder sb = new StringBuilder(); Class<?>[] pt = m.getParameterTypes(); if (pt.length == 0) return ""; sb.append('('); for (int i = 0; i < pt.length; i++) { if (i > 0) sb.append(','); sb.append(full ? ClassUtils.getReadableClassName(pt[i]) : ClassUtils.getSimpleName(pt[i])); } sb.append(')'); return sb.toString(); } }
/** * Given a Java method, returns the arguments signature. * * @param m The Java method. * @param full Whether fully-qualified names should be used for arguments. * @return The arguments signature for the specified method. */ public static String getMethodArgsSignature(Method m, boolean full) { StringBuilder sb = new StringBuilder(); Class<?>[] pt = m.getParameterTypes(); if (pt.length == 0) return ""; sb.append('('); for (int i = 0; i < pt.length; i++) { if (i > 0) sb.append(','); sb.append(full ? ClassUtils.getReadableClassName(pt[i]) : ClassUtils.getSimpleName(pt[i])); } sb.append(')'); return sb.toString(); } }
@Test public void getSimpleName() throws Exception { assertEquals("ClassUtilsTest.G1", ClassUtils.getSimpleName(G1.class)); assertEquals("ClassUtilsTest.G2", ClassUtils.getSimpleName(G2.class)); }
@Test public void testOnParameterType() throws Exception { Type t = Value.getParameterType(C.class.getMethod("m1", Value.class), 0); assertEquals("List<Integer>", ClassUtils.getSimpleName(t)); } }
ObjectMap omSwagger = context.getClasspathResource(ObjectMap.class, MediaType.JSON, ClassUtils.getSimpleName(resource.getClass()) + ".json", locale); if (omSwagger == null) omSwagger = context.getClasspathResource(ObjectMap.class, MediaType.JSON, resource.getClass().getSimpleName() + ".json", locale);
ObjectMap omSwagger = context.getClasspathResource(ObjectMap.class, MediaType.JSON, ClassUtils.getSimpleName(resource.getClass()) + ".json", locale); if (omSwagger == null) omSwagger = context.getClasspathResource(ObjectMap.class, MediaType.JSON, resource.getClass().getSimpleName() + ".json", locale);
ObjectMap omSwagger = context.getClasspathResource(ObjectMap.class, MediaType.JSON, ClassUtils.getSimpleName(resource.getClass()) + ".json", locale); if (omSwagger == null) omSwagger = context.getClasspathResource(ObjectMap.class, MediaType.JSON, resource.getClass().getSimpleName() + ".json", locale);