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-
This commit is contained in:
Peter Verhas 2019-10-16 00:30:59 +02:00 committed by Gary Gregory
parent bedae6950d
commit f3ad91ca38
1 changed files with 7 additions and 13 deletions

View File

@ -68,19 +68,13 @@ public class AnnotationUtils {
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
protected String getShortClassName(final java.lang.Class<?> cls) { protected String getShortClassName(final Class<?> cls) {
Class<? extends Annotation> annotationType = null;
for (final Class<?> iface : ClassUtils.getAllInterfaces(cls)) { for (final Class<?> iface : ClassUtils.getAllInterfaces(cls)) {
if (Annotation.class.isAssignableFrom(iface)) { if (Annotation.class.isAssignableFrom(iface)) {
@SuppressWarnings("unchecked") // OK because we just checked the assignability return "@" + iface.getName();
final
Class<? extends Annotation> found = (Class<? extends Annotation>) iface;
annotationType = found;
break;
} }
} }
return new StringBuilder(annotationType == null ? StringUtils.EMPTY : annotationType.getName()) return StringUtils.EMPTY;
.insert(0, '@').toString();
} }
/** /**
@ -125,15 +119,15 @@ public static boolean equals(final Annotation a1, final Annotation a2) {
if (a1 == null || a2 == null) { if (a1 == null || a2 == null) {
return false; return false;
} }
final Class<? extends Annotation> type = a1.annotationType(); final Class<? extends Annotation> type1 = a1.annotationType();
final Class<? extends Annotation> type2 = a2.annotationType(); final Class<? extends Annotation> 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); Validate.notNull(type2, "Annotation %s with null annotationType()", a2);
if (!type.equals(type2)) { if (!type1.equals(type2)) {
return false; return false;
} }
try { try {
for (final Method m : type.getDeclaredMethods()) { for (final Method m : type1.getDeclaredMethods()) {
if (m.getParameterTypes().length == 0 if (m.getParameterTypes().length == 0
&& isValidAnnotationMemberType(m.getReturnType())) { && isValidAnnotationMemberType(m.getReturnType())) {
final Object v1 = m.invoke(a1); final Object v1 = m.invoke(a1);