From f3ad91ca383a8c0dd8d8f69d6276f2558ad7c924 Mon Sep 17 00:00:00 2001 From: Peter Verhas Date: Wed, 16 Oct 2019 00:30:59 +0200 Subject: [PATCH] AnnotationUtils little cleanup (#467) * LANG-1480 getAbbreviatedName refactored to create appropriate length short class names * LANG-1480 code fixed for special extreme case ".." abbreviated to 1 length should result ".." it was throwing exception. Tests are added * import changed to avoid wild cards apache master merged into current branch * Mutable object import was moved to it's original place * some accidental formatting reverted * some accidental formatting reverted * some accidental formatting reverted * some accidental formatting reverted * some accidental formatting reverted * some accidental formatting reverted * some accidental formatting reverted * added another test case * LANG-1480 fixing JavaDoc documentation as per requested by garydgregory * LANG-1480 shortcut implemented, argument renamed, more tests * LANG-1480 checkstyle update * LANG-1492 tests methods modified to be public * LANG-1480 imports rearranged * LANG-1480 imports rearranged * LANG-1480 imports rearranged * little refactor * unused import deleted * space+ * space- --- .../apache/commons/lang3/AnnotationUtils.java | 20 +++++++------------ 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/src/main/java/org/apache/commons/lang3/AnnotationUtils.java b/src/main/java/org/apache/commons/lang3/AnnotationUtils.java index 81bd0f0e5..bc51037c7 100644 --- a/src/main/java/org/apache/commons/lang3/AnnotationUtils.java +++ b/src/main/java/org/apache/commons/lang3/AnnotationUtils.java @@ -68,19 +68,13 @@ public class AnnotationUtils { * {@inheritDoc} */ @Override - protected String getShortClassName(final java.lang.Class cls) { - Class annotationType = null; + protected String getShortClassName(final Class cls) { for (final Class iface : ClassUtils.getAllInterfaces(cls)) { if (Annotation.class.isAssignableFrom(iface)) { - @SuppressWarnings("unchecked") // OK because we just checked the assignability - final - Class found = (Class) iface; - annotationType = found; - break; + return "@" + iface.getName(); } } - return new StringBuilder(annotationType == null ? StringUtils.EMPTY : annotationType.getName()) - .insert(0, '@').toString(); + return StringUtils.EMPTY; } /** @@ -125,15 +119,15 @@ public static boolean equals(final Annotation a1, final Annotation a2) { if (a1 == null || a2 == null) { return false; } - final Class type = a1.annotationType(); + final Class type1 = a1.annotationType(); final Class type2 = a2.annotationType(); - Validate.notNull(type, "Annotation %s with null annotationType()", a1); + Validate.notNull(type1, "Annotation %s with null annotationType()", a1); Validate.notNull(type2, "Annotation %s with null annotationType()", a2); - if (!type.equals(type2)) { + if (!type1.equals(type2)) { return false; } try { - for (final Method m : type.getDeclaredMethods()) { + for (final Method m : type1.getDeclaredMethods()) { if (m.getParameterTypes().length == 0 && isValidAnnotationMemberType(m.getReturnType())) { final Object v1 = m.invoke(a1);