com.sun.jdi.Type Java Examples
The following examples show how to use
com.sun.jdi.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: VariableMirrorTranslator.java From netbeans with Apache License 2.0 | 6 votes |
private static Type boxType(Type t) { if (t instanceof ClassType) { String name = ((ClassType) t).name(); if (name.equals("java.lang.Boolean")) { t = t.virtualMachine().mirrorOf(true).type(); } else if (name.equals("java.lang.Byte")) { t = t.virtualMachine().mirrorOf((byte) 10).type(); } else if (name.equals("java.lang.Character")) { t = t.virtualMachine().mirrorOf('a').type(); } else if (name.equals("java.lang.Integer")) { t = t.virtualMachine().mirrorOf(10).type(); } else if (name.equals("java.lang.Long")) { t = t.virtualMachine().mirrorOf(10l).type(); } else if (name.equals("java.lang.Short")) { t = t.virtualMachine().mirrorOf((short)10).type(); } else if (name.equals("java.lang.Float")) { t = t.virtualMachine().mirrorOf(10f).type(); } else if (name.equals("java.lang.Double")) { t = t.virtualMachine().mirrorOf(10.0).type(); } } return t; }
Example #2
Source File: AbstractObjectVariable.java From netbeans with Apache License 2.0 | 6 votes |
public boolean hasAllTypes() { if (getInnerValue () == null) { return true; } Type t; synchronized (valueTypeLoaded) { if (!valueTypeLoaded[0]) { return false; } t = valueType; } if (t instanceof ClassType) { ClassType ct = (ClassType) t; if (!getDebugger().hasAllInterfaces(ct)) { return false; } synchronized (superClassLoaded) { if (!superClassLoaded[0]) { return false; } } } return true; }
Example #3
Source File: AbstractObjectVariable.java From netbeans with Apache License 2.0 | 6 votes |
public List<JPDAClassType> getAllInterfaces() { if (getInnerValue () == null) { return null; } try { Type t = getCachedType(); if (!(t instanceof ClassType)) { return null; } ClassType ct = (ClassType) t; return getDebugger().getAllInterfaces(ct); } catch (ObjectCollectedExceptionWrapper ocex) { return null; } catch (InternalExceptionWrapper ex) { return null; } catch (VMDisconnectedExceptionWrapper e) { return null; } }
Example #4
Source File: JavaLogicalStructure.java From java-debug with Eclipse Public License 1.0 | 6 votes |
/** * 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 #5
Source File: SetVariableRequestHandler.java From java-debug with Eclipse Public License 1.0 | 6 votes |
private Value handleSetValueForObject(String name, String belongToClass, String valueString, ObjectReference container, Map<String, Object> options) throws InvalidTypeException, ClassNotLoadedException { Value newValue; if (container instanceof ArrayReference) { ArrayReference array = (ArrayReference) container; Type eleType = ((ArrayType) array.referenceType()).componentType(); newValue = setArrayValue(array, eleType, Integer.parseInt(name), valueString, options); } else { if (StringUtils.isBlank(belongToClass)) { Field field = container.referenceType().fieldByName(name); if (field != null) { if (field.isStatic()) { newValue = this.setStaticFieldValue(container.referenceType(), field, name, valueString, options); } else { newValue = this.setObjectFieldValue(container, field, name, valueString, options); } } else { throw new IllegalArgumentException( String.format("SetVariableRequest: Variable %s cannot be found.", name)); } } else { newValue = setFieldValueWithConflict(container, container.referenceType().allFields(), name, belongToClass, valueString, options); } } return newValue; }
Example #6
Source File: VariableUtils.java From java-debug with Eclipse Public License 1.0 | 5 votes |
/** * Test whether the value has referenced objects. * * @param value * the value. * @param includeStatic * whether or not the static fields are visible. * @return true if this value is reference objects. */ public static boolean hasChildren(Value value, boolean includeStatic) { if (value == null || !(value instanceof ObjectReference)) { return false; } Type type = value.type(); if (type instanceof ArrayType) { return ((ArrayReference) value).length() > 0; } return value.type() instanceof ReferenceType && ((ReferenceType) type).allFields().stream() .filter(t -> includeStatic || !t.isStatic()).toArray().length > 0; }
Example #7
Source File: SimpleTypeFormatter.java From java-debug with Eclipse Public License 1.0 | 5 votes |
/** * Format a JDI type, using the <code>SimpleTypeFormatter.QUALIFIED_FORMAT_OPTION</code> to control whether or not * to use the fully qualified name. Set QUALIFIED_FORMAT_OPTION to true(<code>java.lang.Boolean</code>) to enable * fully qualified name, the default option for QUALIFIED_FORMAT_OPTION is false. * * @param type the Jdi type * @param options the format options * @return the type name */ @Override public String toString(Object type, Map<String, Object> options) { if (type == null) { return NullObjectFormatter.NULL_STRING; } String typeName = ((Type) type).name(); return showQualifiedClassName(options) ? typeName : trimTypeName(typeName); }
Example #8
Source File: NumericFormatter.java From java-debug with Eclipse Public License 1.0 | 5 votes |
@Override public Value valueOf(String value, Type type, Map<String, Object> options) { VirtualMachine vm = type.virtualMachine(); char signature0 = type.signature().charAt(0); if (signature0 == LONG || signature0 == INT || signature0 == SHORT || signature0 == BYTE) { long number = parseNumber(value); if (signature0 == LONG) { return vm.mirrorOf(number); } else if (signature0 == INT) { return vm.mirrorOf((int) number); } else if (signature0 == SHORT) { return vm.mirrorOf((short) number); } else if (signature0 == BYTE) { return vm.mirrorOf((byte) number); } } else if (hasFraction(signature0)) { double doubleNumber = parseFloatDouble(value); if (signature0 == DOUBLE) { return vm.mirrorOf(doubleNumber); } else { return vm.mirrorOf((float) doubleNumber); } } throw new UnsupportedOperationException(String.format("%s is not a numeric type.", type.name())); }
Example #9
Source File: NumericFormatter.java From java-debug with Eclipse Public License 1.0 | 5 votes |
/** * The conditional function for this formatter. * * @param type the JDI type * @return whether or not this formatter is expected to work on this value. */ @Override public boolean acceptType(Type type, Map<String, Object> options) { if (type == null) { return false; } char signature0 = type.signature().charAt(0); return signature0 == LONG || signature0 == INT || signature0 == SHORT || signature0 == BYTE || signature0 == FLOAT || signature0 == DOUBLE; }
Example #10
Source File: CharacterFormatter.java From java-debug with Eclipse Public License 1.0 | 5 votes |
@Override public boolean acceptType(Type type, Map<String, Object> options) { if (type == null) { return false; } char signature0 = type.signature().charAt(0); return signature0 == CHAR; }
Example #11
Source File: CharacterFormatter.java From java-debug with Eclipse Public License 1.0 | 5 votes |
@Override public Value valueOf(String value, Type type, Map<String, Object> options) { VirtualMachine vm = type.virtualMachine(); if (value == null) { return null; } if (value.length() == 3 && value.startsWith("'") && value.endsWith("'")) { return type.virtualMachine().mirrorOf(value.charAt(1)); } return vm.mirrorOf(value.charAt(0)); }
Example #12
Source File: NullObjectFormatter.java From java-debug with Eclipse Public License 1.0 | 5 votes |
@Override public Value valueOf(String value, Type type, Map<String, Object> options) { if (value == null || NULL_STRING.equals(value)) { return null; } throw new UnsupportedOperationException("Set value is not supported by NullObjectFormatter."); }
Example #13
Source File: BooleanFormatter.java From java-debug with Eclipse Public License 1.0 | 5 votes |
@Override public boolean acceptType(Type type, Map<String, Object> options) { if (type == null) { return false; } char signature0 = type.signature().charAt(0); return signature0 == BOOLEAN; }
Example #14
Source File: SetVariableRequestHandler.java From java-debug with Eclipse Public License 1.0 | 5 votes |
private Value setStaticFieldValue(Type declaringType, Field field, String name, String value, Map<String, Object> options) throws ClassNotLoadedException, InvalidTypeException { if (field.isFinal()) { throw new UnsupportedOperationException( String.format("SetVariableRequest: Final field %s cannot be changed.", name)); } if (!(declaringType instanceof ClassType)) { throw new UnsupportedOperationException( String.format("SetVariableRequest: Field %s in interface cannot be changed.", name)); } return setValueProxy(field.type(), value, newValue -> ((ClassType) declaringType).setValue(field, newValue), options); }
Example #15
Source File: Variable.java From java-debug with Eclipse Public License 1.0 | 5 votes |
/** * Get the declaring type of this variable if it is a field declared by some class. * * @return the declaring type of this variable. */ public Type getDeclaringType() { if (this.field != null) { return this.field.declaringType(); } return null; }
Example #16
Source File: JavaComponentInfo.java From netbeans with Apache License 2.0 | 5 votes |
@Override public Object getValue() throws IllegalAccessException, InvocationTargetException { synchronized (valueLock) { if (value == null) { value = valueCalculating; debugger.getRequestProcessor().post(new Runnable() { @Override public void run() { try { RemoteServices.runOnStoppedThread(t, new Runnable() { @Override public void run() { boolean[] isEditablePtr = new boolean[] { false }; Type[] typePtr = new Type[] { null }; String v = getValueLazy(isEditablePtr, typePtr); synchronized (valueLock) { value = v; valueIsEditable = isEditablePtr[0]; valueType = typePtr[0]; } ci.firePropertyChange(propertyName, null, v); } }, sType); } catch (PropertyVetoException ex) { value = ex.getLocalizedMessage(); } } }); } return value; } }
Example #17
Source File: VariableUtils.java From java-debug with Eclipse Public License 1.0 | 5 votes |
/** * 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 #18
Source File: VariableUtils.java From java-debug with Eclipse Public License 1.0 | 5 votes |
/** * 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."); }
Example #19
Source File: VariableFormatter.java From java-debug with Eclipse Public License 1.0 | 5 votes |
private static IFormatter getFormatter(Map<? extends IFormatter, Integer> formatterMap, Type type, Map<String, Object> options) { List<? extends IFormatter> formatterList = formatterMap.keySet().stream().filter(t -> t.acceptType(type, options)) .sorted((a, b) -> -Integer.compare(formatterMap.get(a), formatterMap.get(b))).collect(Collectors.toList()); if (formatterList.isEmpty()) { throw new UnsupportedOperationException(String.format("There is no related formatter for type %s.", type == null ? "null" : type.name())); } return formatterList.get(0); }
Example #20
Source File: VariableDetailUtils.java From java-debug with Eclipse Public License 1.0 | 5 votes |
private static String findInheritedType(Value value, Set<String> typeNames) { if (!(value instanceof ObjectReference)) { return null; } Type variableType = ((ObjectReference) value).type(); if (!(variableType instanceof ClassType)) { return null; } ClassType classType = (ClassType) variableType; while (classType != null) { if (typeNames.contains(classType.name())) { return classType.name(); } classType = classType.superclass(); } List<InterfaceType> interfaceTypes = ((ClassType) variableType).allInterfaces(); for (InterfaceType interfaceType : interfaceTypes) { if (typeNames.contains(interfaceType.name())) { return interfaceType.name(); } } return null; }
Example #21
Source File: JdtUtils.java From java-debug with Eclipse Public License 1.0 | 5 votes |
private static String getGenericName(ReferenceType type) throws DebugException { if (type instanceof ArrayType) { try { Type componentType; componentType = ((ArrayType) type).componentType(); if (componentType instanceof ReferenceType) { return getGenericName((ReferenceType) componentType) + "[]"; //$NON-NLS-1$ } return type.name(); } catch (ClassNotLoadedException e) { // we cannot create the generic name using the component type, // just try to create one with the information } } String signature = type.signature(); StringBuffer res = new StringBuffer(getTypeName(signature)); String genericSignature = type.genericSignature(); if (genericSignature != null) { String[] typeParameters = Signature.getTypeParameters(genericSignature); if (typeParameters.length > 0) { res.append('<').append(Signature.getTypeVariable(typeParameters[0])); for (int i = 1; i < typeParameters.length; i++) { res.append(',').append(Signature.getTypeVariable(typeParameters[i])); } res.append('>'); } } return res.toString(); }
Example #22
Source File: Candidates.java From nopol with GNU General Public License v2.0 | 5 votes |
public Candidates filter(Type type) { Candidates exps = new Candidates(); for (int i = 0; i < this.size(); i++) { Expression expression = this.get(i); if (expression instanceof Method) { continue; } if (expression.getValue().isAssignableTo(type)) { exps.add(expression); } } return exps; }
Example #23
Source File: StringObjectFormatter.java From java-debug with Eclipse Public License 1.0 | 5 votes |
@Override public Value valueOf(String value, Type type, Map<String, Object> options) { if (value == null || NullObjectFormatter.NULL_STRING.equals(value)) { return null; } if (value.length() >= 2 && value.startsWith(QUOTE_STRING) && value.endsWith(QUOTE_STRING)) { return type.virtualMachine().mirrorOf(StringUtils.substring(value, 1, -1)); } return type.virtualMachine().mirrorOf(value); }
Example #24
Source File: AbstractObjectVariable.java From netbeans with Apache License 2.0 | 5 votes |
public AbstractObjectVariable ( JPDADebuggerImpl debugger, Value value, String id ) { this(debugger, value, (com.sun.jdi.Type) null, id); }
Example #25
Source File: ObjectFormatter.java From java-debug with Eclipse Public License 1.0 | 5 votes |
@Override public Value valueOf(String value, Type type, Map<String, Object> options) { if (value == null || NullObjectFormatter.NULL_STRING.equals(value)) { return null; } throw new UnsupportedOperationException(String.format("Set value is not supported yet for type %s.", type.name())); }
Example #26
Source File: ObjectFormatter.java From java-debug with Eclipse Public License 1.0 | 5 votes |
@Override public boolean acceptType(Type type, Map<String, Object> options) { if (type == null) { return false; } char tag = type.signature().charAt(0); return (tag == OBJECT) || (tag == ARRAY) || (tag == STRING) || (tag == THREAD) || (tag == THREAD_GROUP) || (tag == CLASS_LOADER) || (tag == CLASS_OBJECT); }
Example #27
Source File: EvaluationContext.java From netbeans with Apache License 2.0 | 5 votes |
public ScriptVariable createScriptLocalVariable(String name, Type type) { Map<String, ScriptVariable> map = stack.peek(); ScriptVariable var = new ScriptVariable(name, type); map.put(name, var); scriptLocalVariables.put(name, var); return var; }
Example #28
Source File: EvaluationContext.java From netbeans with Apache License 2.0 | 4 votes |
@Override public Type getType() throws ClassNotLoadedException { return var.type(); }
Example #29
Source File: RemoteServices.java From netbeans with Apache License 2.0 | 4 votes |
public static List<ReferenceType> getAttachableListeners(JavaComponentInfo ci) { ObjectReference component = ci.getComponent(); List<ReferenceType> listenerClasses = new ArrayList<ReferenceType>(); try { ReferenceType clazz = ObjectReferenceWrapper.referenceType(component); List<Method> visibleMethods = ReferenceTypeWrapper.visibleMethods(clazz); for (Method m : visibleMethods) { String name = TypeComponentWrapper.name(m); if (!name.startsWith("add") || !name.endsWith("Listener")) { continue; } List<Type> argTypes; try { argTypes = MethodWrapper.argumentTypes(m); } catch (ClassNotLoadedException ex) { continue; } if (argTypes.size() != 1) { continue; } Type t = argTypes.get(0); if (!(t instanceof ReferenceType)) { continue; } ReferenceType rt = (ReferenceType) t; String lname = ReferenceTypeWrapper.name(rt); int i = lname.lastIndexOf('.'); if (i < 0) { i = 0; } else { i++; } int ii = lname.lastIndexOf('$', i); if (ii > i) { i = ii + 1; } //System.err.println(" getAttachableListeners() '"+name.substring(3)+"' should equal to '"+lname.substring(i)+"', lname = "+lname+", i = "+i); if (!name.substring(3).equals(lname.substring(i))) { // addXXXListener() method name does not match XXXListener simple class name. // TODO: Perhaps check removeXXXListener method instead of this. continue; } listenerClasses.add(rt); } } catch (ClassNotPreparedExceptionWrapper cnpex) { } catch (ObjectCollectedExceptionWrapper ocex) { } catch (InternalExceptionWrapper iex) { } catch (VMDisconnectedExceptionWrapper vdex) { } return listenerClasses; }
Example #30
Source File: Value.java From nopol with GNU General Public License v2.0 | 4 votes |
@Override public boolean isAssignableTo(Type refAss) { throw new NotImplementedException(); }