PageRenderTime 17ms CodeModel.GetById 8ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

/testability-explorer/src/main/java/com/google/test/metric/VariableState.java

http://testability-explorer.googlecode.com/
Java | 83 lines | 58 code | 9 blank | 16 comment | 14 complexity | bcaf709de73984bdb5228871a14b9de3 MD5 | raw file
 1/*
 2 * Copyright 2008 Google Inc.
 3 *
 4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 5 * use this file except in compliance with the License. You may obtain a copy of
 6 * the License at
 7 *
 8 * http://www.apache.org/licenses/LICENSE-2.0
 9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 * License for the specific language governing permissions and limitations under
14 * the License.
15 */
16// Copyright 2008 Google Inc. All Rights Reserved.
17
18package com.google.test.metric;
19
20import java.util.HashSet;
21import java.util.Set;
22
23public class VariableState {
24  private final Set<Variable> injectables = new HashSet<Variable>();
25  private final Set<Variable> globals = new HashSet<Variable>();
26
27  boolean isGlobal(Variable var) {
28    if (var == null) {
29      return false;
30    }
31    if (var.isGlobal()) {
32      return true;
33    }
34    if (globals.contains(var)) {
35      return true;
36    }
37    if (var instanceof LocalField) {
38      LocalField field = (LocalField) var;
39      return globals.contains(field.getInstance()) || globals.contains(field.getField());
40    }
41    return false;
42  }
43
44  boolean isInjectable(Variable var) {
45    if (var == null) {
46      return false;
47    }
48    if (injectables.contains(var)) {
49      return true;
50    } else {
51      if (var instanceof LocalField) {
52        return injectables.contains(((LocalField) var).getField());
53      } else {
54        return false;
55      }
56    }
57  }
58
59  void setGlobal(Variable var) {
60    globals.add(var);
61  }
62
63  void setInjectable(Variable var) {
64    injectables.add(var);
65  }
66
67  @Override
68  public String toString() {
69    StringBuilder buf = new StringBuilder();
70    buf.append("\nInjectables:");
71    for (Variable var : injectables) {
72      buf.append("\n   ");
73      buf.append(var);
74    }
75    buf.append("\nGlobals:");
76    for (Variable var : globals) {
77      buf.append("\n   ");
78      buf.append(var);
79    }
80    return buf.toString();
81  }
82
83}