2
2
3
3
import java .io .File ;
4
4
import java .util .HashSet ;
5
+ import java .util .List ;
6
+ import java .util .Set ;
5
7
import java .util .Vector ;
6
8
7
9
import org .eclipse .cdt .core .CCorePlugin ;
@@ -37,16 +39,18 @@ public class Common extends InstancePreferences {
37
39
// request him to disconnect
38
40
// when we need the serial port
39
41
42
+ static Set <IProject > fProjects = new HashSet <>();
43
+
40
44
/**
41
45
* This method is used to register a serial user. A serial user is alerted
42
46
* when the serial port will be disconnected (for instance for a upload) The
43
47
* serial user is requested to act appropriately Only 1 serial user can be
44
48
* registered at a given time. No check is done.
45
49
*
46
- * @param SerialUser
50
+ * @param serialUser
47
51
*/
48
- public static void registerSerialUser (ISerialUser SerialUser ) {
49
- OtherSerialUser = SerialUser ;
52
+ public static void registerSerialUser (ISerialUser serialUser ) {
53
+ OtherSerialUser = serialUser ;
50
54
}
51
55
52
56
/**
@@ -85,14 +89,14 @@ public static void UnRegisterSerialUser() {
85
89
* redirect input, allowed in Unix filenames, see Note 1 > greater than used
86
90
* to redirect output, allowed in Unix filenames, see Note 1 . period or dot
87
91
*
88
- * @param Name
92
+ * @param name
89
93
* the string that needs to be checked
90
94
* @return a name safe to create files or folders
91
95
*/
92
- public static String MakeNameCompileSafe (String Name ) {
93
- char badChars [] = { ' ' , '/' , '.' , '/' , ':' , ' ' , '\\' , '(' , ')' , '*' , '?' , '%' , '|' , '<' , '>' , ',' , '-' };
96
+ public static String MakeNameCompileSafe (String name ) {
97
+ char [] badChars = { ' ' , '/' , '.' , '/' , ':' , ' ' , '\\' , '(' , ')' , '*' , '?' , '%' , '|' , '<' , '>' , ',' , '-' };
94
98
95
- String ret = Name .trim ();
99
+ String ret = name .trim ();
96
100
for (char curchar : badChars ) {
97
101
ret = ret .replace (curchar , '_' );
98
102
}
@@ -105,39 +109,37 @@ public static String MakeNameCompileSafe(String Name) {
105
109
* @param project
106
110
* The project for which the property is needed
107
111
*
108
- * @param Tag
112
+ * @param tag
109
113
* The tag identifying the property to read
110
114
* @return returns the property when found. When not found returns an empty
111
115
* string
112
116
*/
113
- public static String getPersistentProperty (IProject project , String Tag ) {
117
+ public static String getPersistentProperty (IProject project , String tag ) {
114
118
try {
115
- String sret = project .getPersistentProperty (new QualifiedName (CORE_PLUGIN_ID , Tag ));
119
+ String sret = project .getPersistentProperty (new QualifiedName (CORE_PLUGIN_ID , tag ));
116
120
if (sret == null ) {
117
- sret = project .getPersistentProperty (new QualifiedName (EMPTY_STRING , Tag )); // for
121
+ sret = project .getPersistentProperty (new QualifiedName (EMPTY_STRING , tag )); // for
118
122
// downwards
119
123
// compatibility
120
124
if (sret == null )
121
125
sret = EMPTY_STRING ;
122
126
}
123
127
return sret ;
124
128
} 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$
127
130
return EMPTY_STRING ;
128
131
}
129
132
}
130
133
131
- public static int getPersistentPropertyInt (IProject project , String Tag , int defaultValue ) {
134
+ public static int getPersistentPropertyInt (IProject project , String tag , int defaultValue ) {
132
135
try {
133
- String sret = project .getPersistentProperty (new QualifiedName (CORE_PLUGIN_ID , Tag ));
136
+ String sret = project .getPersistentProperty (new QualifiedName (CORE_PLUGIN_ID , tag ));
134
137
if (sret == null ) {
135
138
return defaultValue ;
136
139
}
137
140
return Integer .parseInt (sret );
138
141
} 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$
141
143
return defaultValue ;
142
144
}
143
145
}
@@ -148,15 +150,15 @@ public static int getPersistentPropertyInt(IProject project, String Tag, int def
148
150
* @param project
149
151
* The project for which the property needs to be set
150
152
*
151
- * @param Tag
153
+ * @param tag
152
154
* The tag identifying the property to read
153
155
* @return returns the property when found. When not found returns an empty
154
156
* string
155
157
*/
156
- public static void setPersistentProperty (IProject project , String Tag , String Value ) {
158
+ public static void setPersistentProperty (IProject project , String tag , String value ) {
157
159
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
160
162
// downwards
161
163
// compatibility
162
164
} catch (CoreException e ) {
@@ -166,8 +168,8 @@ public static void setPersistentProperty(IProject project, String Tag, String Va
166
168
}
167
169
}
168
170
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 ));
171
173
}
172
174
173
175
/**
@@ -177,7 +179,7 @@ public static void setPersistentProperty(IProject project, String Tag, int Value
177
179
* the status information to log
178
180
*/
179
181
public static void log (IStatus status ) {
180
- int style = StatusManager . LOG ;
182
+ int style ;
181
183
182
184
if (status .getSeverity () == IStatus .ERROR ) {
183
185
style = StatusManager .LOG | StatusManager .SHOW | StatusManager .BLOCK ;
@@ -209,20 +211,20 @@ public static String UploadPortPrefix() {
209
211
/**
210
212
* ToInt converts a string to a integer in a save way
211
213
*
212
- * @param Number
214
+ * @param number
213
215
* is a String that will be converted to an integer. Number can
214
216
* be null or empty and can contain leading and trailing white
215
217
* space
216
218
* @return The integer value represented in the string based on parseInt
217
219
* @see parseInt. After error checking and modifications parseInt is used
218
220
* for the conversion
219
221
**/
220
- public static int ToInt (String Number ) {
221
- if (Number == null )
222
+ public static int ToInt (String number ) {
223
+ if (number == null )
222
224
return 0 ;
223
- if (Number .isEmpty ())
225
+ if (number .isEmpty ())
224
226
return 0 ;
225
- return Integer .parseInt (Number .trim ());
227
+ return Integer .parseInt (number .trim ());
226
228
}
227
229
228
230
public static IWorkbenchWindow getActiveWorkbenchWindow () {
@@ -237,8 +239,6 @@ public static IWorkbenchPage getActivePage() {
237
239
return null ;
238
240
}
239
241
240
- static HashSet <IProject > fProjects = new HashSet <>();
241
-
242
242
public static boolean StopSerialMonitor (String mComPort ) {
243
243
if (OtherSerialUser != null ) {
244
244
return OtherSerialUser .PauzePort (mComPort );
@@ -254,9 +254,9 @@ public static void StartSerialMonitor(String mComPort) {
254
254
}
255
255
256
256
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 );
260
260
return outgoing ;
261
261
}
262
262
@@ -294,16 +294,16 @@ public static String getLineEnding(int selectionIndex) {
294
294
* the project that contains the environment variable
295
295
* @param configName
296
296
* the project configuration to use
297
- * @param EnvName
297
+ * @param envName
298
298
* the key that describes the variable
299
299
* @param defaultvalue
300
300
* The return value if the variable is not found.
301
301
* @return The expanded build environment variable
302
302
*/
303
- static public String getBuildEnvironmentVariable (IProject project , String configName , String EnvName ,
303
+ static public String getBuildEnvironmentVariable (IProject project , String configName , String envName ,
304
304
String defaultvalue ) {
305
305
ICProjectDescription prjDesc = CoreModel .getDefault ().getProjectDescription (project );
306
- return getBuildEnvironmentVariable (prjDesc .getConfigurationByName (configName ), EnvName , defaultvalue );
306
+ return getBuildEnvironmentVariable (prjDesc .getConfigurationByName (configName ), envName , defaultvalue );
307
307
}
308
308
309
309
/**
@@ -314,15 +314,15 @@ static public String getBuildEnvironmentVariable(IProject project, String config
314
314
* @param project
315
315
* the project that contains the environment variable
316
316
*
317
- * @param EnvName
317
+ * @param envName
318
318
* the key that describes the variable
319
319
* @param defaultvalue
320
320
* The return value if the variable is not found.
321
321
* @return The expanded build environment variable
322
322
*/
323
- static public String getBuildEnvironmentVariable (IProject project , String EnvName , String defaultvalue ) {
323
+ static public String getBuildEnvironmentVariable (IProject project , String envName , String defaultvalue ) {
324
324
ICProjectDescription prjDesc = CoreModel .getDefault ().getProjectDescription (project );
325
- return getBuildEnvironmentVariable (prjDesc .getDefaultSettingConfiguration (), EnvName , defaultvalue );
325
+ return getBuildEnvironmentVariable (prjDesc .getDefaultSettingConfiguration (), envName , defaultvalue );
326
326
}
327
327
328
328
/**
@@ -332,24 +332,24 @@ static public String getBuildEnvironmentVariable(IProject project, String EnvNam
332
332
*
333
333
* @param project
334
334
* the project that contains the environment variable
335
- * @param EnvName
335
+ * @param envName
336
336
* the key that describes the variable
337
337
* @param defaultvalue
338
338
* The return value if the variable is not found.
339
339
* @return The expanded build environment variable
340
340
*/
341
341
static public String getBuildEnvironmentVariable (ICConfigurationDescription configurationDescription ,
342
- String EnvName , String defaultvalue ) {
342
+ String envName , String defaultvalue ) {
343
343
344
- return getBuildEnvironmentVariable (configurationDescription , EnvName , defaultvalue , true );
344
+ return getBuildEnvironmentVariable (configurationDescription , envName , defaultvalue , true );
345
345
}
346
346
347
347
static public String getBuildEnvironmentVariable (ICConfigurationDescription configurationDescription ,
348
- String EnvName , String defaultvalue , boolean expanded ) {
348
+ String envName , String defaultvalue , boolean expanded ) {
349
349
350
350
IEnvironmentVariableManager envManager = CCorePlugin .getDefault ().getBuildEnvironmentManager ();
351
351
try {
352
- return envManager .getVariable (EnvName , configurationDescription , expanded ).getValue ();
352
+ return envManager .getVariable (envName , configurationDescription , expanded ).getValue ();
353
353
} catch (Exception e ) {// ignore all errors and return the default value
354
354
}
355
355
return defaultvalue ;
@@ -374,8 +374,7 @@ public static String getDefaultPrivateHardwarePath() {
374
374
375
375
public static File getWorkspaceRoot () {
376
376
IWorkspaceRoot myWorkspaceRoot = ResourcesPlugin .getWorkspace ().getRoot ();
377
- File ret = myWorkspaceRoot .getLocation ().toFile ();
378
- return ret ;
377
+ return myWorkspaceRoot .getLocation ().toFile ();
379
378
}
380
379
381
380
public static void setBuildEnvironmentVariable (IContributedEnvironment contribEnv ,
0 commit comments