Java 类com.sun.jdi.ByteValue 实例源码

项目:openjdk-jdk10    文件:PacketStream.java   
void writeUntaggedValueChecked(Value val) throws InvalidTypeException {
    byte tag = ValueImpl.typeValueKey(val);
    if (isObjectTag(tag)) {
        if (val == null) {
             writeObjectRef(0);
        } else {
            if (!(val instanceof ObjectReference)) {
                throw new InvalidTypeException();
            }
            writeObjectRef(((ObjectReferenceImpl)val).ref());
        }
    } else {
        switch (tag) {
            case JDWP.Tag.BYTE:
                if(!(val instanceof ByteValue))
                    throw new InvalidTypeException();

                writeByte(((PrimitiveValue)val).byteValue());
                break;

            case JDWP.Tag.CHAR:
                if(!(val instanceof CharValue))
                    throw new InvalidTypeException();

                writeChar(((PrimitiveValue)val).charValue());
                break;

            case JDWP.Tag.FLOAT:
                if(!(val instanceof FloatValue))
                    throw new InvalidTypeException();

                writeFloat(((PrimitiveValue)val).floatValue());
                break;

            case JDWP.Tag.DOUBLE:
                if(!(val instanceof DoubleValue))
                    throw new InvalidTypeException();

                writeDouble(((PrimitiveValue)val).doubleValue());
                break;

            case JDWP.Tag.INT:
                if(!(val instanceof IntegerValue))
                    throw new InvalidTypeException();

                writeInt(((PrimitiveValue)val).intValue());
                break;

            case JDWP.Tag.LONG:
                if(!(val instanceof LongValue))
                    throw new InvalidTypeException();

                writeLong(((PrimitiveValue)val).longValue());
                break;

            case JDWP.Tag.SHORT:
                if(!(val instanceof ShortValue))
                    throw new InvalidTypeException();

                writeShort(((PrimitiveValue)val).shortValue());
                break;

            case JDWP.Tag.BOOLEAN:
                if(!(val instanceof BooleanValue))
                    throw new InvalidTypeException();

                writeBoolean(((PrimitiveValue)val).booleanValue());
                break;
        }
    }
}
项目:JavaTracer    文件:ClassUtils.java   
private Data getPrimitiveObject(String name, Value value) {
    Data object = null;
    if (value instanceof BooleanValue)
        object = new SimpleData(name,((BooleanValue) value).booleanValue());
    else if (value instanceof ByteValue)
        object = new SimpleData(name,((ByteValue) value).byteValue());
    else if (value instanceof CharValue)
        object = new SimpleData(name,((CharValue) value).charValue());
    else if (value instanceof DoubleValue)
        object = new SimpleData(name,((DoubleValue) value).doubleValue());
    else if (value instanceof FloatValue)
        object = new SimpleData(name,((FloatValue) value).floatValue());
    else if (value instanceof IntegerValue)
        object = new SimpleData(name,((IntegerValue) value).intValue());
    else if (value instanceof LongValue)
        object = new SimpleData(name,((LongValue) value).longValue());
    else if (value instanceof ShortValue)
        object = new SimpleData(name,((ShortValue)value).shortValue());
    return object;
}
项目:incubator-netbeans    文件:RemoteServices.java   
private static ArrayReference createTargetBytes(VirtualMachine vm, byte[] bytes,
                                                ByteValue[] mirrorBytesCache) throws InvalidTypeException,
                                                                                     ClassNotLoadedException,
                                                                                     InternalExceptionWrapper,
                                                                                     VMDisconnectedExceptionWrapper,
                                                                                     ObjectCollectedExceptionWrapper,
                                                                                     UnsupportedOperationExceptionWrapper {
    ArrayType bytesArrayClass = getArrayClass(vm, "byte[]");
    ArrayReference array = null;
    boolean disabledCollection = false;
    while (!disabledCollection) {
        array = ArrayTypeWrapper.newInstance(bytesArrayClass, bytes.length);
        try {
            ObjectReferenceWrapper.disableCollection(array);
            disabledCollection = true;
        } catch (ObjectCollectedExceptionWrapper ocex) {
            // Collected too soon, try again...
        }
    }
    List<Value> values = new ArrayList<Value>(bytes.length);
    for (int i = 0; i < bytes.length; i++) {
        byte b = bytes[i];
        ByteValue mb = mirrorBytesCache[128 + b];
        if (mb == null) {
            mb = VirtualMachineWrapper.mirrorOf(vm, b);
            mirrorBytesCache[128 + b] = mb;
        }
        values.add(mb);
    }
    ArrayReferenceWrapper.setValues(array, values);
    return array;
}
项目:incubator-netbeans    文件:RemoteServices.java   
private static ArrayReference createTargetBytes(VirtualMachine vm, byte[] bytes,
                                                ByteValue[] mirrorBytesCache) throws InvalidTypeException,
                                                                                     ClassNotLoadedException,
                                                                                     InternalExceptionWrapper,
                                                                                     VMDisconnectedExceptionWrapper,
                                                                                     ObjectCollectedExceptionWrapper {
    ArrayType bytesArrayClass = getArrayClass(vm, "byte[]");
    ArrayReference array = null;
    boolean disabledCollection = false;
    while (!disabledCollection) {
        array = ArrayTypeWrapper.newInstance(bytesArrayClass, bytes.length);
        try {
            ObjectReferenceWrapper.disableCollection(array);
            disabledCollection = true;
        } catch (ObjectCollectedExceptionWrapper ocex) {
            // Collected too soon, try again...
        } catch (UnsupportedOperationExceptionWrapper uex) {
            // Hope it will not be GC'ed...
            disabledCollection = true;
        }
    }
    List<Value> values = new ArrayList<Value>(bytes.length);
    for (int i = 0; i < bytes.length; i++) {
        byte b = bytes[i];
        ByteValue mb = mirrorBytesCache[128 + b];
        if (mb == null) {
            mb = VirtualMachineWrapper.mirrorOf(vm, b);
            mirrorBytesCache[128 + b] = mb;
        }
        values.add(mb);
    }
    ArrayReferenceWrapper.setValues(array, values);
    return array;
}
项目:openjdk-jdk10    文件:ByteValueImpl.java   
public boolean equals(Object obj) {
    if ((obj != null) && (obj instanceof ByteValue)) {
        return (value == ((ByteValue)obj).value())
               && super.equals(obj);
    } else {
        return false;
    }
}
项目:form-follows-function    文件:F3Wrapper.java   
public static F3Value wrap(F3VirtualMachine f3vm, Value value) {
    if (value == null) {
        return null;
    }

    if (value instanceof PrimitiveValue) {
        if (value instanceof BooleanValue) {
            return f3vm.booleanValue((BooleanValue)value);
        } else if (value instanceof CharValue) {
            return f3vm.charValue((CharValue)value);
        } else if (value instanceof ByteValue) {
            return f3vm.byteValue((ByteValue)value);
        } else if (value instanceof ShortValue) {
            return f3vm.shortValue((ShortValue)value);
        } else if (value instanceof IntegerValue) {
            return f3vm.integerValue((IntegerValue)value);
        } else if (value instanceof LongValue) {
            return f3vm.longValue((LongValue)value);
        } else if (value instanceof FloatValue) {
            return f3vm.floatValue((FloatValue)value);
        } else if (value instanceof DoubleValue) {
            return f3vm.doubleValue((DoubleValue)value);
        } else {
            throw new IllegalArgumentException("illegal primitive value : " + value);
        }
    } else if (value instanceof VoidValue) {
        return f3vm.voidValue();
    } else if (value instanceof ObjectReference) {
        return  wrap(f3vm, (ObjectReference)value);
    } else {
        throw new IllegalArgumentException("illegal value: " + value);
    }
}
项目:form-follows-function    文件:F3SequenceReference.java   
/**
 * Replace a sequence element with another value.
 *
 * Object values must be assignment compatible with the element type.
 * (This implies that the component type must be loaded through the
 * declaring class's class loader). Primitive values must be
 * assignment compatible with the component type.
 *
 * @param value the new value
 * @param index the index of the component to set.  If this is beyond the 
 * end of the sequence, the new value is appended to the sequence.
 *
 * @throws InvalidTypeException if the type of <CODE><I>value</I></CODE>
 * is not compatible with the declared type of sequence elements.
 * @throws ClassNotLoadedException if the sequence element type
 * has not yet been loaded through the appropriate class loader.
 * @throws VMCannotBeModifiedException if the VirtualMachine is read-only - see {@link com.sun.jdi.VirtualMachine#canBeModified()}.
 * @return a new sequence with the specified element replaced/added.
 */
