Skip to content

Commit 69efee0

Browse files
committed
Merge pull request #406 from DevFactory/release/multiple-code-improvements-fix-1
multiple code improvements: squid:S00117, squid:S1181, squid:S1213, squid:S00116, squid:UselessParenthesesCheck, squid:S1197
2 parents 839ed91 + 170d5a6 commit 69efee0

File tree

1 file changed

+49
-49
lines changed
  • it.baeyens.arduino.common/src/it/baeyens/arduino/arduino

1 file changed

+49
-49
lines changed

it.baeyens.arduino.common/src/it/baeyens/arduino/arduino/Serial.java

Lines changed: 49 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -58,41 +58,6 @@ public class Serial implements SerialPortEventListener {
5858
// for the classloading problem.. because if code ran again,
5959
// the static class would have an object that could be closed
6060

61-
/**
62-
* General error reporting, all correlated here just in case I think of
63-
* something slightly more intelligent to do.
64-
*/
65-
static public void errorMessage(String where, Throwable e) {
66-
Common.log(new Status(IStatus.WARNING, Const.CORE_PLUGIN_ID, "Error inside Serial. " + where, e)); //$NON-NLS-1$
67-
68-
}
69-
70-
/**
71-
* If this just hangs and never completes on Windows, it may be because the
72-
* DLL doesn't have its exec bit set. Why the hell that'd be the case, who
73-
* knows.
74-
*/
75-
public static Vector<String> list() {
76-
try {
77-
String[] portNames;
78-
String OS = System.getProperty("os.name").toLowerCase(); //$NON-NLS-1$
79-
if (OS.indexOf("mac") >= 0) { //$NON-NLS-1$
80-
portNames = SerialPortList.getPortNames("/dev/", Pattern.compile("^cu\\..*(serial|usb).*")); //$NON-NLS-1$ //$NON-NLS-2$
81-
} else {
82-
portNames = SerialPortList.getPortNames();
83-
}
84-
return new Vector<>(Arrays.asList(portNames));
85-
} catch (Error e) {
86-
Common.log(new Status(IStatus.ERROR, Const.CORE_PLUGIN_ID,
87-
"There is a config problem on your system.\nFor more detail see https://github.com/jantje/arduino-eclipse-plugin/issues/252", //$NON-NLS-1$
88-
e));
89-
Vector<String> ret = new Vector<>();
90-
ret.add("config error:"); //$NON-NLS-1$
91-
ret.add("see https://github.com/jantje/arduino-eclipse-plugin/issues/252"); //$NON-NLS-1$
92-
return ret;
93-
}
94-
}
95-
9661
SerialPort port = null;
9762
int rate;
9863
int parity;
@@ -108,7 +73,7 @@ public static Vector<String> list() {
10873
// RTS and DTR low.
10974
boolean dtr = true;
11075

111-
String PortName;
76+
String portName;
11277

11378
private ServiceRegistration<Serial> fServiceRegistration;
11479

@@ -123,7 +88,7 @@ public Serial(String iname, int irate, boolean dtr) {
12388
}
12489

12590
public Serial(String iname, int irate, char iparity, int idatabits, float istopbits, boolean dtr) {
126-
this.PortName = iname;
91+
this.portName = iname;
12792
this.rate = irate;
12893
this.dtr = dtr;
12994

@@ -144,6 +109,41 @@ public Serial(String iname, int irate, char iparity, int idatabits, float istopb
144109

145110
}
146111

112+
/**
113+
* General error reporting, all correlated here just in case I think of
114+
* something slightly more intelligent to do.
115+
*/
116+
public static void errorMessage(String where, Throwable e) {
117+
Common.log(new Status(IStatus.WARNING, Const.CORE_PLUGIN_ID, "Error inside Serial. " + where, e)); //$NON-NLS-1$
118+
119+
}
120+
121+
/**
122+
* If this just hangs and never completes on Windows, it may be because the
123+
* DLL doesn't have its exec bit set. Why the hell that'd be the case, who
124+
* knows.
125+
*/
126+
public static Vector<String> list() {
127+
try {
128+
String[] portNames;
129+
String os = System.getProperty("os.name").toLowerCase(); //$NON-NLS-1$
130+
if (os.indexOf("mac") >= 0) { //$NON-NLS-1$
131+
portNames = SerialPortList.getPortNames("/dev/", Pattern.compile("^cu\\..*(serial|usb).*")); //$NON-NLS-1$ //$NON-NLS-2$
132+
} else {
133+
portNames = SerialPortList.getPortNames();
134+
}
135+
return new Vector<>(Arrays.asList(portNames));
136+
} catch (Exception e) {
137+
Common.log(new Status(IStatus.ERROR, Const.CORE_PLUGIN_ID,
138+
"There is a config problem on your system.\nFor more detail see https://github.com/jantje/arduino-eclipse-plugin/issues/252", //$NON-NLS-1$
139+
e));
140+
Vector<String> ret = new Vector<>();
141+
ret.add("config error:"); //$NON-NLS-1$
142+
ret.add("see https://github.com/jantje/arduino-eclipse-plugin/issues/252"); //$NON-NLS-1$
143+
return ret;
144+
}
145+
}
146+
147147
public void addListener(MessageConsumer consumer) {
148148
if (this.fConsumers == null) {
149149
this.fConsumers = new ArrayList<>();
@@ -166,7 +166,7 @@ public void connect(int maxTries) {
166166
int count = 0;
167167
while (true) {
168168
try {
169-
this.port = new SerialPort(this.PortName);
169+
this.port = new SerialPort(this.portName);
170170
this.port.openPort();
171171
this.port.setParams(this.rate, this.databits, this.stopbits, this.parity, this.dtr, this.dtr);
172172

@@ -178,17 +178,17 @@ public void connect(int maxTries) {
178178
if (++count == maxTries) {
179179
if (SerialPortException.TYPE_PORT_BUSY.equals(e.getExceptionType())) {
180180
Common.log(new Status(IStatus.ERROR, Const.CORE_PLUGIN_ID,
181-
"Serial port " + this.PortName //$NON-NLS-1$
181+
"Serial port " + this.portName //$NON-NLS-1$
182182
+ " already in use. Try quiting any programs that may be using it", //$NON-NLS-1$
183183
e));
184184
} else if (SerialPortException.TYPE_PORT_NOT_FOUND.equals(e.getExceptionType())) {
185185
Common.log(new Status(IStatus.ERROR, Const.CORE_PLUGIN_ID, "Serial port " //$NON-NLS-1$
186-
+ this.PortName
186+
+ this.portName
187187
+ " not found. Did you select the right one from the project properties -> Arduino -> Arduino?", //$NON-NLS-1$
188188
e));
189189
} else {
190190
Common.log(new Status(IStatus.ERROR, Const.CORE_PLUGIN_ID,
191-
"Error opening serial port " + this.PortName, e)); //$NON-NLS-1$
191+
"Error opening serial port " + this.portName, e)); //$NON-NLS-1$
192192
}
193193
return;
194194
}
@@ -225,7 +225,7 @@ public void dispose() {
225225
}
226226

227227
public boolean IsConnected() {
228-
return (this.port != null && this.port.isOpened());
228+
return this.port != null && this.port.isOpened();
229229
}
230230

231231
private void notifyConsumersOfData(byte[] message) {
@@ -263,7 +263,7 @@ public void reset() {
263263
}
264264

265265
@Override
266-
synchronized public void serialEvent(SerialPortEvent serialEvent) {
266+
public synchronized void serialEvent(SerialPortEvent serialEvent) {
267267
switch (serialEvent.getEventType()) {
268268
case SerialPortEvent.RXCHAR:
269269
int bytesCount = serialEvent.getEventValue();
@@ -310,10 +310,10 @@ public void setup() {// JABA is not going to add code
310310
// needed to fill viewers in jfases
311311
@Override
312312
public String toString() {
313-
return this.PortName;
313+
return this.portName;
314314
}
315315

316-
public void write(byte bytes[]) {
316+
public void write(byte[] bytes) {
317317
if (this.port != null) {
318318
try {
319319
this.port.writeBytes(bytes);
@@ -351,13 +351,13 @@ public void write(String what) {
351351
write(what.getBytes());
352352
}
353353

354-
public void write(String what, String LineEnd) {
354+
public void write(String what, String lineEnd) {
355355
notifyConsumersOfEvent(
356-
System.getProperty("line.separator") + ">>Send to " + this.PortName + ": \"" + what + "\"<<" //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
356+
System.getProperty("line.separator") + ">>Send to " + this.portName + ": \"" + what + "\"<<" //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
357357
+ System.getProperty("line.separator")); //$NON-NLS-1$
358358
write(what.getBytes());
359-
if (LineEnd.length() > 0) {
360-
write(LineEnd.getBytes());
359+
if (lineEnd.length() > 0) {
360+
write(lineEnd.getBytes());
361361
}
362362
}
363363
}

0 commit comments

Comments
 (0)