Coverage Report - com.sun.tools.javafx.comp.JavafxVarUsageAnalysis
 
Classes in this File Line Coverage Branch Coverage Complexity
JavafxVarUsageAnalysis
92%
57/62
90%
9/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 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.tree.*;
 29  
 import com.sun.tools.javac.tree.JCTree.*;
 30  
 import com.sun.tools.javafx.tree.*;
 31  
 import com.sun.tools.javafx.code.*;
 32  
 import com.sun.tools.javac.code.Symbol;
 33  
 import com.sun.tools.javac.code.Symbol.VarSymbol;
 34  
 import com.sun.tools.javac.util.Context;
 35  
 import com.sun.tools.javafx.comp.JavafxTypeMorpher.VarMorphInfo;
 36  
 
 37  
 /**
 38  
  *
 39  
  * @author Robert Field
 40  
  */
 41  
 public class JavafxVarUsageAnalysis extends JavafxTreeScanner {
 42  12
     protected static final Context.Key<JavafxVarUsageAnalysis> varUsageKey =
 43  
             new Context.Key<JavafxVarUsageAnalysis>();
 44  
     
 45  
     private final JavafxTypeMorpher typeMorpher;
 46  
     private boolean inLHS;
 47  
     private boolean inBindContext;
 48  
     
 49  
     public static JavafxVarUsageAnalysis instance(Context context) {
 50  399
         JavafxVarUsageAnalysis instance = context.get(varUsageKey);
 51  399
         if (instance == null)
 52  399
             instance = new JavafxVarUsageAnalysis(context);
 53  399
         return instance;
 54  
     }
 55  
     
 56  399
     JavafxVarUsageAnalysis(Context context) {
 57  399
         context.put(varUsageKey, this);
 58  
         
 59  399
         this.typeMorpher = JavafxTypeMorpher.instance(context);
 60  399
         inLHS = false;
 61  399
         inBindContext = false;
 62  399
     }
 63  
     
 64  
     public void analyzeVarUse(JavafxEnv<JavafxAttrContext> attrEnv) {
 65  379
         scan(attrEnv.tree);
 66  379
     }
 67  
     
 68  
     private void markVarUse(Symbol sym) {
 69  19503
         if (sym instanceof VarSymbol) {
 70  13246
             VarSymbol vsym = (VarSymbol)sym;
 71  13246
             VarMorphInfo vmi = typeMorpher.varMorphInfo(vsym);
 72  13246
             if (inBindContext) {
 73  875
                 if (inLHS) {
 74  
                     // ??? assignment in function / bind expression
 75  
                 } else {
 76  874
                     vmi.markBoundTo();
 77  
                 }
 78  
             } else {
 79  12371
                 if (inLHS) {
 80  928
                     vmi.markAssignedTo();
 81  
                 }
 82  
             }
 83  
         }
 84  19503
     }
 85  
     
 86  
     @Override
 87  
     public void visitVar(JFXVar tree) {
 88  3263
         boolean wasInBindContext = inBindContext;
 89  3263
         inBindContext |= tree.isBound();
 90  3263
         scan(tree.getInitializer());
 91  3263
         markVarUse(tree.sym);
 92  3263
         inBindContext = wasInBindContext;
 93  
         //TODO: need global handling of 'on replace' in bind context -- probably disallowed
 94  3263
         scan(tree.getOnReplace());
 95  3263
     }
 96  
     
 97  
    @Override
 98  
     public void visitFunctionDefinition(JFXFunctionDefinition tree) {
 99  1065
         boolean wasInBindContext = inBindContext;
 100  1065
         inBindContext = false; //TODO should reset, but if bound, should mark as such (once there is only one)
 101  1065
         scan(tree.getFunctionValue());
 102  1065
         inBindContext = wasInBindContext;
 103  1065
     }
 104  
    
 105  
     @Override
 106  
     public void visitBindExpression(JFXBindExpression tree) {
 107  0
         boolean wasInBindContext = inBindContext;
 108  0
         inBindContext |= tree.getBindStatus().isBound();
 109  0
         tree.getExpression().accept(this);
 110  0
         inBindContext = wasInBindContext;
 111  0
     }
 112  
 
 113  
     @Override
 114  
     public void visitObjectLiteralPart(JFXObjectLiteralPart tree) {
 115  736
         boolean wasInBindContext = inBindContext;
 116  736
         inBindContext |= tree.isBound();
 117  736
         markVarUse(tree.sym);
 118  736
         tree.getExpression().accept(this);
 119  736
         inBindContext = wasInBindContext;
 120  736
     }
 121  
 
 122  
     @Override
 123  
     public void visitAssign(JCAssign tree) {
 124  910
         boolean wasLHS = inLHS;
 125  910
         inLHS = true;
 126  910
         scan(tree.lhs);
 127  910
         inLHS = wasLHS;
 128  910
         scan(tree.rhs);
 129  910
     }
 130  
 
 131  
     @Override
 132  
     public void visitIdent(JCIdent tree) {
 133  10501
         markVarUse(tree.sym);
 134  10501
     }
 135  
     
 136  
     @Override
 137  
     public void visitSelect(JCFieldAccess tree) {
 138  
         // this may or may not be in a LHS but in either
 139  
         // event the selector is a value expression
 140  5003
         boolean wasLHS = inLHS;
 141  5003
         inLHS = false;
 142  5003
         scan(tree.selected);
 143  5003
         inLHS = wasLHS;
 144  
         
 145  5003
         markVarUse(tree.sym);
 146  5003
     }
 147  
     
 148  
     public void visitBlockExpression(JFXBlockExpression tree) {
 149  1925
         scan(tree.stats);
 150  1925
         scan(tree.value);
 151  1925
     }
 152  
 }