Class AnnotationLookup

java.lang.Object
de.Keyle.MyPet.api.util.AnnotationLookup

public final class AnnotationLookup extends Object
Resolve an annotation-carried name (e.g. @SkillName("Damage"), @LeashFlagName("BelowHP"), @RequirementName("PetLevel")) by walking a class's superclass chain and implemented interfaces.

The annotation is only honored on classes assignable to a given marker type — e.g. @SkillName on a class that doesn't implement Skill is ignored. This matches the historical behavior of the three near-identical walkers that lived on SkillManager#getSkillName, LeashFlagManager#getLeashFlagName, and SkilltreeManager#getRequirementName.

  • Method Details

    • find

      public static <A extends Annotation> A find(Class<?> clazz, Class<A> annotationType)
      Searches clazz, its superclass chain and every implemented interface for an annotation of the given type, regardless of any marker type. The class itself is checked first, then the superclass chain, then the interfaces; the first match wins.
      Type Parameters:
      A - the annotation type
      Parameters:
      clazz - the class to start searching from, may be null
      annotationType - the annotation class to look for, may be null
      Returns:
      the annotation instance if found, or null
    • findName

      public static <A extends Annotation> String findName(Class<?> clazz, Class<A> annotationType, Class<?> markerType, Function<A,String> nameExtractor)
      Recursively search clazz, its superclass chain, and every implemented interface for an instance of annotationType carried on a class assignable to markerType. The first match wins.
      Type Parameters:
      A - the annotation carrying the name
      Parameters:
      clazz - the class to inspect (or any ancestor reached during recursion)
      annotationType - the annotation class to look for
      markerType - the marker interface/class the annotated type must extend or implement
      nameExtractor - pulls the value() (or equivalent) off the annotation instance
      Returns:
      the extracted name, or null if no annotated ancestor is found