Skip to content

Commit e6a93da

Browse files
eclipse-platform-botlaeubi
authored andcommitted
Perform clean code of terminal/bundles/org.eclipse.terminal.control
1 parent a5a46f8 commit e6a93da

26 files changed

+472
-253
lines changed

terminal/bundles/org.eclipse.terminal.control/src/org/eclipse/terminal/internal/connector/TerminalConnector.java

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,9 @@ public TerminalConnector(TerminalConnector.Factory terminalConnectorFactory, Str
116116
@Override
117117
public String getInitializationErrorMessage() {
118118
getConnectorImpl();
119-
if (fException != null)
119+
if (fException != null) {
120120
return fException.getLocalizedMessage();
121+
}
121122
return null;
122123
}
123124

@@ -164,8 +165,9 @@ public String getSettingsSummary() {
164165
// that's the place where we log the exception
165166
Logger.logException(e);
166167
}
167-
if (fConnector != null && fStore != null)
168+
if (fConnector != null && fStore != null) {
168169
fConnector.load(fStore);
170+
}
169171
}
170172
return fConnector;
171173
}
@@ -192,10 +194,11 @@ public OutputStream getTerminalToRemoteStream() {
192194

193195
@Override
194196
public String getSettingsSummary() {
195-
if (fConnector != null)
197+
if (fConnector != null) {
196198
return getConnectorImpl().getSettingsSummary();
197-
else
199+
} else {
198200
return TerminalMessages.NotInitialized;
201+
}
199202
}
200203

201204
@Override
@@ -221,8 +224,9 @@ public void setDefaultSettings() {
221224
public void save(ISettingsStore store) {
222225
// no need to save the settings: it cannot have changed
223226
// because we are not initialized....
224-
if (fConnector != null)
227+
if (fConnector != null) {
225228
getConnectorImpl().save(store);
229+
}
226230
}
227231

228232
@Override
@@ -238,23 +242,27 @@ public void setTerminalSize(int newWidth, int newHeight) {
238242
@Override
239243
public <T> T getAdapter(Class<T> adapter) {
240244
TerminalConnectorImpl connector = null;
241-
if (isInitialized())
245+
if (isInitialized()) {
242246
connector = getConnectorImpl();
247+
}
243248
// if we cannot create the connector then we cannot adapt...
244249
if (connector != null) {
245250
// maybe the connector is adaptable
246251
if (connector instanceof IAdaptable) {
247252
Object result = ((IAdaptable) connector).getAdapter(adapter);
248253
// Not sure if the next block is needed....
249-
if (result == null)
254+
if (result == null) {
250255
//defer to the platform
251256
result = Platform.getAdapterManager().getAdapter(connector, adapter);
252-
if (result != null)
257+
}
258+
if (result != null) {
253259
return adapter.cast(result);
260+
}
254261
}
255262
// maybe the real adapter is what we need....
256-
if (adapter.isInstance(connector))
263+
if (adapter.isInstance(connector)) {
257264
return adapter.cast(connector);
265+
}
258266
}
259267
// maybe we have to be adapted....
260268
return Platform.getAdapterManager().getAdapter(this, adapter);

terminal/bundles/org.eclipse.terminal.control/src/org/eclipse/terminal/internal/connector/TerminalToRemoteInjectionOutputStream.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,9 @@ public void write(int b) throws IOException {
130130
}
131131

132132
private void checkStream() throws IOException {
133-
if (fInjection != this)
133+
if (fInjection != this) {
134134
throw new IOException("Stream is closed"); //$NON-NLS-1$
135+
}
135136
}
136137
}
137138

@@ -185,24 +186,27 @@ synchronized public void close() throws IOException {
185186

186187
@Override
187188
synchronized public void flush() throws IOException {
188-
if (fInterceptor != null)
189+
if (fInterceptor != null) {
189190
fInterceptor.flush();
191+
}
190192
out.flush();
191193
}
192194

193195
@Override
194196
synchronized public void write(byte[] b, int off, int len) throws IOException {
195-
if (fInterceptor != null)
197+
if (fInterceptor != null) {
196198
fInterceptor.write(b, off, len);
197-
else
199+
} else {
198200
out.write(b, off, len);
201+
}
199202
}
200203

201204
@Override
202205
synchronized public void write(int b) throws IOException {
203-
if (fInterceptor != null)
206+
if (fInterceptor != null) {
204207
fInterceptor.write(b);
205-
else
208+
} else {
206209
out.write(b);
210+
}
207211
}
208212
}

terminal/bundles/org.eclipse.terminal.control/src/org/eclipse/terminal/internal/control/CommandInputFieldWithHistory.java

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -138,15 +138,18 @@ public CommandInputFieldWithHistory(int maxHistorySize) {
138138
protected void pushLine(String line) {
139139
endHistoryMode();
140140
// anything to remember?
141-
if (line == null || line.trim().length() == 0)
141+
if (line == null || line.trim().length() == 0) {
142142
return;
143+
}
143144
fHistory.add(0, line);
144145
// ignore if the same as last
145-
if (fHistory.size() > 1 && line.equals(fHistory.get(1)))
146+
if (fHistory.size() > 1 && line.equals(fHistory.get(1))) {
146147
fHistory.remove(0);
148+
}
147149
// limit the history size.
148-
if (fHistory.size() >= fMaxSize)
150+
if (fHistory.size() >= fMaxSize) {
149151
fHistory.remove(fHistory.size() - 1);
152+
}
150153
}
151154

152155
/**
@@ -156,15 +159,17 @@ protected void pushLine(String line) {
156159
public void setHistory(String history) {
157160
endHistoryMode();
158161
fHistory.clear();
159-
if (history == null)
162+
if (history == null) {
160163
return;
164+
}
161165
// add history entries separated by '\n'
162166
// fHistory.addAll(Arrays.asList(history.split("\n"))); //$NON-NLS-1$
163167
//<J2ME CDC-1.1 Foundation-1.1 variant>
164168
StringTokenizer tok = new StringTokenizer(history, "\n"); //$NON-NLS-1$
165-
while (tok.hasMoreElements())
169+
while (tok.hasMoreElements()) {
166170
fHistory.add((String) tok.nextElement());
167171
//</J2ME CDC-1.1 Foundation-1.1 variant>
172+
}
168173
}
169174

170175
/**
@@ -176,10 +181,11 @@ public String getHistory() {
176181
for (Iterator<String> iterator = fHistory.iterator(); iterator.hasNext();) {
177182
String line = iterator.next();
178183
if (line.length() > 0) {
179-
if (sep)
184+
if (sep) {
180185
buff.append("\n"); //$NON-NLS-1$
181-
else
186+
} else {
182187
sep = true;
188+
}
183189
buff.append(line);
184190
}
185191
}
@@ -200,10 +206,12 @@ public String move(String currLine, int count) {
200206
fEditHistoryPos = 0;
201207
}
202208
fEditedHistory.set(fEditHistoryPos, currLine);
203-
if (fEditHistoryPos + count >= fEditedHistory.size())
209+
if (fEditHistoryPos + count >= fEditedHistory.size()) {
204210
return null;
205-
if (fEditHistoryPos + count < 0)
211+
}
212+
if (fEditHistoryPos + count < 0) {
206213
return null;
214+
}
207215
fEditHistoryPos += count;
208216
return (String) fEditedHistory.get(fEditHistoryPos);
209217
}
@@ -217,8 +225,9 @@ private boolean inHistoryMode() {
217225
* @return the string to be shown in the command line
218226
*/
219227
protected String escape() {
220-
if (!inHistoryMode())
228+
if (!inHistoryMode()) {
221229
return null;
230+
}
222231
String line = (String) fEditedHistory.get(0);
223232
endHistoryMode();
224233
return line;
@@ -289,13 +298,15 @@ public void createControl(final Composite parent, final ITerminalViewControl ter
289298
public void keyPressed(KeyEvent e) {
290299
// if the field assist has handled the key already then
291300
// ignore it (https://bugs.eclipse.org/bugs/show_bug.cgi?id=211659)
292-
if (!e.doit)
301+
if (!e.doit) {
293302
return;
303+
}
294304
if (e.character == SWT.CR || e.character == SWT.LF) {
295305
e.doit = false;
296306
String line = fInputField.getText();
297-
if (!terminal.pasteString(line + '\r'))
307+
if (!terminal.pasteString(line + '\r')) {
298308
return;
309+
}
299310
pushLine(line);
300311
setCommand("");//$NON-NLS-1$
301312
} else if (e.keyCode == SWT.ARROW_UP || e.keyCode == SWT.PAGE_UP) {
@@ -311,8 +322,9 @@ public void keyPressed(KeyEvent e) {
311322
}
312323

313324
private void setCommand(String line) {
314-
if (line == null)
325+
if (line == null) {
315326
return;
327+
}
316328
fInputField.setText(line);
317329
fInputField.setSelection(fInputField.getCharCount());
318330
}

terminal/bundles/org.eclipse.terminal.control/src/org/eclipse/terminal/internal/control/impl/TerminalPlugin.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,9 @@ public void stop(BundleContext context) throws Exception {
6161

6262
public static boolean isOptionEnabled(String strOption) {
6363
String strEnabled = Platform.getDebugOption(strOption);
64-
if (strEnabled == null)
64+
if (strEnabled == null) {
6565
return false;
66+
}
6667

6768
return Boolean.parseBoolean(strEnabled);
6869
}

terminal/bundles/org.eclipse.terminal.control/src/org/eclipse/terminal/internal/emulator/LoggingOutputStream.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,17 @@ public LoggingOutputStream(OutputStream out) {
2424

2525
@Override
2626
public void write(byte[] b, int off, int len) throws IOException {
27-
if (Logger.isLogEnabled())
27+
if (Logger.isLogEnabled()) {
2828
Logger.log("Received " + len + " bytes: '" + //$NON-NLS-1$ //$NON-NLS-2$
2929
Logger.encode(new String(b, 0, len)) + "'"); //$NON-NLS-1$
30+
}
3031

3132
// we cannot call super.write, because this would call our write
3233
// which logs character by character.....
3334
//super.write(b, off, len);
34-
if ((off | len | (b.length - (len + off)) | (off + len)) < 0)
35+
if ((off | len | (b.length - (len + off)) | (off + len)) < 0) {
3536
throw new IndexOutOfBoundsException();
37+
}
3638

3739
for (int i = 0; i < len; i++) {
3840
super.write(b[off + i]);
@@ -41,9 +43,10 @@ public void write(byte[] b, int off, int len) throws IOException {
4143

4244
@Override
4345
public void write(int b) throws IOException {
44-
if (Logger.isLogEnabled())
46+
if (Logger.isLogEnabled()) {
4547
Logger.log("Received " + 1 + " bytes: '" + //$NON-NLS-1$ //$NON-NLS-2$
4648
Logger.encode(new String(new byte[] { (byte) b }, 0, 1)) + "'"); //$NON-NLS-1$
49+
}
4750
super.write(b);
4851
}
4952

terminal/bundles/org.eclipse.terminal.control/src/org/eclipse/terminal/internal/emulator/VT100Emulator.java

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -168,10 +168,11 @@ public VT100Emulator(ITerminalTextData data, ITerminalControlForText terminal, R
168168
ansiParameters[i] = new StringBuffer();
169169
}
170170
setInputStreamReader(reader);
171-
if (TerminalPlugin.isOptionEnabled(Logger.TRACE_DEBUG_LOG_VT100BACKEND))
171+
if (TerminalPlugin.isOptionEnabled(Logger.TRACE_DEBUG_LOG_VT100BACKEND)) {
172172
text = new VT100BackendTraceDecorator(new VT100EmulatorBackend(data), System.out);
173-
else
173+
} else {
174174
text = new VT100EmulatorBackend(data);
175+
}
175176

176177
// text.setDimensions(24, 80);
177178
TerminalStyle style = TerminalStyle.getDefaultStyle();
@@ -249,8 +250,9 @@ public void clearTerminal() {
249250
public void fontChanged() {
250251
Logger.log("entered"); //$NON-NLS-1$
251252

252-
if (text != null)
253+
if (text != null) {
253254
adjustTerminalDimensions();
255+
}
254256
}
255257

256258
// /**
@@ -326,8 +328,9 @@ private void processNewText() throws IOException {
326328

327329
case '\n':
328330
processNewline(); // Newline (Control-J)
329-
if (fCrAfterNewLine)
331+
if (fCrAfterNewLine) {
330332
processCarriageReturn(); // Carriage Return (Control-M)
333+
}
331334
break;
332335

333336
case '\r':
@@ -464,8 +467,9 @@ private void processNewText() throws IOException {
464467
break;
465468

466469
case ANSISTATE_EXPECTING_CHARSET_DESIGNATION:
467-
if (character != '%')
470+
if (character != '%') {
468471
ansiState = ANSISTATE_INITIAL;
472+
}
469473
// Character set designation commands are ignored
470474
break;
471475

@@ -774,10 +778,11 @@ private void processAnsiCommand_h() {
774778
private void processAnsiCommand_J() {
775779
int ansiParameter;
776780

777-
if (ansiParameters[0].length() == 0)
781+
if (ansiParameters[0].length() == 0) {
778782
ansiParameter = 0;
779-
else
783+
} else {
780784
ansiParameter = getAnsiParameter(0);
785+
}
781786

782787
switch (ansiParameter) {
783788
case 0:
@@ -813,8 +818,9 @@ private void processAnsiCommand_J() {
813818
private void processAnsiCommand_K() {
814819
//Bug 401386: missing parameter must be interpreted as 0, and not 1 like most other defaults.
815820
int ansiParameter = 0;
816-
if (ansiParameters[0].length() > 0)
821+
if (ansiParameters[0].length() > 0) {
817822
ansiParameter = getAnsiParameter(0);
823+
}
818824

819825
switch (ansiParameter) {
820826
case 0:
@@ -1311,8 +1317,9 @@ private int getAnsiParameter(int parameterIndex) {
13111317

13121318
String parameter = ansiParameters[parameterIndex].toString();
13131319

1314-
if (parameter.length() == 0)
1320+
if (parameter.length() == 0) {
13151321
return 1;
1322+
}
13161323

13171324
// return 1 on failed parseInt
13181325
int parameterValue = 1;
@@ -1340,8 +1347,9 @@ private void processAnsiParameterCharacter(char ch) {
13401347
if (ch == ';') {
13411348
++nextAnsiParameter;
13421349
} else {
1343-
if (nextAnsiParameter < ansiParameters.length)
1350+
if (nextAnsiParameter < ansiParameters.length) {
13441351
ansiParameters[nextAnsiParameter].append(ch);
1352+
}
13451353
}
13461354
}
13471355

@@ -1482,8 +1490,9 @@ private void adjustTerminalDimensions() {
14821490
}
14831491

14841492
private ITerminalConnector getConnector() {
1485-
if (terminal.getTerminalConnector() != null)
1493+
if (terminal.getTerminalConnector() != null) {
14861494
return terminal.getTerminalConnector();
1495+
}
14871496
return null;
14881497
}
14891498

@@ -1575,8 +1584,9 @@ private char getNextChar() throws IOException {
15751584
c = fReader.read();
15761585
}
15771586
// TODO: better end of file handling
1578-
if (c == -1)
1587+
if (c == -1) {
15791588
c = 0;
1589+
}
15801590
return (char) c;
15811591
}
15821592

0 commit comments

Comments
 (0)