49 * or deletion without notice.</b></p> |
49 * or deletion without notice.</b></p> |
50 * |
50 * |
51 * @author Sucheta Dambalkar |
51 * @author Sucheta Dambalkar |
52 */ |
52 */ |
53 |
53 |
54 public class TypeSignature{ |
54 public class TypeSignature { |
|
55 static class SignatureException extends Exception { |
|
56 private static final long serialVersionUID = 1L; |
|
57 SignatureException(String reason) { |
|
58 super(reason); |
|
59 } |
|
60 } |
55 |
61 |
56 Elements elems; |
62 Elements elems; |
57 |
63 |
58 /* Signature Characters */ |
64 /* Signature Characters */ |
59 |
65 |
76 } |
82 } |
77 |
83 |
78 /* |
84 /* |
79 * Returns the type signature of a field according to JVM specs |
85 * Returns the type signature of a field according to JVM specs |
80 */ |
86 */ |
81 public String getTypeSignature(String javasignature){ |
87 public String getTypeSignature(String javasignature) throws SignatureException { |
82 return getParamJVMSignature(javasignature); |
88 return getParamJVMSignature(javasignature); |
83 } |
89 } |
84 |
90 |
85 /* |
91 /* |
86 * Returns the type signature of a method according to JVM specs |
92 * Returns the type signature of a method according to JVM specs |
87 */ |
93 */ |
88 public String getTypeSignature(String javasignature, TypeMirror returnType){ |
94 public String getTypeSignature(String javasignature, TypeMirror returnType) |
|
95 throws SignatureException { |
89 String signature = null; //Java type signature. |
96 String signature = null; //Java type signature. |
90 String typeSignature = null; //Internal type signature. |
97 String typeSignature = null; //Internal type signature. |
91 List<String> params = new ArrayList<String>(); //List of parameters. |
98 List<String> params = new ArrayList<String>(); //List of parameters. |
92 String paramsig = null; //Java parameter signature. |
99 String paramsig = null; //Java parameter signature. |
93 String paramJVMSig = null; //Internal parameter signature. |
100 String paramJVMSig = null; //Internal parameter signature. |
164 } |
171 } |
165 |
172 |
166 /* |
173 /* |
167 * Returns internal signature of a parameter. |
174 * Returns internal signature of a parameter. |
168 */ |
175 */ |
169 private String getParamJVMSignature(String paramsig) { |
176 private String getParamJVMSignature(String paramsig) throws SignatureException { |
170 String paramJVMSig = ""; |
177 String paramJVMSig = ""; |
171 String componentType =""; |
178 String componentType =""; |
172 |
179 |
173 if(paramsig != null){ |
180 if(paramsig != null){ |
174 |
181 |
214 else { |
221 else { |
215 if(!componentType.equals("")){ |
222 if(!componentType.equals("")){ |
216 TypeElement classNameDoc = elems.getTypeElement(componentType); |
223 TypeElement classNameDoc = elems.getTypeElement(componentType); |
217 |
224 |
218 if(classNameDoc == null){ |
225 if(classNameDoc == null){ |
219 System.out.println("Invalid class type for " + componentType); |
226 throw new SignatureException(componentType); |
220 new Exception().printStackTrace(); |
|
221 }else { |
227 }else { |
222 String classname = classNameDoc.getQualifiedName().toString(); |
228 String classname = classNameDoc.getQualifiedName().toString(); |
223 String newclassname = classname.replace('.', '/'); |
229 String newclassname = classname.replace('.', '/'); |
224 JVMSig += "L"; |
230 JVMSig += "L"; |
225 JVMSig += newclassname; |
231 JVMSig += newclassname; |