Search in sources :

Example 11 with SignatureVisitor

use of org.objectweb.asm.signature.SignatureVisitor in project cdap by caskdata.

the class Signatures method getMethodSignature.

/**
   * Generates signature for the given method.
   *
   * @param method Method that needs signature to be generated
   * @param returnType the {@link TypeToken} of the return type
   * @param argTypes List of {@link TypeToken} that matches with the number of arguments in the given method.
   *              For a given method argument, if the corresponding {@link TypeToken} is non-null, it will be
   *              used to generate the type parameter in the signature, otherwise, the one in the method will be used.
   *              It's useful if the method is parameterized so that parameterize type information can be passed
   *              through the type tokens.
   * @return A method signature string
   */
public static String getMethodSignature(Method method, TypeToken<?> returnType, TypeToken<?>... argTypes) {
    SignatureWriter signWriter = new SignatureWriter();
    Type[] argumentTypes = method.getArgumentTypes();
    for (int i = 0; i < argumentTypes.length; i++) {
        SignatureVisitor sv = signWriter.visitParameterType();
        if (argTypes[i] != null) {
            visitTypeSignature(argTypes[i], sv);
        } else {
            sv.visitClassType(argumentTypes[i].getInternalName());
            sv.visitEnd();
        }
    }
    visitTypeSignature(returnType, signWriter.visitReturnType());
    return signWriter.toString();
}
Also used : ParameterizedType(java.lang.reflect.ParameterizedType) Type(org.objectweb.asm.Type) SignatureVisitor(org.objectweb.asm.signature.SignatureVisitor) SignatureWriter(org.objectweb.asm.signature.SignatureWriter)

Example 12 with SignatureVisitor

use of org.objectweb.asm.signature.SignatureVisitor in project cdap by caskdata.

the class FieldAccessorGenerator method setterSignature.

/**
   * @return the setter signature {@code <T> void set(Object object, T value)}
   */
private String setterSignature() {
    SignatureWriter writer = new SignatureWriter();
    writer.visitFormalTypeParameter("T");
    SignatureVisitor sv = writer.visitClassBound();
    sv.visitClassType(Type.getInternalName(Object.class));
    sv.visitEnd();
    sv = writer.visitParameterType();
    sv.visitClassType(Type.getInternalName(Object.class));
    sv.visitEnd();
    sv = writer.visitParameterType();
    sv.visitTypeVariable("T");
    sv.visitReturnType().visitBaseType('V');
    return writer.toString();
}
Also used : SignatureVisitor(org.objectweb.asm.signature.SignatureVisitor) SignatureWriter(org.objectweb.asm.signature.SignatureWriter)

Example 13 with SignatureVisitor

use of org.objectweb.asm.signature.SignatureVisitor in project cdap by caskdata.

the class Signatures method getClassSignature.

public static String getClassSignature(TypeToken<?> interfaceType) {
    SignatureWriter signWriter = new SignatureWriter();
    SignatureVisitor sv = signWriter.visitSuperclass();
    sv.visitClassType(Type.getInternalName(Object.class));
    sv.visitEnd();
    SignatureVisitor interfaceVisitor = sv.visitInterface();
    interfaceVisitor.visitClassType(Type.getInternalName(interfaceType.getRawType()));
    if (interfaceType.getType() instanceof ParameterizedType) {
        for (java.lang.reflect.Type paramType : ((ParameterizedType) interfaceType.getType()).getActualTypeArguments()) {
            interfaceVisitor.visitTypeArgument(SignatureVisitor.INSTANCEOF);
            visitTypeSignature(interfaceType.resolveType(paramType), interfaceVisitor);
        }
    }
    sv.visitEnd();
    return signWriter.toString();
}
Also used : ParameterizedType(java.lang.reflect.ParameterizedType) SignatureVisitor(org.objectweb.asm.signature.SignatureVisitor) SignatureWriter(org.objectweb.asm.signature.SignatureWriter)

Aggregations

SignatureVisitor (org.objectweb.asm.signature.SignatureVisitor)13 SignatureWriter (org.objectweb.asm.signature.SignatureWriter)6 SignatureReader (org.objectweb.asm.signature.SignatureReader)3 ParameterizedType (java.lang.reflect.ParameterizedType)2 Type (org.objectweb.asm.Type)1