Uploaded image for project: 'Solder'
  1. Solder
  2. SOLDER-23

Provide utility to extract type parameter from Instance

This issue belongs to an archived project. You can view it, but you can't modify it. Learn more

    XMLWordPrintable

Details

    • Feature Request
    • Status: Open
    • Minor
    • Resolution: Unresolved
    • 3.0.0.Beta1
    • Future
    • Reflections
    • None
    • Low

    Description

      When discovering injection points, a type of Instance<T> is effectively the same as discovering a type T. You don't want to create a producer method for an Instance, for instance, hence why you want to figure out what T is. Thus, it's common to want to extract the type parameter from Instance. Having a utility would be convenient.

      Here's an example that collects the actual bean types (extracting from the Instance type parameter if necessary)

      Set<Type> types = new HashSet<Type>();
      for (InjectionPoint ip : event.getInjectionTarget().getInjectionPoints())
      {
      types.add(Reflections.getActualType(ip.Type()));
      }

      Here's the utility:

      private static Type getActualType(Type t)
      {
      if (t instanceof ParameterizedType && ((ParameterizedType) t).getRawType().equals(Instance.class))

      { return ((ParameterizedType) t).getActualTypeArguments()[0]; }

      return t;
      }

      Attachments

        Activity

          People

            dan.j.allen Dan Allen (Inactive)
            dan.j.allen Dan Allen (Inactive)
            Archiver:
            samahaja@redhat.com Sagar Mahajan

            Dates

              Created:
              Updated:
              Archived:

              PagerDuty