/** * Returns the Java type corresponding to the given type descriptor. * * @param typeDescriptor * a field or method type descriptor. * @return the Java type corresponding to the given type descriptor. */ public static Type getType(final String typeDescriptor) { return getType(typeDescriptor.toCharArray(), 0); }
/** * Returns the Java type corresponding to the return type of the given * method. * * @param method * a method. * @return the Java type corresponding to the return type of the given * method. */ public static Type getReturnType(final Method method) { return getType(method.getReturnType()); }
/** * Returns the Java type corresponding to the given method descriptor. * Equivalent to <code>Type.getType(methodDescriptor)</code>. * * @param methodDescriptor * a method descriptor. * @return the Java type corresponding to the given method descriptor. */ public static Type getMethodType(final String methodDescriptor) { return getType(methodDescriptor.toCharArray(), 0); }
/** * Returns the Java type corresponding to the return type of the given * method descriptor. * * @param methodDescriptor * a method descriptor. * @return the Java type corresponding to the return type of the given * method descriptor. */ public static Type getReturnType(final String methodDescriptor) { char[] buf = methodDescriptor.toCharArray(); return getType(buf, methodDescriptor.indexOf(')') + 1); }
/** * Returns the Java types corresponding to the argument types of the given * method. * * @param method * a method. * @return the Java types corresponding to the argument types of the given * method. */ public static Type[] getArgumentTypes(final 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 method type corresponding to the given method. * * @param m * a {@link Method Method} object. * @return the Java method type corresponding to the given method. */ public static Type getType(final Method m) { return getType(getMethodDescriptor(m)); }
/** * Returns the Java method type corresponding to the given constructor. * * @param c * a {@link Constructor Constructor} object. * @return the Java method type corresponding to the given constructor. */ public static Type getType(final Constructor<?> c) { return getType(getConstructorDescriptor(c)); }
/** * 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()); }
void addDesc(final String desc) { addType(Type.getType(desc)); }
/** * Returns the Java method type corresponding to the given argument and * return types. * * @param returnType * the return type of the method. * @param argumentTypes * the argument types of the method. * @return the Java type corresponding to the given argument and return * types. */ public static Type getMethodType(final Type returnType, final Type... argumentTypes) { return getType(getMethodDescriptor(returnType, argumentTypes)); }
protected Type getSuperClass(final Type t) { if (currentClass != null && t.equals(currentClass)) { return currentSuperClass; } Class<?> c = getClass(t).getSuperclass(); return c == null ? null : Type.getType(c); }
@Override public void visitLocalVariable(final String name, final String desc, final String signature, final Label start, final Label end, final int index) { int newIndex = remap(index, Type.getType(desc)); mv.visitLocalVariable(name, desc, signature, start, end, newIndex); }
public static Map<String,Object> getAnnotationValues(AnnotationNode a) { Map<String,Object> map = new LinkedHashMap<>(); if(null != a.values) { for(int i=0;i<a.values.size();i++) { String name = (String)a.values.get(i); Object value = a.values.get(i+1); if(value instanceof String[]) { //enum value String[] array = (String[])value; Class<? extends Enum> enumType = (Class<? extends Enum>)Classes.forName(Type.getType(array[0]).getClassName()); map.put(name, Enums.nameOf(enumType, array[1])); }else{ map.put(name, value); } i+=1; } } return map; }
@Override public AnnotationVisitor visitLocalVariableAnnotation(int typeRef, TypePath typePath, Label[] start, Label[] end, int[] index, String desc, boolean visible) { Type t = Type.getType(desc); int[] newIndex = new int[index.length]; for (int i = 0; i < newIndex.length; ++i) { newIndex[i] = remap(index[i], t); } return mv.visitLocalVariableAnnotation(typeRef, typePath, start, end, newIndex, desc, visible); }
@Override protected BasicValue getElementValue(final BasicValue objectArrayValue) throws AnalyzerException { Type arrayType = objectArrayValue.getType(); if (arrayType != null) { if (arrayType.getSort() == Type.ARRAY) { return newValue(Type.getType(arrayType.getDescriptor() .substring(1))); } else if ("Lnull;".equals(arrayType.getDescriptor())) { return objectArrayValue; } } throw new Error("Internal error"); }
private Type getFieldType(MethodInterceptorConfig interceptor) { if(!Strings.isEmpty(interceptor.getBeanName())) { return INTERCEPTOR_TYPE; }else{ return Type.getType(ASM.getObjectTypeDescriptor(interceptor.getClassName())); } }
@Override public BasicValue naryOperation(final AbstractInsnNode insn, final List<? extends BasicValue> values) throws AnalyzerException { int opcode = insn.getOpcode(); if (opcode == MULTIANEWARRAY) { return newValue(Type.getType(((MultiANewArrayInsnNode) insn).desc)); } else if (opcode == INVOKEDYNAMIC) { return newValue(Type .getReturnType(((InvokeDynamicInsnNode) insn).desc)); } else { return newValue(Type.getReturnType(((MethodInsnNode) insn).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; }
@Override public void visitMaxs(int maxStack, int maxLocals) { visitTryCatchBlock(tryLabel, finallyLabel, finallyLabel, null); visitLabel(finallyLabel); int errLocal = newLocal(Type.getType(Throwable.class)); storeLocal(errLocal); notifyMonitorError(errLocal); exitMonitor(); loadLocal(errLocal); visitInsn(Opcodes.ATHROW); super.visitMaxs(maxStack, maxLocals); }
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; }