Search in sources :

Example 11 with Type

use of org.powermock.api.mockito.repackaged.asm.Type in project powermock by powermock.

the class TypeUtils method add.

public static Type[] add(Type[] types, Type extra) {
    if (types == null) {
        return new Type[] { extra };
    } else {
        List list = Arrays.asList(types);
        if (list.contains(extra)) {
            return types;
        }
        Type[] copy = new Type[types.length + 1];
        System.arraycopy(types, 0, copy, 0, types.length);
        copy[types.length] = extra;
        return copy;
    }
}
Also used : Type(org.powermock.api.mockito.repackaged.asm.Type) List(java.util.List) ArrayList(java.util.ArrayList)

Example 12 with Type

use of org.powermock.api.mockito.repackaged.asm.Type in project powermock by powermock.

the class TypeUtils method parseTypes.

public static Type[] parseTypes(String s) {
    List names = parseTypes(s, 0, s.length());
    Type[] types = new Type[names.size()];
    for (int i = 0; i < types.length; i++) {
        types[i] = Type.getType((String) names.get(i));
    }
    return types;
}
Also used : Type(org.powermock.api.mockito.repackaged.asm.Type) List(java.util.List) ArrayList(java.util.ArrayList)

Example 13 with Type

use of org.powermock.api.mockito.repackaged.asm.Type in project powermock by powermock.

the class ClassEmitter method begin_class.

public void begin_class(int version, final int access, String className, final Type superType, final Type[] interfaces, String source) {
    final Type classType = Type.getType("L" + className.replace('.', '/') + ";");
    classInfo = new ClassInfo() {

        public Type getType() {
            return classType;
        }

        public Type getSuperType() {
            return (superType != null) ? superType : Constants.TYPE_OBJECT;
        }

        public Type[] getInterfaces() {
            return interfaces;
        }

        public int getModifiers() {
            return access;
        }
    };
    cv.visit(version, access, classInfo.getType().getInternalName(), null, classInfo.getSuperType().getInternalName(), TypeUtils.toInternalNames(interfaces));
    if (source != null)
        cv.visitSource(source, null);
    init();
}
Also used : Type(org.powermock.api.mockito.repackaged.asm.Type)

Example 14 with Type

use of org.powermock.api.mockito.repackaged.asm.Type in project powermock by powermock.

the class CodeEmitter method unbox.

/**
     * If the argument is a primitive class, replaces the object
     * on the top of the stack with the unwrapped (primitive)
     * equivalent. For example, Character -> char.
     * @param type the class indicating the desired type of the top stack value
     */
public void unbox(Type type) {
    Type t = Constants.TYPE_NUMBER;
    Signature sig = null;
    switch(type.getSort()) {
        case Type.VOID:
            return;
        case Type.CHAR:
            t = Constants.TYPE_CHARACTER;
            sig = CHAR_VALUE;
            break;
        case Type.BOOLEAN:
            t = Constants.TYPE_BOOLEAN;
            sig = BOOLEAN_VALUE;
            break;
        case Type.DOUBLE:
            sig = DOUBLE_VALUE;
            break;
        case Type.FLOAT:
            sig = FLOAT_VALUE;
            break;
        case Type.LONG:
            sig = LONG_VALUE;
            break;
        case Type.INT:
        case Type.SHORT:
        case Type.BYTE:
            sig = INT_VALUE;
    }
    if (sig == null) {
        checkcast(type);
    } else {
        checkcast(t);
        invoke_virtual(t, sig);
    }
}
Also used : Type(org.powermock.api.mockito.repackaged.asm.Type)

Example 15 with Type

use of org.powermock.api.mockito.repackaged.asm.Type in project powermock by powermock.

the class CodeEmitter method invoke.

public void invoke(MethodInfo method, Type virtualType) {
    ClassInfo classInfo = method.getClassInfo();
    Type type = classInfo.getType();
    Signature sig = method.getSignature();
    if (sig.getName().equals(Constants.CONSTRUCTOR_NAME)) {
        invoke_constructor(type, sig);
    } else if (TypeUtils.isInterface(classInfo.getModifiers())) {
        invoke_interface(type, sig);
    } else if (TypeUtils.isStatic(method.getModifiers())) {
        invoke_static(type, sig);
    } else {
        invoke_virtual(virtualType, sig);
    }
}
Also used : Type(org.powermock.api.mockito.repackaged.asm.Type)

Aggregations

Type (org.powermock.api.mockito.repackaged.asm.Type)29 Label (org.powermock.api.mockito.repackaged.asm.Label)9 CodeEmitter (org.powermock.api.mockito.repackaged.cglib.core.CodeEmitter)9 List (java.util.List)6 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 CodeGenerationException (org.powermock.api.mockito.repackaged.cglib.core.CodeGenerationException)3 Signature (org.powermock.api.mockito.repackaged.cglib.core.Signature)3 TryCatchBlockNode (org.powermock.api.mockito.repackaged.asm.tree.TryCatchBlockNode)2 ClassEmitter (org.powermock.api.mockito.repackaged.cglib.core.ClassEmitter)2 ObjectSwitchCallback (org.powermock.api.mockito.repackaged.cglib.core.ObjectSwitchCallback)2 ProcessSwitchCallback (org.powermock.api.mockito.repackaged.cglib.core.ProcessSwitchCallback)2 Method (java.lang.reflect.Method)1 Iterator (java.util.Iterator)1 AbstractInsnNode (org.powermock.api.mockito.repackaged.asm.tree.AbstractInsnNode)1 ClassNode (org.powermock.api.mockito.repackaged.asm.tree.ClassNode)1 IincInsnNode (org.powermock.api.mockito.repackaged.asm.tree.IincInsnNode)1 InsnList (org.powermock.api.mockito.repackaged.asm.tree.InsnList)1 JumpInsnNode (org.powermock.api.mockito.repackaged.asm.tree.JumpInsnNode)1