Skip to content

Commit e9c7fa9

Browse files
SougandhSjukzi
authored andcommitted
Ignore HCR Failures for current session #347
Adds a checkbox to the HCR error alert box that allows users to ignore HCR failures only for the current debug session, rather than applying it to all future debug sessions. Fixes : #347
1 parent a59b48d commit e9c7fa9

6 files changed

Lines changed: 92 additions & 25 deletions

File tree

org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/DebugUIMessages.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ public class DebugUIMessages extends NLS {
142142
public static String JDIDebugUIPlugin_The_target_VM_does_not_support_hot_code_replace_1;
143143
public static String JDIDebugUIPlugin_3;
144144
public static String JDIDebugUIPlugin_4;
145+
public static String JDIDebugUIPlugin_5;
145146

146147
public static String JDIModelPresentation__No_explicit_return_value__30;
147148
public static String JDIModelPresentation__conditional__2;

org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/DebugUIMessages.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ JDIDebugUIPlugin_Stepping_may_be_hazardous_1=The virtual machine was unable to r
8888
JDIDebugUIPlugin_The_target_VM_does_not_support_hot_code_replace_1=The target VM does not support hot code replace
8989
JDIDebugUIPlugin_3=Do not show error &when hot code replace is not supported
9090
JDIDebugUIPlugin_0=Warning
91+
JDIDebugUIPlugin_5=Ignore errors in current session
9192

9293
JDIModelPresentation__No_explicit_return_value__30=(No explicit return value)
9394
JDIModelPresentation__conditional__2=[conditional]

org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/ErrorDialogWithToggle.java

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2011 IBM Corporation and others.
2+
* Copyright (c) 2000, 2024 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -15,6 +15,8 @@
1515

1616

1717
import org.eclipse.core.runtime.IStatus;
18+
import org.eclipse.debug.core.model.IDebugTarget;
19+
import org.eclipse.jdt.internal.debug.core.model.JDIDebugTarget;
1820
import org.eclipse.jface.dialogs.ErrorDialog;
1921
import org.eclipse.jface.dialogs.IDialogConstants;
2022
import org.eclipse.jface.preference.IPreferenceStore;
@@ -39,29 +41,45 @@ public class ErrorDialogWithToggle extends ErrorDialog {
3941
* The preference key which is set by the toggle button.
4042
* This key must be a boolean preference in the preference store.
4143
*/
42-
private String fPreferenceKey= null;
44+
private String fPreferenceKey;
4345
/**
4446
* The message displayed to the user, with the toggle button
4547
*/
46-
private String fToggleMessage= null;
47-
private Button fToggleButton= null;
48+
private String fToggleMessage1;
49+
private Button fToggleButton;
50+
/**
51+
* Optional message displayed to the user only applicable for HCR Failure, with the toggle button
52+
*/
53+
private String fToggleMessage2;
54+
55+
private Button fToggleButton2;
4856
/**
4957
* The preference store which will be affected by the toggle button
5058
*/
5159
IPreferenceStore fStore= null;
5260

61+
public ErrorDialogWithToggle(Shell parentShell, String dialogTitle, String message, IStatus status, String preferenceKey, String toggleMessage1, String toggleMessage2, IPreferenceStore store) {
62+
super(parentShell, dialogTitle, message, status, IStatus.WARNING | IStatus.ERROR | IStatus.INFO);
63+
fStore = store;
64+
fPreferenceKey = preferenceKey;
65+
fToggleMessage1 = toggleMessage1;
66+
fToggleMessage2 = toggleMessage2;
67+
}
5368
public ErrorDialogWithToggle(Shell parentShell, String dialogTitle, String message, IStatus status, String preferenceKey, String toggleMessage, IPreferenceStore store) {
5469
super(parentShell, dialogTitle, message, status, IStatus.WARNING | IStatus.ERROR | IStatus.INFO);
5570
fStore= store;
5671
fPreferenceKey= preferenceKey;
57-
fToggleMessage= toggleMessage;
72+
fToggleMessage1= toggleMessage;
5873
}
5974

6075
@Override
6176
protected Control createDialogArea(Composite parent) {
6277
Composite dialogComposite= (Composite) super.createDialogArea(parent);
6378
dialogComposite.setFont(parent.getFont());
64-
setToggleButton(createCheckButton(dialogComposite, fToggleMessage));
79+
setToggleButton(createCheckButton(dialogComposite, fToggleMessage1));
80+
if (fToggleMessage2 != null) {
81+
fToggleButton2 = createCheckButton(dialogComposite, fToggleMessage2);
82+
}
6583
getToggleButton().setSelection(!fStore.getBoolean(fPreferenceKey));
6684
applyDialogFont(dialogComposite);
6785
return dialogComposite;
@@ -76,24 +94,28 @@ private Button createCheckButton(Composite parent, String label) {
7694
button.setText(label);
7795

7896
GridData data = new GridData(SWT.NONE);
79-
data.horizontalSpan= 2;
97+
data.horizontalSpan = 2;
8098
data.horizontalAlignment= GridData.CENTER;
8199
button.setLayoutData(data);
82100
button.setFont(parent.getFont());
83101

84102
return button;
85103
}
86104

87-
@Override
88-
protected void buttonPressed(int id) {
105+
protected void buttonPressed(int id, IDebugTarget target) {
89106
if (id == IDialogConstants.OK_ID) { // was the OK button pressed?
90-
storePreference();
107+
storePreference(target);
91108
}
92109
super.buttonPressed(id);
93110
}
94111

95-
private void storePreference() {
112+
private void storePreference(IDebugTarget target) {
96113
fStore.setValue(fPreferenceKey, !getToggleButton().getSelection());
114+
if (fToggleButton2 != null) {
115+
if (target instanceof JDIDebugTarget jdiTarget) {
116+
jdiTarget.setHcrDebugErrorPref(fToggleButton2.getSelection());
117+
}
118+
}
97119
}
98120

99121
protected Button getToggleButton() {

org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/HotCodeReplaceErrorDialog.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2015 IBM Corporation and others.
2+
* Copyright (c) 2000, 2024 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -47,11 +47,10 @@ public class HotCodeReplaceErrorDialog extends ErrorDialogWithToggle {
4747
/**
4848
* Creates a new dialog which can terminate, disconnect or restart the given debug target.
4949
*
50-
* @param target the debug target
51-
* @see ErrorDialogWithToggle#ErrorDialogWithToggle(Shell, String, String, IStatus, String, String, IPreferenceStore)
50+
* @see ErrorDialogWithToggle#ErrorDialogWithToggle(Shell, String, String, IStatus, String, String,String, IPreferenceStore)
5251
*/
53-
public HotCodeReplaceErrorDialog(Shell parentShell, String dialogTitle, String message, IStatus status, String preferenceKey, String toggleMessage, IPreferenceStore store, IDebugTarget target) {
54-
super(parentShell, dialogTitle, message, status, preferenceKey, toggleMessage, store);
52+
public HotCodeReplaceErrorDialog(Shell parentShell, String dialogTitle, String message, IStatus status, String preferenceKey, String toggleMessage, String toggleMessage2, IPreferenceStore store, IDebugTarget target) {
53+
super(parentShell, dialogTitle, message, status, preferenceKey, toggleMessage, toggleMessage2, store);
5554
this.target = target;
5655
}
5756

@@ -143,7 +142,7 @@ public void run() {
143142
}
144143
okPressed();
145144
} else {
146-
super.buttonPressed(id);
145+
super.buttonPressed(id, target);
147146
}
148147
}
149148
}

org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/JavaHotCodeReplaceListener.java

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2015 IBM Corporation and others.
2+
* Copyright (c) 2000, 2024 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -22,6 +22,7 @@
2222
import org.eclipse.debug.ui.DebugUITools;
2323
import org.eclipse.jdt.debug.core.IJavaDebugTarget;
2424
import org.eclipse.jdt.debug.core.IJavaHotCodeReplaceListener;
25+
import org.eclipse.jdt.internal.debug.core.model.JDIDebugTarget;
2526
import org.eclipse.jdt.internal.debug.ui.snippeteditor.ScrapbookLauncher;
2627
import org.eclipse.jface.viewers.ILabelProvider;
2728
import org.eclipse.osgi.util.NLS;
@@ -33,7 +34,7 @@ public class JavaHotCodeReplaceListener implements IJavaHotCodeReplaceListener {
3334
private HotCodeReplaceErrorDialog fHotCodeReplaceFailedErrorDialog = null;
3435

3536
private final ILabelProvider fLabelProvider= DebugUITools.newDebugModelPresentation();
36-
37+
private final String toggleMessage = DebugUIMessages.JDIDebugUIPlugin_5;
3738
/**
3839
* @see IJavaHotCodeReplaceListener#hotCodeReplaceSucceeded(IJavaDebugTarget)
3940
*/
@@ -47,9 +48,11 @@ public void hotCodeReplaceSucceeded(IJavaDebugTarget target) {
4748
@Override
4849
public void hotCodeReplaceFailed(final IJavaDebugTarget target, final DebugException exception) {
4950
if ((exception != null &&!JDIDebugUIPlugin.getDefault().getPreferenceStore().getBoolean(IJDIPreferencesConstants.PREF_ALERT_HCR_FAILED)) ||
50-
((exception == null) && !JDIDebugUIPlugin.getDefault().getPreferenceStore().getBoolean(IJDIPreferencesConstants.PREF_ALERT_HCR_NOT_SUPPORTED))) {
51+
((exception == null) && !JDIDebugUIPlugin.getDefault().getPreferenceStore().getBoolean(IJDIPreferencesConstants.PREF_ALERT_HCR_NOT_SUPPORTED))
52+
|| checkFailurePopUpPref(target)) {
5153
return;
5254
}
55+
5356
// do not report errors for snippet editor targets
5457
// that do not support HCR. HCR is simulated by using
5558
// a new class loader for each evaluation
@@ -101,7 +104,7 @@ public void run() {
101104
}
102105
}
103106
Shell shell= JDIDebugUIPlugin.getActiveWorkbenchShell();
104-
fHotCodeReplaceFailedErrorDialog = new HotCodeReplaceErrorDialog(shell, title, message, status, preference, alertMessage, JDIDebugUIPlugin.getDefault().getPreferenceStore(), target) {
107+
fHotCodeReplaceFailedErrorDialog = new HotCodeReplaceErrorDialog(shell, title, message, status, preference, alertMessage, toggleMessage, JDIDebugUIPlugin.getDefault().getPreferenceStore(), target) {
105108
@Override
106109
public boolean close() {
107110
fHotCodeReplaceFailedErrorDialog = null;
@@ -119,7 +122,8 @@ public boolean close() {
119122
*/
120123
@Override
121124
public void obsoleteMethods(final IJavaDebugTarget target) {
122-
if (!JDIDebugUIPlugin.getDefault().getPreferenceStore().getBoolean(IJDIPreferencesConstants.PREF_ALERT_OBSOLETE_METHODS)) {
125+
if (!JDIDebugUIPlugin.getDefault().getPreferenceStore().getBoolean(IJDIPreferencesConstants.PREF_ALERT_OBSOLETE_METHODS)
126+
|| checkFailurePopUpPref(target)) {
123127
return;
124128
}
125129
final Display display= JDIDebugUIPlugin.getStandardDisplay();
@@ -131,19 +135,33 @@ public void obsoleteMethods(final IJavaDebugTarget target) {
131135
final String message= NLS.bind(DebugUIMessages.JDIDebugUIPlugin__0__contains_obsolete_methods_1, new Object[] {vmName});
132136
final IStatus status= new Status(IStatus.WARNING, JDIDebugUIPlugin.getUniqueIdentifier(), IStatus.WARNING, DebugUIMessages.JDIDebugUIPlugin_Stepping_may_be_hazardous_1, null);
133137
final String toggleMessage= DebugUIMessages.JDIDebugUIPlugin_2;
138+
final String toggleMessage2= DebugUIMessages.JDIDebugUIPlugin_5;
134139
display.asyncExec(new Runnable() {
135140
@Override
136141
public void run() {
137142
if (display.isDisposed()) {
138143
return;
139144
}
140145
Shell shell= JDIDebugUIPlugin.getActiveWorkbenchShell();
141-
HotCodeReplaceErrorDialog dialog= new HotCodeReplaceErrorDialog(shell, dialogTitle, message, status, IJDIPreferencesConstants.PREF_ALERT_OBSOLETE_METHODS,
142-
toggleMessage, JDIDebugUIPlugin.getDefault().getPreferenceStore(), target);
146+
HotCodeReplaceErrorDialog dialog = new HotCodeReplaceErrorDialog(shell, dialogTitle, message, status, IJDIPreferencesConstants.PREF_ALERT_OBSOLETE_METHODS, toggleMessage, toggleMessage2, JDIDebugUIPlugin.getDefault().getPreferenceStore(), target);
143147
dialog.setBlockOnOpen(false);
144148
dialog.open();
145149
}
146150
});
147151
}
148152

153+
/**
154+
* Check whether user has enabled or disabled HCR failure error pop up for current debug session
155+
*
156+
* @param target
157+
* IJavaDebugTarget of current debugging session
158+
* @return false if user wishes to see failure pop up, else true if user don't want see pop up
159+
*/
160+
private boolean checkFailurePopUpPref(IJavaDebugTarget target) {
161+
if (target instanceof JDIDebugTarget jdiTarget) {
162+
return jdiTarget.isHcrFailurePopUpEnabled();
163+
}
164+
return false;
165+
}
166+
149167
}

org.eclipse.jdt.debug/model/org/eclipse/jdt/internal/debug/core/model/JDIDebugTarget.java

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2017 IBM Corporation and others.
2+
* Copyright (c) 2000, 2024 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -338,6 +338,31 @@ public class JDIDebugTarget extends JDIDebugElement implements
338338
*/
339339
private final Map<Long, String> objectLabels = new HashMap<>();
340340

341+
/**
342+
* HCR failure alert pref for current debug session.
343+
*/
344+
private volatile boolean hcrDebugErrors = false;
345+
346+
/**
347+
* Returns the hcrDebugErrors boolean to decide whether HCR error pop-up should be shown or not for a debugging session dispatcher per debug
348+
* target.
349+
*
350+
* @return boolean
351+
*/
352+
public boolean isHcrFailurePopUpEnabled() {
353+
return hcrDebugErrors;
354+
}
355+
356+
/**
357+
* Sets the user preference for ignoring error pop-up for a debugging session
358+
*
359+
* @param preference
360+
* Sets true or false for showing pop-up
361+
*/
362+
public void setHcrDebugErrorPref(boolean preference) {
363+
hcrDebugErrors = preference;
364+
}
365+
341366
/**
342367
* Creates a new JDI debug target for the given virtual machine.
343368
*
@@ -3246,4 +3271,5 @@ public void filterNotLoadedTypes(List<IResource> resources, List<String> qualifi
32463271
}
32473272
}
32483273
}
3274+
32493275
}

0 commit comments

Comments
 (0)