1 30 package org.objectweb.asm.optimizer; 31 32 import java.io.FileInputStream ; 33 import java.io.IOException ; 34 import java.util.Properties ; 35 36 import org.objectweb.asm.Type; 37 38 43 public class NameMapping extends Properties { 44 45 public NameMapping(final String file) throws IOException { 46 load(new FileInputStream (file)); 47 } 48 49 public String map(final String name) { 50 String s = (String ) get(name); 51 if (s == null) { 52 int p = name.indexOf('.'); 53 if (p != -1) { 54 int q = name.indexOf('('); 55 if (q != -1) { 56 s = name.substring(p + 1, q); 57 } else { 58 s = name.substring(p + 1); 59 } 60 } else { 61 s = name; 62 } 63 } 64 return s; 65 } 66 67 public String fix(final String desc) { 68 if (desc.startsWith("(")) { 69 Type[] arguments = Type.getArgumentTypes(desc); 70 Type result = Type.getReturnType(desc); 71 for (int i = 0; i < arguments.length; ++i) { 72 arguments[i] = fix(arguments[i]); 73 } 74 result = fix(result); 75 return Type.getMethodDescriptor(result, arguments); 76 } else { 77 return fix(Type.getType(desc)).getDescriptor(); 78 } 79 } 80 81 private Type fix(final Type t) { 82 if (t.getSort() == Type.OBJECT) { 83 return Type.getType("L" + map(t.getInternalName()) + ";"); 84 } else if (t.getSort() == Type.ARRAY) { 85 String s = fix(t.getElementType()).getDescriptor(); 86 for (int i = 0; i < t.getDimensions(); ++i) { 87 s = "[" + s; 88 } 89 return Type.getType(s); 90 } else { 91 return t; 92 } 93 } 94 } 95 | Popular Tags |