@Test public void testAnnotatationToStringConversion() throws NoSuchMethodException { String expectedOutcome = "@org.jboss.weld.probe.JsonObjectsTest$SomeAnnotation(someInt=1, someString=\"bar\", someStringArray={\"charlie\", \"delta\"})"; assertEquals(expectedOutcome, JsonObjects.annotationToString(getBarTypeAnnotation())); assertEquals(expectedOutcome, JsonObjects.annotationToString(getBarMethodParamAnnotation())); assertEquals(expectedOutcome, JsonObjects.annotationToString(getBarMethodAnnotation())); }
static String annotationToString(Annotation annotation) { StringBuilder string = new StringBuilder(); string.append('@').append(annotation.annotationType().getName()).append('('); String classAffix = ".class"; String quotationMark = "\""; try { List<Method> methods = Arrays.asList(annotation.annotationType().getDeclaredMethods()); methods.sort(new Comparator<Method>() { @Override public int compare(Method o1, Method o2) { return o1.toGenericString().compareTo(o2.toGenericString()); } }); for (int i = 0; i < methods.size(); i++) { string.append(methods.get(i).getName()).append('='); Object value = methods.get(i).invoke(annotation); if (value instanceof boolean[]) { appendInBraces(string, Arrays.toString((boolean[]) value)); } else if (value instanceof byte[]) { appendInBraces(string, Arrays.toString((byte[]) value)); } else if (value instanceof short[]) { appendInBraces(string, Arrays.toString((short[]) value)); } else if (value instanceof int[]) { appendInBraces(string, Arrays.toString((int[]) value)); } else if (value instanceof long[]) { appendInBraces(string, Arrays.toString((long[]) value)); } else if (value instanceof float[]) { appendInBraces(string, Arrays.toString((float[]) value)); } else if (value instanceof double[]) { appendInBraces(string, Arrays.toString((double[]) value)); } else if (value instanceof char[]) { appendInBraces(string, Arrays.toString((char[]) value)); } else if (value instanceof String[]) { String[] strings = (String[]) value; String[] quoted = new String[strings.length]; for (int j = 0; j < strings.length; j++) { quoted[j] = quotationMark + strings[j] + quotationMark; } appendInBraces(string, Arrays.toString(quoted)); } else if (value instanceof Class<?>[]) { Class<?>[] classes = (Class<?>[]) value; String[] names = new String[classes.length]; for (int j = 0; j < classes.length; j++) { names[j] = classes[j].getName() + classAffix; } appendInBraces(string, Arrays.toString(names)); } else if (value instanceof Object[]) { appendInBraces(string, Arrays.toString((Object[]) value)); } else if (value instanceof String) { string.append('"').append(value).append('"'); } else if (value instanceof Class<?>) { string.append(((Class<?>) value).getName()).append(classAffix); } else { string.append(value); } if (i < methods.size() - 1) { string.append(", "); } } } catch (IllegalAccessException | IllegalArgumentException | SecurityException | InvocationTargetException ex) { ProbeLogger.LOG.cannotUseUnifiedAnnotationToStringConversion(ex); return annotation.toString(); } return string.append(')').toString(); }
JsonObjects { static String annotationToString(Annotation annotation) { StringBuilder string = new StringBuilder(); string.append('@').append(annotation.annotationType().getName()).append('('); String classAffix = ".class"; String quotationMark = "\""; try { List<Method> methods = Arrays.asList(annotation.annotationType().getDeclaredMethods()); methods.sort(new Comparator<Method>() { @Override public int compare(Method o1, Method o2) { return o1.toGenericString().compareTo(o2.toGenericString()); } }); for (int i = 0; i < methods.size(); i++) { string.append(methods.get(i).getName()).append('='); Object value = methods.get(i).invoke(annotation); if (value instanceof boolean[]) { appendInBraces(string, Arrays.toString((boolean[]) value)); } else if (value instanceof byte[]) { appendInBraces(string, Arrays.toString((byte[]) value)); } else if (value instanceof short[]) { appendInBraces(string, Arrays.toString((short[]) value)); } else if (value instanceof int[]) { appendInBraces(string, Arrays.toString((int[]) value)); } else if (value instanceof long[]) { appendInBraces(string, Arrays.toString((long[]) value)); } else if (value instanceof float[]) { appendInBraces(string, Arrays.toString((float[]) value)); } else if (value instanceof double[]) { appendInBraces(string, Arrays.toString((double[]) value)); } else if (value instanceof char[]) { appendInBraces(string, Arrays.toString((char[]) value)); } else if (value instanceof String[]) { String[] strings = (String[]) value; String[] quoted = new String[strings.length]; for (int j = 0; j < strings.length; j++) { quoted[j] = quotationMark + strings[j] + quotationMark; } appendInBraces(string, Arrays.toString(quoted)); } else if (value instanceof Class<?>[]) { Class<?>[] classes = (Class<?>[]) value; String[] names = new String[classes.length]; for (int j = 0; j < classes.length; j++) { names[j] = classes[j].getName() + classAffix; } appendInBraces(string, Arrays.toString(names)); } else if (value instanceof Object[]) { appendInBraces(string, Arrays.toString((Object[]) value)); } else if (value instanceof String) { string.append('"').append(value).append('"'); } else if (value instanceof Class<?>) { string.append(((Class<?>) value).getName()).append(classAffix); } else { string.append(value); } if (i < methods.size() - 1) { string.append(", "); } } } catch (IllegalAccessException | IllegalArgumentException | SecurityException | InvocationTargetException ex) { ProbeLogger.LOG.cannotUseUnifiedAnnotationToStringConversion(ex); return annotation.toString(); } return string.append(')').toString(); } }
JsonObjects { static String annotationToString(Annotation annotation) { StringBuilder string = new StringBuilder(); string.append('@').append(annotation.annotationType().getName()).append('('); String classAffix = ".class"; String quotationMark = "\""; try { List<Method> methods = Arrays.asList(annotation.annotationType().getDeclaredMethods()); methods.sort(new Comparator<Method>() { @Override public int compare(Method o1, Method o2) { return o1.toGenericString().compareTo(o2.toGenericString()); } }); for (int i = 0; i < methods.size(); i++) { string.append(methods.get(i).getName()).append('='); Object value = methods.get(i).invoke(annotation); if (value instanceof boolean[]) { appendInBraces(string, Arrays.toString((boolean[]) value)); } else if (value instanceof byte[]) { appendInBraces(string, Arrays.toString((byte[]) value)); } else if (value instanceof short[]) { appendInBraces(string, Arrays.toString((short[]) value)); } else if (value instanceof int[]) { appendInBraces(string, Arrays.toString((int[]) value)); } else if (value instanceof long[]) { appendInBraces(string, Arrays.toString((long[]) value)); } else if (value instanceof float[]) { appendInBraces(string, Arrays.toString((float[]) value)); } else if (value instanceof double[]) { appendInBraces(string, Arrays.toString((double[]) value)); } else if (value instanceof char[]) { appendInBraces(string, Arrays.toString((char[]) value)); } else if (value instanceof String[]) { String[] strings = (String[]) value; String[] quoted = new String[strings.length]; for (int j = 0; j < strings.length; j++) { quoted[j] = quotationMark + strings[j] + quotationMark; } appendInBraces(string, Arrays.toString(quoted)); } else if (value instanceof Class<?>[]) { Class<?>[] classes = (Class<?>[]) value; String[] names = new String[classes.length]; for (int j = 0; j < classes.length; j++) { names[j] = classes[j].getName() + classAffix; } appendInBraces(string, Arrays.toString(names)); } else if (value instanceof Object[]) { appendInBraces(string, Arrays.toString((Object[]) value)); } else if (value instanceof String) { string.append('"').append(value).append('"'); } else if (value instanceof Class<?>) { string.append(((Class<?>) value).getName()).append(classAffix); } else { string.append(value); } if (i < methods.size() - 1) { string.append(", "); } } } catch (IllegalAccessException | IllegalArgumentException | SecurityException | InvocationTargetException ex) { ProbeLogger.LOG.cannotUseUnifiedAnnotationToStringConversion(ex); return annotation.toString(); } return string.append(')').toString(); } private  JsonObjects(); }
JsonObjects { static String annotationToString(Annotation annotation) { StringBuilder string = new StringBuilder(); string.append('@').append(annotation.annotationType().getName()).append('('); String classAffix = ".class"; String quotationMark = "\""; try { List<Method> methods = Arrays.asList(annotation.annotationType().getDeclaredMethods()); methods.sort(new Comparator<Method>() { @Override public int compare(Method o1, Method o2) { return o1.toGenericString().compareTo(o2.toGenericString()); } }); for (int i = 0; i < methods.size(); i++) { string.append(methods.get(i).getName()).append('='); Object value = methods.get(i).invoke(annotation); if (value instanceof boolean[]) { appendInBraces(string, Arrays.toString((boolean[]) value)); } else if (value instanceof byte[]) { appendInBraces(string, Arrays.toString((byte[]) value)); } else if (value instanceof short[]) { appendInBraces(string, Arrays.toString((short[]) value)); } else if (value instanceof int[]) { appendInBraces(string, Arrays.toString((int[]) value)); } else if (value instanceof long[]) { appendInBraces(string, Arrays.toString((long[]) value)); } else if (value instanceof float[]) { appendInBraces(string, Arrays.toString((float[]) value)); } else if (value instanceof double[]) { appendInBraces(string, Arrays.toString((double[]) value)); } else if (value instanceof char[]) { appendInBraces(string, Arrays.toString((char[]) value)); } else if (value instanceof String[]) { String[] strings = (String[]) value; String[] quoted = new String[strings.length]; for (int j = 0; j < strings.length; j++) { quoted[j] = quotationMark + strings[j] + quotationMark; } appendInBraces(string, Arrays.toString(quoted)); } else if (value instanceof Class<?>[]) { Class<?>[] classes = (Class<?>[]) value; String[] names = new String[classes.length]; for (int j = 0; j < classes.length; j++) { names[j] = classes[j].getName() + classAffix; } appendInBraces(string, Arrays.toString(names)); } else if (value instanceof Object[]) { appendInBraces(string, Arrays.toString((Object[]) value)); } else if (value instanceof String) { string.append('"').append(value).append('"'); } else if (value instanceof Class<?>) { string.append(((Class<?>) value).getName()).append(classAffix); } else { string.append(value); } if (i < methods.size() - 1) { string.append(", "); } } } catch (IllegalAccessException | IllegalArgumentException | SecurityException | InvocationTargetException ex) { ProbeLogger.LOG.cannotUseUnifiedAnnotationToStringConversion(ex); return annotation.toString(); } return string.append(')').toString(); } private  JsonObjects();  }
JsonObjects { static String annotationToString(Annotation annotation) { StringBuilder string = new StringBuilder(); string.append('@').append(annotation.annotationType().getName()).append('('); String classAffix = ".class"; String quotationMark = "\""; try { List<Method> methods = Arrays.asList(annotation.annotationType().getDeclaredMethods()); methods.sort(new Comparator<Method>() { @Override public int compare(Method o1, Method o2) { return o1.toGenericString().compareTo(o2.toGenericString()); } }); for (int i = 0; i < methods.size(); i++) { string.append(methods.get(i).getName()).append('='); Object value = methods.get(i).invoke(annotation); if (value instanceof boolean[]) { appendInBraces(string, Arrays.toString((boolean[]) value)); } else if (value instanceof byte[]) { appendInBraces(string, Arrays.toString((byte[]) value)); } else if (value instanceof short[]) { appendInBraces(string, Arrays.toString((short[]) value)); } else if (value instanceof int[]) { appendInBraces(string, Arrays.toString((int[]) value)); } else if (value instanceof long[]) { appendInBraces(string, Arrays.toString((long[]) value)); } else if (value instanceof float[]) { appendInBraces(string, Arrays.toString((float[]) value)); } else if (value instanceof double[]) { appendInBraces(string, Arrays.toString((double[]) value)); } else if (value instanceof char[]) { appendInBraces(string, Arrays.toString((char[]) value)); } else if (value instanceof String[]) { String[] strings = (String[]) value; String[] quoted = new String[strings.length]; for (int j = 0; j < strings.length; j++) { quoted[j] = quotationMark + strings[j] + quotationMark; } appendInBraces(string, Arrays.toString(quoted)); } else if (value instanceof Class<?>[]) { Class<?>[] classes = (Class<?>[]) value; String[] names = new String[classes.length]; for (int j = 0; j < classes.length; j++) { names[j] = classes[j].getName() + classAffix; } appendInBraces(string, Arrays.toString(names)); } else if (value instanceof Object[]) { appendInBraces(string, Arrays.toString((Object[]) value)); } else if (value instanceof String) { string.append('"').append(value).append('"'); } else if (value instanceof Class<?>) { string.append(((Class<?>) value).getName()).append(classAffix); } else { string.append(value); } if (i < methods.size() - 1) { string.append(", "); } } } catch (IllegalAccessException | IllegalArgumentException | SecurityException | InvocationTargetException ex) { ProbeLogger.LOG.cannotUseUnifiedAnnotationToStringConversion(ex); return annotation.toString(); } return string.append(')').toString(); } private  JsonObjects();   }