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