Search in sources :

Example 16 with Type

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

the class CodeEmitter method load_args.

// zero-based (see load_this)
public void load_args(int fromArg, int count) {
    int pos = state.localOffset + skipArgs(fromArg);
    for (int i = 0; i < count; i++) {
        Type t = state.argumentTypes[fromArg + i];
        load_local(t, pos);
        pos += t.getSize();
    }
}
Also used : Type(org.powermock.api.mockito.repackaged.asm.Type)

Example 17 with Type

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

the class AddDelegateTransformer method addDelegate.

private void addDelegate(Method m) {
    Method delegate;
    try {
        delegate = delegateImpl.getMethod(m.getName(), m.getParameterTypes());
        if (!delegate.getReturnType().getName().equals(m.getReturnType().getName())) {
            throw new IllegalArgumentException("Invalid delegate signature " + delegate);
        }
    } catch (NoSuchMethodException e) {
        throw new CodeGenerationException(e);
    }
    final Signature sig = ReflectUtils.getSignature(m);
    Type[] exceptions = TypeUtils.getTypes(m.getExceptionTypes());
    CodeEmitter e = super.begin_method(Constants.ACC_PUBLIC, sig, exceptions);
    e.load_this();
    e.getfield(DELEGATE);
    e.load_args();
    e.invoke_virtual(delegateType, sig);
    e.return_value();
    e.end_method();
}
Also used : CodeEmitter(org.powermock.api.mockito.repackaged.cglib.core.CodeEmitter) Type(org.powermock.api.mockito.repackaged.asm.Type) CodeGenerationException(org.powermock.api.mockito.repackaged.cglib.core.CodeGenerationException) Signature(org.powermock.api.mockito.repackaged.cglib.core.Signature) Method(java.lang.reflect.Method)

Example 18 with Type

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

the class FieldProviderTransformer method getField.

// TODO: if this is used to enhance class files SWITCH_STYLE_TRIE should be used
// to avoid JVM hashcode implementation incompatibilities
private void getField(String[] names) throws Exception {
    final CodeEmitter e = begin_method(Constants.ACC_PUBLIC, PROVIDER_GET, null);
    e.load_this();
    e.load_arg(0);
    EmitUtils.string_switch(e, names, Constants.SWITCH_STYLE_HASH, new ObjectSwitchCallback() {

        public void processCase(Object key, Label end) {
            Type type = (Type) fields.get(key);
            e.getfield((String) key);
            e.box(type);
            e.return_value();
        }

        public void processDefault() {
            e.throw_exception(ILLEGAL_ARGUMENT_EXCEPTION, "Unknown field name");
        }
    });
    e.end_method();
}
Also used : CodeEmitter(org.powermock.api.mockito.repackaged.cglib.core.CodeEmitter) Type(org.powermock.api.mockito.repackaged.asm.Type) Label(org.powermock.api.mockito.repackaged.asm.Label) ObjectSwitchCallback(org.powermock.api.mockito.repackaged.cglib.core.ObjectSwitchCallback)

Example 19 with Type

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

the class FieldProviderTransformer method initFieldProvider.

private void initFieldProvider(String[] names) {
    CodeEmitter e = getStaticHook();
    EmitUtils.push_object(e, names);
    e.putstatic(getClassType(), FIELD_NAMES, Constants.TYPE_STRING_ARRAY);
    e.push(names.length);
    e.newarray(Constants.TYPE_CLASS);
    e.dup();
    for (int i = 0; i < names.length; i++) {
        e.dup();
        e.push(i);
        Type type = (Type) fields.get(names[i]);
        EmitUtils.load_class(e, type);
        e.aastore();
    }
    e.putstatic(getClassType(), FIELD_TYPES, Constants.TYPE_CLASS_ARRAY);
}
Also used : CodeEmitter(org.powermock.api.mockito.repackaged.cglib.core.CodeEmitter) Type(org.powermock.api.mockito.repackaged.asm.Type)

Example 20 with Type

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

the class FieldProviderTransformer method setByIndex.

private void setByIndex(final String[] names, final int[] indexes) throws Exception {
    final CodeEmitter e = super.begin_method(Constants.ACC_PUBLIC, PROVIDER_SET_BY_INDEX, null);
    e.load_this();
    e.load_arg(1);
    e.load_arg(0);
    e.process_switch(indexes, new ProcessSwitchCallback() {

        public void processCase(int key, Label end) throws Exception {
            Type type = (Type) fields.get(names[key]);
            e.unbox(type);
            e.putfield(names[key]);
            e.return_value();
        }

        public void processDefault() throws Exception {
            e.throw_exception(ILLEGAL_ARGUMENT_EXCEPTION, "Unknown field index");
        }
    });
    e.end_method();
}
Also used : CodeEmitter(org.powermock.api.mockito.repackaged.cglib.core.CodeEmitter) Type(org.powermock.api.mockito.repackaged.asm.Type) ProcessSwitchCallback(org.powermock.api.mockito.repackaged.cglib.core.ProcessSwitchCallback) Label(org.powermock.api.mockito.repackaged.asm.Label) CodeGenerationException(org.powermock.api.mockito.repackaged.cglib.core.CodeGenerationException)

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