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