Search in sources :

Example 16 with Label

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

the class CodeEmitter method mark.

Label mark() {
    Label label = make_label();
    mv.visitLabel(label);
    return label;
}
Also used : Label(org.powermock.api.mockito.repackaged.asm.Label)

Example 17 with Label

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

the class CodeEmitter method unbox_or_zero.

/**
     * Unboxes the object on the top of the stack. If the object is null, the
     * unboxed primitive value becomes zero.
     */
public void unbox_or_zero(Type type) {
    if (TypeUtils.isPrimitive(type)) {
        if (type != Type.VOID_TYPE) {
            Label nonNull = make_label();
            Label end = make_label();
            dup();
            ifnonnull(nonNull);
            pop();
            zero_or_null(type);
            goTo(end);
            mark(nonNull);
            unbox(type);
            mark(end);
        }
    } else {
        checkcast(type);
    }
}
Also used : Label(org.powermock.api.mockito.repackaged.asm.Label)

Example 18 with Label

use of org.powermock.api.mockito.repackaged.asm.Label 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 Label

use of org.powermock.api.mockito.repackaged.asm.Label 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)

Example 20 with Label

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

the class InterceptFieldTransformer method addWriteMethod.

private void addWriteMethod(String name, Type type) {
    CodeEmitter e = super.begin_method(Constants.ACC_PUBLIC, writeMethodSig(name, type.getDescriptor()), null);
    e.load_this();
    e.dup();
    e.invoke_interface(ENABLED, ENABLED_GET);
    Label skip = e.make_label();
    e.ifnull(skip);
    e.load_this();
    e.invoke_interface(ENABLED, ENABLED_GET);
    e.load_this();
    e.push(name);
    e.load_this();
    e.getfield(name);
    e.load_arg(0);
    e.invoke_interface(CALLBACK, writeCallbackSig(type));
    if (!TypeUtils.isPrimitive(type)) {
        e.checkcast(type);
    }
    Label go = e.make_label();
    e.goTo(go);
    e.mark(skip);
    e.load_arg(0);
    e.mark(go);
    e.putfield(name);
    e.return_value();
    e.end_method();
}
Also used : CodeEmitter(org.powermock.api.mockito.repackaged.cglib.core.CodeEmitter) Label(org.powermock.api.mockito.repackaged.asm.Label)

Aggregations

Label (org.powermock.api.mockito.repackaged.asm.Label)36 CodeEmitter (org.powermock.api.mockito.repackaged.cglib.core.CodeEmitter)17 Type (org.powermock.api.mockito.repackaged.asm.Type)9 HashMap (java.util.HashMap)8 List (java.util.List)8 Map (java.util.Map)8 ObjectSwitchCallback (org.powermock.api.mockito.repackaged.cglib.core.ObjectSwitchCallback)8 MethodInfo (org.powermock.api.mockito.repackaged.cglib.core.MethodInfo)7 ProcessSwitchCallback (org.powermock.api.mockito.repackaged.cglib.core.ProcessSwitchCallback)5 BigInteger (java.math.BigInteger)4 Iterator (java.util.Iterator)4 PropertyDescriptor (java.beans.PropertyDescriptor)3 CodeGenerationException (org.powermock.api.mockito.repackaged.cglib.core.CodeGenerationException)3 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 Set (java.util.Set)2 Local (org.powermock.api.mockito.repackaged.cglib.core.Local)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 BitSet (java.util.BitSet)1