Coverage Report - com.sun.tools.javafx.comp.BlockExprAttr
 
Classes in this File Line Coverage Branch Coverage Complexity
BlockExprAttr
77%
40/52
43%
20/46
0
BlockExprAttr$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.*;
 29  
 import com.sun.tools.javac.code.Symbol.ClassSymbol;
 30  
 import static com.sun.tools.javac.code.Flags.FINAL;
 31  
 import static com.sun.tools.javac.code.Kinds.*;
 32  
 import static com.sun.tools.javac.code.TypeTags.*;
 33  
 import static com.sun.tools.javac.code.TypeTags.WILDCARD;
 34  
 import com.sun.tools.javac.comp.Attr;
 35  
 import com.sun.tools.javac.comp.AttrContext;
 36  
 import com.sun.tools.javac.comp.Env;
 37  
 import com.sun.tools.javac.tree.JCTree;
 38  
 import com.sun.tools.javac.tree.JCTree.*;
 39  
 import com.sun.tools.javac.util.*;
 40  
 import com.sun.tools.javafx.tree.JFXBlockExpression;
 41  
 import com.sun.tools.javafx.tree.*;
 42  
 import com.sun.tools.javafx.util.MsgSym;
 43  
 
 44  
 /** This is the main context-dependent analysis phase in GJC. It
 45  
  *  encompasses name resolution, type checking and constant folding as
 46  
  *  subtasks. Some subtasks involve auxiliary classes.
 47  
  *  @see Check
 48  
  *  @see Resolve
 49  
  *  @see ConstFold
 50  
  *  @see Infer
 51  
  *
 52  
  *  <p><b>This is NOT part of any API supported by Sun Microsystems.  If
 53  
  *  you write code that depends on this, you do so at your own risk.
 54  
  *  This code and its internal interfaces are subject to change or
 55  
  *  deletion without notice.</b>
 56  
  */
 57  12
 public class BlockExprAttr extends Attr  {
 58  
     
 59  
     public static Attr instance0(Context context) {
 60  0
         Attr instance = context.get(attrKey);
 61  0
         if (instance == null)
 62  0
             instance = new BlockExprAttr(context);
 63  0
         return instance;
 64  
     }
 65  
 
 66  
     public static void preRegister(final Context context) {
 67  798
         context.put(attrKey, new Context.Factory<Attr>() {
 68  
                public Attr make() {
 69  399
                    return new BlockExprAttr(context);
 70  
                }
 71  
         });
 72  399
     }
 73  
 
 74  
     protected BlockExprAttr(Context context) {
 75  399
         super(context);
 76  399
     }
 77  
 
 78  
 
 79  
     public void visitBlockExpression(JFXBlockExpression tree) {
 80  
         // Create a new local environment with a local scope.
 81  1198
         Env<AttrContext> localEnv =
 82  
                 env.dup(tree,
 83  
                 env.info.dup(env.info.scope.dup()));
 84  5378
         for (List<JCStatement> l = tree.stats; l.nonEmpty(); l = l.tail)
 85  4180
             attribStat(l.head, localEnv);
 86  1198
         if (tree.value == null) {
 87  0
             result = check(tree, syms.voidType, VAL, pkind, pt);
 88  
         } else {
 89  1198
             Type valtype = attribExpr(tree.value, localEnv);
 90  1198
             result = check(tree, valtype, VAL, pkind, pt);
 91  
         }
 92  1198
         localEnv.info.scope.leave();
 93  1198
     }
 94  
 
 95  
     /** Finish the attribution of a class. */
 96  
     protected void attribClassBody(Env<AttrContext> env, ClassSymbol c) {
 97  1770
         JCClassDecl tree = (JCClassDecl)env.tree;
 98  1770
         assert c == tree.sym;
 99  
 
 100  
         // Validate annotations
 101  1770
         chk.validateAnnotations(tree.mods.annotations, c);
 102  
 
 103  
         // Validate type parameters, supertype and interfaces.
 104  1770
         attribBounds(tree.typarams);
 105  1770
         chk.validateTypeParams(tree.typarams);
 106  1770
         chk.validate(tree.extending);
 107  1770
         chk.validate(tree.implementing);
 108  
 
 109  
         // If this is a non-abstract class, check that it has no abstract
 110  
         // methods or unimplemented methods of an implemented interface.
 111  1770
         if ((c.flags() & (Flags.ABSTRACT | Flags.INTERFACE)) == 0) {
 112  1184
             if (!relax)
 113  1184
                 chk.checkAllDefined(tree.pos(), c);
 114  
         }
 115  
 
 116  1770
         if ((c.flags() & Flags.ANNOTATION) != 0) {
 117  0
             if (tree.implementing.nonEmpty())
 118  0
                 log.error(tree.implementing.head.pos(),
 119  
                           MsgSym.MESSAGE_CANNOT_EXTEND_INTERFACE_ANNOTATION);
 120  0
             if (tree.typarams.nonEmpty())
 121  0
                 log.error(tree.typarams.head.pos(),
 122  
                           MsgSym.MESSAGE_INTF_ANNOTATION_CANNOT_HAVE_TYPE_PARAMS);
 123  
         } else {
 124  
             // Check that all extended classes and interfaces
 125  
             // are compatible (i.e. no two define methods with same arguments
 126  
             // yet different return types).  (JLS 8.4.6.3)
 127  1770
             chk.checkCompatibleSupertypes(tree.pos(), c.type);
 128  
         }
 129  
 
 130  
         // Check that class does not import the same parameterized interface
 131  
         // with two different argument lists.
 132  1770
         chk.checkClassBounds(tree.pos(), c.type);
 133  
 
 134  1770
         tree.type = c.type;
 135  
 
 136  1770
         boolean assertsEnabled = false;
 137  1770
         assert assertsEnabled = true;
 138  1770
         if (assertsEnabled) {
 139  1730
             for (List<JCTypeParameter> l = tree.typarams;
 140  1730
                  l.nonEmpty(); l = l.tail)
 141  0
                 assert env.info.scope.lookup(l.head.name).scope != null;
 142  
         }
 143  
 
 144  
         // Check that a generic class doesn't extend Throwable
 145  1770
         if (!c.type.allparams().isEmpty() && types.isSubtype(c.type, syms.throwableType))
 146  0
             log.error(tree.extending.pos(), MsgSym.MESSAGE_GENERIC_THROWABLE);
 147  
 
 148  
         // Check that all methods which implement some
 149  
         // method conform to the method they implement.
 150  1770
         chk.checkImplementations(tree);
 151  
 
 152  14651
         for (List<JCTree> l = tree.defs; l.nonEmpty(); l = l.tail) {
 153  
             // Attribute declaration
 154  12881
             attribStat(l.head, env);
 155  
             // Check that declarations in inner classes are not static (JLS 8.1.2)
 156  
             // Make an exception for static constants.
 157  
             // Javafx doesn't have this restriction
 158  
 //            if (c.owner.kind != PCK &&
 159  
 //                ((c.flags() & STATIC) == 0 || c.name == names.empty) &&
 160  
 //                (TreeInfo.flags(l.head) & (STATIC | INTERFACE)) != 0) {
 161  
 //                Symbol sym = null;
 162  
 //                if (l.head.getTag() == JCTree.VARDEF) sym = ((JCVariableDecl) l.head).sym;
 163  
 //                if (sym == null ||
 164  
 //                    sym.kind != VAR ||
 165  
 //                    ((VarSymbol) sym).getConstValue() == null)
 166  
 //                    log.error(l.head.pos(), "icls.cant.have.static.decl");
 167  
 //            }
 168  
         }
 169  
 
 170  
         // Check for cycles among non-initial constructors.
 171  1770
         chk.checkCyclicConstructors(tree);
 172  
 
 173  
         // Check for cycles among annotation elements.
 174  1770
         chk.checkNonCyclicElements(tree);
 175  
 
 176  
         // Check for proper use of serialVersionUID
 177  1770
         if (env.info.lint.isEnabled(Lint.LintCategory.SERIAL) &&
 178  
             isSerializable(c) &&
 179  
             (c.flags() & Flags.ENUM) == 0 &&
 180  
             (c.flags() & Flags.ABSTRACT) == 0) {
 181  0
             checkSerialVersionUID(tree, c);
 182  
         }
 183  1770
     }
 184  
 }