Skip to content

Commit 8327877

Browse files
committed
Merge pull request #414 from DevFactory/release/multiple-code-improvements-fix-3
multiple code improvements: squid:S00117, squid:S1149, squid:S1197, squid:S1854, squid:CommentedOutCodeLine, squid:S1488, squid:S1213, squid:SwitchLastCaseIsDefaultCheck
2 parents 3058740 + 26180a0 commit 8327877

File tree

1 file changed

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

1 file changed

+46
-47
lines changed

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

Lines changed: 46 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import java.io.File;
44
import java.util.HashSet;
5+
import java.util.List;
6+
import java.util.Set;
57
import java.util.Vector;
68

79
import org.eclipse.cdt.core.CCorePlugin;
@@ -37,16 +39,18 @@ public class Common extends InstancePreferences {
3739
// request him to disconnect
3840
// when we need the serial port
3941

42+
static Set<IProject> fProjects = new HashSet<>();
43+
4044
/**
4145
* This method is used to register a serial user. A serial user is alerted
4246
* when the serial port will be disconnected (for instance for a upload) The
4347
* serial user is requested to act appropriately Only 1 serial user can be
4448
* registered at a given time. No check is done.
4549
*
46-
* @param SerialUser
50+
* @param serialUser
4751
*/
48-
public static void registerSerialUser(ISerialUser SerialUser) {
49-
OtherSerialUser = SerialUser;
52+
public static void registerSerialUser(ISerialUser serialUser) {
53+
OtherSerialUser = serialUser;
5054
}
5155

5256
/**
@@ -85,14 +89,14 @@ public static void UnRegisterSerialUser() {
8589
* redirect input, allowed in Unix filenames, see Note 1 > greater than used
8690
* to redirect output, allowed in Unix filenames, see Note 1 . period or dot
8791
*
88-
* @param Name
92+
* @param name
8993
* the string that needs to be checked
9094
* @return a name safe to create files or folders
9195
*/
92-
public static String MakeNameCompileSafe(String Name) {
93-
char badChars[] = { ' ', '/', '.', '/', ':', ' ', '\\', '(', ')', '*', '?', '%', '|', '<', '>', ',', '-' };
96+
public static String MakeNameCompileSafe(String name) {
97+
char[] badChars = { ' ', '/', '.', '/', ':', ' ', '\\', '(', ')', '*', '?', '%', '|', '<', '>', ',', '-' };
9498

95-
String ret = Name.trim();
99+
String ret = name.trim();
96100
for (char curchar : badChars) {
97101
ret = ret.replace(curchar, '_');
98102
}
@@ -105,39 +109,37 @@ public static String MakeNameCompileSafe(String Name) {
105109
* @param project
106110
* The project for which the property is needed
107111
*
108-
* @param Tag
112+
* @param tag
109113
* The tag identifying the property to read
110114
* @return returns the property when found. When not found returns an empty
111115
* string
112116
*/
113-
public static String getPersistentProperty(IProject project, String Tag) {
117+
public static String getPersistentProperty(IProject project, String tag) {
114118
try {
115-
String sret = project.getPersistentProperty(new QualifiedName(CORE_PLUGIN_ID, Tag));
119+
String sret = project.getPersistentProperty(new QualifiedName(CORE_PLUGIN_ID, tag));
116120
if (sret == null) {
117-
sret = project.getPersistentProperty(new QualifiedName(EMPTY_STRING, Tag)); // for
121+
sret = project.getPersistentProperty(new QualifiedName(EMPTY_STRING, tag)); // for
118122
// downwards
119123
// compatibility
120124
if (sret == null)
121125
sret = EMPTY_STRING;
122126
}
123127
return sret;
124128
} catch (CoreException e) {
125-
log(new Status(IStatus.ERROR, Const.CORE_PLUGIN_ID, "Failed to read persistent setting " + Tag, e)); //$NON-NLS-1$
126-
// e.printStackTrace();
129+
log(new Status(IStatus.ERROR, Const.CORE_PLUGIN_ID, "Failed to read persistent setting " + tag, e)); //$NON-NLS-1$
127130
return EMPTY_STRING;
128131
}
129132
}
130133

131-
public static int getPersistentPropertyInt(IProject project, String Tag, int defaultValue) {
134+
public static int getPersistentPropertyInt(IProject project, String tag, int defaultValue) {
132135
try {
133-
String sret = project.getPersistentProperty(new QualifiedName(CORE_PLUGIN_ID, Tag));
136+
String sret = project.getPersistentProperty(new QualifiedName(CORE_PLUGIN_ID, tag));
134137
if (sret == null) {
135138
return defaultValue;
136139
}
137140
return Integer.parseInt(sret);
138141
} catch (CoreException e) {
139-
log(new Status(IStatus.ERROR, Const.CORE_PLUGIN_ID, "Failed to read persistent setting " + Tag, e)); //$NON-NLS-1$
140-
// e.printStackTrace();
142+
log(new Status(IStatus.ERROR, Const.CORE_PLUGIN_ID, "Failed to read persistent setting " + tag, e)); //$NON-NLS-1$
141143
return defaultValue;
142144
}
143145
}
@@ -148,15 +150,15 @@ public static int getPersistentPropertyInt(IProject project, String Tag, int def
148150
* @param project
149151
* The project for which the property needs to be set
150152
*
151-
* @param Tag
153+
* @param tag
152154
* The tag identifying the property to read
153155
* @return returns the property when found. When not found returns an empty
154156
* string
155157
*/
156-
public static void setPersistentProperty(IProject project, String Tag, String Value) {
158+
public static void setPersistentProperty(IProject project, String tag, String value) {
157159
try {
158-
project.setPersistentProperty(new QualifiedName(CORE_PLUGIN_ID, Tag), Value);
159-
project.setPersistentProperty(new QualifiedName(EMPTY_STRING, Tag), Value); // for
160+
project.setPersistentProperty(new QualifiedName(CORE_PLUGIN_ID, tag), value);
161+
project.setPersistentProperty(new QualifiedName(EMPTY_STRING, tag), value); // for
160162
// downwards
161163
// compatibility
162164
} catch (CoreException e) {
@@ -166,8 +168,8 @@ public static void setPersistentProperty(IProject project, String Tag, String Va
166168
}
167169
}
168170

169-
public static void setPersistentProperty(IProject project, String Tag, int Value) {
170-
setPersistentProperty(project, Tag, Integer.toString(Value));
171+
public static void setPersistentProperty(IProject project, String tag, int value) {
172+
setPersistentProperty(project, tag, Integer.toString(value));
171173
}
172174

173175
/**
@@ -177,7 +179,7 @@ public static void setPersistentProperty(IProject project, String Tag, int Value
177179
* the status information to log
178180
*/
179181
public static void log(IStatus status) {
180-
int style = StatusManager.LOG;
182+
int style;
181183

182184
if (status.getSeverity() == IStatus.ERROR) {
183185
style = StatusManager.LOG | StatusManager.SHOW | StatusManager.BLOCK;
@@ -209,20 +211,20 @@ public static String UploadPortPrefix() {
209211
/**
210212
* ToInt converts a string to a integer in a save way
211213
*
212-
* @param Number
214+
* @param number
213215
* is a String that will be converted to an integer. Number can
214216
* be null or empty and can contain leading and trailing white
215217
* space
216218
* @return The integer value represented in the string based on parseInt
217219
* @see parseInt. After error checking and modifications parseInt is used
218220
* for the conversion
219221
**/
220-
public static int ToInt(String Number) {
221-
if (Number == null)
222+
public static int ToInt(String number) {
223+
if (number == null)
222224
return 0;
223-
if (Number.isEmpty())
225+
if (number.isEmpty())
224226
return 0;
225-
return Integer.parseInt(Number.trim());
227+
return Integer.parseInt(number.trim());
226228
}
227229

228230
public static IWorkbenchWindow getActiveWorkbenchWindow() {
@@ -237,8 +239,6 @@ public static IWorkbenchPage getActivePage() {
237239
return null;
238240
}
239241

240-
static HashSet<IProject> fProjects = new HashSet<>();
241-
242242
public static boolean StopSerialMonitor(String mComPort) {
243243
if (OtherSerialUser != null) {
244244
return OtherSerialUser.PauzePort(mComPort);
@@ -254,9 +254,9 @@ public static void StartSerialMonitor(String mComPort) {
254254
}
255255

256256
public static String[] listComPorts() {
257-
Vector<String> SerialList = Serial.list();
258-
String outgoing[] = new String[SerialList.size()];
259-
SerialList.copyInto(outgoing);
257+
List<String> serialList = Serial.list();
258+
String[] outgoing = new String[serialList.size()];
259+
serialList.toArray(outgoing);
260260
return outgoing;
261261
}
262262

@@ -294,16 +294,16 @@ public static String getLineEnding(int selectionIndex) {
294294
* the project that contains the environment variable
295295
* @param configName
296296
* the project configuration to use
297-
* @param EnvName
297+
* @param envName
298298
* the key that describes the variable
299299
* @param defaultvalue
300300
* The return value if the variable is not found.
301301
* @return The expanded build environment variable
302302
*/
303-
static public String getBuildEnvironmentVariable(IProject project, String configName, String EnvName,
303+
static public String getBuildEnvironmentVariable(IProject project, String configName, String envName,
304304
String defaultvalue) {
305305
ICProjectDescription prjDesc = CoreModel.getDefault().getProjectDescription(project);
306-
return getBuildEnvironmentVariable(prjDesc.getConfigurationByName(configName), EnvName, defaultvalue);
306+
return getBuildEnvironmentVariable(prjDesc.getConfigurationByName(configName), envName, defaultvalue);
307307
}
308308

309309
/**
@@ -314,15 +314,15 @@ static public String getBuildEnvironmentVariable(IProject project, String config
314314
* @param project
315315
* the project that contains the environment variable
316316
*
317-
* @param EnvName
317+
* @param envName
318318
* the key that describes the variable
319319
* @param defaultvalue
320320
* The return value if the variable is not found.
321321
* @return The expanded build environment variable
322322
*/
323-
static public String getBuildEnvironmentVariable(IProject project, String EnvName, String defaultvalue) {
323+
static public String getBuildEnvironmentVariable(IProject project, String envName, String defaultvalue) {
324324
ICProjectDescription prjDesc = CoreModel.getDefault().getProjectDescription(project);
325-
return getBuildEnvironmentVariable(prjDesc.getDefaultSettingConfiguration(), EnvName, defaultvalue);
325+
return getBuildEnvironmentVariable(prjDesc.getDefaultSettingConfiguration(), envName, defaultvalue);
326326
}
327327

328328
/**
@@ -332,24 +332,24 @@ static public String getBuildEnvironmentVariable(IProject project, String EnvNam
332332
*
333333
* @param project
334334
* the project that contains the environment variable
335-
* @param EnvName
335+
* @param envName
336336
* the key that describes the variable
337337
* @param defaultvalue
338338
* The return value if the variable is not found.
339339
* @return The expanded build environment variable
340340
*/
341341
static public String getBuildEnvironmentVariable(ICConfigurationDescription configurationDescription,
342-
String EnvName, String defaultvalue) {
342+
String envName, String defaultvalue) {
343343

344-
return getBuildEnvironmentVariable(configurationDescription, EnvName, defaultvalue, true);
344+
return getBuildEnvironmentVariable(configurationDescription, envName, defaultvalue, true);
345345
}
346346

347347
static public String getBuildEnvironmentVariable(ICConfigurationDescription configurationDescription,
348-
String EnvName, String defaultvalue, boolean expanded) {
348+
String envName, String defaultvalue, boolean expanded) {
349349

350350
IEnvironmentVariableManager envManager = CCorePlugin.getDefault().getBuildEnvironmentManager();
351351
try {
352-
return envManager.getVariable(EnvName, configurationDescription, expanded).getValue();
352+
return envManager.getVariable(envName, configurationDescription, expanded).getValue();
353353
} catch (Exception e) {// ignore all errors and return the default value
354354
}
355355
return defaultvalue;
@@ -374,8 +374,7 @@ public static String getDefaultPrivateHardwarePath() {
374374

375375
public static File getWorkspaceRoot() {
376376
IWorkspaceRoot myWorkspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
377-
File ret = myWorkspaceRoot.getLocation().toFile();
378-
return ret;
377+
return myWorkspaceRoot.getLocation().toFile();
379378
}
380379

381380
public static void setBuildEnvironmentVariable(IContributedEnvironment contribEnv,

0 commit comments

Comments
 (0)