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

http://testability-explorer.googlecode.com/ · Java · 59 lines · 37 code · 7 blank · 15 comment · 5 complexity · 946e1739e7eaac4d1b8558c37c5df017 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.asm;
  17. import static com.google.test.metric.JavaType.fromDescParameters;
  18. import static com.google.test.metric.JavaType.fromDescReturn;
  19. import com.google.test.metric.Type;
  20. public class JavaNamer {
  21. public String nameMethod(String className, String methodName,
  22. String methodDesc) {
  23. StringBuilder fullName = new StringBuilder();
  24. if (methodName.equals("<init>")) {
  25. int index = Math.max(className.lastIndexOf("."), className
  26. .lastIndexOf("$")) + 1;
  27. fullName.append(className.substring(index));
  28. } else if (methodName.equals("<clinit>")) {
  29. fullName.append("<static init>");
  30. } else {
  31. fullName.append(toClass(fromDescReturn(methodDesc)));
  32. fullName.append(" ");
  33. fullName.append(methodName);
  34. }
  35. fullName.append("(");
  36. String sep = "";
  37. for (Type type : fromDescParameters(methodDesc)) {
  38. fullName.append(sep);
  39. fullName.append(toClass(type));
  40. sep = ", ";
  41. }
  42. fullName.append(")");
  43. String javaName = fullName.toString();
  44. return javaName;
  45. }
  46. private String toClass(Type type) {
  47. return type.toString().replace('$', '.');
  48. }
  49. public String nameClass(String name) {
  50. return name.replace('/', '.').replace('$', '.');
  51. }
  52. }