src/jdk.compiler/share/classes/com/sun/tools/javac/processing/PrintingProcessor.java
changeset 54602 848a2f381e2c
parent 53023 6879069d9d94
child 55382 30b1b7b4dd86
equal deleted inserted replaced
54601:c40b2a190173 54602:848a2f381e2c
   422         }
   422         }
   423 
   423 
   424         private void printModifiers(Element e) {
   424         private void printModifiers(Element e) {
   425             ElementKind kind = e.getKind();
   425             ElementKind kind = e.getKind();
   426             if (kind == PARAMETER) {
   426             if (kind == PARAMETER) {
   427                 printAnnotationsInline(e);
   427                 // Print annotation inline
       
   428                 writer.print(annotationsToString(e));
   428             } else {
   429             } else {
   429                 printAnnotations(e);
   430                 printAnnotations(e);
   430                 indent();
   431                 indent();
   431             }
   432             }
   432 
   433 
   458                     modifiers.remove(Modifier.FINAL);    // only for fields
   459                     modifiers.remove(Modifier.FINAL);    // only for fields
   459                 }
   460                 }
   460                 break;
   461                 break;
   461 
   462 
   462             }
   463             }
   463 
   464             if (!modifiers.isEmpty()) {
   464             for(Modifier m: modifiers) {
   465                 writer.print(modifiers.stream()
   465                 writer.print(m.toString() + " ");
   466                              .map(Modifier::toString)
       
   467                              .collect(Collectors.joining(" ", "", " ")));
   466             }
   468             }
   467         }
   469         }
   468 
   470 
   469         private void printFormalTypeParameters(Parameterizable e,
   471         private void printFormalTypeParameters(Parameterizable e,
   470                                                boolean pad) {
   472                                                boolean pad) {
   471             List<? extends TypeParameterElement> typeParams = e.getTypeParameters();
   473             List<? extends TypeParameterElement> typeParams = e.getTypeParameters();
   472             if (typeParams.size() > 0) {
   474             if (!typeParams.isEmpty()) {
   473                 writer.print("<");
   475                 writer.print(typeParams.stream()
   474 
   476                              .map(tpe -> annotationsToString(tpe) + tpe.toString())
   475                 boolean first = true;
   477                              .collect(Collectors.joining(", ", "<", ">")));
   476                 for(TypeParameterElement tpe: typeParams) {
       
   477                     if (!first)
       
   478                         writer.print(", ");
       
   479                     printAnnotationsInline(tpe);
       
   480                     writer.print(tpe.toString());
       
   481                     first = false;
       
   482                 }
       
   483 
       
   484                 writer.print(">");
       
   485                 if (pad)
   478                 if (pad)
   486                     writer.print(" ");
   479                     writer.print(" ");
   487             }
   480             }
   488         }
   481         }
   489 
   482 
   490         private void printAnnotationsInline(Element e) {
   483         private String annotationsToString(Element e) {
   491             List<? extends AnnotationMirror> annots = e.getAnnotationMirrors();
   484             List<? extends AnnotationMirror> annotations = e.getAnnotationMirrors();
   492             for(AnnotationMirror annotationMirror : annots) {
   485             return annotations.isEmpty() ?
   493                 writer.print(annotationMirror);
   486                 "" :
   494                 writer.print(" ");
   487                 annotations.stream()
   495             }
   488                 .map(AnnotationMirror::toString)
       
   489                 .collect(Collectors.joining(" ", "", " "));
   496         }
   490         }
   497 
   491 
   498         private void printAnnotations(Element e) {
   492         private void printAnnotations(Element e) {
   499             List<? extends AnnotationMirror> annots = e.getAnnotationMirrors();
   493             List<? extends AnnotationMirror> annots = e.getAnnotationMirrors();
   500             for(AnnotationMirror annotationMirror : annots) {
   494             for(AnnotationMirror annotationMirror : annots) {
   567         private void printInterfaces(TypeElement e) {
   561         private void printInterfaces(TypeElement e) {
   568             ElementKind kind = e.getKind();
   562             ElementKind kind = e.getKind();
   569 
   563 
   570             if(kind != ANNOTATION_TYPE) {
   564             if(kind != ANNOTATION_TYPE) {
   571                 List<? extends TypeMirror> interfaces = e.getInterfaces();
   565                 List<? extends TypeMirror> interfaces = e.getInterfaces();
   572                 if (interfaces.size() > 0) {
   566                 if (!interfaces.isEmpty()) {
   573                     writer.print((kind.isClass() ? " implements" : " extends"));
   567                     writer.print((kind.isClass() ? " implements " : " extends "));
   574 
   568                     writer.print(interfaces.stream()
   575                     boolean first = true;
   569                                  .map(TypeMirror::toString)
   576                     for(TypeMirror interf: interfaces) {
   570                                  .collect(Collectors.joining(", ")));
   577                         if (!first)
       
   578                             writer.print(",");
       
   579                         writer.print(" ");
       
   580                         writer.print(interf.toString());
       
   581                         first = false;
       
   582                     }
       
   583                 }
   571                 }
   584             }
   572             }
   585         }
   573         }
   586 
   574 
   587         private void printThrows(ExecutableElement e) {
   575         private void printThrows(ExecutableElement e) {