Skip to content

Commit 47ea4b0

Browse files
vogellaakurtakov
authored andcommitted
Remove dispose call for Colors in AntPreviewerUpdater
According to the Javadoc on Colors: * Colors do not need to be disposed, however to maintain compatibility * with older code, disposing a Color is not an error.
1 parent 0faca59 commit 47ea4b0

File tree

3 files changed

+9
-80
lines changed

3 files changed

+9
-80
lines changed

ant/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/preferences/AntCodeFormatterPreferencePage.java

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* https://www.eclipse.org/legal/epl-2.0/
88
*
99
* SPDX-License-Identifier: EPL-2.0
10-
*
10+
*
1111
* Contributors:
1212
* IBM Corporation - initial API and implementation
1313
*******************************************************************************/
@@ -44,7 +44,6 @@
4444
public class AntCodeFormatterPreferencePage extends AbstractAntEditorPreferencePage {
4545

4646
private SourceViewer fPreviewViewer;
47-
private AntPreviewerUpdater fPreviewerUpdater;
4847

4948
@Override
5049
protected OverlayPreferenceStore createOverlayStore() {
@@ -137,7 +136,7 @@ private Control createPreviewer(Composite parent) {
137136
fPreviewViewer.getTextWidget().setFont(font);
138137

139138
IPreferenceStore store = new ChainedPreferenceStore(new IPreferenceStore[] { getOverlayStore(), EditorsUI.getPreferenceStore() });
140-
fPreviewerUpdater = new AntPreviewerUpdater(fPreviewViewer, configuration, store);
139+
new AntPreviewerUpdater(fPreviewViewer, configuration, store);
141140

142141
String content = loadPreviewContentFromFile("FormatPreviewCode.txt"); //$NON-NLS-1$
143142
content = formatContent(content, store);
@@ -159,14 +158,6 @@ protected void handleDefaults() {
159158
// do nothing
160159
}
161160

162-
@Override
163-
public void dispose() {
164-
super.dispose();
165-
if (fPreviewerUpdater != null) {
166-
fPreviewerUpdater.dispose();
167-
}
168-
}
169-
170161
@Override
171162
protected String getHelpContextId() {
172163
return IAntUIHelpContextIds.ANT_EDITOR_FORMATTER_PREFERENCE_PAGE;

ant/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/preferences/AntEditorPreferencePage.java

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
import java.util.ArrayList;
1818
import java.util.HashMap;
19-
import java.util.Iterator;
2019
import java.util.List;
2120
import java.util.Map;
2221

@@ -105,7 +104,7 @@ public int getSelection(String value) {
105104

106105
/**
107106
* Item in the highlighting color list.
108-
*
107+
*
109108
* @since 3.0
110109
*/
111110
private static class HighlightingColorListItem {
@@ -122,7 +121,7 @@ private static class HighlightingColorListItem {
122121

123122
/**
124123
* Initialize the item with the given values.
125-
*
124+
*
126125
* @param displayName
127126
* the display name
128127
* @param colorKey
@@ -180,7 +179,7 @@ public Color getItemColor() {
180179

181180
/**
182181
* Color list label provider.
183-
*
182+
*
184183
* @since 3.0
185184
*/
186185
private static class ColorListLabelProvider extends LabelProvider implements IColorProvider {
@@ -203,7 +202,7 @@ public Color getBackground(Object element) {
203202

204203
/**
205204
* Color list content provider.
206-
*
205+
*
207206
* @since 3.0
208207
*/
209208
private static class ColorListContentProvider implements IStructuredContentProvider {
@@ -239,7 +238,6 @@ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
239238
private final List<HighlightingColorListItem> fHighlightingColorList = new ArrayList<>(5);
240239

241240
private SourceViewer fPreviewViewer;
242-
private AntPreviewerUpdater fPreviewerUpdater;
243241

244242
private SelectionListener fSelectionListener;
245243
protected Map<String, String> fWorkingValues;
@@ -522,7 +520,7 @@ private Control createPreviewer(Composite parent) {
522520
fPreviewViewer.getTextWidget().setFont(font);
523521

524522
IPreferenceStore store = new ChainedPreferenceStore(new IPreferenceStore[] { getOverlayStore(), EditorsUI.getPreferenceStore() });
525-
fPreviewerUpdater = new AntPreviewerUpdater(fPreviewViewer, configuration, store);
523+
new AntPreviewerUpdater(fPreviewViewer, configuration, store);
526524

527525
String content = loadPreviewContentFromFile("SyntaxPreviewCode.txt"); //$NON-NLS-1$
528526
IDocument document = new Document(content);
@@ -542,7 +540,7 @@ private void handleSyntaxColorListSelection() {
542540

543541
/**
544542
* Returns the current highlighting color list item.
545-
*
543+
*
546544
* @return the current highlighting color list item
547545
* @since 3.0
548546
*/
@@ -551,14 +549,6 @@ private HighlightingColorListItem getHighlightingColorListItem() {
551549
return (HighlightingColorListItem) selection.getFirstElement();
552550
}
553551

554-
@Override
555-
public void dispose() {
556-
super.dispose();
557-
if (fPreviewerUpdater != null) {
558-
fPreviewerUpdater.dispose();
559-
}
560-
}
561-
562552
private Composite createProblemsTabContent(TabFolder folder) {
563553
fComboBoxes = new ArrayList<>();
564554
fProblemLabels = new ArrayList<>();
@@ -712,10 +702,8 @@ protected void updateControls() {
712702

713703
@Override
714704
public boolean performOk() {
715-
Iterator<String> iter = fWorkingValues.keySet().iterator();
716705
IPreferenceStore store = getPreferenceStore();
717-
while (iter.hasNext()) {
718-
String key = iter.next();
706+
for (String key : fWorkingValues.keySet()) {
719707
store.putValue(key, fWorkingValues.get(key));
720708
}
721709
if (store.needsSaving()) {

ant/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/preferences/AntPreviewerUpdater.java

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,6 @@
3838
*/
3939
class AntPreviewerUpdater {
4040

41-
private Color fForegroundColor = null;
42-
private Color fBackgroundColor = null;
43-
private Color fSelectionBackgroundColor = null;
44-
private Color fSelectionForegroundColor = null;
45-
4641
/**
4742
* Creates a source preview updater for the given viewer, configuration and preference store.
4843
*
@@ -122,44 +117,20 @@ protected void initializeViewerColors(ISourceViewer viewer, IPreferenceStore sto
122117
: createColor(store, AbstractTextEditor.PREFERENCE_COLOR_FOREGROUND, styledText.getDisplay());
123118
styledText.setForeground(color);
124119

125-
if (fForegroundColor != null) {
126-
fForegroundColor.dispose();
127-
}
128-
129-
fForegroundColor = color;
130-
131120
// ---------- background color ----------------------
132121
color = store.getBoolean(AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT) ? null
133122
: createColor(store, AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND, styledText.getDisplay());
134123
styledText.setBackground(color);
135124

136-
if (fBackgroundColor != null) {
137-
fBackgroundColor.dispose();
138-
}
139-
140-
fBackgroundColor = color;
141-
142125
// ----------- selection foreground color --------------------
143126
color = store.getBoolean(AbstractTextEditor.PREFERENCE_COLOR_SELECTION_FOREGROUND_SYSTEM_DEFAULT) ? null
144127
: createColor(store, AbstractTextEditor.PREFERENCE_COLOR_SELECTION_FOREGROUND, styledText.getDisplay());
145128
styledText.setSelectionForeground(color);
146129

147-
if (fSelectionForegroundColor != null) {
148-
fSelectionForegroundColor.dispose();
149-
}
150-
151-
fSelectionForegroundColor = color;
152-
153130
// ---------- selection background color ----------------------
154131
color = store.getBoolean(AbstractTextEditor.PREFERENCE_COLOR_SELECTION_BACKGROUND_SYSTEM_DEFAULT) ? null
155132
: createColor(store, AbstractTextEditor.PREFERENCE_COLOR_SELECTION_BACKGROUND, styledText.getDisplay());
156133
styledText.setSelectionBackground(color);
157-
158-
if (fSelectionBackgroundColor != null) {
159-
fSelectionBackgroundColor.dispose();
160-
}
161-
162-
fSelectionBackgroundColor = color;
163134
}
164135

165136
/**
@@ -192,25 +163,4 @@ private Color createColor(IPreferenceStore store, String key, Display display) {
192163
return null;
193164
}
194165

195-
public void dispose() {
196-
if (fForegroundColor != null) {
197-
fForegroundColor.dispose();
198-
fForegroundColor = null;
199-
}
200-
201-
if (fBackgroundColor != null) {
202-
fBackgroundColor.dispose();
203-
fBackgroundColor = null;
204-
}
205-
206-
if (fSelectionForegroundColor != null) {
207-
fSelectionForegroundColor.dispose();
208-
fSelectionForegroundColor = null;
209-
}
210-
211-
if (fSelectionBackgroundColor != null) {
212-
fSelectionBackgroundColor.dispose();
213-
fSelectionBackgroundColor = null;
214-
}
215-
}
216166
}

0 commit comments

Comments
 (0)