allow to set value using the code with imports

This commit is contained in:
Egor Ushakov
2018-01-24 16:25:33 +03:00
parent 5772ba7eb0
commit 9e6f03a5ec
12 changed files with 52 additions and 131 deletions
@@ -1,18 +1,4 @@
/*
* Copyright 2000-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.debugger.actions;
import com.intellij.debugger.engine.DebuggerUtils;
@@ -28,6 +14,7 @@ import com.intellij.openapi.util.text.StringUtil;
import com.intellij.util.ui.JBUI;
import com.intellij.util.ui.components.BorderLayoutPanel;
import com.intellij.xdebugger.frame.XValue;
import com.intellij.xdebugger.impl.breakpoints.XExpressionImpl;
import com.intellij.xdebugger.impl.ui.DebuggerUIUtil;
import com.intellij.xdebugger.impl.ui.TextViewer;
import com.intellij.xdebugger.impl.ui.tree.XDebuggerTree;
@@ -131,7 +118,8 @@ public class ViewTextAction extends XFetchValueActionBase {
protected void doOKAction() {
if (myStringNode != null) {
DebuggerUIUtil.setTreeNodeValue(myStringNode,
StringUtil.wrapWithDoubleQuote(DebuggerUtils.translateStringValue(myTextViewer.getText())),
XExpressionImpl.fromText(
StringUtil.wrapWithDoubleQuote(DebuggerUtils.translateStringValue(myTextViewer.getText()))),
errorMessage -> Messages.showErrorDialog(myStringNode.getTree(), errorMessage));
}
super.doOKAction();
@@ -1,4 +1,4 @@
// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.debugger.engine;
import com.intellij.debugger.DebuggerBundle;
@@ -17,6 +17,7 @@ import com.intellij.openapi.progress.util.ProgressWindow;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.PsiElement;
import com.intellij.xdebugger.XExpression;
import com.intellij.xdebugger.frame.XValueModifier;
import com.sun.jdi.*;
import org.jetbrains.annotations.NotNull;
@@ -88,10 +89,10 @@ public abstract class JavaValueModifier extends XValueModifier {
//node.setState(context);
}
protected abstract void setValueImpl(@NotNull String expression, @NotNull XModificationCallback callback);
protected abstract void setValueImpl(@NotNull XExpression expression, @NotNull XModificationCallback callback);
@Override
public void setValue(@NotNull String expression, @NotNull XModificationCallback callback) {
public void setValue(@NotNull XExpression expression, @NotNull XModificationCallback callback) {
final NodeDescriptorImpl descriptor = myJavaValue.getDescriptor();
if(!((ValueDescriptorImpl)descriptor).canSetValue()) {
return;
@@ -145,7 +146,7 @@ public abstract class JavaValueModifier extends XValueModifier {
InvalidTypeException;
}
private static void setValue(String expressionToShow, ExpressionEvaluator evaluator, EvaluationContextImpl evaluationContext, SetValueRunnable setValueRunnable) throws EvaluateException {
private static void setValue(ExpressionEvaluator evaluator, EvaluationContextImpl evaluationContext, SetValueRunnable setValueRunnable) throws EvaluateException {
Value value;
try {
value = evaluator.evaluate(evaluationContext);
@@ -170,7 +171,7 @@ public abstract class JavaValueModifier extends XValueModifier {
refType = setValueRunnable.loadClass(evaluationContext, ex.className());
if (refType != null) {
//try again
setValue(expressionToShow, evaluator, evaluationContext, setValueRunnable);
setValue(evaluator, evaluationContext, setValueRunnable);
}
}
catch (InvocationException | InvalidTypeException | IncompatibleThreadStateException | ClassNotLoadedException e) {
@@ -182,7 +183,7 @@ public abstract class JavaValueModifier extends XValueModifier {
}
}
protected void set(@NotNull final String expression, final XModificationCallback callback, final DebuggerContextImpl debuggerContext, final SetValueRunnable setValueRunnable) {
protected void set(@NotNull final XExpression expression, final XModificationCallback callback, final DebuggerContextImpl debuggerContext, final SetValueRunnable setValueRunnable) {
final ProgressWindow progressWindow = new ProgressWindow(true, debuggerContext.getProject());
final EvaluationContextImpl evaluationContext = myJavaValue.getEvaluationContext();
@@ -200,12 +201,12 @@ public abstract class JavaValueModifier extends XValueModifier {
evaluator = DebuggerInvocationUtil.commitAndRunReadAction(project, new EvaluatingComputable<ExpressionEvaluator>() {
public ExpressionEvaluator compute() throws EvaluateException {
return EvaluatorBuilderImpl
.build(new TextWithImportsImpl(CodeFragmentKind.EXPRESSION, expression), context, position, project);
.build(TextWithImportsImpl.fromXExpression(expression), context, position, project);
}
});
setValue(expression, evaluator, evaluationContext, new SetValueRunnable() {
setValue(evaluator, evaluationContext, new SetValueRunnable() {
public void setValue(EvaluationContextImpl evaluationContext, Value newValue) throws ClassNotLoadedException,
InvalidTypeException,
EvaluateException,
@@ -1,18 +1,4 @@
/*
* Copyright 2000-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.debugger.ui.impl.watch;
import com.intellij.debugger.DebuggerBundle;
@@ -31,6 +17,7 @@ import com.intellij.psi.JavaPsiFacade;
import com.intellij.psi.PsiElementFactory;
import com.intellij.psi.PsiExpression;
import com.intellij.util.IncorrectOperationException;
import com.intellij.xdebugger.XExpression;
import com.intellij.xdebugger.frame.XValueModifier;
import com.sun.jdi.*;
import org.jetbrains.annotations.NotNull;
@@ -83,7 +70,7 @@ public class ArgumentValueDescriptorImpl extends ValueDescriptorImpl{
public XValueModifier getModifier(JavaValue value) {
return new JavaValueModifier(value) {
@Override
protected void setValueImpl(@NotNull String expression, @NotNull XModificationCallback callback) {
protected void setValueImpl(@NotNull XExpression expression, @NotNull XModificationCallback callback) {
final DecompiledLocalVariable local = ArgumentValueDescriptorImpl.this.getVariable();
if (local != null) {
final DebuggerContextImpl debuggerContext = DebuggerManagerEx.getInstanceEx(getProject()).getContext();
@@ -1,18 +1,4 @@
/*
* Copyright 2000-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.debugger.ui.impl.watch;
import com.intellij.debugger.DebuggerBundle;
@@ -32,6 +18,7 @@ import com.intellij.psi.JavaPsiFacade;
import com.intellij.psi.PsiElementFactory;
import com.intellij.psi.PsiExpression;
import com.intellij.util.IncorrectOperationException;
import com.intellij.xdebugger.XExpression;
import com.intellij.xdebugger.frame.XValueModifier;
import com.sun.jdi.*;
import org.jetbrains.annotations.NotNull;
@@ -86,7 +73,7 @@ public class ArrayElementDescriptorImpl extends ValueDescriptorImpl implements A
public XValueModifier getModifier(JavaValue value) {
return new JavaValueModifier(value) {
@Override
protected void setValueImpl(@NotNull String expression, @NotNull XModificationCallback callback) {
protected void setValueImpl(@NotNull XExpression expression, @NotNull XModificationCallback callback) {
final ArrayElementDescriptorImpl elementDescriptor = ArrayElementDescriptorImpl.this;
final ArrayReference array = elementDescriptor.getArray();
if (array != null) {
@@ -1,4 +1,4 @@
// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.debugger.ui.impl.watch;
import com.intellij.debugger.DebuggerBundle;
@@ -23,6 +23,7 @@ import com.intellij.openapi.application.ReadAction;
import com.intellij.openapi.project.IndexNotReadyException;
import com.intellij.openapi.project.Project;
import com.intellij.psi.*;
import com.intellij.xdebugger.XExpression;
import com.intellij.xdebugger.frame.XValueModifier;
import com.sun.jdi.*;
import org.jetbrains.annotations.NotNull;
@@ -136,7 +137,7 @@ public abstract class EvaluationDescriptor extends ValueDescriptorImpl {
public XValueModifier getModifier(JavaValue value) {
return new JavaValueModifier(value) {
@Override
protected void setValueImpl(@NotNull String expression, @NotNull XModificationCallback callback) {
protected void setValueImpl(@NotNull XExpression expression, @NotNull XModificationCallback callback) {
final EvaluationDescriptor evaluationDescriptor = EvaluationDescriptor.this;
if (evaluationDescriptor.canSetValue()) {
final DebuggerContextImpl debuggerContext = DebuggerManagerEx.getInstanceEx(getProject()).getContext();
@@ -1,4 +1,4 @@
// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.debugger.ui.impl.watch;
import com.intellij.debugger.DebuggerBundle;
@@ -24,6 +24,7 @@ import com.intellij.psi.JavaPsiFacade;
import com.intellij.psi.PsiElementFactory;
import com.intellij.psi.PsiExpression;
import com.intellij.util.IncorrectOperationException;
import com.intellij.xdebugger.XExpression;
import com.intellij.xdebugger.frame.XValueModifier;
import com.sun.jdi.*;
import org.jetbrains.annotations.NotNull;
@@ -175,7 +176,7 @@ public class FieldDescriptorImpl extends ValueDescriptorImpl implements FieldDes
public XValueModifier getModifier(JavaValue value) {
return new JavaValueModifier(value) {
@Override
protected void setValueImpl(@NotNull String expression, @NotNull XModificationCallback callback) {
protected void setValueImpl(@NotNull XExpression expression, @NotNull XModificationCallback callback) {
final DebuggerContextImpl debuggerContext = DebuggerManagerEx.getInstanceEx(getProject()).getContext();
FieldDescriptorImpl fieldDescriptor = FieldDescriptorImpl.this;
final Field field = fieldDescriptor.getField();
@@ -1,18 +1,4 @@
/*
* Copyright 2000-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.debugger.ui.impl.watch;
import com.intellij.debugger.DebuggerBundle;
@@ -34,6 +20,7 @@ import com.intellij.psi.JavaPsiFacade;
import com.intellij.psi.PsiElementFactory;
import com.intellij.psi.PsiExpression;
import com.intellij.util.IncorrectOperationException;
import com.intellij.xdebugger.XExpression;
import com.intellij.xdebugger.frame.XValueModifier;
import com.sun.jdi.*;
import org.jetbrains.annotations.NotNull;
@@ -121,7 +108,7 @@ public class LocalVariableDescriptorImpl extends ValueDescriptorImpl implements
public XValueModifier getModifier(JavaValue value) {
return new JavaValueModifier(value) {
@Override
protected void setValueImpl(@NotNull String expression, @NotNull XModificationCallback callback) {
protected void setValueImpl(@NotNull XExpression expression, @NotNull XModificationCallback callback) {
final LocalVariableProxyImpl local = LocalVariableDescriptorImpl.this.getLocalVariable();
if (local != null) {
final DebuggerContextImpl debuggerContext = DebuggerManagerEx.getInstanceEx(getProject()).getContext();
@@ -1,18 +1,4 @@
/*
* Copyright 2000-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package org.jetbrains.debugger
import com.intellij.icons.AllIcons
@@ -24,6 +10,7 @@ import com.intellij.psi.PsiElement
import com.intellij.psi.PsiReference
import com.intellij.util.SmartList
import com.intellij.util.ThreeState
import com.intellij.xdebugger.XExpression
import com.intellij.xdebugger.XSourcePositionWrapper
import com.intellij.xdebugger.frame.*
import com.intellij.xdebugger.frame.presentation.XKeywordValuePresentation
@@ -313,8 +300,8 @@ class VariableView(override val variableName: String, private val variable: Vari
}
}
override fun setValue(expression: String, callback: XValueModifier.XModificationCallback) {
variable.valueModifier!!.setValue(variable, expression, evaluateContext)
override fun setValue(expression: XExpression, callback: XValueModifier.XModificationCallback) {
variable.valueModifier!!.setValue(variable, expression.expression, evaluateContext)
.doneRun {
value = null
callback.valueModified()
@@ -1,20 +1,7 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.xdebugger.frame;
import com.intellij.xdebugger.XExpression;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -23,12 +10,22 @@ import org.jetbrains.annotations.Nullable;
*/
public abstract class XValueModifier {
/**
* @deprecated Use {@link #setValue(XExpression, XModificationCallback)} instead
*/
@Deprecated
public void setValue(@NotNull String expression, @NotNull XModificationCallback callback) {
throw new AbstractMethodError();
}
/**
* Start modification of the value. Note that this method is called from the Event Dispatch Thread so it should return quickly
* @param expression new value
* @param callback used to notify that value has been successfully modified or an error occurs
*/
public abstract void setValue(@NotNull String expression, @NotNull XModificationCallback callback);
public void setValue(@NotNull XExpression expression, @NotNull XModificationCallback callback) {
setValue(expression.getExpression(), callback);
}
/**
* @return return text to show in expression editor when "Set Value" action is invoked
@@ -1,6 +1,4 @@
/*
* Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
*/
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.xdebugger.impl.ui;
import com.intellij.codeInsight.hint.HintUtil;
@@ -426,7 +424,7 @@ public class DebuggerUIUtil {
return object instanceof Obsolescent && ((Obsolescent)object).isObsolete();
}
public static void setTreeNodeValue(XValueNodeImpl valueNode, String text, Consumer<String> errorConsumer) {
public static void setTreeNodeValue(XValueNodeImpl valueNode, XExpression text, Consumer<String> errorConsumer) {
XDebuggerTree tree = valueNode.getTree();
Project project = tree.getProject();
XValueModifier modifier = valueNode.getValueContainer().getModifier();
@@ -1,18 +1,4 @@
/*
* Copyright 2000-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.xdebugger.impl.ui.tree;
import com.intellij.codeInsight.hint.HintManager;
@@ -106,7 +92,7 @@ public class SetValueInplaceEditor extends XDebuggerTreeInplaceEditor {
public void doOKAction() {
if (myModifier == null) return;
DebuggerUIUtil.setTreeNodeValue(myValueNode, getExpression().getExpression(), errorMessage -> {
DebuggerUIUtil.setTreeNodeValue(myValueNode, getExpression(), errorMessage -> {
Editor editor = getEditor();
if (editor != null) {
HintManager.getInstance().showErrorHint(editor, errorMessage);
@@ -1,6 +1,7 @@
package com.jetbrains.python.debugger;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.xdebugger.XExpression;
import com.intellij.xdebugger.frame.XValueModifier;
import org.jetbrains.annotations.NotNull;
@@ -16,10 +17,10 @@ public class PyValueModifier extends XValueModifier {
}
@Override
public void setValue(@NotNull final String expression, @NotNull final XModificationCallback callback) {
public void setValue(@NotNull final XExpression expression, @NotNull final XModificationCallback callback) {
ApplicationManager.getApplication().executeOnPooledThread(() -> {
try {
myDebugProcess.changeVariable(myVariable, expression);
myDebugProcess.changeVariable(myVariable, expression.getExpression());
callback.valueModified();
}
catch (PyDebuggerException e) {