< prev index next >

src/jdk.compiler/share/classes/com/sun/tools/javac/processing/PrintingProcessor.java

Print this page

        

@@ -37,10 +37,12 @@
 
 import java.io.PrintWriter;
 import java.io.Writer;
 import java.util.*;
 import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
 
 import com.sun.tools.javac.util.DefinedBy;
 import com.sun.tools.javac.util.DefinedBy.Api;
 import com.sun.tools.javac.util.StringUtils;
 

@@ -214,10 +216,20 @@
                 writer.print(" ");
                 writer.print(e.getSimpleName());
 
                 printFormalTypeParameters(e, false);
 
+                if (kind == RECORD) {
+                    // Print out state components
+                    writer.print("(");
+                    writer.print(e.getStateComponents()
+                                 .stream()
+                                 .map(stateDes -> stateDes.asType().toString() + " " + stateDes.getSimpleName())
+                                 .collect(Collectors.joining(", ")));
+                    writer.print(")");
+                }
+
                 // Print superclass information if informative
                 if (kind == CLASS) {
                     TypeMirror supertype = e.getSuperclass();
                     if (supertype.getKind() != TypeKind.NONE) {
                         TypeElement e2 = (TypeElement)

@@ -226,10 +238,11 @@
                             writer.print(" extends " + supertype);
                     }
                 }
 
                 printInterfaces(e);
+                printPermittedSubtypes(e);
             }
             writer.println(" {");
             indentation++;
 
             if (kind == ENUM) {

@@ -253,11 +266,17 @@
                 }
 
                 for(Element element : enclosedElements)
                     this.visit(element);
             } else {
-                for(Element element : e.getEnclosedElements())
+                for(Element element :
+                        (kind != RECORD ?
+                         e.getEnclosedElements() :
+                         e.getEnclosedElements()
+                         .stream()
+                         .filter(elt -> elementUtils.getOrigin(elt) == Elements.Origin.EXPLICIT )
+                         .collect(Collectors.toList()) ) )
                     this.visit(element);
             }
 
             indentation--;
             indent();

@@ -446,10 +465,14 @@
             case ENUM:
                 modifiers.remove(Modifier.FINAL);
                 modifiers.remove(Modifier.ABSTRACT);
                 break;
 
+            case RECORD:
+                modifiers.remove(Modifier.FINAL);
+                break;
+
             case METHOD:
             case FIELD:
                 Element enclosingElement = e.getEnclosingElement();
                 if (enclosingElement != null &&
                     enclosingElement.getKind().isInterface()) {

@@ -570,10 +593,21 @@
                                  .collect(Collectors.joining(", ")));
                 }
             }
         }
 
+        private void printPermittedSubtypes(TypeElement e) {
+            List<? extends TypeMirror> subtypes = e.getPermittedSubtypes();
+            if (!subtypes.isEmpty()) { // could remove this check with more complicated joining call
+                writer.print(" permits ");
+                writer.print(subtypes
+                             .stream()
+                             .map(subtype -> subtype.toString())
+                             .collect(Collectors.joining(", ")));
+            }
+        }
+
         private void printThrows(ExecutableElement e) {
             List<? extends TypeMirror> thrownTypes = e.getThrownTypes();
             final int size = thrownTypes.size();
             if (size != 0) {
                 writer.print(" throws");
< prev index next >