Java Code Examples for com.sun.jdi.ObjectReference#type()

The following examples show how to use com.sun.jdi.ObjectReference#type() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JavaLogicalStructure.java    From java-debug with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Returns whether to support the logical structure view for the given object instance.
 */
public boolean providesLogicalStructure(ObjectReference obj) {
    Type variableType = obj.type();
    if (!(variableType instanceof ClassType)) {
        return false;
    }

    ClassType classType = (ClassType) variableType;
    while (classType != null) {
        if (Objects.equals(type, classType.name())) {
            return true;
        }

        classType = classType.superclass();
    }

    List<InterfaceType> interfaceTypes = ((ClassType) variableType).allInterfaces();
    for (InterfaceType interfaceType : interfaceTypes) {
        if (Objects.equals(type, interfaceType.name())) {
            return true;
        }
    }

    return false;
}
 
Example 2
Source File: VariableUtils.java    From java-debug with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Get the variables of the object.
 *
 * @param obj
 *            the object
 * @return the variable list
 * @throws AbsentInformationException
 *             when there is any error in retrieving information
 */
public static List<Variable> listFieldVariables(ObjectReference obj, boolean includeStatic) throws AbsentInformationException {
    List<Variable> res = new ArrayList<>();
    Type type = obj.type();
    if (type instanceof ArrayType) {
        int arrayIndex = 0;
        for (Value elementValue : ((ArrayReference) obj).getValues()) {
            Variable ele = new Variable(String.valueOf(arrayIndex++), elementValue);
            res.add(ele);
        }
        return res;
    }
    List<Field> fields = obj.referenceType().allFields().stream().filter(t -> includeStatic || !t.isStatic())
            .sorted((a, b) -> {
                try {
                    boolean v1isStatic = a.isStatic();
                    boolean v2isStatic = b.isStatic();
                    if (v1isStatic && !v2isStatic) {
                        return -1;
                    }
                    if (!v1isStatic && v2isStatic) {
                        return 1;
                    }
                    return a.name().compareToIgnoreCase(b.name());
                } catch (Exception e) {
                    logger.log(Level.SEVERE, String.format("Cannot sort fields: %s", e), e);
                    return -1;
                }
            }).collect(Collectors.toList());
    fields.forEach(f -> {
        Variable var = new Variable(f.name(), obj.getValue(f));
        var.field = f;
        res.add(var);
    });
    return res;
}
 
Example 3
Source File: VariableUtils.java    From java-debug with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Get the variables of the object with pagination.
 *
 * @param obj
 *            the object
 * @param start
 *            the start of the pagination
 * @param count
 *            the number of variables needed
 * @return the variable list
 * @throws AbsentInformationException
 *             when there is any error in retrieving information
 */
public static List<Variable> listFieldVariables(ObjectReference obj, int start, int count)
        throws AbsentInformationException {
    List<Variable> res = new ArrayList<>();
    Type type = obj.type();
    if (type instanceof ArrayType) {
        int arrayIndex = start;
        for (Value elementValue : ((ArrayReference) obj).getValues(start, count)) {
            res.add(new Variable(String.valueOf(arrayIndex++), elementValue));
        }
        return res;
    }
    throw new UnsupportedOperationException("Only Array type is supported.");
}