changeset 57913:6b2b5e4c01a7 records-and-sealed

Fix printing processor and TestRecordDesugar.java for record component elements.
author darcy
date Thu, 10 Oct 2019 16:24:39 -0700
parents 3525f011e46d
children 22a2bee294f4
files src/jdk.compiler/share/classes/com/sun/tools/javac/processing/PrintingProcessor.java test/langtools/tools/javac/processing/model/element/TestRecordDesugar.java
diffstat 2 files changed, 35 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/processing/PrintingProcessor.java	Thu Oct 10 16:43:26 2019 -0400
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/processing/PrintingProcessor.java	Thu Oct 10 16:24:39 2019 -0700
@@ -113,6 +113,13 @@
         }
 
         @Override @DefinedBy(Api.LANGUAGE_MODEL)
+	public PrintingElementVisitor visitRecordComponent(RecordComponentElement e, Boolean p) {
+	    // Do nothing; printing of component information done by
+	    // printing the record type itself
+	    return this;
+	}
+
+        @Override @DefinedBy(Api.LANGUAGE_MODEL)
         public PrintingElementVisitor visitExecutable(ExecutableElement e, Boolean p) {
             ElementKind kind = e.getKind();
 
--- a/test/langtools/tools/javac/processing/model/element/TestRecordDesugar.java	Thu Oct 10 16:43:26 2019 -0400
+++ b/test/langtools/tools/javac/processing/model/element/TestRecordDesugar.java	Thu Oct 10 16:24:39 2019 -0700
@@ -95,7 +95,7 @@
             System.out.println("\tChecking " + enclosedElement.getKind() + " " + enclosedElement);
             String key = enclosedElement.getKind().toString() + " " + enclosedElement.getSimpleName();
             ElementInfo expected = expectedInfoMap.get(key);
-            Objects.requireNonNull(expected, "Missing mapping for " + elementToString(enclosedElement));
+            Objects.requireNonNull(expected, "\t\tMissing mapping for " + elementToString(enclosedElement));
 
             expectedInfoMap.remove(key);
 
@@ -104,7 +104,7 @@
             // Modifiers
             if (!enclosedElement.getModifiers().equals(Set.of(expected.modifiers()))) {
                 errors++;
-                System.out.println("Unexpected modifiers on " + enclosedElement + ":\t"
+                System.out.println("\t\tUnexpected modifiers on " + enclosedElement + ":\t"
                                    + enclosedElement.getModifiers());
             }
 
@@ -216,17 +216,23 @@
      *}
      */
     @TypeElementInfo(elements =
-                     // For now, the desugared private fields are
-                     // marked as state components with a mandated
-                     // origin, but state components should get their
-                     // own representation.
-                     {@ElementInfo(kind = ElementKind.STATE_COMPONENT,
+                     {@ElementInfo(kind = ElementKind.RECORD_COMPONENT,
+                                   modifiers = {Modifier.PUBLIC},
+                                   name = "r",
+                                   type = TypeKind.DOUBLE),
+
+	              @ElementInfo(kind = ElementKind.FIELD,
                                    modifiers = {Modifier.PRIVATE, Modifier.FINAL},
                                    name = "r",
                                    type = TypeKind.DOUBLE,
                                    origin = Elements.Origin.MANDATED),
 
-                      @ElementInfo(kind = ElementKind.STATE_COMPONENT,
+                      @ElementInfo(kind = ElementKind.RECORD_COMPONENT,
+                                   modifiers = {Modifier.PUBLIC},
+                                   name = "theta",
+                                   type = TypeKind.DOUBLE),
+
+            	      @ElementInfo(kind = ElementKind.FIELD,
                                    modifiers = {Modifier.PRIVATE, Modifier.FINAL},
                                    name = "theta",
                                    type = TypeKind.DOUBLE,
@@ -281,17 +287,23 @@
      * Cartesian coordinate complex number.
      */
     @TypeElementInfo(elements =
-                     // For now, the desugared private fields are
-                     // marked as state components with a mandated
-                     // origin, but state components should get their
-                     // own representation.
-                     {@ElementInfo(kind = ElementKind.STATE_COMPONENT,
+                     {@ElementInfo(kind = ElementKind.RECORD_COMPONENT,
+                                   modifiers = {Modifier.PUBLIC},
+                                   name = "real",
+                                   type = TypeKind.DOUBLE),
+
+ 		      @ElementInfo(kind = ElementKind.FIELD,
                                    modifiers = {Modifier.PRIVATE, Modifier.FINAL},
                                    name = "real",
                                    type = TypeKind.DOUBLE,
                                    origin = Elements.Origin.MANDATED),
 
-                      @ElementInfo(kind = ElementKind.STATE_COMPONENT,
+                      @ElementInfo(kind = ElementKind.RECORD_COMPONENT,
+                                   modifiers = {Modifier.PUBLIC},
+                                   name = "imag",
+                                   type = TypeKind.DOUBLE),
+
+		      @ElementInfo(kind = ElementKind.FIELD,
                                    modifiers = {Modifier.PRIVATE, Modifier.FINAL},
                                    name = "imag",
                                    type = TypeKind.DOUBLE,
@@ -342,6 +354,8 @@
      record ComplexCartesian(double real, double imag) implements ComplexNumber {
         // Explicit constructor declaration allowed
         public ComplexCartesian(double real, double imag) {
+	    this.real = real;
+	    this.imag = imag;
         }
 
         @Override