Ejemplo n.º 1
0
 /** Test JDI equals() and hashCode(). */
 public void testJDIEquality() {
   assertTrue("1", fField.equals(fField));
   Field other = getField("fString");
   assertTrue("2", !fField.equals(other));
   assertTrue("3", !fField.equals(new Object()));
   assertTrue("4", !fField.equals(null));
 }
 public FieldDescriptorImpl(Project project, ObjectReference objRef, @NotNull Field field) {
   super(project);
   myObject = objRef;
   myField = field;
   myIsStatic = field.isStatic();
   setLvalue(!field.isFinal());
 }
Ejemplo n.º 3
0
  protected boolean shouldDisplay(
      EvaluationContext context, @NotNull ObjectReference objInstance, @NotNull Field field) {
    final boolean isSynthetic = DebuggerUtils.isSynthetic(field);
    if (!SHOW_SYNTHETICS && isSynthetic) {
      return false;
    }
    if (SHOW_VAL_FIELDS_AS_LOCAL_VARIABLES && isSynthetic) {
      try {
        final StackFrameProxy frameProxy = context.getFrameProxy();
        if (frameProxy != null) {
          final Location location = frameProxy.location();
          if (location != null
              && objInstance.equals(context.getThisObject())
              && Comparing.equal(objInstance.referenceType(), location.declaringType())
              && StringUtil.startsWith(
                  field.name(), FieldDescriptorImpl.OUTER_LOCAL_VAR_FIELD_PREFIX)) {
            return false;
          }
        }
      } catch (EvaluateException ignored) {
      }
    }
    if (!SHOW_STATIC && field.isStatic()) {
      return false;
    }

    if (!SHOW_STATIC_FINAL && field.isStatic() && field.isFinal()) {
      return false;
    }

    return true;
  }
Ejemplo n.º 4
0
 @Override
 public String getName() {
   String name = myField.name();
   if (myField.isStatic()
       && !(myField.declaringType().name().equals(myParent.referenceType().name()))) {
     name = name + " (" + myField.declaringType().name() + ")";
   }
   return name;
 }
 @Override
 public String calcValueName() {
   if (NodeRendererSettings.getInstance().getClassRenderer().SHOW_DECLARED_TYPE) {
     return addDeclaredType(myField.typeName());
   }
   return super.calcValueName();
 }
Ejemplo n.º 6
0
 /** Test JDI type(). */
 public void testJDIType() {
   try {
     assertEquals("1", getMainClass(), fField.type());
   } catch (ClassNotLoadedException e) {
     assertTrue("2", false);
   }
 }
 public boolean isOuterLocalVariableValue() {
   try {
     return DebuggerUtils.isSynthetic(myField)
         && myField.name().startsWith(OUTER_LOCAL_VAR_FIELD_PREFIX);
   } catch (UnsupportedOperationException ignored) {
     return false;
   }
 }
 @Override
 public Value calcValue(EvaluationContextImpl evaluationContext) throws EvaluateException {
   DebuggerManagerThreadImpl.assertIsManagerThread();
   try {
     return (myObject != null)
         ? myObject.getValue(myField)
         : myField.declaringType().getValue(myField);
   } catch (ObjectCollectedException ignored) {
     throw EvaluateExceptionUtil.OBJECT_WAS_COLLECTED;
   }
 }
 @Override
 public String getName() {
   final String fieldName = myField.name();
   if (isOuterLocalVariableValue()
       && NodeRendererSettings.getInstance()
           .getClassRenderer()
           .SHOW_VAL_FIELDS_AS_LOCAL_VARIABLES) {
     return StringUtil.trimStart(fieldName, OUTER_LOCAL_VAR_FIELD_PREFIX);
   }
   return fieldName;
 }
 @Override
 public boolean isPrimitive() {
   if (myIsPrimitive == null) {
     final Value value = getValue();
     if (value != null) {
       myIsPrimitive = super.isPrimitive();
     } else {
       myIsPrimitive = DebuggerUtils.isPrimitiveType(myField.typeName());
     }
   }
   return myIsPrimitive.booleanValue();
 }
 @Override
 public String calcValueName() {
   String res = super.calcValueName();
   if (Boolean.TRUE.equals(getUserData(SHOW_DECLARING_TYPE))) {
     return NodeRendererSettings.getInstance()
             .getClassRenderer()
             .renderTypeName(myField.declaringType().name())
         + "."
         + res;
   }
   return res;
 }
Ejemplo n.º 12
0
 private void dump(
     OutputSink out, ObjectReference obj, ReferenceType refType, ReferenceType refTypeBase) {
   for (Field field : refType.fields()) {
     out.print("    ");
     if (!refType.equals(refTypeBase)) {
       out.print(refType.name() + ".");
     }
     out.print(field.name() + ": ");
     Object o = obj.getValue(field);
     out.println((o == null) ? "null" : o.toString()); // Bug ID 4374471
   }
   if (refType instanceof ClassType) {
     ClassType sup = ((ClassType) refType).superclass();
     if (sup != null) {
       dump(out, obj, sup, refTypeBase);
     }
   } else if (refType instanceof InterfaceType) {
     for (InterfaceType sup : ((InterfaceType) refType).superinterfaces()) {
       dump(out, obj, sup, refTypeBase);
     }
   }
 }
Ejemplo n.º 13
0
  public void setValue(Field field, Value value)
      throws InvalidTypeException, ClassNotLoadedException {

    validateMirror(field);
    validateMirrorOrNull(value);
    validateFieldSet(field);

    // More validation specific to setting from a ClassType
    if (!field.isStatic()) {
      throw new IllegalArgumentException("Must set non-static field through an instance");
    }

    try {
      JDWP.ClassType.SetValues.FieldValue[] values = new JDWP.ClassType.SetValues.FieldValue[1];
      values[0] =
          new JDWP.ClassType.SetValues.FieldValue(
              ((FieldImpl) field).ref(),
              // validate and convert if necessary
              ValueImpl.prepareForAssignment(value, (FieldImpl) field));

      try {
        JDWP.ClassType.SetValues.process(vm, this, values);
      } catch (JDWPException exc) {
        throw exc.toJDIException();
      }
    } catch (ClassNotLoadedException e) {
      /*
       * Since we got this exception,
       * the field type must be a reference type. The value
       * we're trying to set is null, but if the field's
       * class has not yet been loaded through the enclosing
       * class loader, then setting to null is essentially a
       * no-op, and we should allow it without an exception.
       */
      if (value != null) {
        throw e;
      }
    }
  }
 @Override
 public PsiExpression getDescriptorEvaluation(DebuggerContext context) throws EvaluateException {
   PsiElementFactory elementFactory = JavaPsiFacade.getInstance(myProject).getElementFactory();
   String fieldName;
   if (isStatic()) {
     String typeName = myField.declaringType().name().replace('$', '.');
     typeName =
         DebuggerTreeNodeExpression.normalize(
             typeName, PositionUtil.getContextElement(context), myProject);
     fieldName = typeName + "." + getName();
   } else {
     //noinspection HardCodedStringLiteral
     fieldName =
         isOuterLocalVariableValue()
             ? StringUtil.trimStart(getName(), OUTER_LOCAL_VAR_FIELD_PREFIX)
             : "this." + getName();
   }
   try {
     return elementFactory.createExpressionFromText(fieldName, null);
   } catch (IncorrectOperationException e) {
     throw new EvaluateException(DebuggerBundle.message("error.invalid.field.name", getName()), e);
   }
 }
Ejemplo n.º 15
0
  // copied from FrameVariablesTree
  private void buildVariables(
      DebuggerContextImpl debuggerContext,
      final EvaluationContextImpl evaluationContext,
      @NotNull DebugProcessImpl debugProcess,
      XValueChildrenList children,
      ObjectReference thisObjectReference,
      Location location)
      throws EvaluateException {
    final Set<String> visibleLocals = new HashSet<String>();
    if (NodeRendererSettings.getInstance().getClassRenderer().SHOW_VAL_FIELDS_AS_LOCAL_VARIABLES) {
      if (thisObjectReference != null
          && debugProcess.getVirtualMachineProxy().canGetSyntheticAttribute()) {
        final ReferenceType thisRefType = thisObjectReference.referenceType();
        if (thisRefType instanceof ClassType
            && location != null
            && thisRefType.equals(location.declaringType())
            && thisRefType.name().contains("$")) { // makes sense for nested classes only
          for (Field field : thisRefType.fields()) {
            if (DebuggerUtils.isSynthetic(field)
                && StringUtil.startsWith(
                    field.name(), FieldDescriptorImpl.OUTER_LOCAL_VAR_FIELD_PREFIX)) {
              final FieldDescriptorImpl fieldDescriptor =
                  myNodeManager.getFieldDescriptor(myDescriptor, thisObjectReference, field);
              children.add(JavaValue.create(fieldDescriptor, evaluationContext, myNodeManager));
              visibleLocals.add(fieldDescriptor.calcValueName());
            }
          }
        }
      }
    }

    boolean myAutoWatchMode = DebuggerSettings.getInstance().AUTO_VARIABLES_MODE;
    if (evaluationContext == null) {
      return;
    }
    final SourcePosition sourcePosition = debuggerContext.getSourcePosition();
    if (sourcePosition == null) {
      return;
    }

    try {
      if (!XDebuggerSettingsManager.getInstance().getDataViewSettings().isAutoExpressions()
          && !myAutoWatchMode) {
        // optimization
        superBuildVariables(evaluationContext, children);
      } else {
        final Map<String, LocalVariableProxyImpl> visibleVariables =
            getVisibleVariables(getStackFrameProxy());
        final Pair<Set<String>, Set<TextWithImports>> usedVars =
            ApplicationManager.getApplication()
                .runReadAction(
                    new Computable<Pair<Set<String>, Set<TextWithImports>>>() {
                      @Override
                      public Pair<Set<String>, Set<TextWithImports>> compute() {
                        return findReferencedVars(
                            ContainerUtil.union(visibleVariables.keySet(), visibleLocals),
                            sourcePosition);
                      }
                    });
        // add locals
        if (myAutoWatchMode) {
          for (String var : usedVars.first) {
            LocalVariableProxyImpl local = visibleVariables.get(var);
            if (local != null) {
              children.add(
                  JavaValue.create(
                      myNodeManager.getLocalVariableDescriptor(null, local),
                      evaluationContext,
                      myNodeManager));
            }
          }
        } else {
          superBuildVariables(evaluationContext, children);
        }
        final EvaluationContextImpl evalContextCopy =
            evaluationContext.createEvaluationContext(evaluationContext.getThisObject());
        evalContextCopy.setAutoLoadClasses(false);

        final Set<TextWithImports> extraVars =
            computeExtraVars(usedVars, sourcePosition, evaluationContext);

        // add extra vars
        addToChildrenFrom(extraVars, children, evaluationContext);

        // add expressions
        addToChildrenFrom(usedVars.second, children, evalContextCopy);
      }
    } catch (EvaluateException e) {
      if (e.getCause() instanceof AbsentInformationException) {
        children.add(
            new DummyMessageValueNode(
                MessageDescriptor.LOCAL_VARIABLES_INFO_UNAVAILABLE.getLabel(),
                XDebuggerUIConstants.INFORMATION_MESSAGE_ICON));
        // trying to collect values from variable slots
        try {
          for (Map.Entry<DecompiledLocalVariable, Value> entry :
              LocalVariablesUtil.fetchValues(getStackFrameProxy(), debugProcess).entrySet()) {
            children.add(
                JavaValue.create(
                    myNodeManager.getArgumentValueDescriptor(
                        null, entry.getKey(), entry.getValue()),
                    evaluationContext,
                    myNodeManager));
          }
        } catch (Exception ex) {
          LOG.info(ex);
        }
      } else {
        throw e;
      }
    }
  }
Ejemplo n.º 16
0
 /** Test JDI isTransient(). */
 public void testJDIIsTransient() {
   assertTrue("1", !fField.isTransient());
 }
Ejemplo n.º 17
0
 public int hashCode() {
   return myField.hashCode();
 }
 @Nullable
 @Override
 public String getDeclaredType() {
   return myField.typeName();
 }
Ejemplo n.º 19
0
 /** Test JDI typeName(). */
 public void testJDITypeName() {
   assertEquals("1", "org.eclipse.debug.jdi.tests.program.MainClass", fField.typeName());
 }
Ejemplo n.º 20
0
 /** Test JDI isVolatile(). */
 public void testJDIIsVolatile() {
   assertTrue("1", !fField.isVolatile());
 }
 @Override
 public String getName() {
   return myField.name();
 }