AnnotationUtils.java 10.5 KB
package org.apache.commons.lang3;

import java.lang.annotation.Annotation;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

public class AnnotationUtils
{
  private static final ToStringStyle a = new ToStringStyle()
  {
    private static final long serialVersionUID = 1L;
    
    protected final void appendDetail(StringBuffer paramAnonymousStringBuffer, String paramAnonymousString, Object paramAnonymousObject)
    {
      Object localObject = paramAnonymousObject;
      if ((paramAnonymousObject instanceof Annotation)) {
        localObject = AnnotationUtils.toString((Annotation)paramAnonymousObject);
      }
      super.appendDetail(paramAnonymousStringBuffer, paramAnonymousString, localObject);
    }
    
    protected final String getShortClassName(Class<?> paramAnonymousClass)
    {
      Iterator localIterator = ClassUtils.getAllInterfaces(paramAnonymousClass).iterator();
      do
      {
        if (!localIterator.hasNext()) {
          break;
        }
        paramAnonymousClass = (Class)localIterator.next();
      } while (!Annotation.class.isAssignableFrom(paramAnonymousClass));
      for (;;)
      {
        if (paramAnonymousClass == null) {}
        for (paramAnonymousClass = "";; paramAnonymousClass = paramAnonymousClass.getName()) {
          return new StringBuilder(paramAnonymousClass).insert(0, '@').toString();
        }
        paramAnonymousClass = null;
      }
    }
  };
  
  public static boolean equals(Annotation paramAnnotation1, Annotation paramAnnotation2)
  {
    if (paramAnnotation1 == paramAnnotation2) {
      return true;
    }
    if ((paramAnnotation1 == null) || (paramAnnotation2 == null)) {
      return false;
    }
    Object localObject1 = paramAnnotation1.annotationType();
    Object localObject2 = paramAnnotation2.annotationType();
    Validate.notNull(localObject1, "Annotation %s with null annotationType()", new Object[] { paramAnnotation1 });
    Validate.notNull(localObject2, "Annotation %s with null annotationType()", new Object[] { paramAnnotation2 });
    if (!localObject1.equals(localObject2)) {
      return false;
    }
    label225:
    label609:
    label616:
    label632:
    label637:
    label644:
    label648:
    for (;;)
    {
      Object localObject3;
      boolean bool;
      int j;
      try
      {
        localObject1 = ((Class)localObject1).getDeclaredMethods();
        int k = localObject1.length;
        int i = 0;
        if (i < k)
        {
          Class localClass = localObject1[i];
          if ((localClass.getParameterTypes().length == 0) && (isValidAnnotationMemberType(localClass.getReturnType())))
          {
            localObject3 = localClass.invoke(paramAnnotation1, new Object[0]);
            localObject2 = localClass.invoke(paramAnnotation2, new Object[0]);
            localClass = localClass.getReturnType();
            if (localObject3 != localObject2) {
              break label616;
            }
            bool = true;
            break label609;
            if (localClass.isArray())
            {
              localClass = localClass.getComponentType();
              if (localClass.isAnnotation())
              {
                localObject3 = (Annotation[])localObject3;
                localObject2 = (Annotation[])localObject2;
                if (localObject3.length == localObject2.length) {
                  break label632;
                }
                bool = false;
                break label609;
                if (j >= localObject3.length) {
                  break label644;
                }
                if (equals(localObject3[j], localObject2[j])) {
                  break label637;
                }
                bool = false;
              }
              else if (localClass.equals(Byte.TYPE))
              {
                bool = Arrays.equals((byte[])localObject3, (byte[])localObject2);
              }
              else if (localClass.equals(Short.TYPE))
              {
                bool = Arrays.equals((short[])localObject3, (short[])localObject2);
              }
              else if (localClass.equals(Integer.TYPE))
              {
                bool = Arrays.equals((int[])localObject3, (int[])localObject2);
              }
              else if (localClass.equals(Character.TYPE))
              {
                bool = Arrays.equals((char[])localObject3, (char[])localObject2);
              }
              else if (localClass.equals(Long.TYPE))
              {
                bool = Arrays.equals((long[])localObject3, (long[])localObject2);
              }
              else if (localClass.equals(Float.TYPE))
              {
                bool = Arrays.equals((float[])localObject3, (float[])localObject2);
              }
              else if (localClass.equals(Double.TYPE))
              {
                bool = Arrays.equals((double[])localObject3, (double[])localObject2);
              }
              else if (localClass.equals(Boolean.TYPE))
              {
                bool = Arrays.equals((boolean[])localObject3, (boolean[])localObject2);
              }
              else
              {
                bool = Arrays.equals((Object[])localObject3, (Object[])localObject2);
              }
            }
            else if (localClass.isAnnotation())
            {
              bool = equals((Annotation)localObject3, (Annotation)localObject2);
            }
            else
            {
              bool = localObject3.equals(localObject2);
            }
          }
          else
          {
            i += 1;
          }
        }
        else
        {
          return true;
        }
      }
      catch (IllegalAccessException paramAnnotation1)
      {
        return false;
      }
      catch (InvocationTargetException paramAnnotation1)
      {
        return false;
      }
      for (;;)
      {
        if (bool) {
          break label648;
        }
        return false;
        if ((localObject3 != null) && (localObject2 != null)) {
          break;
        }
        bool = false;
        continue;
        j = 0;
        break label225;
        j += 1;
        break label225;
        bool = true;
      }
    }
  }
  
