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

http://testability-explorer.googlecode.com/ · Java · 45 lines · 21 code · 9 blank · 15 comment · 0 complexity · e6c12385a1cceb925dd1d9e7d17b47e3 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;
  17. public class LoDViolation extends ViolationCost {
  18. private final String methodName;
  19. private final int distance;
  20. public LoDViolation(SourceLocation sourceLocation, String methodName, Cost lod, int distance) {
  21. super(sourceLocation, lod);
  22. this.methodName = methodName;
  23. this.distance = distance;
  24. }
  25. @Override
  26. public String getDescription() {
  27. return methodName + "[distance=" + distance + "]";
  28. }
  29. public String getReason() {
  30. return "cost from breaking the Law of Demeter";
  31. }
  32. @Override
  33. public void link(Cost directCost, Cost dependentCost, Cost constructorDependentCost) {
  34. directCost.add(getCost());
  35. }
  36. }