diff --git a/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/DebugUIMessages.java b/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/DebugUIMessages.java index 223d5fa756..e1647cf15f 100644 --- a/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/DebugUIMessages.java +++ b/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/DebugUIMessages.java @@ -142,6 +142,7 @@ public class DebugUIMessages extends NLS { public static String JDIDebugUIPlugin_The_target_VM_does_not_support_hot_code_replace_1; public static String JDIDebugUIPlugin_3; public static String JDIDebugUIPlugin_4; + public static String JDIDebugUIPlugin_5; public static String JDIModelPresentation__No_explicit_return_value__30; public static String JDIModelPresentation__conditional__2; diff --git a/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/DebugUIMessages.properties b/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/DebugUIMessages.properties index e93b81afbd..c57c23c01d 100644 --- a/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/DebugUIMessages.properties +++ b/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/DebugUIMessages.properties @@ -88,6 +88,7 @@ JDIDebugUIPlugin_Stepping_may_be_hazardous_1=The virtual machine was unable to r JDIDebugUIPlugin_The_target_VM_does_not_support_hot_code_replace_1=The target VM does not support hot code replace JDIDebugUIPlugin_3=Do not show error &when hot code replace is not supported JDIDebugUIPlugin_0=Warning +JDIDebugUIPlugin_5=Ignore errors in current session JDIModelPresentation__No_explicit_return_value__30=(No explicit return value) JDIModelPresentation__conditional__2=[conditional] diff --git a/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/ErrorDialogWithToggle.java b/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/ErrorDialogWithToggle.java index 7524f6411f..0089761bc2 100644 --- a/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/ErrorDialogWithToggle.java +++ b/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/ErrorDialogWithToggle.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2011 IBM Corporation and others. + * Copyright (c) 2000, 2024 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -15,6 +15,8 @@ import org.eclipse.core.runtime.IStatus; +import org.eclipse.debug.core.model.IDebugTarget; +import org.eclipse.jdt.internal.debug.core.model.JDIDebugTarget; import org.eclipse.jface.dialogs.ErrorDialog; import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.jface.preference.IPreferenceStore; @@ -39,29 +41,45 @@ public class ErrorDialogWithToggle extends ErrorDialog { * The preference key which is set by the toggle button. * This key must be a boolean preference in the preference store. */ - private String fPreferenceKey= null; + private String fPreferenceKey; /** * The message displayed to the user, with the toggle button */ - private String fToggleMessage= null; - private Button fToggleButton= null; + private String fToggleMessage1; + private Button fToggleButton; + /** + * Optional message displayed to the user only applicable for HCR Failure, with the toggle button + */ + private String fToggleMessage2; + + private Button fToggleButton2; /** * The preference store which will be affected by the toggle button */ IPreferenceStore fStore= null; + public ErrorDialogWithToggle(Shell parentShell, String dialogTitle, String message, IStatus status, String preferenceKey, String toggleMessage1, String toggleMessage2, IPreferenceStore store) { + super(parentShell, dialogTitle, message, status, IStatus.WARNING | IStatus.ERROR | IStatus.INFO); + fStore = store; + fPreferenceKey = preferenceKey; + fToggleMessage1 = toggleMessage1; + fToggleMessage2 = toggleMessage2; + } public ErrorDialogWithToggle(Shell parentShell, String dialogTitle, String message, IStatus status, String preferenceKey, String toggleMessage, IPreferenceStore store) { super(parentShell, dialogTitle, message, status, IStatus.WARNING | IStatus.ERROR | IStatus.INFO); fStore= store; fPreferenceKey= preferenceKey; - fToggleMessage= toggleMessage; + fToggleMessage1= toggleMessage; } @Override protected Control createDialogArea(Composite parent) { Composite dialogComposite= (Composite) super.createDialogArea(parent); dialogComposite.setFont(parent.getFont()); - setToggleButton(createCheckButton(dialogComposite, fToggleMessage)); + setToggleButton(createCheckButton(dialogComposite, fToggleMessage1)); + if (fToggleMessage2 != null) { + fToggleButton2 = createCheckButton(dialogComposite, fToggleMessage2); + } getToggleButton().setSelection(!fStore.getBoolean(fPreferenceKey)); applyDialogFont(dialogComposite); return dialogComposite; @@ -76,7 +94,7 @@ private Button createCheckButton(Composite parent, String label) { button.setText(label); GridData data = new GridData(SWT.NONE); - data.horizontalSpan= 2; + data.horizontalSpan = 2; data.horizontalAlignment= GridData.CENTER; button.setLayoutData(data); button.setFont(parent.getFont()); @@ -84,16 +102,20 @@ private Button createCheckButton(Composite parent, String label) { return button; } - @Override - protected void buttonPressed(int id) { + protected void buttonPressed(int id, IDebugTarget target) { if (id == IDialogConstants.OK_ID) { // was the OK button pressed? - storePreference(); + storePreference(target); } super.buttonPressed(id); } - private void storePreference() { + private void storePreference(IDebugTarget target) { fStore.setValue(fPreferenceKey, !getToggleButton().getSelection()); + if (fToggleButton2 != null) { + if (target instanceof JDIDebugTarget jdiTarget) { + jdiTarget.setHcrDebugErrorPref(fToggleButton2.getSelection()); + } + } } protected Button getToggleButton() { diff --git a/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/HotCodeReplaceErrorDialog.java b/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/HotCodeReplaceErrorDialog.java index 63511be2e0..39fd683000 100644 --- a/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/HotCodeReplaceErrorDialog.java +++ b/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/HotCodeReplaceErrorDialog.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2015 IBM Corporation and others. + * Copyright (c) 2000, 2024 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -47,11 +47,12 @@ public class HotCodeReplaceErrorDialog extends ErrorDialogWithToggle { /** * Creates a new dialog which can terminate, disconnect or restart the given debug target. * - * @param target the debug target - * @see ErrorDialogWithToggle#ErrorDialogWithToggle(Shell, String, String, IStatus, String, String, IPreferenceStore) + * @param target + * the debug target + * @see ErrorDialogWithToggle#ErrorDialogWithToggle(Shell, String, String, IStatus, String, String,String, IPreferenceStore) */ - public HotCodeReplaceErrorDialog(Shell parentShell, String dialogTitle, String message, IStatus status, String preferenceKey, String toggleMessage, IPreferenceStore store, IDebugTarget target) { - super(parentShell, dialogTitle, message, status, preferenceKey, toggleMessage, store); + public HotCodeReplaceErrorDialog(Shell parentShell, String dialogTitle, String message, IStatus status, String preferenceKey, String toggleMessage, String toggleMessage2, IPreferenceStore store, IDebugTarget target) { + super(parentShell, dialogTitle, message, status, preferenceKey, toggleMessage, toggleMessage2, store); this.target = target; } @@ -143,7 +144,7 @@ public void run() { } okPressed(); } else { - super.buttonPressed(id); + super.buttonPressed(id, target); } } } diff --git a/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/JavaHotCodeReplaceListener.java b/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/JavaHotCodeReplaceListener.java index 8eaca1ca13..3cedb09fda 100644 --- a/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/JavaHotCodeReplaceListener.java +++ b/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/JavaHotCodeReplaceListener.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2015 IBM Corporation and others. + * Copyright (c) 2000, 2024 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -22,6 +22,7 @@ import org.eclipse.debug.ui.DebugUITools; import org.eclipse.jdt.debug.core.IJavaDebugTarget; import org.eclipse.jdt.debug.core.IJavaHotCodeReplaceListener; +import org.eclipse.jdt.internal.debug.core.model.JDIDebugTarget; import org.eclipse.jdt.internal.debug.ui.snippeteditor.ScrapbookLauncher; import org.eclipse.jface.viewers.ILabelProvider; import org.eclipse.osgi.util.NLS; @@ -33,7 +34,7 @@ public class JavaHotCodeReplaceListener implements IJavaHotCodeReplaceListener { private HotCodeReplaceErrorDialog fHotCodeReplaceFailedErrorDialog = null; private final ILabelProvider fLabelProvider= DebugUITools.newDebugModelPresentation(); - + private final String toggleMessage = DebugUIMessages.JDIDebugUIPlugin_5; /** * @see IJavaHotCodeReplaceListener#hotCodeReplaceSucceeded(IJavaDebugTarget) */ @@ -46,10 +47,20 @@ public void hotCodeReplaceSucceeded(IJavaDebugTarget target) { */ @Override public void hotCodeReplaceFailed(final IJavaDebugTarget target, final DebugException exception) { + + boolean failurePopUp; + + if (target instanceof JDIDebugTarget jdiTarget) { + failurePopUp = jdiTarget.getHcrDebugErrorPref(); + } else { + failurePopUp = false; + } if ((exception != null &&!JDIDebugUIPlugin.getDefault().getPreferenceStore().getBoolean(IJDIPreferencesConstants.PREF_ALERT_HCR_FAILED)) || - ((exception == null) && !JDIDebugUIPlugin.getDefault().getPreferenceStore().getBoolean(IJDIPreferencesConstants.PREF_ALERT_HCR_NOT_SUPPORTED))) { + ((exception == null) && !JDIDebugUIPlugin.getDefault().getPreferenceStore().getBoolean(IJDIPreferencesConstants.PREF_ALERT_HCR_NOT_SUPPORTED)) + || failurePopUp) { return; } + // do not report errors for snippet editor targets // that do not support HCR. HCR is simulated by using // a new class loader for each evaluation @@ -101,7 +112,7 @@ public void run() { } } Shell shell= JDIDebugUIPlugin.getActiveWorkbenchShell(); - fHotCodeReplaceFailedErrorDialog = new HotCodeReplaceErrorDialog(shell, title, message, status, preference, alertMessage, JDIDebugUIPlugin.getDefault().getPreferenceStore(), target) { + fHotCodeReplaceFailedErrorDialog = new HotCodeReplaceErrorDialog(shell, title, message, status, preference, alertMessage, toggleMessage, JDIDebugUIPlugin.getDefault().getPreferenceStore(), target) { @Override public boolean close() { fHotCodeReplaceFailedErrorDialog = null; @@ -119,7 +130,14 @@ public boolean close() { */ @Override public void obsoleteMethods(final IJavaDebugTarget target) { - if (!JDIDebugUIPlugin.getDefault().getPreferenceStore().getBoolean(IJDIPreferencesConstants.PREF_ALERT_OBSOLETE_METHODS)) { + boolean failurePopUp; + if (target instanceof JDIDebugTarget jdiTarget) { + failurePopUp = jdiTarget.getHcrDebugErrorPref(); + } else { + failurePopUp = false; + } + if (!JDIDebugUIPlugin.getDefault().getPreferenceStore().getBoolean(IJDIPreferencesConstants.PREF_ALERT_OBSOLETE_METHODS) + || failurePopUp) { return; } final Display display= JDIDebugUIPlugin.getStandardDisplay(); @@ -131,6 +149,7 @@ public void obsoleteMethods(final IJavaDebugTarget target) { final String message= NLS.bind(DebugUIMessages.JDIDebugUIPlugin__0__contains_obsolete_methods_1, new Object[] {vmName}); final IStatus status= new Status(IStatus.WARNING, JDIDebugUIPlugin.getUniqueIdentifier(), IStatus.WARNING, DebugUIMessages.JDIDebugUIPlugin_Stepping_may_be_hazardous_1, null); final String toggleMessage= DebugUIMessages.JDIDebugUIPlugin_2; + final String toggleMessage2= DebugUIMessages.JDIDebugUIPlugin_5; display.asyncExec(new Runnable() { @Override public void run() { @@ -138,8 +157,7 @@ public void run() { return; } Shell shell= JDIDebugUIPlugin.getActiveWorkbenchShell(); - HotCodeReplaceErrorDialog dialog= new HotCodeReplaceErrorDialog(shell, dialogTitle, message, status, IJDIPreferencesConstants.PREF_ALERT_OBSOLETE_METHODS, - toggleMessage, JDIDebugUIPlugin.getDefault().getPreferenceStore(), target); + HotCodeReplaceErrorDialog dialog = new HotCodeReplaceErrorDialog(shell, dialogTitle, message, status, IJDIPreferencesConstants.PREF_ALERT_OBSOLETE_METHODS, toggleMessage, toggleMessage2, JDIDebugUIPlugin.getDefault().getPreferenceStore(), target); dialog.setBlockOnOpen(false); dialog.open(); } diff --git a/org.eclipse.jdt.debug/model/org/eclipse/jdt/internal/debug/core/model/JDIDebugTarget.java b/org.eclipse.jdt.debug/model/org/eclipse/jdt/internal/debug/core/model/JDIDebugTarget.java index 528d691dc1..73a99d5753 100644 --- a/org.eclipse.jdt.debug/model/org/eclipse/jdt/internal/debug/core/model/JDIDebugTarget.java +++ b/org.eclipse.jdt.debug/model/org/eclipse/jdt/internal/debug/core/model/JDIDebugTarget.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2017 IBM Corporation and others. + * Copyright (c) 2000, 2024 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -338,6 +338,19 @@ public class JDIDebugTarget extends JDIDebugElement implements */ private final Map objectLabels = new HashMap<>(); + /** + * HCR failure alert pref for current debug session. + */ + private boolean hcrDebugErrors = false; + + public boolean getHcrDebugErrorPref() { + return hcrDebugErrors; + } + + public void setHcrDebugErrorPref(boolean preference) { + hcrDebugErrors = preference; + } + /** * Creates a new JDI debug target for the given virtual machine. * @@ -3246,4 +3259,5 @@ public void filterNotLoadedTypes(List resources, List qualifi } } } + }