Skip to content

Commit a075c94

Browse files
committed
Manual code cleanup for base Console classes
- Moved final field inits to constructor - Added trivial toString() implementation to the AbstractConsole - Fixed possible NP in IOConsole
1 parent b6e2643 commit a075c94

3 files changed

Lines changed: 26 additions & 18 deletions

File tree

debug/org.eclipse.ui.console/src/org/eclipse/ui/console/AbstractConsole.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,17 @@ public abstract class AbstractConsole implements IConsole {
3939
/**
4040
* Console name
4141
*/
42-
private String fName = null;
42+
private String fName;
4343

4444
/**
4545
* Console image descriptor
4646
*/
47-
private ImageDescriptor fImageDescriptor = null;
47+
private ImageDescriptor fImageDescriptor;
4848

4949
/**
5050
* Console type identifier
5151
*/
52-
private String fType = null;
52+
private String fType;
5353

5454
/**
5555
* Used to notify this console of lifecycle methods <code>init()</code>
@@ -316,4 +316,9 @@ public String getHelpContextId() {
316316
return null;
317317
}
318318

319+
@Override
320+
public String toString() {
321+
return "Console [" + fName + "]"; //$NON-NLS-1$ //$NON-NLS-2$
322+
}
323+
319324
}

debug/org.eclipse.ui.console/src/org/eclipse/ui/console/IOConsole.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public class IOConsole extends TextConsole {
5454
/**
5555
* A collection of open streams connected to this console.
5656
*/
57-
private final List<Closeable> openStreams = Collections.synchronizedList(new ArrayList<>());
57+
private final List<Closeable> openStreams;
5858

5959
/**
6060
* The encoding used to for displaying console output.
@@ -113,10 +113,9 @@ public IOConsole(String name, String consoleType, ImageDescriptor imageDescripto
113113
public IOConsole(String name, String consoleType, ImageDescriptor imageDescriptor, Charset charset, boolean autoLifecycle) {
114114
super(name, consoleType, imageDescriptor, autoLifecycle);
115115
this.charset = charset;
116-
synchronized (openStreams) {
117-
inputStream = new IOConsoleInputStream(this);
118-
openStreams.add(inputStream);
119-
}
116+
openStreams = Collections.synchronizedList(new ArrayList<>());
117+
inputStream = new IOConsoleInputStream(this);
118+
openStreams.add(inputStream);
120119
partitioner = new IOConsolePartitioner(this);
121120
final IDocument document = getDocument();
122121
if (document != null) {
@@ -313,16 +312,17 @@ protected void dispose() {
313312
try {
314313
closable.close();
315314
} catch (IOException e) {
316-
// e.printStackTrace();
315+
// ignore
317316
}
318317
}
319318
inputStream = null;
320319
}
321320

322321
final IDocument document = partitioner.getDocument();
323322
partitioner.disconnect();
324-
document.setDocumentPartitioner(null);
325-
323+
if (document != null) {
324+
document.setDocumentPartitioner(null);
325+
}
326326
super.dispose();
327327
}
328328

debug/org.eclipse.ui.console/src/org/eclipse/ui/console/TextConsole.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,28 +83,27 @@ public abstract class TextConsole extends AbstractConsole {
8383
/**
8484
* indication that the console's partitioner is not expecting more input
8585
*/
86-
private volatile boolean fPartitionerFinished = false;
86+
private volatile boolean fPartitionerFinished;
8787

8888
/**
8989
* Indication that the console's pattern matcher has finished.
9090
* (all matches have been found and all listeners notified)
9191
*/
92-
private volatile boolean fMatcherFinished = false;
92+
private volatile boolean fMatcherFinished;
9393

9494
/**
9595
* indication that the console output complete property has been fired
9696
*/
97-
private boolean fCompleteFired = false;
98-
99-
private volatile boolean fConsoleAutoScrollLock = true;
97+
private boolean fCompleteFired;
10098

99+
private volatile boolean fConsoleAutoScrollLock;
101100

102101
/**
103102
* Map of client defined attributes
104103
*/
105-
private final HashMap<String, Object> fAttributes = new HashMap<>();
104+
private final HashMap<String, Object> fAttributes;
106105

107-
private final IConsoleManager fConsoleManager = ConsolePlugin.getDefault().getConsoleManager();
106+
private final IConsoleManager fConsoleManager;
108107
private ScopedPreferenceStore store;
109108
private IPropertyChangeListener propListener;
110109

@@ -119,6 +118,7 @@ protected void dispose() {
119118
store.removePropertyChangeListener(propListener);
120119
}
121120
}
121+
122122
/**
123123
* Constructs a console with the given name, image descriptor, and lifecycle
124124
*
@@ -130,6 +130,9 @@ protected void dispose() {
130130
*/
131131
public TextConsole(String name, String consoleType, ImageDescriptor imageDescriptor, boolean autoLifecycle) {
132132
super(name, consoleType, imageDescriptor, autoLifecycle);
133+
fConsoleAutoScrollLock = true;
134+
fAttributes = new HashMap<>();
135+
fConsoleManager = ConsolePlugin.getDefault().getConsoleManager();
133136
fDocument = new ConsoleDocument();
134137
fDocument.addPositionCategory(ConsoleHyperlinkPosition.HYPER_LINK_CATEGORY);
135138
fPatternMatcher = new ConsolePatternMatcher(this);

0 commit comments

Comments
 (0)