Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJared Burns2004-11-16 23:53:20 +0000
committerJared Burns2004-11-16 23:53:20 +0000
commita8faf351654727eba60984d12a721d9c83c2695e (patch)
tree89eeab38dcd526d00d6e7a01b16626d308ab414e
parentf40c7afded201ce15ea2c035deb2a03ceda7c330 (diff)
downloadeclipse.jdt.debug-a8faf351654727eba60984d12a721d9c83c2695e.tar.gz
eclipse.jdt.debug-a8faf351654727eba60984d12a721d9c83c2695e.tar.xz
eclipse.jdt.debug-a8faf351654727eba60984d12a721d9c83c2695e.zip
Bug 56057 - AssignValueAction should do evaluations
-rw-r--r--org.eclipse.jdt.debug.ui/plugin.xml6
-rw-r--r--org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/JDIModelPresentation.java2
-rw-r--r--org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/actions/ActionMessages.properties16
-rw-r--r--org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/actions/ExpressionInputDialog.java245
-rw-r--r--org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/actions/JavaObjectValueEditor.java182
-rw-r--r--org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/actions/JavaPrimitiveValueEditor.java139
-rw-r--r--org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/actions/JavaVariableValueEditor.java53
-rw-r--r--org.eclipse.jdt.debug/model/org/eclipse/jdt/internal/debug/core/model/JDIArrayEntryVariable.java5
-rw-r--r--org.eclipse.jdt.debug/model/org/eclipse/jdt/internal/debug/core/model/JDIFieldVariable.java6
-rw-r--r--org.eclipse.jdt.debug/model/org/eclipse/jdt/internal/debug/core/model/JDILocalVariable.java5
-rw-r--r--org.eclipse.jdt.debug/model/org/eclipse/jdt/internal/debug/core/model/JDIModificationVariable.java30
11 files changed, 657 insertions, 32 deletions
diff --git a/org.eclipse.jdt.debug.ui/plugin.xml b/org.eclipse.jdt.debug.ui/plugin.xml
index 3314448d1..2e49345ce 100644
--- a/org.eclipse.jdt.debug.ui/plugin.xml
+++ b/org.eclipse.jdt.debug.ui/plugin.xml
@@ -2749,6 +2749,12 @@ M4 = Platform-specific fourth key
label="%InDeadlockColorDefinition.label"
categoryId="org.eclipse.debug.ui.presentation"
id="org.eclipse.jdt.debug.ui.InDeadlockColor"/>
+ </extension>
+ <extension
+ point="org.eclipse.debug.ui.variableValueEditors">
+ <variableValueEditor
+ modelId="org.eclipse.jdt.debug"
+ class="org.eclipse.jdt.internal.debug.ui.actions.JavaVariableValueEditor"/>
</extension>
</plugin>
diff --git a/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/JDIModelPresentation.java b/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/JDIModelPresentation.java
index c379d9c9a..1d6388f8b 100644
--- a/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/JDIModelPresentation.java
+++ b/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/JDIModelPresentation.java
@@ -527,7 +527,7 @@ public class JDIModelPresentation extends LabelProvider implements IDebugModelPr
* Given a JNI-style signature String for a IJavaValue, return true
* if the signature represents an Object or an array of Objects.
*/
- protected boolean isObjectValue(String signature) {
+ public static boolean isObjectValue(String signature) {
if (signature == null) {
return false;
}
diff --git a/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/actions/ActionMessages.properties b/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/actions/ActionMessages.properties
index bed2062d1..a632dd6f5 100644
--- a/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/actions/ActionMessages.properties
+++ b/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/actions/ActionMessages.properties
@@ -148,3 +148,19 @@ DetailOptionsDialog.2=As the label for variables with detail &formatters
DetailOptionsDialog.3=As the label for &all variables
DetailOptionsDialog.4=In &detail pane only
DetailOptionsDialog.5=&Edit Detail Formatters...
+JavaVariableValueEditor.0=Error Changing Value
+JavaVariableValueEditor.1=An exception occurred attempting to access variable.
+JavaObjectValueEditor.0=Error Changing Value
+JavaObjectValueEditor.1=An exception occurred attempting to change variable value
+JavaObjectValueEditor.2=Exception Changing Variable
+JavaObjectValueEditor.3=Unable to change variable value to the specified expression.
+JavaObjectValueEditor.4=Error Changing Variable
+JavaObjectValueEditor.5=Compilation errors:
+JavaPrimitiveValueEditor.0=Change Primitive Value
+JavaPrimitiveValueEditor.1=Enter a new value for {0}:
+JavaPrimitiveValueEditor.2=Error Changing Value
+JavaPrimitiveValueEditor.3=An exception occurred attempting to change the variable value.
+JavaPrimitiveValueEditor.4=Input must be a valid {0}.
+ExpressionInputDialog.0=Enter an evaluation for {0}. Valid evaluations can be either a single expression (e.g. "new Object()") or a series of statements that return a value.
+ExpressionInputDialog.1=Input an expression.
+ExpressionInputDialog.2=Change Object Value
diff --git a/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/actions/ExpressionInputDialog.java b/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/actions/ExpressionInputDialog.java
new file mode 100644
index 000000000..41be4cdd1
--- /dev/null
+++ b/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/actions/ExpressionInputDialog.java
@@ -0,0 +1,245 @@
+/*******************************************************************************
+ * Copyright (c) 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial implementation
+ *******************************************************************************/
+package org.eclipse.jdt.internal.debug.ui.actions;
+
+import java.util.Map;
+
+import org.eclipse.debug.core.DebugException;
+import org.eclipse.debug.core.model.IValue;
+import org.eclipse.jdt.debug.core.IJavaVariable;
+import org.eclipse.jdt.internal.debug.core.model.JDINullValue;
+import org.eclipse.jdt.internal.debug.ui.JDISourceViewer;
+import org.eclipse.jdt.internal.debug.ui.display.DisplayCompletionProcessor;
+import org.eclipse.jdt.internal.debug.ui.display.DisplayViewerConfiguration;
+import org.eclipse.jdt.internal.ui.JavaPlugin;
+import org.eclipse.jdt.ui.text.JavaTextTools;
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.resource.JFaceResources;
+import org.eclipse.jface.text.DefaultUndoManager;
+import org.eclipse.jface.text.Document;
+import org.eclipse.jface.text.DocumentEvent;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.IDocumentListener;
+import org.eclipse.jface.text.IDocumentPartitioner;
+import org.eclipse.jface.text.IUndoManager;
+import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
+import org.eclipse.jface.text.source.ISourceViewer;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.commands.AbstractHandler;
+import org.eclipse.ui.commands.ExecutionException;
+import org.eclipse.ui.commands.HandlerSubmission;
+import org.eclipse.ui.commands.IHandler;
+import org.eclipse.ui.commands.IWorkbenchCommandSupport;
+import org.eclipse.ui.commands.Priority;
+import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds;
+
+/**
+ * A dialog which prompts the user to enter an expression.
+ */
+public class ExpressionInputDialog extends Dialog {
+
+ private JDISourceViewer fViewer;
+ private DisplayCompletionProcessor fCompletionProcessor;
+ private IDocumentListener fDocumentListener;
+ private HandlerSubmission fSubmission;
+ private Text fErrorText;
+ private IJavaVariable fVariable;
+
+ private String fResult= null;
+
+ /**
+ * @param parentShell
+ */
+ protected ExpressionInputDialog(Shell parentShell, IJavaVariable variable) {
+ super(parentShell);
+ fVariable= variable;
+ }
+
+ protected Control createDialogArea(Composite parent) {
+ Composite composite= (Composite) super.createDialogArea(parent);
+ Label label= new Label(composite, SWT.WRAP);
+ label.setText(ActionMessages.getString("ExpressionInputDialog.0")); //$NON-NLS-1$
+ GridData data = new GridData(GridData.GRAB_HORIZONTAL
+ | GridData.GRAB_VERTICAL | GridData.HORIZONTAL_ALIGN_FILL
+ | GridData.VERTICAL_ALIGN_CENTER);
+ data.widthHint = convertHorizontalDLUsToPixels(IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH);
+ label.setLayoutData(data);
+ label.setFont(parent.getFont());
+
+ fViewer= new JDISourceViewer(composite, null, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
+ fViewer.setInput(parent);
+
+ fErrorText= new Text(composite, SWT.READ_ONLY);
+ fErrorText.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL
+ | GridData.HORIZONTAL_ALIGN_FILL));
+ fErrorText.setBackground(fErrorText.getDisplay()
+ .getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
+ fErrorText.setFont(parent.getFont());
+
+ // Configure the source viewer after creating the error text so that any
+ // necessary error messages can be set.
+ configureSourceViewer();
+ return composite;
+ }
+
+ private void configureSourceViewer() {
+ JavaTextTools tools= JavaPlugin.getDefault().getJavaTextTools();
+ IDocument document= new Document();
+ IDocumentPartitioner partitioner= tools.createDocumentPartitioner();
+ document.setDocumentPartitioner(partitioner);
+ partitioner.connect(document);
+ fViewer.configure(new DisplayViewerConfiguration() {
+ public IContentAssistProcessor getContentAssistantProcessor() {
+ return getCompletionProcessor();
+ }
+ });
+ fViewer.setEditable(true);
+ fViewer.setDocument(document);
+ final IUndoManager undoManager= new DefaultUndoManager(10);
+ fViewer.setUndoManager(undoManager);
+ undoManager.connect(fViewer);
+
+ fViewer.getTextWidget().setFont(JFaceResources.getTextFont());
+
+ Control control= fViewer.getControl();
+ GridData gd = new GridData(GridData.FILL_BOTH);
+ control.setLayoutData(gd);
+
+ gd= (GridData)fViewer.getControl().getLayoutData();
+ gd.heightHint= convertHeightInCharsToPixels(10);
+ gd.widthHint= convertWidthInCharsToPixels(40);
+ document.set(getInitialText(fVariable));
+
+ fDocumentListener= new IDocumentListener() {
+ public void documentAboutToBeChanged(DocumentEvent event) {
+ }
+ public void documentChanged(DocumentEvent event) {
+ refreshValidState();
+ }
+ };
+ fViewer.getDocument().addDocumentListener(fDocumentListener);
+
+ IHandler handler = new AbstractHandler() {
+ public Object execute(Map parameter) throws ExecutionException {
+ fViewer.doOperation(ISourceViewer.CONTENTASSIST_PROPOSALS);
+ return null;
+ }
+ };
+ fSubmission = new HandlerSubmission(null, fViewer.getControl().getShell(), null, ITextEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS, handler, Priority.MEDIUM); //$NON-NLS-1$
+ IWorkbench workbench = PlatformUI.getWorkbench();
+ IWorkbenchCommandSupport commandSupport = workbench.getCommandSupport();
+ commandSupport.addHandlerSubmission(fSubmission);
+ }
+
+ /**
+ * @param variable
+ * @return
+ */
+ private String getInitialText(IJavaVariable variable) {
+ try {
+ String signature = variable.getSignature();
+ if (signature.equals("Ljava/lang/String;")) { //$NON-NLS-1$
+ IValue value = variable.getValue();
+ if (!(value instanceof JDINullValue)) {
+ String currentValue= value.getValueString();
+ StringBuffer buffer= new StringBuffer(currentValue.length());
+ buffer.append('"'); // Surround value in quotes
+ char[] chars = currentValue.toCharArray();
+ for (int i = 0; i < chars.length; i++) {
+ char c = chars[i];
+ if (c == '"') {
+ buffer.append("\\\""); //$NON-NLS-1$
+ } else {
+ buffer.append(c);
+ }
+ }
+ buffer.append('"'); // Surround value in quotes
+ return buffer.toString();
+ }
+ }
+ } catch (DebugException e) {
+ }
+ return null;
+ }
+
+ /**
+ * Return the completion processor associated with this viewer.
+ * @return BreakPointConditionCompletionProcessor
+ */
+ protected DisplayCompletionProcessor getCompletionProcessor() {
+ if (fCompletionProcessor == null) {
+ fCompletionProcessor= new DisplayCompletionProcessor();
+ }
+ return fCompletionProcessor;
+ }
+
+ /**
+ * @see org.eclipse.jface.preference.FieldEditor#refreshValidState()
+ */
+ private void refreshValidState() {
+ String errorMessage= null;
+ String text= fViewer.getDocument().get();
+ boolean valid= text != null && text.trim().length() > 0;
+ if (!valid) {
+ errorMessage= ActionMessages.getString("ExpressionInputDialog.1"); //$NON-NLS-1$
+ }
+ setErrorMessage(errorMessage);
+ }
+
+ private void setErrorMessage(String message) {
+ if (message == null) {
+ message= ""; //$NON-NLS-1$
+ }
+ fErrorText.setText(message);
+ getButton(IDialogConstants.OK_ID).setEnabled(message.length() == 0);
+ }
+
+ protected void okPressed() {
+ fResult= fViewer.getDocument().get();
+
+ IWorkbench workbench = PlatformUI.getWorkbench();
+ IWorkbenchCommandSupport commandSupport = workbench.getCommandSupport();
+ commandSupport.removeHandlerSubmission(fSubmission);
+
+ fViewer.getDocument().removeDocumentListener(fDocumentListener);
+
+ super.okPressed();
+ }
+
+ /**
+ * Returns the text entered by the user or <code>null</code> if the user cancelled.
+ * @return
+ */
+ public String getResult() {
+ return fResult;
+ }
+
+ protected void configureShell(Shell newShell) {
+ super.configureShell(newShell);
+ newShell.setText(ActionMessages.getString("ExpressionInputDialog.2")); //$NON-NLS-1$
+ }
+
+ protected void createButtonsForButtonBar(Composite parent) {
+ super.createButtonsForButtonBar(parent);
+ //do this here because setting the text will set enablement on the ok
+ // button
+ refreshValidState();
+ }
+}
diff --git a/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/actions/JavaObjectValueEditor.java b/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/actions/JavaObjectValueEditor.java
new file mode 100644
index 000000000..d94252f1e
--- /dev/null
+++ b/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/actions/JavaObjectValueEditor.java
@@ -0,0 +1,182 @@
+/*******************************************************************************
+ * Copyright (c) 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial implementation
+ *******************************************************************************/
+package org.eclipse.jdt.internal.debug.ui.actions;
+
+import java.text.MessageFormat;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.debug.core.DebugEvent;
+import org.eclipse.debug.core.DebugException;
+import org.eclipse.debug.core.ILaunch;
+import org.eclipse.debug.core.model.ISourceLocator;
+import org.eclipse.debug.core.model.IValue;
+import org.eclipse.debug.core.model.IVariable;
+import org.eclipse.debug.internal.ui.DebugUIPlugin;
+import org.eclipse.debug.ui.DebugUITools;
+import org.eclipse.debug.ui.actions.IVariableValueEditor;
+import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.debug.core.IJavaDebugTarget;
+import org.eclipse.jdt.debug.core.IJavaStackFrame;
+import org.eclipse.jdt.debug.core.IJavaThread;
+import org.eclipse.jdt.debug.core.IJavaVariable;
+import org.eclipse.jdt.debug.eval.IAstEvaluationEngine;
+import org.eclipse.jdt.debug.eval.IEvaluationListener;
+import org.eclipse.jdt.debug.eval.IEvaluationResult;
+import org.eclipse.jdt.internal.debug.core.JDIDebugPlugin;
+import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin;
+import org.eclipse.jface.window.Window;
+import org.eclipse.swt.widgets.Shell;
+
+import com.sun.jdi.InvocationException;
+import com.sun.jdi.ObjectReference;
+
+/**
+ * A variable value editor which prompts the user to enter an expression
+ * for evaluation. The result of the evaluation is assigned to the variable.
+ */
+public class JavaObjectValueEditor implements IVariableValueEditor {
+
+ /* (non-Javadoc)
+ * @see org.eclipse.debug.ui.actions.IVariableValueEditor#editVariable(org.eclipse.debug.core.model.IVariable, org.eclipse.swt.widgets.Shell)
+ */
+ public boolean editVariable(IVariable variable, Shell shell) {
+ try {
+ ExpressionInputDialog dialog= new ExpressionInputDialog(shell, (IJavaVariable) variable);
+ //InputDialog dialog= new InputDialog(shell, "Change Object Value", MessageFormat.format("To assign a new value to {0}, enter a single expression or a series of statements that return a value:", new String[] { name }), initialValue, new ExpressionValidator());
+ if (dialog.open() == Window.OK) {
+ String result = dialog.getResult();
+ IValue newValue = evaluate(shell, result);
+ if (newValue != null) {
+ variable.setValue(newValue);
+ }
+ }
+ } catch (DebugException e) {
+ DebugUIPlugin.errorDialog(shell, ActionMessages.getString("JavaObjectValueEditor.0"), ActionMessages.getString("JavaObjectValueEditor.1"), e); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ return true;
+ }
+
+ /**
+ * Evaluates the given snippet. Reports any errors to the user.
+ * @param stringValue the snippet to evaluate
+ * @return the value that was computed or <code>null</code> if any errors occurred.
+ */
+ private IValue evaluate(Shell shell, String stringValue) throws DebugException {
+ IAdaptable adaptable = DebugUITools.getDebugContext();
+ IJavaStackFrame frame= (IJavaStackFrame) adaptable.getAdapter(IJavaStackFrame.class);
+ if (frame != null) {
+ IJavaThread thread = (IJavaThread) frame.getThread();
+ IJavaProject project= getProject(frame);
+ if (project != null) {
+ final IEvaluationResult[] results= new IEvaluationResult[1];
+ IAstEvaluationEngine engine = JDIDebugPlugin.getDefault().getEvaluationEngine(project, (IJavaDebugTarget) thread.getDebugTarget());
+ IEvaluationListener listener= new IEvaluationListener() {
+ public void evaluationComplete(IEvaluationResult result) {
+ synchronized (JavaObjectValueEditor.this) {
+ results[0]= result;
+ JavaObjectValueEditor.this.notifyAll();
+ }
+ }
+ };
+ synchronized(this) {
+ engine.evaluate(stringValue, frame, listener, DebugEvent.EVALUATION_IMPLICIT, false);
+ try {
+ this.wait();
+ } catch (InterruptedException e) {
+ }
+ }
+ IEvaluationResult result= results[0];
+ if (result == null) {
+ return null;
+ }
+ if (result.hasErrors()) {
+ DebugException exception = result.getException();
+ if (exception != null) {
+ String message = getExceptionMessage(exception);
+ IStatus status= DebugUIPlugin.newErrorStatus(message, null);
+ DebugUIPlugin.errorDialog(shell, ActionMessages.getString("JavaObjectValueEditor.2"), //$NON-NLS-1$
+ MessageFormat.format(ActionMessages.getString("JavaObjectValueEditor.3"), new String[] { message }), status); //$NON-NLS-1$
+ return null;
+ }
+ String[] messages = result.getErrorMessages();
+ StringBuffer buffer= new StringBuffer();
+ for (int i = 0; i < messages.length; i++) {
+ buffer.append(messages[i]).append("\n "); //$NON-NLS-1$
+ }
+ IStatus status= new Status(IStatus.ERROR, JDIDebugUIPlugin.getUniqueIdentifier(), IStatus.ERROR, buffer.toString(), null);
+ DebugUIPlugin.errorDialog(shell, ActionMessages.getString("JavaObjectValueEditor.4"), ActionMessages.getString("JavaObjectValueEditor.5"), status); //$NON-NLS-1$ //$NON-NLS-2$
+ return null;
+ }
+ return result.getValue();
+ }
+ }
+ return null;
+ }
+
+ /**
+ * (copied from EvaluateAction)
+ */
+ protected String getExceptionMessage(Throwable exception) {
+ if (exception instanceof CoreException) {
+ CoreException ce = (CoreException)exception;
+ Throwable throwable= ce.getStatus().getException();
+ if (throwable instanceof com.sun.jdi.InvocationException) {
+ return getInvocationExceptionMessage((com.sun.jdi.InvocationException)throwable);
+ } else if (throwable instanceof CoreException) {
+ // Traverse nested CoreExceptions
+ return getExceptionMessage(throwable);
+ }
+ return ce.getStatus().getMessage();
+ }
+ String message= MessageFormat.format(ActionMessages.getString("Evaluate.error.message.direct_exception"), new Object[] { exception.getClass() }); //$NON-NLS-1$
+ if (exception.getMessage() != null) {
+ message= MessageFormat.format(ActionMessages.getString("Evaluate.error.message.exception.pattern"), new Object[] { message, exception.getMessage() }); //$NON-NLS-1$
+ }
+ return message;
+ }
+
+ /**
+ * Returns a message for the exception wrapped in an invocation exception
+ */
+ protected String getInvocationExceptionMessage(com.sun.jdi.InvocationException exception) {
+ InvocationException ie= exception;
+ ObjectReference ref= ie.exception();
+ return MessageFormat.format(ActionMessages.getString("Evaluate.error.message.wrapped_exception"), new Object[] { ref.referenceType().name() }); //$NON-NLS-1$
+ }
+
+ /**
+ * Return the project associated with the given stack frame.
+ * (copied from JavaWatchExpressionDelegate)
+ */
+ private IJavaProject getProject(IJavaStackFrame javaStackFrame) {
+ ILaunch launch = javaStackFrame.getLaunch();
+ if (launch == null) {
+ return null;
+ }
+ ISourceLocator locator= launch.getSourceLocator();
+ if (locator == null) {
+ return null;
+ }
+
+ Object sourceElement = locator.getSourceElement(javaStackFrame);
+ if (!(sourceElement instanceof IJavaElement) && sourceElement instanceof IAdaptable) {
+ sourceElement = ((IAdaptable)sourceElement).getAdapter(IJavaElement.class);
+ }
+ if (sourceElement instanceof IJavaElement) {
+ return ((IJavaElement) sourceElement).getJavaProject();
+ }
+ return null;
+ }
+}
diff --git a/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/actions/JavaPrimitiveValueEditor.java b/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/actions/JavaPrimitiveValueEditor.java
new file mode 100644
index 000000000..68f81a9ae
--- /dev/null
+++ b/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/actions/JavaPrimitiveValueEditor.java
@@ -0,0 +1,139 @@
+/*******************************************************************************
+ * Copyright (c) 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial implementation
+ *******************************************************************************/
+package org.eclipse.jdt.internal.debug.ui.actions;
+
+import java.text.MessageFormat;
+
+import org.eclipse.debug.core.DebugException;
+import org.eclipse.debug.core.model.IVariable;
+import org.eclipse.debug.internal.ui.DebugUIPlugin;
+import org.eclipse.debug.ui.actions.IVariableValueEditor;
+import org.eclipse.jface.dialogs.IInputValidator;
+import org.eclipse.jface.dialogs.InputDialog;
+import org.eclipse.jface.window.Window;
+import org.eclipse.swt.widgets.Shell;
+
+/**
+ * A variable value editor that prompts the user to set a primitive's value.
+ */
+public class JavaPrimitiveValueEditor implements IVariableValueEditor {
+
+ /**
+ * The signature of the edited variable.
+ */
+ private String fSignature= null;
+
+ /**
+ * Creates a new editor for a variable with the given signature
+ * @param signature the signature of the primitive to be edited
+ */
+ public JavaPrimitiveValueEditor(String signature) {
+ fSignature= signature;
+ }
+
+ private JavaPrimitiveValueEditor() {
+ // Do not call.
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.debug.ui.actions.IVariableValueEditor#editVariable(org.eclipse.debug.core.model.IVariable, org.eclipse.swt.widgets.Shell)
+ */
+ public boolean editVariable(IVariable variable, Shell shell) {
+ try {
+ String name= variable.getName();
+ String title= ActionMessages.getString("JavaPrimitiveValueEditor.0"); //$NON-NLS-1$
+ String message= MessageFormat.format(ActionMessages.getString("JavaPrimitiveValueEditor.1"), new String[] {name}); //$NON-NLS-1$
+ String initialValue= variable.getValue().getValueString();
+ IInputValidator validator= new PrimitiveValidator();
+ InputDialog dialog= new InputDialog(shell, title, message, initialValue, validator);
+ if (dialog.open() == Window.OK) {
+ String stringValue = dialog.getValue();
+ variable.setValue(stringValue);
+ }
+ } catch (DebugException e) {
+ DebugUIPlugin.errorDialog(shell, ActionMessages.getString("JavaPrimitiveValueEditor.2"), ActionMessages.getString("JavaPrimitiveValueEditor.3"), e); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ return true;
+ }
+
+ /**
+ * Input validator for primitive types
+ */
+ protected class PrimitiveValidator implements IInputValidator {
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.dialogs.IInputValidator#isValid(java.lang.String)
+ */
+ public String isValid(String newText) {
+ String type= null;
+ switch (fSignature.charAt(0)) {
+ case 'B':
+ try {
+ Byte.parseByte(newText);
+ } catch (NumberFormatException e) {
+ type= "byte"; //$NON-NLS-1$
+ }
+ break;
+ case 'C':
+ if (newText.length() != 1) {
+ type="char"; //$NON-NLS-1$
+ }
+ break;
+ case 'D':
+ try {
+ Double.parseDouble(newText);
+ } catch (NumberFormatException e) {
+ type="double"; //$NON-NLS-1$
+ }
+ break;
+ case 'F':
+ try {
+ Float.parseFloat(newText);
+ } catch (NumberFormatException e) {
+ type="float"; //$NON-NLS-1$
+ }
+ break;
+ case 'I':
+ try {
+ Integer.parseInt(newText);
+ } catch (NumberFormatException e) {
+ type="int"; //$NON-NLS-1$
+ }
+ break;
+ case 'J':
+ try {
+ Long.parseLong(newText);
+ } catch (NumberFormatException e) {
+ type="long"; //$NON-NLS-1$
+ }
+ break;
+ case 'S':
+ try {
+ Short.parseShort(newText);
+ } catch (NumberFormatException e) {
+ type="short"; //$NON-NLS-1$
+ }
+ break;
+ case 'Z':
+ try {
+ Boolean.parseBoolean(newText);
+ } catch (NumberFormatException e) {
+ type="boolean"; //$NON-NLS-1$
+ }
+ break;
+ }
+ if (type != null) {
+ return MessageFormat.format(ActionMessages.getString("JavaPrimitiveValueEditor.4"), new String[] { type }); //$NON-NLS-1$
+ }
+ return null;
+ }
+ }
+
+}
diff --git a/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/actions/JavaVariableValueEditor.java b/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/actions/JavaVariableValueEditor.java
new file mode 100644
index 000000000..16d2eedea
--- /dev/null
+++ b/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/actions/JavaVariableValueEditor.java
@@ -0,0 +1,53 @@
+/*******************************************************************************
+ * Copyright (c) 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial implementation
+ *******************************************************************************/
+package org.eclipse.jdt.internal.debug.ui.actions;
+
+import org.eclipse.debug.core.DebugException;
+import org.eclipse.debug.core.model.IVariable;
+import org.eclipse.debug.internal.ui.DebugUIPlugin;
+import org.eclipse.debug.ui.actions.IVariableValueEditor;
+import org.eclipse.jdt.debug.core.IJavaType;
+import org.eclipse.jdt.debug.core.IJavaVariable;
+import org.eclipse.jdt.debug.eval.IEvaluationResult;
+import org.eclipse.jdt.internal.debug.ui.JDIModelPresentation;
+import org.eclipse.swt.widgets.Shell;
+
+/**
+ * Variable editor that prompts the user to edit Java variables
+ */
+public class JavaVariableValueEditor implements IVariableValueEditor {
+
+ /* (non-Javadoc)
+ * @see org.eclipse.debug.ui.actions.IVariableValueEditor#editVariable(org.eclipse.debug.core.model.IVariable, org.eclipse.swt.widgets.Shell)
+ */
+ public boolean editVariable(IVariable variable, Shell shell) {
+ IJavaVariable javaVariable = (IJavaVariable) variable.getAdapter(IJavaVariable.class);
+ if (javaVariable == null) {
+ return false;
+ }
+ String signature= null;
+ try {
+ IJavaType javaType = javaVariable.getJavaType();
+ signature = javaType.getSignature();
+ } catch (DebugException e) {
+ DebugUIPlugin.errorDialog(shell, ActionMessages.getString("JavaVariableValueEditor.0"), ActionMessages.getString("JavaVariableValueEditor.1"), e); //$NON-NLS-1$ //$NON-NLS-2$
+ return true;
+ }
+ if (JDIModelPresentation.isObjectValue(signature)) {
+ JavaObjectValueEditor editor= new JavaObjectValueEditor();
+ return editor.editVariable(javaVariable, shell);
+ }
+ // Primitive variabel
+ JavaPrimitiveValueEditor editor= new JavaPrimitiveValueEditor(signature);
+ return editor.editVariable(javaVariable, shell);
+ }
+
+}
diff --git a/org.eclipse.jdt.debug/model/org/eclipse/jdt/internal/debug/core/model/JDIArrayEntryVariable.java b/org.eclipse.jdt.debug/model/org/eclipse/jdt/internal/debug/core/model/JDIArrayEntryVariable.java
index d3caea22a..25baa0834 100644
--- a/org.eclipse.jdt.debug/model/org/eclipse/jdt/internal/debug/core/model/JDIArrayEntryVariable.java
+++ b/org.eclipse.jdt.debug/model/org/eclipse/jdt/internal/debug/core/model/JDIArrayEntryVariable.java
@@ -13,6 +13,7 @@ package org.eclipse.jdt.internal.debug.core.model;
import java.text.MessageFormat;
+import org.eclipse.debug.core.DebugEvent;
import org.eclipse.debug.core.DebugException;
import org.eclipse.debug.core.model.IValue;
@@ -72,13 +73,14 @@ public class JDIArrayEntryVariable extends JDIModificationVariable {
return "[" + getIndex() + "]"; //$NON-NLS-2$ //$NON-NLS-1$
}
- protected void setValue(Value value) throws DebugException {
+ protected void setJDIValue(Value value) throws DebugException {
ArrayReference ar= getArrayReference();
if (ar == null) {
requestFailed(JDIDebugModelMessages.getString("JDIArrayEntryVariable.value_modification_failed"), null); //$NON-NLS-1$
}
try {
ar.setValue(getIndex(), value);
+ fireChangeEvent(DebugEvent.CONTENT);
} catch (ClassNotLoadedException e) {
targetRequestFailed(MessageFormat.format(JDIDebugModelMessages.getString("JDIArrayEntryVariable.exception_modifying_variable_value"), new String[] {e.toString()}), e); //$NON-NLS-1$
} catch (InvalidTypeException e) {
@@ -169,6 +171,7 @@ public class JDIArrayEntryVariable extends JDIModificationVariable {
JDIValue value = (JDIValue)v;
try {
getArrayReference().setValue(getIndex(), value.getUnderlyingValue());
+ fireChangeEvent(DebugEvent.CONTENT);
} catch (InvalidTypeException e) {
targetRequestFailed(MessageFormat.format(JDIDebugModelMessages.getString("JDIArrayEntryVariable.exception_attempting_to_set_value_of_field"), new String[]{e.toString()}), e); //$NON-NLS-1$
} catch (ClassNotLoadedException e) {
diff --git a/org.eclipse.jdt.debug/model/org/eclipse/jdt/internal/debug/core/model/JDIFieldVariable.java b/org.eclipse.jdt.debug/model/org/eclipse/jdt/internal/debug/core/model/JDIFieldVariable.java
index 110c03c45..cd791c895 100644
--- a/org.eclipse.jdt.debug/model/org/eclipse/jdt/internal/debug/core/model/JDIFieldVariable.java
+++ b/org.eclipse.jdt.debug/model/org/eclipse/jdt/internal/debug/core/model/JDIFieldVariable.java
@@ -13,6 +13,7 @@ package org.eclipse.jdt.internal.debug.core.model;
import java.text.MessageFormat;
+import org.eclipse.debug.core.DebugEvent;
import org.eclipse.debug.core.DebugException;
import org.eclipse.debug.core.model.IValue;
import org.eclipse.jdt.debug.core.IJavaFieldVariable;
@@ -98,13 +99,14 @@ public class JDIFieldVariable extends JDIModificationVariable implements IJavaFi
}
}
- protected void setValue(Value value) throws DebugException {
+ protected void setJDIValue(Value value) throws DebugException {
try {
if (isStatic()) {
((ClassType)getField().declaringType()).setValue(getField(), value);
} else {
getObjectReference().setValue(getField(), value);
}
+ fireChangeEvent(DebugEvent.CONTENT);
} catch (ClassNotLoadedException e) {
targetRequestFailed(MessageFormat.format(JDIDebugModelMessages.getString("JDIFieldVariable.exception_modifying_value_1"), new String[] {e.toString()}), e); //$NON-NLS-1$
} catch (InvalidTypeException e) {
@@ -248,7 +250,7 @@ public class JDIFieldVariable extends JDIModificationVariable implements IJavaFi
*/
public void setValue(IValue v) throws DebugException {
if (verifyValue(v)) {
- setValue(((JDIValue)v).getUnderlyingValue());
+ setJDIValue(((JDIValue)v).getUnderlyingValue());
}
}
diff --git a/org.eclipse.jdt.debug/model/org/eclipse/jdt/internal/debug/core/model/JDILocalVariable.java b/org.eclipse.jdt.debug/model/org/eclipse/jdt/internal/debug/core/model/JDILocalVariable.java
index a50391fa2..2feaff860 100644
--- a/org.eclipse.jdt.debug/model/org/eclipse/jdt/internal/debug/core/model/JDILocalVariable.java
+++ b/org.eclipse.jdt.debug/model/org/eclipse/jdt/internal/debug/core/model/JDILocalVariable.java
@@ -13,6 +13,7 @@ package org.eclipse.jdt.internal.debug.core.model;
import java.text.MessageFormat;
+import org.eclipse.debug.core.DebugEvent;
import org.eclipse.debug.core.DebugException;
import org.eclipse.debug.core.model.IValue;
@@ -76,9 +77,10 @@ public class JDILocalVariable extends JDIModificationVariable {
/**
* @see JDIModificationVariable#setValue(Value)
*/
- protected void setValue(Value value) throws DebugException {
+ protected void setJDIValue(Value value) throws DebugException {
try {
getStackFrame().getUnderlyingStackFrame().setValue(getLocal(), value);
+ fireChangeEvent(DebugEvent.CONTENT);
} catch (ClassNotLoadedException e) {
targetRequestFailed(MessageFormat.format(JDIDebugModelMessages.getString("JDILocalVariable.exception_modifying_local_variable_value_1"), new String[] {e.toString()}), e); //$NON-NLS-1$
} catch (InvalidTypeException e) {
@@ -165,6 +167,7 @@ public class JDILocalVariable extends JDIModificationVariable {
JDIValue value = (JDIValue)v;
try {
getStackFrame().getUnderlyingStackFrame().setValue(getLocal(), value.getUnderlyingValue());
+ fireChangeEvent(DebugEvent.CONTENT);
} catch (InvalidTypeException e) {
targetRequestFailed(MessageFormat.format(JDIDebugModelMessages.getString("JDILocalVariable.exception_while_attempting_to_set_value_of_local_variable"), new String[]{e.toString()}), e); //$NON-NLS-1$
} catch (ClassNotLoadedException e) {
diff --git a/org.eclipse.jdt.debug/model/org/eclipse/jdt/internal/debug/core/model/JDIModificationVariable.java b/org.eclipse.jdt.debug/model/org/eclipse/jdt/internal/debug/core/model/JDIModificationVariable.java
index 7dc77d1a1..019671709 100644
--- a/org.eclipse.jdt.debug/model/org/eclipse/jdt/internal/debug/core/model/JDIModificationVariable.java
+++ b/org.eclipse.jdt.debug/model/org/eclipse/jdt/internal/debug/core/model/JDIModificationVariable.java
@@ -12,12 +12,10 @@ package org.eclipse.jdt.internal.debug.core.model;
import java.util.ArrayList;
-import org.eclipse.debug.core.DebugEvent;
import org.eclipse.debug.core.DebugException;
import org.eclipse.debug.core.model.IValue;
import org.eclipse.jdt.debug.core.IJavaValue;
-import com.sun.jdi.VMDisconnectedException;
import com.sun.jdi.Value;
import com.sun.jdi.VirtualMachine;
@@ -47,28 +45,7 @@ public abstract class JDIModificationVariable extends JDIVariable {
* @see org.eclipse.debug.core.model.IValueModification#supportsValueModification()
*/
public boolean supportsValueModification() {
- try {
- if (!isFinal()) {
- Value currentValue= getCurrentValue();
- if (currentValue != null) {
- String signature = currentValue.type().signature();
- return fgValidSignatures.contains(signature);
- }
- String signature = getSignature();
- return fgValidSignatures.contains(signature);
- }
- } catch (DebugException e) {
- logError(e);
- } catch (VMDisconnectedException e) {
- JDIDebugTarget target = (JDIDebugTarget)getDebugTarget();
- if (!target.isAvailable()) {
- return false;
- }
- logError(e);
- } catch (RuntimeException e) {
- logError(e);
- }
- return false;
+ return !isFinal();
}
protected Value generateVMValue(String expression) throws DebugException {
@@ -205,13 +182,12 @@ public abstract class JDIModificationVariable extends JDIVariable {
*/
public final void setValue(String expression) throws DebugException {
Value value= generateVMValue(expression);
- setValue(value);
- fireChangeEvent(DebugEvent.CONTENT);
+ setJDIValue(value);
}
/**
* Set this variable's value to the given value
*/
- protected abstract void setValue(Value value) throws DebugException;
+ protected abstract void setJDIValue(Value value) throws DebugException;
} \ No newline at end of file

Back to the top