Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8304088

Refactor VisibleMemberTable (convenient query methods)

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Won't Fix
    • Icon: P4 P4
    • tbd
    • 21
    • tools

      We want to avoid casting to a subtype of Element when querying VisibleMemberTable for a specific kind of element. Such casting is inconvenient, error-prone, and not DRY.

      For example, this method could return `List<ExecutableElement>` if the kind is METHODS or CONSTRUCTORS, `List<VariableElement>` if the kind is FIELDS or ENUM_CONSTANTS, or `List<TypeElement>` if the kind is NESTED_CLASSES:

          public List<Element> getVisibleMembers(Kind kind)

      Unfortunately, we cannot parameterize Kind with a subtype of Element; generic enums are problematic, see: https://openjdk.org/jeps/301. So this is not an option:

          public List<T extends Element> getVisibleMembers(Kind<T> kind)

      However, we could use a type token (`Class<T extends Element>`), which would be more convenient, but still error-prone and not DRY:

          public List<T extends Element> getVisibleMembers(Kind kind, Class<T> clazz)

      Alternatively, we could emulate generic enums using sealed generic interfaces: interfaces can be generic while sealing and pattern matching for switch would allow enum-like treatment.

            prappo Pavel Rappo
            prappo Pavel Rappo
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: