@Override
 public PsiExpression getDescriptorEvaluation(DebuggerContext context) throws EvaluateException {
   PsiElementFactory elementFactory =
       JavaPsiFacade.getInstance(context.getProject()).getElementFactory();
   try {
     return elementFactory.createExpressionFromText(
         getName(), PositionUtil.getContextElement(context));
   } catch (IncorrectOperationException e) {
     throw new EvaluateException(
         DebuggerBundle.message("error.invalid.local.variable.name", getName()), 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);
   }
 }
  public void editNode(final DebuggerTreeNodeImpl node) {
    final DebuggerContextImpl context = getContext();
    final DebuggerExpressionComboBox comboBox =
        new DebuggerExpressionComboBox(
            getProject(),
            PositionUtil.getContextElement(context),
            "evaluation",
            DefaultCodeFragmentFactory.getInstance());
    comboBox.setText(((WatchItemDescriptor) node.getDescriptor()).getEvaluationText());
    comboBox.selectAll();

    DebuggerTreeInplaceEditor editor =
        new DebuggerTreeInplaceEditor(node) {
          public JComponent createInplaceEditorComponent() {
            return comboBox;
          }

          public JComponent getPreferredFocusedComponent() {
            return comboBox.getPreferredFocusedComponent();
          }

          public Editor getEditor() {
            return comboBox.getEditor();
          }

          public JComponent getEditorComponent() {
            return comboBox.getEditorComponent();
          }

          public void doOKAction() {
            if (comboBox.isPopupVisible()) {
              comboBox.selectPopupValue();
            }

            TextWithImports text = comboBox.getText();
            if (!text.isEmpty()) {
              WatchDebuggerTree.setWatchNodeText(node, text);
              comboBox.addRecent(text);
            } else {
              getWatchTree().removeWatch(node);
            }
            try {
              super.doOKAction();
            } finally {
              comboBox.dispose();
            }
          }

          public void cancelEditing() {
            comboBox.setPopupVisible(false);
            if (((WatchItemDescriptor) node.getDescriptor()).getEvaluationText().isEmpty()) {
              getWatchTree().removeWatch(node);
            }

            try {
              super.cancelEditing();
            } finally {
              comboBox.dispose();
            }
          }
        };
    editor.show();
  }
 protected DebuggerExpressionComboBox createEditor(final CodeFragmentFactory factory) {
   return new DebuggerExpressionComboBox(
       getProject(), PositionUtil.getContextElement(getDebuggerContext()), "evaluation", factory);
 }
 public PsiElement getEvaluationElement() {
   return PositionUtil.getContextElement(getSourcePosition());
 }
Exemple #6
0
 protected void setDebuggerContext(DebuggerContextImpl context) {
   final PsiElement contextElement = PositionUtil.getContextElement(context);
   myEditor.setContext(contextElement);
 }