Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'org.eclipse.jdt.debug/jdi/org/eclipse/jdi/internal/ValueImpl.java')
-rw-r--r--org.eclipse.jdt.debug/jdi/org/eclipse/jdi/internal/ValueImpl.java404
1 files changed, 222 insertions, 182 deletions
diff --git a/org.eclipse.jdt.debug/jdi/org/eclipse/jdi/internal/ValueImpl.java b/org.eclipse.jdt.debug/jdi/org/eclipse/jdi/internal/ValueImpl.java
index b006622ea..0bf7cb057 100644
--- a/org.eclipse.jdt.debug/jdi/org/eclipse/jdi/internal/ValueImpl.java
+++ b/org.eclipse.jdt.debug/jdi/org/eclipse/jdi/internal/ValueImpl.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2008 IBM Corporation and others.
+ * Copyright (c) 2000, 2011 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -10,7 +10,6 @@
*******************************************************************************/
package org.eclipse.jdi.internal;
-
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
@@ -35,10 +34,9 @@ import com.sun.jdi.Value;
import com.sun.jdi.VoidType;
/**
- * this class implements the corresponding interfaces
- * declared by the JDI specification. See the com.sun.jdi package
- * for more information.
- *
+ * this class implements the corresponding interfaces declared by the JDI
+ * specification. See the com.sun.jdi package for more information.
+ *
*/
public abstract class ValueImpl extends MirrorImpl implements Value {
/**
@@ -57,65 +55,70 @@ public abstract class ValueImpl extends MirrorImpl implements Value {
* @returns type of value.
*/
public abstract byte getTag();
-
+
/**
* @return Reads JDWP representation and returns new instance.
*/
- public static ValueImpl readWithTag(MirrorImpl target, DataInputStream in) throws IOException {
+ public static ValueImpl readWithTag(MirrorImpl target, DataInputStream in)
+ throws IOException {
byte tag = target.readByte("object tag", JdwpID.tagMap(), in); //$NON-NLS-1$
- return readWithoutTag(target, tag, in);
+ return readWithoutTag(target, tag, in);
}
-
+
/**
* @return Reads JDWP representation and returns new instance.
*/
- public static ValueImpl readWithoutTag(MirrorImpl target, int type, DataInputStream in) throws IOException {
+ public static ValueImpl readWithoutTag(MirrorImpl target, int type,
+ DataInputStream in) throws IOException {
VirtualMachineImpl vmImpl = target.virtualMachineImpl();
// See also ArrayReference Impl.
- switch(type) {
- case ArrayReferenceImpl.tag:
- return ArrayReferenceImpl.read(target, in);
- case ClassLoaderReferenceImpl.tag:
- return ClassLoaderReferenceImpl.read(target, in);
- case ClassObjectReferenceImpl.tag:
- return ClassObjectReferenceImpl.read(target, in);
- case StringReferenceImpl.tag:
- return StringReferenceImpl.read(target, in);
- case ObjectReferenceImpl.tag:
- return ObjectReferenceImpl.readObjectRefWithoutTag(target, in);
- case ThreadGroupReferenceImpl.tag:
- return ThreadGroupReferenceImpl.read(target, in);
- case ThreadReferenceImpl.tag:
- return ThreadReferenceImpl.read(target, in);
- case BooleanValueImpl.tag:
- return BooleanValueImpl.read(target, in);
- case ByteValueImpl.tag:
- return ByteValueImpl.read(target, in);
- case CharValueImpl.tag:
- return CharValueImpl.read(target, in);
- case DoubleValueImpl.tag:
- return DoubleValueImpl.read(target, in);
- case FloatValueImpl.tag:
- return FloatValueImpl.read(target, in);
- case IntegerValueImpl.tag:
- return IntegerValueImpl.read(target, in);
- case LongValueImpl.tag:
- return LongValueImpl.read(target, in);
- case ShortValueImpl.tag:
- return ShortValueImpl.read(target, in);
- case VoidValueImpl.tag:
- return new VoidValueImpl(vmImpl);
- case 0:
- return null;
- default:
- throw new InternalException(JDIMessages.ValueImpl_Invalid_Value_tag_encountered___1 + type);
+ switch (type) {
+ case ArrayReferenceImpl.tag:
+ return ArrayReferenceImpl.read(target, in);
+ case ClassLoaderReferenceImpl.tag:
+ return ClassLoaderReferenceImpl.read(target, in);
+ case ClassObjectReferenceImpl.tag:
+ return ClassObjectReferenceImpl.read(target, in);
+ case StringReferenceImpl.tag:
+ return StringReferenceImpl.read(target, in);
+ case ObjectReferenceImpl.tag:
+ return ObjectReferenceImpl.readObjectRefWithoutTag(target, in);
+ case ThreadGroupReferenceImpl.tag:
+ return ThreadGroupReferenceImpl.read(target, in);
+ case ThreadReferenceImpl.tag:
+ return ThreadReferenceImpl.read(target, in);
+ case BooleanValueImpl.tag:
+ return BooleanValueImpl.read(target, in);
+ case ByteValueImpl.tag:
+ return ByteValueImpl.read(target, in);
+ case CharValueImpl.tag:
+ return CharValueImpl.read(target, in);
+ case DoubleValueImpl.tag:
+ return DoubleValueImpl.read(target, in);
+ case FloatValueImpl.tag:
+ return FloatValueImpl.read(target, in);
+ case IntegerValueImpl.tag:
+ return IntegerValueImpl.read(target, in);
+ case LongValueImpl.tag:
+ return LongValueImpl.read(target, in);
+ case ShortValueImpl.tag:
+ return ShortValueImpl.read(target, in);
+ case VoidValueImpl.tag:
+ return new VoidValueImpl(vmImpl);
+ case 0:
+ return null;
+ default:
+ throw new InternalException(
+ JDIMessages.ValueImpl_Invalid_Value_tag_encountered___1
+ + type);
}
}
/**
* Writes value with value tag.
*/
- public void writeWithTag(MirrorImpl target, DataOutputStream out) throws IOException {
+ public void writeWithTag(MirrorImpl target, DataOutputStream out)
+ throws IOException {
target.writeByte(getTag(), "tag", JdwpID.tagMap(), out); //$NON-NLS-1$
write(target, out);
}
@@ -123,189 +126,226 @@ public abstract class ValueImpl extends MirrorImpl implements Value {
/**
* Writes value without value tag.
*/
- public abstract void write(MirrorImpl target, DataOutputStream out) throws IOException;
-
+ public abstract void write(MirrorImpl target, DataOutputStream out)
+ throws IOException;
+
/**
* Writes null value without value tag.
*/
- public static void writeNull(MirrorImpl target, DataOutputStream out) throws IOException {
+ public static void writeNull(MirrorImpl target, DataOutputStream out)
+ throws IOException {
JdwpObjectID nullID = new JdwpObjectID(target.virtualMachineImpl());
nullID.write(out);
if (target.fVerboseWriter != null)
target.fVerboseWriter.println("objectReference", nullID.value()); //$NON-NLS-1$
}
-
+
/**
* Writes null value with value tag.
*/
- public static void writeNullWithTag(MirrorImpl target, DataOutputStream out) throws IOException {
+ public static void writeNullWithTag(MirrorImpl target, DataOutputStream out)
+ throws IOException {
target.writeByte(ObjectReferenceImpl.tag, "tag", JdwpID.tagMap(), out); //$NON-NLS-1$
writeNull(target, out);
}
/**
- * Check the type and the vm of each values, according to the associated type.
- * For primitive values, convert the value for match the given type if needed.
- * The two list must have the same size.
+ * Check the type and the vm of each values, according to the associated
+ * type. For primitive values, convert the value for match the given type if
+ * needed. The two list must have the same size.
+ *
* @return the (converted) values.
* @see checkValue(Value, Type, VirtualMachineImpl)
*/
- protected static List checkValues(List values, List types, VirtualMachineImpl vm) throws InvalidTypeException {
- List result= new ArrayList(values.size());
- Iterator iterValues= values.iterator();
- Iterator iterTypes= types.iterator();
+ protected static List<Value> checkValues(List<?extends Value> values, List<Type> types,
+ VirtualMachineImpl vm) throws InvalidTypeException {
+ List<Value> result = new ArrayList<Value>(values.size());
+ Iterator<? extends Value> iterValues = values.iterator();
+ Iterator<Type> iterTypes = types.iterator();
while (iterValues.hasNext()) {
- Value value= (Value)iterValues.next();
- Type type= (Type)iterTypes.next();
+ Value value = iterValues.next();
+ Type type = iterTypes.next();
result.add(checkValue(value, type, vm));
}
return result;
}
/**
- * Check the type and the vm of the given value.
- * In case of primitive value, the value is converted if needed.
+ * Check the type and the vm of the given value. In case of primitive value,
+ * the value is converted if needed.
+ *
* @return the (converted) value.
- * @throws InvalidTypeException if the given value is no assignment
- * compatible with the given type.
- * @see checkPrimitiveValue(PrimitiveValueImpl, PrimitiveTypeImpl, PrimitiveTypeImpl)
+ * @throws InvalidTypeException
+ * if the given value is no assignment compatible with the given
+ * type.
+ * @see checkPrimitiveValue(PrimitiveValueImpl, PrimitiveTypeImpl,
+ * PrimitiveTypeImpl)
*/
- public static ValueImpl checkValue(Value value, Type type, VirtualMachineImpl vm) throws InvalidTypeException {
+ public static ValueImpl checkValue(Value value, Type type,
+ VirtualMachineImpl vm) throws InvalidTypeException {
if (value == null) {
if (!(type instanceof PrimitiveType)) {
- return null;
+ return null;
}
} else {
vm.checkVM(value);
- TypeImpl valueType= (TypeImpl)value.type();
- if (valueType instanceof PrimitiveType && type instanceof PrimitiveType) {
- return checkPrimitiveValue((PrimitiveValueImpl) value, (PrimitiveTypeImpl) valueType, (PrimitiveTypeImpl) type);
- }
- if (valueType instanceof ReferenceType && type instanceof ReferenceType) {
- checkReferenceType((ReferenceType) valueType, (ReferenceType) type);
- return (ValueImpl)value;
+ TypeImpl valueType = (TypeImpl) value.type();
+ if (valueType instanceof PrimitiveType
+ && type instanceof PrimitiveType) {
+ return checkPrimitiveValue((PrimitiveValueImpl) value,
+ (PrimitiveTypeImpl) valueType, (PrimitiveTypeImpl) type);
+ }
+ if (valueType instanceof ReferenceType
+ && type instanceof ReferenceType) {
+ checkReferenceType((ReferenceType) valueType,
+ (ReferenceType) type);
+ return (ValueImpl) value;
}
- if(valueType instanceof VoidType && type instanceof VoidType) {
+ if (valueType instanceof VoidType && type instanceof VoidType) {
return (VoidValueImpl) value;
}
}
- throw new InvalidTypeException(MessageFormat.format(JDIMessages.ValueImpl_Type_of_the_value_not_compatible_with_the_expected_type__1, new String[]{value != null ? value.type().name() : "null", type.name()})); //$NON-NLS-1$
+ throw new InvalidTypeException(
+ MessageFormat
+ .format(JDIMessages.ValueImpl_Type_of_the_value_not_compatible_with_the_expected_type__1,
+ new Object[] {
+ value != null ? value.type().name()
+ : "null", type.name() })); //$NON-NLS-1$
}
/**
*/
- private static void checkReferenceType(ReferenceType valueType, ReferenceType type) throws InvalidTypeException {
- if (valueType instanceof ArrayType) {
- if (type instanceof ArrayType) {
- try {
- Type valueComponentType= ((ArrayType) valueType).componentType();
- Type componentType= ((ArrayType) type).componentType();
- if (valueComponentType instanceof PrimitiveType) {
- if (valueComponentType.equals(componentType)) {
- return;
- }
- } else if (valueComponentType instanceof ReferenceType && componentType instanceof ReferenceType) {
- checkReferenceType((ReferenceType) valueComponentType, (ReferenceType) componentType);
- return;
- }
- } catch (ClassNotLoadedException e) {
- // should not append
- }
- } else {
- // an array can be assigned to an object
- if (type.signature().equals("Ljava/lang/Object;")) { //$NON-NLS-1$
- return;
- }
- }
- } else {
- if (type instanceof ClassType) {
- if (valueType instanceof ClassType) {
- ClassType superClass= (ClassType) valueType;
- while (superClass != null) {
- if (superClass.equals(type)) {
- return;
- }
- superClass= superClass.superclass();
- }
- } else if (valueType instanceof InterfaceType) {
- // an interface can be assigned to an object
- if (type.signature().equals("Ljava/lang/Object;")) { //$NON-NLS-1$
- return;
- }
- }
- } else if (type instanceof InterfaceType) {
- if (valueType instanceof InterfaceType) {
- if (checkInterfaceType((InterfaceType) valueType, (InterfaceType) type)) {
- return;
- }
- } else {
- List interfaces= ((ClassType)valueType).allInterfaces();
- for (Iterator iter= interfaces.iterator(); iter.hasNext();) {
- if (checkInterfaceType((InterfaceType) iter.next(), (InterfaceType) type)) {
- return;
- }
- }
- }
- }
- }
-
- throw new InvalidTypeException(MessageFormat.format(JDIMessages.ValueImpl_Type_of_the_value_not_compatible_with_the_expected_type__1, new String[]{valueType.name(), type.name()}));
- }
-
- private static boolean checkInterfaceType(InterfaceType valueType, InterfaceType type) {
- if (valueType.equals(type)) {
- return true;
- }
- List superInterfaces= valueType.superinterfaces();
- for (Iterator iter= superInterfaces.iterator(); iter.hasNext();) {
- if (checkInterfaceType((InterfaceType) iter.next(), type)) {
- return true;
- }
- }
- return false;
- }
+ private static void checkReferenceType(ReferenceType valueType,
+ ReferenceType type) throws InvalidTypeException {
+ if (valueType instanceof ArrayType) {
+ if (type instanceof ArrayType) {
+ try {
+ Type valueComponentType = ((ArrayType) valueType)
+ .componentType();
+ Type componentType = ((ArrayType) type).componentType();
+ if (valueComponentType instanceof PrimitiveType) {
+ if (valueComponentType.equals(componentType)) {
+ return;
+ }
+ } else if (valueComponentType instanceof ReferenceType
+ && componentType instanceof ReferenceType) {
+ checkReferenceType((ReferenceType) valueComponentType,
+ (ReferenceType) componentType);
+ return;
+ }
+ } catch (ClassNotLoadedException e) {
+ // should not append
+ }
+ } else {
+ // an array can be assigned to an object
+ if (type.signature().equals("Ljava/lang/Object;")) { //$NON-NLS-1$
+ return;
+ }
+ }
+ } else {
+ if (type instanceof ClassType) {
+ if (valueType instanceof ClassType) {
+ ClassType superClass = (ClassType) valueType;
+ while (superClass != null) {
+ if (superClass.equals(type)) {
+ return;
+ }
+ superClass = superClass.superclass();
+ }
+ } else if (valueType instanceof InterfaceType) {
+ // an interface can be assigned to an object
+ if (type.signature().equals("Ljava/lang/Object;")) { //$NON-NLS-1$
+ return;
+ }
+ }
+ } else if (type instanceof InterfaceType) {
+ if (valueType instanceof InterfaceType) {
+ if (checkInterfaceType((InterfaceType) valueType,
+ (InterfaceType) type)) {
+ return;
+ }
+ } else {
+ List<InterfaceType> interfaces = ((ClassType) valueType).allInterfaces();
+ for (Iterator<InterfaceType> iter = interfaces.iterator(); iter.hasNext();) {
+ if (checkInterfaceType(iter.next(),
+ (InterfaceType) type)) {
+ return;
+ }
+ }
+ }
+ }
+ }
- /**
+ throw new InvalidTypeException(
+ MessageFormat
+ .format(JDIMessages.ValueImpl_Type_of_the_value_not_compatible_with_the_expected_type__1,
+ new Object[] { valueType.name(), type.name() }));
+ }
+
+ private static boolean checkInterfaceType(InterfaceType valueType,
+ InterfaceType type) {
+ if (valueType.equals(type)) {
+ return true;
+ }
+ List<InterfaceType> superInterfaces = valueType.superinterfaces();
+ for (Iterator<InterfaceType> iter = superInterfaces.iterator(); iter.hasNext();) {
+ if (checkInterfaceType(iter.next(), type)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
* Check the type of the given value, and convert the value to the given
* type if needed (see Java Language Spec, section 5.2).
+ *
* @return the (converted) value.
- * @throws InvalidTypeException if the given value is no assignment
- * compatible with the given type.
+ * @throws InvalidTypeException
+ * if the given value is no assignment compatible with the given
+ * type.
*/
- protected static ValueImpl checkPrimitiveValue(PrimitiveValueImpl value, PrimitiveTypeImpl valueType, PrimitiveTypeImpl type) throws InvalidTypeException {
- char valueTypeSignature= valueType.signature().charAt(0);
- char typeSignature= type.signature().charAt(0);
+ protected static ValueImpl checkPrimitiveValue(PrimitiveValueImpl value,
+ PrimitiveTypeImpl valueType, PrimitiveTypeImpl type)
+ throws InvalidTypeException {
+ char valueTypeSignature = valueType.signature().charAt(0);
+ char typeSignature = type.signature().charAt(0);
if (valueTypeSignature == typeSignature) {
return value;
}
- VirtualMachineImpl vm= value.virtualMachineImpl();
+ VirtualMachineImpl vm = value.virtualMachineImpl();
switch (typeSignature) {
- case 'D':
- if (valueTypeSignature != 'Z') {
- return new DoubleValueImpl(vm, new Double(value.doubleValue()));
- }
- break;
- case 'F':
- if (valueTypeSignature != 'Z' && valueTypeSignature != 'D') {
- return new FloatValueImpl(vm, new Float(value.floatValue()));
- }
- break;
- case 'J':
- if (valueTypeSignature != 'Z' && valueTypeSignature != 'D' && valueTypeSignature != 'F') {
- return new LongValueImpl(vm, new Long(value.longValue()));
- }
- break;
- case 'I':
- if (valueTypeSignature == 'B' || valueTypeSignature == 'C' || valueTypeSignature == 'S') {
- return new IntegerValueImpl(vm, new Integer(value.intValue()));
- }
- break;
- case 'S':
- if (valueTypeSignature == 'B') {
- return new ShortValueImpl(vm, new Short(value.shortValue()));
- }
- break;
+ case 'D':
+ if (valueTypeSignature != 'Z') {
+ return new DoubleValueImpl(vm, new Double(value.doubleValue()));
+ }
+ break;
+ case 'F':
+ if (valueTypeSignature != 'Z' && valueTypeSignature != 'D') {
+ return new FloatValueImpl(vm, new Float(value.floatValue()));
+ }
+ break;
+ case 'J':
+ if (valueTypeSignature != 'Z' && valueTypeSignature != 'D'
+ && valueTypeSignature != 'F') {
+ return new LongValueImpl(vm, new Long(value.longValue()));
+ }
+ break;
+ case 'I':
+ if (valueTypeSignature == 'B' || valueTypeSignature == 'C'
+ || valueTypeSignature == 'S') {
+ return new IntegerValueImpl(vm, new Integer(value.intValue()));
+ }
+ break;
+ case 'S':
+ if (valueTypeSignature == 'B') {
+ return new ShortValueImpl(vm, new Short(value.shortValue()));
+ }
+ break;
}
- throw new InvalidTypeException(MessageFormat.format(JDIMessages.ValueImpl_Type_of_the_value_not_compatible_with_the_expected_type__1, new String[]{valueType.name(), type.name()}));
+ throw new InvalidTypeException(
+ MessageFormat
+ .format(JDIMessages.ValueImpl_Type_of_the_value_not_compatible_with_the_expected_type__1,
+ new Object[] { valueType.name(), type.name() }));
}
}

Back to the top