1 package alt.jiapi.reflect; 2 3 6 public class Signature { 7 private String descriptor; 8 private String returnType; 9 private String [] params; 10 11 18 public Signature(String returnType, String [] params) { 19 if (params == null) { 20 throw new IllegalArgumentException ("params may not be null"); 21 } 22 23 for (int i = 0; i < params.length; i++) { 25 String s = params[i].trim(); 26 int idx = s.indexOf(' '); 27 28 if (idx != -1) { 29 StringBuffer sb = new StringBuffer (); 30 for (int j = 0; j < s.length(); j++) { 31 if (s.charAt(j) != ' ') { 32 sb.append(s.charAt(j)); 33 } 34 } 35 36 params[i] = sb.toString(); 37 } 38 } 39 40 41 this.returnType = returnType; 42 this.params = params; 43 this.descriptor = TypeHelper.signatureToDescriptor(this); 44 } 45 46 51 public Signature(String descriptor) { 52 try { 53 this.descriptor = descriptor; 54 55 int idx = descriptor.lastIndexOf(')'); 56 this.returnType = 57 TypeHelper.descriptorToType(descriptor.substring(idx + 1)); 58 59 this.params = 60 TypeHelper.descriptorsToTypes(descriptor.substring(1, idx)); 61 } 62 catch(RuntimeException e) { 63 System.err.println("Failed to create Signature from " + 64 descriptor); 65 throw e ; 66 } 67 } 68 69 72 public String getReturnType() { 73 return returnType; 74 } 75 76 79 public String [] getParameters() { 80 return params; 81 } 82 83 86 public String getDescriptor() { 87 return descriptor; 88 } 89 90 public String toString() { 91 return descriptor; 92 } 93 94 95 public boolean equals(Signature s) { 96 99 String [] otherParams = s.getParameters(); 100 if (params.length != otherParams.length) { 101 return false; 102 } 103 104 for (int i = 0; i < params.length; i++) { 105 if (!params[i].equals(otherParams[i])) { 106 return false; 107 } 108 } 109 110 return true; 111 } 112 } 113 | Popular Tags |