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