| Method from org.objectweb.asm.Type Detail: |
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof Type)) {
return false;
}
Type t = (Type) o;
if (sort != t.sort) {
return false;
}
if (sort == OBJECT || sort == ARRAY) {
if (len != t.len) {
return false;
}
for (int i = off, j = t.off, end = i + len; i < end; i++, j++) {
if (buf[i] != t.buf[j]) {
return false;
}
}
}
return true;
}
Tests if the given object is equal to this type. |
public static Type[] getArgumentTypes(String methodDescriptor) {
char[] buf = methodDescriptor.toCharArray();
int off = 1;
int size = 0;
while (true) {
char car = buf[off++];
if (car == ')") {
break;
} else if (car == 'L") {
while (buf[off++] != ';") {
}
++size;
} else if (car != '[") {
++size;
}
}
Type[] args = new Type[size];
off = 1;
size = 0;
while (buf[off] != ')") {
args[size] = getType(buf, off);
off += args[size].len + (args[size].sort == OBJECT ? 2 : 0);
size += 1;
}
return args;
}
Returns the Java types corresponding to the argument types of the given
method descriptor. |
public static Type[] getArgumentTypes(Method method) {
Class[] classes = method.getParameterTypes();
Type[] types = new Type[classes.length];
for (int i = classes.length - 1; i >= 0; --i) {
types[i] = getType(classes[i]);
}
return types;
}
Returns the Java types corresponding to the argument types of the given
method. |
public String getClassName() {
switch (sort) {
case VOID:
return "void";
case BOOLEAN:
return "boolean";
case CHAR:
return "char";
case BYTE:
return "byte";
case SHORT:
return "short";
case INT:
return "int";
case FLOAT:
return "float";
case LONG:
return "long";
case DOUBLE:
return "double";
case ARRAY:
StringBuffer b = new StringBuffer(getElementType().getClassName());
for (int i = getDimensions(); i > 0; --i) {
b.append("[]");
}
return b.toString();
// case OBJECT:
default:
return new String(buf, off, len).replace('/", '.");
}
}
Returns the name of the class corresponding to this type. |
public static String getConstructorDescriptor(Constructor c) {
Class[] parameters = c.getParameterTypes();
StringBuffer buf = new StringBuffer();
buf.append('(");
for (int i = 0; i < parameters.length; ++i) {
getDescriptor(buf, parameters[i]);
}
return buf.append(")V").toString();
}
Returns the descriptor corresponding to the given constructor. |
public String getDescriptor() {
StringBuffer buf = new StringBuffer();
getDescriptor(buf);
return buf.toString();
}
Returns the descriptor corresponding to this Java type. |
public static String getDescriptor(Class c) {
StringBuffer buf = new StringBuffer();
getDescriptor(buf, c);
return buf.toString();
}
Returns the descriptor corresponding to the given Java type. |
public int getDimensions() {
int i = 1;
while (buf[off + i] == '[") {
++i;
}
return i;
}
Returns the number of dimensions of this array type. This method should
only be used for an array type. |
public Type getElementType() {
return getType(buf, off + getDimensions());
}
Returns the type of the elements of this array type. This method should
only be used for an array type. |
public String getInternalName() {
return new String(buf, off, len);
}
Returns the internal name of the class corresponding to this object or
array type. The internal name of a class is its fully qualified name (as
returned by Class.getName(), where '.' are replaced by '/'. This method
should only be used for an object or array type. |
public static String getInternalName(Class c) {
return c.getName().replace('.", '/");
}
Returns the internal name of the given class. The internal name of a
class is its fully qualified name, as returned by Class.getName(), where
'.' are replaced by '/'. |
public static String getMethodDescriptor(Method m) {
Class[] parameters = m.getParameterTypes();
StringBuffer buf = new StringBuffer();
buf.append('(");
for (int i = 0; i < parameters.length; ++i) {
getDescriptor(buf, parameters[i]);
}
buf.append(')");
getDescriptor(buf, m.getReturnType());
return buf.toString();
}
Returns the descriptor corresponding to the given method. |
public static String getMethodDescriptor(Type returnType,
Type[] argumentTypes) {
StringBuffer buf = new StringBuffer();
buf.append('(");
for (int i = 0; i < argumentTypes.length; ++i) {
argumentTypes[i].getDescriptor(buf);
}
buf.append(')");
returnType.getDescriptor(buf);
return buf.toString();
}
Returns the descriptor corresponding to the given argument and return
types. |
public static Type getObjectType(String internalName) {
char[] buf = internalName.toCharArray();
return new Type(buf[0] == '[" ? ARRAY : OBJECT, buf, 0, buf.length);
}
Returns the Java type corresponding to the given internal name. |
public int getOpcode(int opcode) {
if (opcode == Opcodes.IALOAD || opcode == Opcodes.IASTORE) {
switch (sort) {
case BOOLEAN:
case BYTE:
return opcode + 5;
case CHAR:
return opcode + 6;
case SHORT:
return opcode + 7;
case INT:
return opcode;
case FLOAT:
return opcode + 2;
case LONG:
return opcode + 1;
case DOUBLE:
return opcode + 3;
// case ARRAY:
// case OBJECT:
default:
return opcode + 4;
}
} else {
switch (sort) {
case VOID:
return opcode + 5;
case BOOLEAN:
case CHAR:
case BYTE:
case SHORT:
case INT:
return opcode;
case FLOAT:
return opcode + 2;
case LONG:
return opcode + 1;
case DOUBLE:
return opcode + 3;
// case ARRAY:
// case OBJECT:
default:
return opcode + 4;
}
}
}
Returns a JVM instruction opcode adapted to this Java type. |
public static Type getReturnType(String methodDescriptor) {
char[] buf = methodDescriptor.toCharArray();
return getType(buf, methodDescriptor.indexOf(')") + 1);
}
Returns the Java type corresponding to the return type of the given
method descriptor. |
public static Type getReturnType(Method method) {
return getType(method.getReturnType());
}
Returns the Java type corresponding to the return type of the given
method. |
public int getSize() {
return sort == LONG || sort == DOUBLE ? 2 : 1;
}
Returns the size of values of this type. |
public int getSort() {
return sort;
}
Returns the sort of this Java type. |
public static Type getType(String typeDescriptor) {
return getType(typeDescriptor.toCharArray(), 0);
}
Returns the Java type corresponding to the given type descriptor. |
public static Type getType(Class c) {
if (c.isPrimitive()) {
if (c == Integer.TYPE) {
return INT_TYPE;
} else if (c == Void.TYPE) {
return VOID_TYPE;
} else if (c == Boolean.TYPE) {
return BOOLEAN_TYPE;
} else if (c == Byte.TYPE) {
return BYTE_TYPE;
} else if (c == Character.TYPE) {
return CHAR_TYPE;
} else if (c == Short.TYPE) {
return SHORT_TYPE;
} else if (c == Double.TYPE) {
return DOUBLE_TYPE;
} else if (c == Float.TYPE) {
return FLOAT_TYPE;
} else /* if (c == Long.TYPE) */{
return LONG_TYPE;
}
} else {
return getType(getDescriptor(c));
}
}
Returns the Java type corresponding to the given class. |
public int hashCode() {
int hc = 13 * sort;
if (sort == OBJECT || sort == ARRAY) {
for (int i = off, end = i + len; i < end; i++) {
hc = 17 * (hc + buf[i]);
}
}
return hc;
}
Returns a hash code value for this type. |
public String toString() {
return getDescriptor();
}
Returns a string representation of this type. |