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

TypeMirror#toString omits enclosing class names after JDK-8281238

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P2 P2
    • 19
    • 19
    • tools
    • None
    • 19
    • b21
    • Verified

      After the fix for https://bugs.openjdk.java.net/browse/JDK-8281238, TypeMirror#toString does not print the enclosing class name for static member classes with type annotations, e.g. it prints `java.util.@p.T.A Entry<?,?>` for `java.util.Map.Entry` (omitting the 'Map')

      ```
      import java.util.Set;
      import javax.annotation.processing.AbstractProcessor;
      import javax.annotation.processing.RoundEnvironment;
      import javax.annotation.processing.SupportedAnnotationTypes;
      import javax.lang.model.SourceVersion;
      import javax.lang.model.element.Element;
      import javax.lang.model.element.ElementKind;
      import javax.lang.model.element.TypeElement;
      import javax.tools.Diagnostic;

      @SupportedAnnotationTypes("*")
      public class P extends AbstractProcessor {

        @Override
        public SourceVersion getSupportedSourceVersion() {
          return SourceVersion.latestSupported();
        }

        @Override
        public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
          for (Element e : processingEnv.getElementUtils().getTypeElement("p.T").getEnclosedElements()) {
            if (e.getKind().equals(ElementKind.FIELD)) {
              processingEnv.getMessager().printMessage(Diagnostic.Kind.NOTE, e.asType().toString());
            }
          }
          return false;
        }
      }
      ```

      ```
      package p;

      import java.lang.annotation.ElementType;
      import java.lang.annotation.Target;
      import java.util.Map.Entry;

      class T {
        @Target(ElementType.TYPE_USE)
        @interface A {}

        @A Entry<?, ?> e;
      }
      ```

      $ javac -fullversion -processor P T.java
      javac full version "18-ea+35-2085"
      Note: @p.T.A java.util.Map.Entry<?,?>
      Note: @p.T.A java.util.Map.Entry<?,?>

      $ javac -fullversion -processor P T.java
      javac full version "19-ea+15-942"
      Note: java.util.@p.T.A Entry<?,?>
      Note: java.util.@p.T.A Entry<?,?>

            cushon Liam Miller-Cushon
            cushon Liam Miller-Cushon
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: