PageRenderTime 32ms CodeModel.GetById 24ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/testability-explorer/src/main/java/com/google/test/metric/method/op/turing/ArrayAssignment.java

http://testability-explorer.googlecode.com/
Java | 58 lines | 28 code | 6 blank | 24 comment | 1 complexity | edde242e1cf176d9e1c502ce3ea8fd71 MD5 | raw file
 1/*
 2 * Copyright 2007 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 */
16package com.google.test.metric.method.op.turing;
17
18import com.google.test.metric.TestabilityVisitor;
19import com.google.test.metric.Variable;
20
21public class ArrayAssignment extends Operation {
22  /**
23   * Ugliness:
24   * When a Java 1.5 enhanced switch statement is used on an enum, a synthetic
25   * class is created as an anonymous inner class of the class where the
26   * switch statement appears. That synthetic class stores a statuc array of the values
27   * of the enum, which is named {@code $SwitchMap$com$google$AnEnum} or maybe
28   * {@code $SWITCH_TABLE$com$google$AnEnum} depending on the javac that compiled it.
29   * We don't want to record the assignments into this JVM-internal array.
30   */
31  private final String ENUM_SWITCH_MAP_NAME = "$SwitchMap$";
32  private final String ENUM_SWITCH_TABLE_NAME = "$SWITCH_TABLE$";
33  private final Variable array;
34  private final Variable index;
35  private final Variable value;
36
37  public ArrayAssignment(int lineNumber, Variable array, Variable index,
38      Variable value) {
39    super(lineNumber);
40    this.array = array;
41    this.index = index;
42    this.value = value;
43  }
44
45  @Override
46  public void visit(TestabilityVisitor.Frame visitor) {
47    if (!array.getName().startsWith(ENUM_SWITCH_MAP_NAME) &&
48        !array.getName().startsWith(ENUM_SWITCH_TABLE_NAME)) {
49      visitor.assignArray(array, index, value, getLineNumber());
50    }
51  }
52
53  @Override
54  public String toString() {
55    return array + "[" + index + "] <- " + value;
56  }
57
58}