1 21 22 package org.apache.derby.impl.services.bytecode; 23 24 import org.apache.derby.iapi.services.classfile.VMDescriptor; 25 26 33 class BCMethodDescriptor { 34 35 static final String [] EMPTY = new String [0]; 36 37 private final String [] vmParameterTypes; 38 private final String vmReturnType; 39 40 private final String vmDescriptor; 41 42 BCMethodDescriptor(String [] vmParameterTypes, String vmReturnType, BCJava factory) { 43 44 this.vmParameterTypes = vmParameterTypes; 45 this.vmReturnType = vmReturnType; 46 47 vmDescriptor = factory.vmType(this); 48 } 49 66 static String get(String [] vmParameterTypes, String vmReturnType, BCJava factory) { 67 68 return new BCMethodDescriptor(vmParameterTypes, vmReturnType, factory).toString(); 69 } 70 71 75 String buildMethodDescriptor() { 76 77 int paramCount = vmParameterTypes.length; 78 79 int approxLength = (30 * (paramCount + 1)); 80 81 StringBuffer methDesc = new StringBuffer (approxLength); 82 83 methDesc.append(VMDescriptor.C_METHOD); 84 85 for (int i = 0; i < paramCount; i++) { 86 methDesc.append(vmParameterTypes[i]); 87 } 88 89 methDesc.append(VMDescriptor.C_ENDMETHOD); 90 methDesc.append(vmReturnType); 91 92 return methDesc.toString(); 93 } 94 95 public String toString() { 96 return vmDescriptor; 97 } 98 99 100 public int hashCode() { 101 return vmParameterTypes.length | (vmReturnType.hashCode() & 0xFFFFFF00); 102 } 103 104 public boolean equals(Object other) { 105 if (!(other instanceof BCMethodDescriptor)) 106 return false; 107 108 BCMethodDescriptor o = (BCMethodDescriptor) other; 109 110 111 if (o.vmParameterTypes.length != vmParameterTypes.length) 112 return false; 113 114 for (int i = 0; i < vmParameterTypes.length; i++) { 115 if (!vmParameterTypes[i].equals(o.vmParameterTypes[i])) 116 return false; 117 } 118 119 return vmReturnType.equals(o.vmReturnType); 120 } 121 } 122 | Popular Tags |