Coverage Report - com.sun.tools.javafx.tree.JavaPretty
 
Classes in this File Line Coverage Branch Coverage Complexity
JavaPretty
0%
0/43
0%
0/10
0
 
 1  
 /*
 2  
  * Copyright 2007 Sun Microsystems, Inc.  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.  Sun designates this
 8  
  * particular file as subject to the "Classpath" exception as provided
 9  
  * by Sun in the LICENSE file tree accompanied this code.
 10  
  *
 11  
  * This code is distributed in the hope tree 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 tree
 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
 22  
  * CA 95054 USA or visit www.sun.com if you need additional information or
 23  
  * have any questions.
 24  
  */
 25  
 
 26  
 package com.sun.tools.javafx.tree;
 27  
 
 28  
 import java.io.IOException;
 29  
 import java.io.Writer;
 30  
 import java.util.HashSet;
 31  
 
 32  
 import com.sun.tools.javac.tree.JCTree;
 33  
 import com.sun.tools.javac.tree.JCTree.JCFieldAccess;
 34  
 import com.sun.tools.javac.tree.JCTree.JCImport;
 35  
 import com.sun.tools.javac.tree.Pretty;
 36  
 import com.sun.tools.javac.tree.TreeInfo;
 37  
 import com.sun.tools.javac.util.Context;
 38  
 import com.sun.tools.javac.util.Name;
 39  
 import com.sun.tools.javafx.comp.JavafxDefs;
 40  
 
 41  
 /** Prints out a tree as an indented Java source program.
 42  
  *
 43  
  *  <p><b>This is NOT part of any API supported by Sun Microsystems.  If
 44  
  *  you write code tree depends on this, you do so at your own risk.
 45  
  *  This code and its internal interfaces are subject to change or
 46  
  *  deletion without notice.</b>
 47  
  *
 48  
  * @author Robert Field
 49  
  */
 50  
 public class JavaPretty extends Pretty {
 51  0
         private HashSet<Name> importedPackages = new HashSet<Name>();
 52  0
         private HashSet<Name> importedClasses = new HashSet<Name>();
 53  
         
 54  
     public JavaPretty(Writer out, boolean sourceOutput, Context context) {
 55  0
         super(out, sourceOutput);
 56  
 
 57  0
                 JavafxDefs defs = JavafxDefs.instance(context);
 58  0
                 importedPackages.add(defs.runtimePackageName);
 59  0
                 importedPackages.add(defs.locationPackageName);
 60  0
                 importedPackages.add(defs.sequencePackageName);
 61  0
                 importedPackages.add(defs.functionsPackageName);
 62  0
                 importedPackages.add(defs.javaLangPackageName);
 63  0
     }
 64  
 
 65  
     public void visitBlockExpression(JFXBlockExpression tree) {
 66  0
         visitBlockExpression(this, tree);
 67  0
     }
 68  
 
 69  
     public static void visitBlockExpression(Pretty pretty, JFXBlockExpression tree) {
 70  
         try {
 71  0
             pretty.printFlags(tree.flags);
 72  0
             pretty.print("{");
 73  0
             pretty.println();
 74  0
             pretty.indent();
 75  0
             pretty.printStats(tree.stats);
 76  0
             if (tree.value != null) {
 77  0
                 pretty.align();
 78  0
                 pretty.printExpr(tree.value);
 79  
             }
 80  0
             pretty.undent();
 81  0
             pretty.println();
 82  0
             pretty.align();
 83  0
             pretty.print("}");
 84  0
         } catch (IOException e) {
 85  0
             throw new UncheckedIOException(e);
 86  0
         }
 87  0
     }
 88  
         
 89  
         @Override
 90  
     public void visitImport(JCImport tree) {
 91  0
                 super.visitImport(tree);
 92  
 
 93  
                 // save imports for later use
 94  0
                 Name name = TreeInfo.name(tree.qualid);
 95  0
                 if (name == name.table.asterisk)
 96  0
                         if (tree.qualid.getTag() == JCTree.SELECT)
 97  0
                                 importedPackages.add(TreeInfo.fullName(((JCFieldAccess) tree.qualid).selected));
 98  
                         else;
 99  
                 else
 100  0
                         importedClasses.add(TreeInfo.fullName(tree.qualid));
 101  0
     }
 102  
 
 103  
         @Override
 104  
     public void visitSelect(JCFieldAccess tree) {
 105  
         try {
 106  0
                         if (!importedPackages.contains(TreeInfo.fullName(tree.selected)) 
 107  
                                         && !importedClasses.contains(TreeInfo.fullName(tree))) {
 108  0
                                 printExpr(tree.selected, TreeInfo.postfixPrec);
 109  0
                                 print(".");
 110  
                         }
 111  0
             print(tree.name);
 112  0
         } catch (IOException e) {
 113  0
             throw new UncheckedIOException(e);
 114  0
         }
 115  0
     }        
 116  
 }