/** * Returns the type of the elements of this array type. This method should only be used for an * array type. * * @return Returns the type of the elements of this array type. */ public Type getElementType() { final int numDimensions = getDimensions(); return getTypeInternal(valueBuffer, valueBegin + numDimensions, valueEnd); }
public static void main(String[] args) { Type type = Type.getReturnType("(Z)[I"); System.out.println("type = " + type.getSort()); System.out.println("dim = " + type.getDimensions()); System.out.println("element = " + type.getElementType()); }
case ARRAY: StringBuilder stringBuilder = new StringBuilder(getElementType().getClassName()); for (int i = getDimensions(); i > 0; --i) { stringBuilder.append("[]");
case Type.ARRAY: { StringBuilder sb = new StringBuilder(printType(type.getElementType())); for (int i = 0; i < type.getDimensions(); ++i) { sb.append("[]");
private static void loadArrayType(MethodVisitor mv, Type type, Type ownerType) { loadType(mv, type.getElementType(), ownerType); mv.visitLdcInsn(type.getDimensions()); mv.visitMethodInsn(INVOKESTATIC, bytecodeUtilType.getInternalName(), "getArrayClass", "(Ljava/lang/Class;I)Ljava/lang/Class;", false); }
private static Class<?> getType(Type type) throws ClassNotFoundException { switch (type.getSort()) { case Type.VOID: return void.class; case Type.BOOLEAN: return boolean.class; case Type.CHAR: return char.class; case Type.BYTE: return byte.class; case Type.SHORT: return short.class; case Type.INT: return int.class; case Type.FLOAT: return float.class; case Type.LONG: return long.class; case Type.DOUBLE: return double.class; case Type.ARRAY: return Util.getArrayClass(getType(type.getElementType()), type.getDimensions()); default: return Class.forName(type.getClassName(), false, null); } }
/** * Returns the type of the elements of this array type. This method should only be used for an * array type. * * @return Returns the type of the elements of this array type. */ public Type getElementType() { final int numDimensions = getDimensions(); return getType(valueBuffer, valueBegin + numDimensions, valueEnd); }
/** * Returns the type of the elements of this array type. This method should * only be used for an array type. * * @return Returns the type of the elements of this 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. * * @return Returns the type of the elements of this 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. * * @return Returns the type of the elements of this array type. */ public Type getElementType() { final int numDimensions = getDimensions(); return getTypeInternal(valueBuffer, valueBegin + numDimensions, valueEnd); }
/** * Returns the type of the elements of this array type. This method should only be used for an * array type. * * @return Returns the type of the elements of this array type. */ public Type getElementType() { final int numDimensions = getDimensions(); return getTypeInternal(valueBuffer, valueBegin + numDimensions, valueEnd); }
private static Type getArrayElementType(Type arrayType) { int dim = arrayType.getDimensions(); if(dim < 1) throw new IllegalArgumentException("Not an array type: " + arrayType); if(dim > 1) { String descr = arrayType.getDescriptor(); return Type.getType(descr.substring(1)); } return arrayType.getElementType(); }
private String getDescriptor(Type type) { if (type.getSort() == Type.OBJECT) { String name = type.getInternalName(); int index = name.lastIndexOf('/'); return name.substring(index + 1); } if (type.getSort() == Type.ARRAY) { StringBuilder sb = new StringBuilder(getDescriptor(type.getElementType())); for (int dim = type.getDimensions(); dim > 0; --dim) { sb.append("[]"); } return sb.toString(); } return type.getClassName(); }
public String mapDesc(String desc) { Type t = Type.getType(desc); switch (t.getSort()) { case Type.ARRAY: String s = mapDesc(t.getElementType().getDescriptor()); for (int i = 0; i < t.getDimensions(); ++i) { s = '[' + s; } return s; case Type.OBJECT: String newType = map(t.getInternalName()); if (newType != null) { return 'L' + newType + ';'; } } return desc; }
public String mapDesc(String desc) { Type t = Type.getType(desc); switch (t.getSort()) { case Type.ARRAY: String s = mapDesc(t.getElementType().getDescriptor()); for (int i = 0; i < t.getDimensions(); ++i) { s = '[' + s; } return s; case Type.OBJECT: String newType = map(t.getInternalName()); if (newType != null) { return 'L' + newType + ';'; } } return desc; }
private Type getMirrorType(final Type type) { int numDimensions = 0; final Type basicType; if (type.getSort() == Type.ARRAY) { numDimensions = type.getDimensions(); basicType = type.getElementType(); } else { basicType = type; } if (basicType.getSort() != Type.OBJECT) { return type; } final Mirror mirror = getMirror(basicType.getInternalName()); if (mirror.isClassMirror()) { final StringBuilder name = new StringBuilder(); for (int i = 0; i < numDimensions; ++i) { name.append('['); } name.append('L').append(mirror.getTranslatedName()).append(';'); return Type.getType(name.toString()); } return type; }
/** * Returns the given {@link Type}, remapped with {@link #map(String)} or {@link * #mapMethodDesc(String)}. * * @param type a type, which can be a method type. * @return the given type, with its [array element type] internal name remapped with {@link * #map(String)} (if the type is an array or object type, otherwise the type is returned as * is) or, of the type is a method type, with its descriptor remapped with {@link * #mapMethodDesc(String)}. */ private Type mapType(final Type type) { switch (type.getSort()) { case Type.ARRAY: StringBuilder remappedDescriptor = new StringBuilder(); for (int i = 0; i < type.getDimensions(); ++i) { remappedDescriptor.append('['); } remappedDescriptor.append(mapType(type.getElementType()).getDescriptor()); return Type.getType(remappedDescriptor.toString()); case Type.OBJECT: String remappedInternalName = map(type.getInternalName()); return remappedInternalName != null ? Type.getObjectType(remappedInternalName) : type; case Type.METHOD: return Type.getMethodType(mapMethodDesc(type.getDescriptor())); default: return type; } }
/** * Returns the given {@link Type}, remapped with {@link #map(String)} or {@link * #mapMethodDesc(String)}. * * @param type a type, which can be a method type. * @return the given type, with its [array element type] internal name remapped with {@link * #map(String)} (if the type is an array or object type, otherwise the type is returned as * is) or, of the type is a method type, with its descriptor remapped with {@link * #mapMethodDesc(String)}. */ private Type mapType(final Type type) { switch (type.getSort()) { case Type.ARRAY: StringBuilder remappedDescriptor = new StringBuilder(); for (int i = 0; i < type.getDimensions(); ++i) { remappedDescriptor.append('['); } remappedDescriptor.append(mapType(type.getElementType()).getDescriptor()); return Type.getType(remappedDescriptor.toString()); case Type.OBJECT: String remappedInternalName = map(type.getInternalName()); return remappedInternalName != null ? Type.getObjectType(remappedInternalName) : type; case Type.METHOD: return Type.getMethodType(mapMethodDesc(type.getDescriptor())); default: return type; } }
private Type mapType(Type t) { switch (t.getSort()) { case Type.ARRAY: String s = mapDesc(t.getElementType().getDescriptor()); for (int i = 0; i < t.getDimensions(); ++i) { s = '[' + s; } return Type.getType(s); case Type.OBJECT: s = map(t.getInternalName()); return s != null ? Type.getObjectType(s) : t; case Type.METHOD: return Type.getMethodType(mapMethodDesc(t.getDescriptor())); } return t; }
private Type mapType(Type t) { switch (t.getSort()) { case Type.ARRAY: String s = mapDesc(t.getElementType().getDescriptor()); for (int i = 0; i < t.getDimensions(); ++i) { s = '[' + s; } return Type.getType(s); case Type.OBJECT: s = map(t.getInternalName()); return s != null ? Type.getObjectType(s) : t; case Type.METHOD: return Type.getMethodType(mapMethodDesc(t.getDescriptor())); } return t; }