< prev index next >

src/jdk.compiler/share/classes/com/sun/tools/javac/tree/Pretty.java

Print this page


   1 /*
   2  * Copyright (c) 1999, 2017, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 620                 print(" ");
 621                 printStat(tree.body);
 622             } else {
 623                 print(";");
 624             }
 625         } catch (IOException e) {
 626             throw new UncheckedIOException(e);
 627         }
 628     }
 629 
 630     public void visitVarDef(JCVariableDecl tree) {
 631         try {
 632             if (docComments != null && docComments.hasComment(tree)) {
 633                 println(); align();
 634             }
 635             printDocComment(tree);
 636             if ((tree.mods.flags & ENUM) != 0) {
 637                 print("/*public static final*/ ");
 638                 print(tree.name);
 639                 if (tree.init != null) {
 640                     if (sourceOutput && tree.init.hasTag(NEWCLASS)) {
 641                         print(" /*enum*/ ");
 642                         JCNewClass init = (JCNewClass) tree.init;


 643                         if (init.args != null && init.args.nonEmpty()) {
 644                             print("(");
 645                             print(init.args);
 646                             print(")");
 647                         }
 648                         if (init.def != null && init.def.defs != null) {
 649                             print(" ");
 650                             printBlock(init.def.defs);
 651                         }
 652                         return;























 653                     }
 654                     print(" /* = ");
 655                     printExpr(tree.init);
 656                     print(" */");
 657                 }
 658             } else {
 659                 printExpr(tree.mods);
 660                 if ((tree.mods.flags & VARARGS) != 0) {
 661                     JCTree vartype = tree.vartype;
 662                     List<JCAnnotation> tas = null;
 663                     if (vartype instanceof JCAnnotatedType) {
 664                         tas = ((JCAnnotatedType)vartype).annotations;
 665                         vartype = ((JCAnnotatedType)vartype).underlyingType;
 666                     }
 667                     printExpr(((JCArrayTypeTree) vartype).elemtype);
 668                     if (tas != null) {
 669                         print(' ');
 670                         printTypeAnnotations(tas);
 671                     }
 672                     print("... " + tree.name);


   1 /*
   2  * Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 620                 print(" ");
 621                 printStat(tree.body);
 622             } else {
 623                 print(";");
 624             }
 625         } catch (IOException e) {
 626             throw new UncheckedIOException(e);
 627         }
 628     }
 629 
 630     public void visitVarDef(JCVariableDecl tree) {
 631         try {
 632             if (docComments != null && docComments.hasComment(tree)) {
 633                 println(); align();
 634             }
 635             printDocComment(tree);
 636             if ((tree.mods.flags & ENUM) != 0) {
 637                 print("/*public static final*/ ");
 638                 print(tree.name);
 639                 if (tree.init != null) {
 640                     if (tree.init.hasTag(NEWCLASS)) {

 641                         JCNewClass init = (JCNewClass) tree.init;
 642                         if (sourceOutput) {
 643                             print(" /*enum*/ ");
 644                             if (init.args != null && init.args.nonEmpty()) {
 645                                 print("(");
 646                                 print(init.args);
 647                                 print(")");
 648                             }
 649                             if (init.def != null && init.def.defs != null) {
 650                                 print(" ");
 651                                 printBlock(init.def.defs);
 652                             }
 653                             return;
 654                         }else {
 655                             print(" /* = ");
 656                             print("new ");
 657                             if (init.def != null && init.def.mods.annotations.nonEmpty()) {
 658                                 printTypeAnnotations(init.def.mods.annotations);
 659                             }
 660                             printExpr(init.clazz);
 661                             print("(");
 662                             printExprs(init.args);
 663                             print(")");
 664                             print(" */");
 665                             print(" /*enum*/ ");
 666                             if (init.args != null && init.args.nonEmpty()) {
 667                                 print("(");
 668                                 printExprs(init.args);
 669                                 print(")");
 670                             }
 671                             if (init.def != null && init.def.defs != null) {
 672                                 print(" ");
 673                                 printBlock(init.def.defs);
 674                             }
 675                             return;
 676                         } 
 677                     }
 678                     print(" /* = ");
 679                     printExpr(tree.init);
 680                     print(" */");
 681                 }
 682             } else {
 683                 printExpr(tree.mods);
 684                 if ((tree.mods.flags & VARARGS) != 0) {
 685                     JCTree vartype = tree.vartype;
 686                     List<JCAnnotation> tas = null;
 687                     if (vartype instanceof JCAnnotatedType) {
 688                         tas = ((JCAnnotatedType)vartype).annotations;
 689                         vartype = ((JCAnnotatedType)vartype).underlyingType;
 690                     }
 691                     printExpr(((JCArrayTypeTree) vartype).elemtype);
 692                     if (tas != null) {
 693                         print(' ');
 694                         printTypeAnnotations(tas);
 695                     }
 696                     print("... " + tree.name);


< prev index next >