Пример #1
0
 protected static String calcLabel(ValueDescriptor descriptor) {
   final ValueDescriptorImpl valueDescriptor = (ValueDescriptorImpl) descriptor;
   final Value value = valueDescriptor.getValue();
   if (value instanceof ObjectReference) {
     if (value instanceof StringReference) {
       return ((StringReference) value).value();
     } else if (value instanceof ClassObjectReference) {
       ReferenceType type = ((ClassObjectReference) value).reflectedType();
       return (type != null) ? type.name() : "{...}";
     } else {
       final ObjectReference objRef = (ObjectReference) value;
       final Type type = objRef.type();
       if (type instanceof ClassType && ((ClassType) type).isEnum()) {
         final String name = getEnumConstantName(objRef, (ClassType) type);
         if (name != null) {
           return name;
         } else {
           return type.name();
         }
       } else {
         return "";
       }
     }
   } else if (value == null) {
     //noinspection HardCodedStringLiteral
     return "null";
   } else {
     return DebuggerBundle.message("label.undefined");
   }
 }
Пример #2
0
 public boolean equals(Object obj) {
   if ((obj != null) && (obj instanceof Type)) {
     Type other = (Type) obj;
     return signature().equals(other.signature()) && super.equals(obj);
   } else {
     return false;
   }
 }
Пример #3
0
 public List<Type> searchForType(String filter) {
   List<Type> result = new ArrayList<Type>();
   for (Type ref : this.vm.allClasses()) {
     if (ref.name().contains(filter)) {
       result.add(ref);
     }
   }
   return result;
 }
Пример #4
0
 /**
  * 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)
  */
 public static ValueImpl checkValue(Value value, Type type, VirtualMachineImpl vm)
     throws InvalidTypeException {
   if (value == null) {
     if (!(type instanceof PrimitiveType)) {
       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;
     }
     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 Object[] {
             value != null ? value.type().name() : "null", type.name()
           })); //$NON-NLS-1$
 }
 @Nullable
 private static String getTypeName(ValueDescriptorImpl descriptor) {
   Type type = descriptor.getType();
   return type != null ? type.name() : null;
 }
Пример #6
0
  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()}));
  }