  public static int hashCode(Annotation paramAnnotation)
  {
    Method[] arrayOfMethod = paramAnnotation.annotationType().getDeclaredMethods();
    int m = arrayOfMethod.length;
    int j = 0;
    int k = 0;
    for (;;)
    {
      int n;
      int i;
      if (j < m)
      {
        Object localObject2 = arrayOfMethod[j];
        try
        {
          localObject1 = ((Method)localObject2).invoke(paramAnnotation, new Object[0]);
          if (localObject1 == null) {
            throw new IllegalStateException(String.format("Annotation method %s returned null", new Object[] { localObject2 }));
          }
        }
        catch (RuntimeException paramAnnotation)
        {
          Object localObject1;
          throw paramAnnotation;
          n = ((Method)localObject2).getName().hashCode() * 127;
          if (localObject1.getClass().isArray())
          {
            localObject2 = localObject1.getClass().getComponentType();
            if (localObject2.equals(Byte.TYPE))
            {
              i = Arrays.hashCode((byte[])localObject1);
              break label380;
            }
            if (localObject2.equals(Short.TYPE))
            {
              i = Arrays.hashCode((short[])localObject1);
              break label380;
            }
            if (localObject2.equals(Integer.TYPE))
            {
              i = Arrays.hashCode((int[])localObject1);
              break label380;
            }
            if (localObject2.equals(Character.TYPE))
            {
              i = Arrays.hashCode((char[])localObject1);
              break label380;
            }
            if (localObject2.equals(Long.TYPE))
            {
              i = Arrays.hashCode((long[])localObject1);
              break label380;
            }
            if (localObject2.equals(Float.TYPE))
            {
              i = Arrays.hashCode((float[])localObject1);
              break label380;
            }
            if (localObject2.equals(Double.TYPE))
            {
              i = Arrays.hashCode((double[])localObject1);
              break label380;
            }
            if (localObject2.equals(Boolean.TYPE))
            {
              i = Arrays.hashCode((boolean[])localObject1);
              break label380;
            }
            i = Arrays.hashCode((Object[])localObject1);
            break label380;
          }
          if ((localObject1 instanceof Annotation))
          {
            i = hashCode((Annotation)localObject1) ^ n;
          }
          else
          {
            i = localObject1.hashCode();
            i ^= n;
          }
        }
        catch (Exception paramAnnotation)
        {
          throw new RuntimeException(paramAnnotation);
        }
      }
      return k;
      label380:
      i ^= n;
      k += i;
      j += 1;
    }
  }
  
  public static boolean isValidAnnotationMemberType(Class<?> paramClass)
  {
    if (paramClass == null) {}
    Object localObject;
    do
    {
      return false;
      localObject = paramClass;
      if (paramClass.isArray()) {
        localObject = paramClass.getComponentType();
      }
    } while ((!((Class)localObject).isPrimitive()) && (!((Class)localObject).isEnum()) && (!((Class)localObject).isAnnotation()) && (!String.class.equals(localObject)) && (!Class.class.equals(localObject)));
    return true;
  }
  
  public static String toString(Annotation paramAnnotation)
  {
    int i = 0;
    ToStringBuilder localToStringBuilder = new ToStringBuilder(paramAnnotation, a);
    Method[] arrayOfMethod = paramAnnotation.annotationType().getDeclaredMethods();
    int j = arrayOfMethod.length;
    while (i < j)
    {
      Method localMethod = arrayOfMethod[i];
      if (localMethod.getParameterTypes().length <= 0) {}
      try
      {
        localToStringBuilder.append(localMethod.getName(), localMethod.invoke(paramAnnotation, new Object[0]));
        i += 1;
      }
      catch (RuntimeException paramAnnotation)
      {
        throw paramAnnotation;
      }
      catch (Exception paramAnnotation)
      {
        throw new RuntimeException(paramAnnotation);
      }
    }
    return localToStringBuilder.build();
  }
}


/* Location:              /home/merong/decompile/hackery-dex2jar.jar!/org/apache/commons/lang3/AnnotationUtils.class
 * Java compiler version: 6 (50.0)
 * JD-Core Version:       0.7.1
 */