public F3SequenceReference setValue(int index, Value value) {
    Types type = getElementType();
    switch (type) {
        case INT:
            return setIntValue(index, (IntegerValue)value);
        case FLOAT:
            return setFloatValue(index, (FloatValue)value);
        case OBJECT:
            return setObjectValue(index, (ObjectReference)value);
        case DOUBLE:
            return setDoubleValue(index, (DoubleValue)value);
        case BOOLEAN:
            return setBooleanValue(index, (BooleanValue)value);
        case LONG:
            return setLongValue(index, (LongValue)value);
        case SHORT:
            return setShortValue(index, (ShortValue)value);
        case BYTE:
            return setByteValue(index, (ByteValue)value);
        case CHAR:
            return setCharValue(index, (CharValue)value);
        case OTHER:
            return setObjectValue(index, (ObjectReference)value);
        default:
            throw new IllegalArgumentException("Invalid sequence element type");
    }
}
项目:incubator-netbeans    文件:EvaluatorVisitor.java   
public static Value unbox(ObjectReference val, PrimitiveType type,
                          ThreadReference thread,
                          EvaluationContext context) throws InvalidTypeException,
                                                            ClassNotLoadedException,
                                                            IncompatibleThreadStateException,
                                                            InvocationException {
    ReferenceType rt = val.referenceType();
    String classType = rt.name();
    PrimitiveValue pv;
    if (classType.equals("java.lang.Boolean")) {
        pv = invokeUnboxingMethod(val, "booleanValue", thread, context);
    } else if (classType.equals("java.lang.Byte")) {
        pv = invokeUnboxingMethod(val, "byteValue", thread, context);
    } else if (classType.equals("java.lang.Character")) {
        pv = invokeUnboxingMethod(val, "charValue", thread, context);
    } else if (classType.equals("java.lang.Short")) {
        pv = invokeUnboxingMethod(val, "shortValue", thread, context);
    } else if (classType.equals("java.lang.Integer")) {
        pv = invokeUnboxingMethod(val, "intValue", thread, context);
    } else if (classType.equals("java.lang.Long")) {
        pv = invokeUnboxingMethod(val, "longValue", thread, context);
    } else if (classType.equals("java.lang.Float")) {
        pv = invokeUnboxingMethod(val, "floatValue", thread, context);
    } else if (classType.equals("java.lang.Double")) {
        pv = invokeUnboxingMethod(val, "doubleValue", thread, context);
    //throw new RuntimeException("Invalid type while unboxing: " + type.signature());    // never happens
    } else {
        return val;
    }
    VirtualMachine vm = pv.virtualMachine();
    if (type instanceof BooleanType && !(pv instanceof BooleanValue)) {
        return vm.mirrorOf(pv.booleanValue());
    }
    if (type instanceof ByteType && !(pv instanceof ByteValue)) {
        return vm.mirrorOf(pv.byteValue());
    }
    if (type instanceof CharType && !(pv instanceof CharValue)) {
        return vm.mirrorOf(pv.charValue());
    }
    if (type instanceof ShortType && !(pv instanceof ShortValue)) {
        return vm.mirrorOf(pv.shortValue());
    }
    if (type instanceof IntegerType && !(pv instanceof IntegerValue)) {
        return vm.mirrorOf(pv.intValue());
    }
    if (type instanceof LongType && !(pv instanceof LongValue)) {
        return vm.mirrorOf(pv.longValue());
    }
    if (type instanceof FloatType && !(pv instanceof FloatValue)) {
        return vm.mirrorOf(pv.floatValue());
    }
    if (type instanceof DoubleType && !(pv instanceof DoubleValue)) {
        return vm.mirrorOf(pv.doubleValue());
    }
    return pv;
}
项目:incubator-netbeans    文件:EvaluatorVisitor.java   
@Override
public int compareTo(ByteValue o) {
    return value - ((ByteValue)o).value();
}
项目:openjdk-jdk10    文件:ByteValueImpl.java   
public int compareTo(ByteValue obj) {
    byte other = obj.value();
    return value() - other;
}
项目:openjdk-jdk10    文件:VirtualMachineImpl.java   
public ByteValue mirrorOf(byte value) {
    validateVM();
    return new ByteValueImpl(this,value);
}
项目:intellij-ce-playground    文件:ByteValueImpl.java   
@Override
public int compareTo(ByteValue o) {
  return value() - o.value();
}
项目:form-follows-function    文件:F3SequenceReference.java   
private ByteValue getValueAsByte(int index) {
    Method getAsByteMethod = virtualMachine().f3SequenceType().getAsByteMethod();
    return (ByteValue) getElement(getAsByteMethod, index);
}
项目:form-follows-function    文件:F3SequenceReference.java   
private F3SequenceReference setByteValue(int index, ByteValue value) {
    Method setByteElementMethod = virtualMachine().f3SequencesType().setByteElementMethod();
    return setElement(setByteElementMethod, index, value);
}
项目:form-follows-function    文件:F3ByteValue.java   
public F3ByteValue(F3VirtualMachine f3vm, ByteValue underlying) {
    super(f3vm, underlying);
}
项目:form-follows-function    文件:F3ByteValue.java   
public int compareTo(ByteValue o) {
    return underlying().compareTo((ByteValue)F3Wrapper.unwrap(o));
}
项目:form-follows-function    文件:F3ByteValue.java   
@Override
protected ByteValue underlying() {
    return (ByteValue) super.underlying();
}
项目:form-follows-function    文件:F3VirtualMachine.java   
protected F3ByteValue byteValue(ByteValue value) {
    return new F3ByteValue(this, value);
}
项目:java-debug    文件:NumericFormatterTest.java   
@Test
public void testValueOf() throws Exception {

    Value i = this.getLocalValue("i");
    Map<String, Object> options = formatter.getDefaultOptions();
    Value newValue = formatter.valueOf(formatter.toString(i, options), i.type(), options);
    assertNotNull("NumericFormatter should be able to create integer by string.", newValue);
    assertTrue("Should create an integer value.", newValue instanceof IntegerValue);
    assertEquals("Should create an integer with right value.", "111", newValue.toString());

    options.put(NUMERIC_FORMAT_OPTION, NumericFormatEnum.HEX);

    newValue = formatter.valueOf(formatter.toString(i, options), i.type(), options);
    assertNotNull("NumericFormatter should be able to create integer by string.", newValue);
    assertTrue("Should create an integer value.", newValue instanceof IntegerValue);
    assertEquals("Should create an integer with right value.", "111", newValue.toString());

    options.put(NUMERIC_FORMAT_OPTION, NumericFormatEnum.OCT);
    newValue = formatter.valueOf(formatter.toString(i, options), i.type(), options);
    assertNotNull("NumericFormatter should be able to create integer by string.", newValue);
    assertTrue("Should create an integer value.", newValue instanceof IntegerValue);
    assertEquals("Should create an integer with right value.", "111", newValue.toString());


    newValue = formatter.valueOf("-12121212", i.type(), options);
    assertNotNull("NumericFormatter should be able to create integer by string.", newValue);
    assertTrue("Should create an integer value.", newValue instanceof IntegerValue);
    assertEquals("Should create an integer with right value.", "-12121212", newValue.toString());

    newValue = formatter.valueOf("0", i.type(), options);
    assertNotNull("NumericFormatter should be able to create integer by string.", newValue);
    assertTrue("Should create an integer value.", newValue instanceof IntegerValue);
    assertEquals("Should create an integer with right value.", "0", newValue.toString());

    VirtualMachine vm = getVM();

    newValue = formatter.valueOf("0", vm.mirrorOf(10.0f).type(), options);
    assertNotNull("NumericFormatter should be able to create float by string.", newValue);
    assertTrue("Should create an float value.", newValue instanceof FloatValue);
    assertEquals("Should create an float with right value.", "0.0", newValue.toString());

    newValue = formatter.valueOf("10.0", vm.mirrorOf(10.0).type(), options);
    assertNotNull("NumericFormatter should be able to create double by string.", newValue);
    assertTrue("Should create an double value.", newValue instanceof DoubleValue);
    assertEquals("Should create an double with right value.", "10.0", newValue.toString());

    newValue = formatter.valueOf("10", vm.mirrorOf((short)10).type(), options);
    assertNotNull("NumericFormatter should be able to create short by string.", newValue);
    assertTrue("Should create an short value.", newValue instanceof ShortValue);
    assertEquals("Should create an short with right value.", "10", newValue.toString());

    newValue = formatter.valueOf("10", vm.mirrorOf(10L).type(), options);
    assertNotNull("NumericFormatter should be able to create long by string.", newValue);
    assertTrue("Should create an long value.", newValue instanceof LongValue);
    assertEquals("Should create an long with right value.", "10", newValue.toString());

    newValue = formatter.valueOf("10", vm.mirrorOf((byte) 10).type(), options);
    assertNotNull("NumericFormatter should be able to create byte by string.", newValue);
    assertTrue("Should create an byte value.", newValue instanceof ByteValue);
    assertEquals("Should create an byte with right value.", "10", newValue.toString());
}