Coverage Report - com.sun.tools.javafx.comp.BlockExprEnter
 
Classes in this File Line Coverage Branch Coverage Complexity
BlockExprEnter
70%
46/66
70%
31/44
0
BlockExprEnter$1
100%
2/2
N/A
0
 
 1  
 /*
 2  
  * Copyright 1999-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 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 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.comp;
 27  
 
 28  
 import com.sun.tools.javac.code.Flags;
 29  
 import com.sun.tools.javac.code.Scope;
 30  
 import com.sun.tools.javac.code.Symbol;
 31  
 import com.sun.tools.javac.code.Symbol.ClassSymbol;
 32  
 import com.sun.tools.javac.code.Symbol.PackageSymbol;
 33  
 import com.sun.tools.javac.code.Symbol.TypeSymbol;
 34  
 import com.sun.tools.javac.code.Type.ClassType;
 35  
 import com.sun.tools.javac.code.Type.ErrorType;
 36  
 import com.sun.tools.javac.comp.AttrContext;
 37  
 import com.sun.tools.javac.comp.Enter;
 38  
 import com.sun.tools.javac.comp.Env;
 39  
 import com.sun.tools.javac.tree.JCTree;
 40  
 import com.sun.tools.javac.tree.JCTree.JCClassDecl;
 41  
 import com.sun.tools.javac.util.Context;
 42  
 import com.sun.tools.javac.util.List;
 43  
 import com.sun.tools.javafx.tree.JFXBlockExpression;
 44  
 
 45  
 import static com.sun.tools.javac.code.Flags.*;
 46  
 import static com.sun.tools.javac.code.Kinds.*;
 47  
 import static com.sun.tools.javac.code.TypeTags.*;
 48  
 
 49  
 public class BlockExprEnter extends Enter {
 50  
     public static Enter instance0(Context context) {
 51  0
         Enter instance = context.get(enterKey);
 52  0
         if (instance == null)
 53  0
             instance = new BlockExprEnter(context);
 54  0
         return instance;
 55  
     }
 56  
 
 57  
     public static void preRegister(final Context context) {
 58  798
         context.put(enterKey, new Context.Factory<Enter>() {
 59  
             public Enter make() {
 60  399
                 return new BlockExprEnter(context);
 61  
             }
 62  
         });
 63  399
     }
 64  
 
 65  
     protected BlockExprEnter(Context context) {
 66  399
         super(context);
 67  399
     }
 68  
 
 69  
     /** Visitor method: Scan a single node.
 70  
      */
 71  
     public void scan(JCTree tree) {
 72  0
         if(tree!=null) tree.accept(this);
 73  0
     }
 74  
 
 75  
     /** Visitor method: scan a list of nodes.
 76  
      */
 77  
     public void scan(List<? extends JCTree> trees) {
 78  0
         if (trees != null)
 79  0
         for (List<? extends JCTree> l = trees; l.nonEmpty(); l = l.tail)
 80  0
             scan(l.head);
 81  0
     }
 82  
 
 83  
     // Override this method and disable the enforcing of public class being in file with the same name.
 84  
     public void visitClassDef(JCClassDecl tree) {
 85  1772
         Symbol owner = env.info.scope.owner;
 86  1772
         Scope enclScope = enterScope(env);
 87  
         ClassSymbol c;
 88  1772
         if (owner.kind == PCK) {
 89  
             // We are seeing a toplevel class.
 90  674
             PackageSymbol packge = (PackageSymbol)owner;
 91  2036
             for (Symbol q = packge; q != null && q.kind == PCK; q = q.owner)
 92  1362
                 q.flags_field |= EXISTS;
 93  674
             c = reader.enterClass(tree.name, packge);
 94  674
             packge.members().enterIfAbsent(c);
 95  
 // Javafx change start
 96  
 //            if ((tree.mods.flags & PUBLIC) != 0 && !classNameMatchesFileName(c, env)) {
 97  
 //                log.error(tree.pos(),
 98  
 //                          "class.public.should.be.in.file", tree.name);
 99  
 //            }
 100  
 // Javafx change end
 101  674
         } else {
 102  1098
             if (tree.name.len != 0 &&
 103  
                 !chk.checkUniqueClassName(tree.pos(), tree.name, enclScope)) {
 104  0
                 result = null;
 105  0
                 return;
 106  
             }
 107  1098
             if (owner.kind == TYP) {
 108  
                 // We are seeing a member class.
 109  483
                 c = reader.enterClass(tree.name, (TypeSymbol)owner);
 110  483
                 if ((owner.flags_field & INTERFACE) != 0) {
 111  0
                     tree.mods.flags |= PUBLIC | STATIC;
 112  
                 }
 113  
             } else {
 114  
                 // We are seeing a local class.
 115  615
                 c = reader.defineClass(tree.name, owner);
 116  615
                 c.flatname = chk.localClassName(c);
 117  615
                 if (c.name.len != 0)
 118  26
                     chk.checkTransparentClass(tree.pos(), c, env.info.scope);
 119  
             }
 120  
         }
 121  1772
         tree.sym = c;
 122  
 
 123  
         // Enter class into `compiled' table and enclosing scope.
 124  1772
         if (chk.compiled.get(c.flatname) != null) {
 125  0
             duplicateClass(tree.pos(), c);
 126  0
             result = new ErrorType(tree.name, (TypeSymbol)owner);
 127  0
             tree.sym = (ClassSymbol)result.tsym;
 128  0
             return;
 129  
         }
 130  1772
         chk.compiled.put(c.flatname, c);
 131  1772
         enclScope.enter(c);
 132  
 
 133  
         // Set up an environment for class block and store in `typeEnvs'
 134  
         // table, to be retrieved later in memberEnter and attribution.
 135  1772
         Env<AttrContext> localEnv = classEnv(tree, env);
 136  1772
         typeEnvs.put(c, localEnv);
 137  
 
 138  
         // Fill out class fields.
 139  1772
         c.completer = memberEnter;
 140  1772
         boolean wasStatic = (tree.mods.flags & Flags.STATIC) != 0L;
 141  1772
         c.flags_field = chk.checkFlags(tree.pos(), (tree.mods.flags & ~(Flags.STATIC)), c, tree);
 142  1772
         if (wasStatic) {
 143  694
             c.flags_field |= Flags.STATIC;
 144  
         }
 145  
         
 146  1772
         c.sourcefile = env.toplevel.sourcefile;
 147  1772
         c.members_field = new Scope(c);
 148  
 
 149  1772
         ClassType ct = (ClassType)c.type;
 150  1772
         if (owner.kind != PCK && (c.flags_field & STATIC) == 0) {
 151  
             // We are seeing a local or inner class.
 152  
             // Set outer_field of this class to closest enclosing class
 153  
             // which contains this class in a non-static context
 154  
             // (its "enclosing instance class"), provided such a class exists.
 155  167
             Symbol owner1 = owner;
 156  
             while ((owner1.kind & (VAR | MTH)) != 0 &&
 157  311
                    (owner1.flags_field & STATIC) == 0) {
 158  144
                 owner1 = owner1.owner;
 159  
             }
 160  167
             if (owner1.kind == TYP) {
 161  144
                 ct.setEnclosingType(owner1.type);
 162  
             }
 163  
         }
 164  
 
 165  
         // Enter type parameters.
 166  1772
         ct.typarams_field = classEnter(tree.typarams, localEnv);
 167  
 
 168  
         // Add non-local class to uncompleted, to make sure it will be
 169  
         // completed later.
 170  1772
         if (!c.isLocal() && uncompleted != null) uncompleted.append(c);
 171  
 //        System.err.println("entering " + c.fullname + " in " + c.owner);//DEBUG
 172  
 
 173  
         // Recursively enter all member classes.
 174  1772
         classEnter(tree.defs, localEnv);
 175  
 
 176  1772
         result = c.type;
 177  1772
     }
 178  
 
 179  
     public void visitBlockExpression(JFXBlockExpression that) {
 180  0
         scan(that.stats);
 181  0
         scan(that.value);
 182  0
     }
 183  
 }