Lines 19-24
Link Here
|
19 |
import org.eclipse.core.runtime.IStatus; |
19 |
import org.eclipse.core.runtime.IStatus; |
20 |
import org.eclipse.core.runtime.Status; |
20 |
import org.eclipse.core.runtime.Status; |
21 |
import org.eclipse.jdt.core.compiler.*; |
21 |
import org.eclipse.jdt.core.compiler.*; |
|
|
22 |
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; |
23 |
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; |
22 |
import org.eclipse.jdt.internal.compiler.lookup.TypeConstants; |
24 |
import org.eclipse.jdt.internal.compiler.lookup.TypeConstants; |
23 |
import org.eclipse.jdt.internal.compiler.parser.Scanner; |
25 |
import org.eclipse.jdt.internal.compiler.parser.Scanner; |
24 |
import org.eclipse.jdt.internal.compiler.parser.ScannerHelper; |
26 |
import org.eclipse.jdt.internal.compiler.parser.ScannerHelper; |
Lines 36-45
Link Here
|
36 |
*/ |
38 |
*/ |
37 |
public final class JavaConventions { |
39 |
public final class JavaConventions { |
38 |
|
40 |
|
39 |
private final static char DOT= '.'; |
41 |
private static final char DOT= '.'; |
40 |
private static final String PACKAGE_INFO = new String(TypeConstants.PACKAGE_INFO_NAME); |
42 |
private static final String PACKAGE_INFO = new String(TypeConstants.PACKAGE_INFO_NAME); |
41 |
private final static Scanner SCANNER = new Scanner(); |
43 |
private static final Scanner[] SCANNERS = new Scanner[5]; |
42 |
|
44 |
private static final int[][] MAP_INDEXES = { { 0 }, { 0, 1 }, { 2, 3, 4 }, { 2, 3, 4, 4 } }; |
|
|
45 |
|
43 |
private JavaConventions() { |
46 |
private JavaConventions() { |
44 |
// Not instantiable |
47 |
// Not instantiable |
45 |
} |
48 |
} |
Lines 73-82
Link Here
|
73 |
|
76 |
|
74 |
/* |
77 |
/* |
75 |
* Returns the current identifier extracted by the scanner (without unicode |
78 |
* Returns the current identifier extracted by the scanner (without unicode |
76 |
* escapes) from the given id. |
79 |
* escapes) from the given id and for the given source and compliance levels. |
77 |
* Returns <code>null</code> if the id was not valid |
80 |
* Returns <code>null</code> if the id was not valid |
78 |
*/ |
81 |
*/ |
79 |
private static synchronized char[] scannedIdentifier(String id) { |
82 |
private static synchronized char[] scannedIdentifier(String id, String sourceLevel, String complianceLevel) { |
80 |
if (id == null) { |
83 |
if (id == null) { |
81 |
return null; |
84 |
return null; |
82 |
} |
85 |
} |
Lines 84-102
Link Here
|
84 |
if (!trimmed.equals(id)) { |
87 |
if (!trimmed.equals(id)) { |
85 |
return null; |
88 |
return null; |
86 |
} |
89 |
} |
|
|
90 |
|
91 |
// Get scanner for given source and compliance levels |
92 |
long lSourceLevel = CompilerOptions.versionToJdkLevel(sourceLevel); |
93 |
long lComplianceLevel = CompilerOptions.versionToJdkLevel(complianceLevel); |
94 |
int sourceIndex = ((int)(lSourceLevel>>> 16)) - ClassFileConstants.MAJOR_VERSION_1_3 ; |
95 |
int complianceIndex = ((int)(lComplianceLevel >>> 16)) - ClassFileConstants.MAJOR_VERSION_1_3; |
96 |
if (complianceIndex < 0) complianceIndex = 0; |
97 |
if (sourceIndex < 0) sourceIndex = 0; |
98 |
if (sourceIndex > complianceIndex) sourceIndex = complianceIndex; |
99 |
int index = MAP_INDEXES[complianceIndex][sourceIndex]; |
100 |
if (SCANNERS[index] == null) { |
101 |
SCANNERS[index] = new Scanner( |
102 |
false /*comment*/, |
103 |
false /*whitespace*/, |
104 |
false /*nls*/, |
105 |
lSourceLevel, |
106 |
lComplianceLevel, |
107 |
null/*taskTag*/, |
108 |
null/*taskPriorities*/, |
109 |
true /*taskCaseSensitive*/); |
110 |
} |
111 |
Scanner scanner = SCANNERS[index]; |
112 |
|
87 |
try { |
113 |
try { |
88 |
SCANNER.setSource(id.toCharArray()); |
114 |
scanner.setSource(id.toCharArray()); |
89 |
int token = SCANNER.getNextToken(); |
115 |
int token = scanner.getNextToken(); |
90 |
char[] currentIdentifier; |
116 |
char[] currentIdentifier; |
91 |
try { |
117 |
try { |
92 |
currentIdentifier = SCANNER.getCurrentIdentifierSource(); |
118 |
currentIdentifier = scanner.getCurrentIdentifierSource(); |
93 |
} catch (ArrayIndexOutOfBoundsException e) { |
119 |
} catch (ArrayIndexOutOfBoundsException e) { |
94 |
return null; |
120 |
return null; |
95 |
} |
121 |
} |
96 |
int nextToken= SCANNER.getNextToken(); |
122 |
int nextToken= scanner.getNextToken(); |
97 |
if (token == TerminalTokens.TokenNameIdentifier |
123 |
if (token == TerminalTokens.TokenNameIdentifier |
98 |
&& nextToken == TerminalTokens.TokenNameEOF |
124 |
&& nextToken == TerminalTokens.TokenNameEOF |
99 |
&& SCANNER.startPosition == SCANNER.source.length) { // to handle case where we had an ArrayIndexOutOfBoundsException |
125 |
&& scanner.startPosition == scanner.source.length) { // to handle case where we had an ArrayIndexOutOfBoundsException |
100 |
// while reading the last token |
126 |
// while reading the last token |
101 |
return currentIdentifier; |
127 |
return currentIdentifier; |
102 |
} else { |
128 |
} else { |
Lines 125-132
Link Here
|
125 |
* @return a status object with code <code>IStatus.OK</code> if |
151 |
* @return a status object with code <code>IStatus.OK</code> if |
126 |
* the given name is valid as a compilation unit name, otherwise a status |
152 |
* the given name is valid as a compilation unit name, otherwise a status |
127 |
* object indicating what is wrong with the name |
153 |
* object indicating what is wrong with the name |
|
|
154 |
* @deprecated Use {@link #validateCompilationUnitName(String id, String sourceLevel, String complianceLevel)} instead |
128 |
*/ |
155 |
*/ |
129 |
public static IStatus validateCompilationUnitName(String name) { |
156 |
public static IStatus validateCompilationUnitName(String name) { |
|
|
157 |
return validateCompilationUnitName(name,CompilerOptions.VERSION_1_3,CompilerOptions.VERSION_1_3); |
158 |
} |
159 |
|
160 |
/** |
161 |
* Validate the given compilation unit name for the given source and compliance levels. |
162 |
* <p> |
163 |
* A compilation unit name must obey the following rules: |
164 |
* <ul> |
165 |
* <li> it must not be null |
166 |
* <li> it must be suffixed by a dot ('.') followed by one of the |
167 |
* {@link JavaCore#getJavaLikeExtensions() Java-like extensions} |
168 |
* <li> its prefix must be a valid identifier |
169 |
* <li> it must not contain any characters or substrings that are not valid |
170 |
* on the file system on which workspace root is located. |
171 |
* </ul> |
172 |
* </p> |
173 |
* @param name the name of a compilation unit |
174 |
* @param sourceLevel the source level |
175 |
* @param complianceLevel the compliance level |
176 |
* @return a status object with code <code>IStatus.OK</code> if |
177 |
* the given name is valid as a compilation unit name, otherwise a status |
178 |
* object indicating what is wrong with the name |
179 |
* @since 3.3 |
180 |
*/ |
181 |
public static IStatus validateCompilationUnitName(String name, String sourceLevel, String complianceLevel) { |
130 |
if (name == null) { |
182 |
if (name == null) { |
131 |
return new Status(IStatus.ERROR, JavaCore.PLUGIN_ID, -1, Messages.convention_unit_nullName, null); |
183 |
return new Status(IStatus.ERROR, JavaCore.PLUGIN_ID, -1, Messages.convention_unit_nullName, null); |
132 |
} |
184 |
} |
Lines 144-150
Link Here
|
144 |
// file in which to store package annotations and |
196 |
// file in which to store package annotations and |
145 |
// the package-level spec (replaces package.html) |
197 |
// the package-level spec (replaces package.html) |
146 |
if (!identifier.equals(PACKAGE_INFO)) { |
198 |
if (!identifier.equals(PACKAGE_INFO)) { |
147 |
IStatus status = validateIdentifier(identifier); |
199 |
IStatus status = validateIdentifier(identifier, sourceLevel, complianceLevel); |
148 |
if (!status.isOK()) { |
200 |
if (!status.isOK()) { |
149 |
return status; |
201 |
return status; |
150 |
} |
202 |
} |
Lines 173-180
Link Here
|
173 |
* the given name is valid as a .class file name, otherwise a status |
225 |
* the given name is valid as a .class file name, otherwise a status |
174 |
* object indicating what is wrong with the name |
226 |
* object indicating what is wrong with the name |
175 |
* @since 2.0 |
227 |
* @since 2.0 |
|
|
228 |
* @deprecated Use {@link #validateClassFileName(String id, String sourceLevel, String complianceLevel)} instead |
176 |
*/ |
229 |
*/ |
177 |
public static IStatus validateClassFileName(String name) { |
230 |
public static IStatus validateClassFileName(String name) { |
|
|
231 |
return validateClassFileName(name, CompilerOptions.VERSION_1_3, CompilerOptions.VERSION_1_3); |
232 |
} |
233 |
|
234 |
/** |
235 |
* Validate the given .class file name for the given source and compliance levels. |
236 |
* <p> |
237 |
* A .class file name must obey the following rules: |
238 |
* <ul> |
239 |
* <li> it must not be null |
240 |
* <li> it must include the <code>".class"</code> suffix |
241 |
* <li> its prefix must be a valid identifier |
242 |
* <li> it must not contain any characters or substrings that are not valid |
243 |
* on the file system on which workspace root is located. |
244 |
* </ul> |
245 |
* </p> |
246 |
* @param name the name of a .class file |
247 |
* @param sourceLevel the source level |
248 |
* @param complianceLevel the compliance level |
249 |
* @return a status object with code <code>IStatus.OK</code> if |
250 |
* the given name is valid as a .class file name, otherwise a status |
251 |
* object indicating what is wrong with the name |
252 |
* @since 3.3 |
253 |
*/ |
254 |
public static IStatus validateClassFileName(String name, String sourceLevel, String complianceLevel) { |
178 |
if (name == null) { |
255 |
if (name == null) { |
179 |
return new Status(IStatus.ERROR, JavaCore.PLUGIN_ID, -1, Messages.convention_classFile_nullName, null); } |
256 |
return new Status(IStatus.ERROR, JavaCore.PLUGIN_ID, -1, Messages.convention_classFile_nullName, null); } |
180 |
if (!org.eclipse.jdt.internal.compiler.util.Util.isClassFileName(name)) { |
257 |
if (!org.eclipse.jdt.internal.compiler.util.Util.isClassFileName(name)) { |
Lines 191-197
Link Here
|
191 |
// file in which to store package annotations and |
268 |
// file in which to store package annotations and |
192 |
// the package-level spec (replaces package.html) |
269 |
// the package-level spec (replaces package.html) |
193 |
if (!identifier.equals(PACKAGE_INFO)) { |
270 |
if (!identifier.equals(PACKAGE_INFO)) { |
194 |
IStatus status = validateIdentifier(identifier); |
271 |
IStatus status = validateIdentifier(identifier, sourceLevel, complianceLevel); |
195 |
if (!status.isOK()) { |
272 |
if (!status.isOK()) { |
196 |
return status; |
273 |
return status; |
197 |
} |
274 |
} |
Lines 213-221
Link Here
|
213 |
* @return a status object with code <code>IStatus.OK</code> if |
290 |
* @return a status object with code <code>IStatus.OK</code> if |
214 |
* the given name is valid as a field name, otherwise a status |
291 |
* the given name is valid as a field name, otherwise a status |
215 |
* object indicating what is wrong with the name |
292 |
* object indicating what is wrong with the name |
|
|
293 |
* @deprecated Use {@link #validateFieldName(String id, String sourceLevel, String complianceLevel)} instead |
216 |
*/ |
294 |
*/ |
217 |
public static IStatus validateFieldName(String name) { |
295 |
public static IStatus validateFieldName(String name) { |
218 |
return validateIdentifier(name); |
296 |
return validateIdentifier(name, CompilerOptions.VERSION_1_3,CompilerOptions.VERSION_1_3); |
|
|
297 |
} |
298 |
|
299 |
/** |
300 |
* Validate the given field name for the given source and compliance levels. |
301 |
* <p> |
302 |
* Syntax of a field name corresponds to VariableDeclaratorId (JLS2 8.3). |
303 |
* For example, <code>"x"</code>. |
304 |
* |
305 |
* @param name the name of a field |
306 |
* @param sourceLevel the source level |
307 |
* @param complianceLevel the compliance level |
308 |
* @return a status object with code <code>IStatus.OK</code> if |
309 |
* the given name is valid as a field name, otherwise a status |
310 |
* object indicating what is wrong with the name |
311 |
* @since 3.3 |
312 |
*/ |
313 |
public static IStatus validateFieldName(String name, String sourceLevel, String complianceLevel) { |
314 |
return validateIdentifier(name, sourceLevel, complianceLevel); |
219 |
} |
315 |
} |
220 |
|
316 |
|
221 |
/** |
317 |
/** |
Lines 229-237
Link Here
|
229 |
* @return a status object with code <code>IStatus.OK</code> if |
325 |
* @return a status object with code <code>IStatus.OK</code> if |
230 |
* the given identifier is a valid Java identifier, otherwise a status |
326 |
* the given identifier is a valid Java identifier, otherwise a status |
231 |
* object indicating what is wrong with the identifier |
327 |
* object indicating what is wrong with the identifier |
|
|
328 |
* @deprecated Use {@link #validateIdentifier(String id, String sourceLevel, String complianceLevel)} instead |
232 |
*/ |
329 |
*/ |
233 |
public static IStatus validateIdentifier(String id) { |
330 |
public static IStatus validateIdentifier(String id) { |
234 |
if (scannedIdentifier(id) != null) { |
331 |
return validateIdentifier(id,CompilerOptions.VERSION_1_3,CompilerOptions.VERSION_1_3); |
|
|
332 |
} |
333 |
|
334 |
/** |
335 |
* Validate the given Java identifier for the given source and compliance levels |
336 |
* The identifier must not have the same spelling as a Java keyword, |
337 |
* boolean literal (<code>"true"</code>, <code>"false"</code>), or null literal (<code>"null"</code>). |
338 |
* See section 3.8 of the <em>Java Language Specification, Second Edition</em> (JLS2). |
339 |
* A valid identifier can act as a simple type name, method name or field name. |
340 |
* |
341 |
* @param id the Java identifier |
342 |
* @param sourceLevel the source level |
343 |
* @param complianceLevel the compliance level |
344 |
* @return a status object with code <code>IStatus.OK</code> if |
345 |
* the given identifier is a valid Java identifier, otherwise a status |
346 |
* object indicating what is wrong with the identifier |
347 |
* @since 3.3 |
348 |
*/ |
349 |
public static IStatus validateIdentifier(String id, String sourceLevel, String complianceLevel) { |
350 |
if (scannedIdentifier(id, sourceLevel, complianceLevel) != null) { |
235 |
return JavaModelStatus.VERIFIED_OK; |
351 |
return JavaModelStatus.VERIFIED_OK; |
236 |
} else { |
352 |
} else { |
237 |
return new Status(IStatus.ERROR, JavaCore.PLUGIN_ID, -1, Messages.bind(Messages.convention_illegalIdentifier, id), null); |
353 |
return new Status(IStatus.ERROR, JavaCore.PLUGIN_ID, -1, Messages.bind(Messages.convention_illegalIdentifier, id), null); |
Lines 249-267
Link Here
|
249 |
* @return a status object with code <code>IStatus.OK</code> if |
365 |
* @return a status object with code <code>IStatus.OK</code> if |
250 |
* the given name is valid as an import declaration, otherwise a status |
366 |
* the given name is valid as an import declaration, otherwise a status |
251 |
* object indicating what is wrong with the name |
367 |
* object indicating what is wrong with the name |
|
|
368 |
* @deprecated Use {@link #validateImportDeclaration(String id, String sourceLevel, String complianceLevel)} instead |
252 |
*/ |
369 |
*/ |
253 |
public static IStatus validateImportDeclaration(String name) { |
370 |
public static IStatus validateImportDeclaration(String name) { |
|
|
371 |
return validateImportDeclaration(name,CompilerOptions.VERSION_1_3,CompilerOptions.VERSION_1_3); |
372 |
} |
373 |
|
374 |
/** |
375 |
* Validate the given import declaration name for the given source and compliance levels. |
376 |
* <p> |
377 |
* The name of an import corresponds to a fully qualified type name |
378 |
* or an on-demand package name as defined by ImportDeclaration (JLS2 7.5). |
379 |
* For example, <code>"java.util.*"</code> or <code>"java.util.Hashtable"</code>. |
380 |
* |
381 |
* @param name the import declaration |
382 |
* @param sourceLevel the source level |
383 |
* @param complianceLevel the compliance level |
384 |
* @return a status object with code <code>IStatus.OK</code> if |
385 |
* the given name is valid as an import declaration, otherwise a status |
386 |
* object indicating what is wrong with the name |
387 |
* @since 3.3 |
388 |
*/ |
389 |
public static IStatus validateImportDeclaration(String name, String sourceLevel, String complianceLevel) { |
254 |
if (name == null || name.length() == 0) { |
390 |
if (name == null || name.length() == 0) { |
255 |
return new Status(IStatus.ERROR, JavaCore.PLUGIN_ID, -1, Messages.convention_import_nullImport, null); |
391 |
return new Status(IStatus.ERROR, JavaCore.PLUGIN_ID, -1, Messages.convention_import_nullImport, null); |
256 |
} |
392 |
} |
257 |
if (name.charAt(name.length() - 1) == '*') { |
393 |
if (name.charAt(name.length() - 1) == '*') { |
258 |
if (name.charAt(name.length() - 2) == '.') { |
394 |
if (name.charAt(name.length() - 2) == '.') { |
259 |
return validatePackageName(name.substring(0, name.length() - 2)); |
395 |
return validatePackageName(name.substring(0, name.length() - 2), sourceLevel, complianceLevel); |
260 |
} else { |
396 |
} else { |
261 |
return new Status(IStatus.ERROR, JavaCore.PLUGIN_ID, -1, Messages.convention_import_unqualifiedImport, null); |
397 |
return new Status(IStatus.ERROR, JavaCore.PLUGIN_ID, -1, Messages.convention_import_unqualifiedImport, null); |
262 |
} |
398 |
} |
263 |
} |
399 |
} |
264 |
return validatePackageName(name); |
400 |
return validatePackageName(name, sourceLevel, complianceLevel); |
265 |
} |
401 |
} |
266 |
|
402 |
|
267 |
/** |
403 |
/** |
Lines 276-283
Link Here
|
276 |
* indicating why the given name is discouraged, |
412 |
* indicating why the given name is discouraged, |
277 |
* otherwise a status object indicating what is wrong with |
413 |
* otherwise a status object indicating what is wrong with |
278 |
* the name |
414 |
* the name |
|
|
415 |
* @deprecated Use {@link #validateJavaTypeName(String id, String sourceLevel, String complianceLevel)} instead |
279 |
*/ |
416 |
*/ |
280 |
public static IStatus validateJavaTypeName(String name) { |
417 |
public static IStatus validateJavaTypeName(String name) { |
|
|
418 |
return validateJavaTypeName(name, CompilerOptions.VERSION_1_3,CompilerOptions.VERSION_1_3); |
419 |
} |
420 |
|
421 |
/** |
422 |
* Validate the given Java type name, either simple or qualified, for the given source and compliance levels. |
423 |
* For example, <code>"java.lang.Object"</code>, or <code>"Object"</code>. |
424 |
* <p> |
425 |
* |
426 |
* @param name the name of a type |
427 |
* @param sourceLevel the source level |
428 |
* @param complianceLevel the compliance level |
429 |
* @return a status object with code <code>IStatus.OK</code> if |
430 |
* the given name is valid as a Java type name, |
431 |
* a status with code <code>IStatus.WARNING</code> |
432 |
* indicating why the given name is discouraged, |
433 |
* otherwise a status object indicating what is wrong with |
434 |
* the name |
435 |
* @since 3.3 |
436 |
*/ |
437 |
public static IStatus validateJavaTypeName(String name, String sourceLevel, String complianceLevel) { |
281 |
if (name == null) { |
438 |
if (name == null) { |
282 |
return new Status(IStatus.ERROR, JavaCore.PLUGIN_ID, -1, Messages.convention_type_nullName, null); |
439 |
return new Status(IStatus.ERROR, JavaCore.PLUGIN_ID, -1, Messages.convention_type_nullName, null); |
283 |
} |
440 |
} |
Lines 289-304
Link Here
|
289 |
char[] scannedID; |
446 |
char[] scannedID; |
290 |
if (index == -1) { |
447 |
if (index == -1) { |
291 |
// simple name |
448 |
// simple name |
292 |
scannedID = scannedIdentifier(name); |
449 |
scannedID = scannedIdentifier(name, sourceLevel, complianceLevel); |
293 |
} else { |
450 |
} else { |
294 |
// qualified name |
451 |
// qualified name |
295 |
String pkg = name.substring(0, index).trim(); |
452 |
String pkg = name.substring(0, index).trim(); |
296 |
IStatus status = validatePackageName(pkg); |
453 |
IStatus status = validatePackageName(pkg, sourceLevel, complianceLevel); |
297 |
if (!status.isOK()) { |
454 |
if (!status.isOK()) { |
298 |
return status; |
455 |
return status; |
299 |
} |
456 |
} |
300 |
String type = name.substring(index + 1).trim(); |
457 |
String type = name.substring(index + 1).trim(); |
301 |
scannedID = scannedIdentifier(type); |
458 |
scannedID = scannedIdentifier(type, sourceLevel, complianceLevel); |
302 |
} |
459 |
} |
303 |
|
460 |
|
304 |
if (scannedID != null) { |
461 |
if (scannedID != null) { |
Lines 329-338
Link Here
|
329 |
* @return a status object with code <code>IStatus.OK</code> if |
486 |
* @return a status object with code <code>IStatus.OK</code> if |
330 |
* the given name is valid as a method name, otherwise a status |
487 |
* the given name is valid as a method name, otherwise a status |
331 |
* object indicating what is wrong with the name |
488 |
* object indicating what is wrong with the name |
|
|
489 |
* @deprecated Use {@link #validateMethodName(String id, String sourceLevel, String complianceLevel)} instead |
332 |
*/ |
490 |
*/ |
333 |
public static IStatus validateMethodName(String name) { |
491 |
public static IStatus validateMethodName(String name) { |
334 |
|
492 |
return validateMethodName(name, CompilerOptions.VERSION_1_3,CompilerOptions.VERSION_1_3); |
335 |
return validateIdentifier(name); |
493 |
} |
|
|
494 |
|
495 |
/** |
496 |
* Validate the given method name for the given source and compliance levels. |
497 |
* The special names "<init>" and "<clinit>" are not valid. |
498 |
* <p> |
499 |
* The syntax for a method name is defined by Identifier |
500 |
* of MethodDeclarator (JLS2 8.4). For example "println". |
501 |
* |
502 |
* @param name the name of a method |
503 |
* @param sourceLevel the source level |
504 |
* @param complianceLevel the compliance level |
505 |
* @return a status object with code <code>IStatus.OK</code> if |
506 |
* the given name is valid as a method name, otherwise a status |
507 |
* object indicating what is wrong with the name |
508 |
* @since 3.3 |
509 |
*/ |
510 |
public static IStatus validateMethodName(String name, String sourceLevel, String complianceLevel) { |
511 |
return validateIdentifier(name, sourceLevel,complianceLevel); |
336 |
} |
512 |
} |
337 |
|
513 |
|
338 |
/** |
514 |
/** |
Lines 350-357
Link Here
|
350 |
* @return a status object with code <code>IStatus.OK</code> if |
526 |
* @return a status object with code <code>IStatus.OK</code> if |
351 |
* the given name is valid as a package name, otherwise a status |
527 |
* the given name is valid as a package name, otherwise a status |
352 |
* object indicating what is wrong with the name |
528 |
* object indicating what is wrong with the name |
|
|
529 |
* @deprecated Use {@link #validatePackageName(String id, String sourceLevel, String complianceLevel)} instead |
353 |
*/ |
530 |
*/ |
354 |
public static IStatus validatePackageName(String name) { |
531 |
public static IStatus validatePackageName(String name) { |
|
|
532 |
return validatePackageName(name, CompilerOptions.VERSION_1_3,CompilerOptions.VERSION_1_3); |
533 |
} |
534 |
|
535 |
/** |
536 |
* Validate the given package name for the given source and compliance levels. |
537 |
* <p> |
538 |
* The syntax of a package name corresponds to PackageName as |
539 |
* defined by PackageDeclaration (JLS2 7.4). For example, <code>"java.lang"</code>. |
540 |
* <p> |
541 |
* Note that the given name must be a non-empty package name (that is, attempting to |
542 |
* validate the default package will return an error status.) |
543 |
* Also it must not contain any characters or substrings that are not valid |
544 |
* on the file system on which workspace root is located. |
545 |
* |
546 |
* @param name the name of a package |
547 |
* @param sourceLevel the source level |
548 |
* @param complianceLevel the compliance level |
549 |
* @return a status object with code <code>IStatus.OK</code> if |
550 |
* the given name is valid as a package name, otherwise a status |
551 |
* object indicating what is wrong with the name |
552 |
* @since 3.3 |
553 |
*/ |
554 |
public static IStatus validatePackageName(String name, String sourceLevel, String complianceLevel) { |
355 |
|
555 |
|
356 |
if (name == null) { |
556 |
if (name == null) { |
357 |
return new Status(IStatus.ERROR, JavaCore.PLUGIN_ID, -1, Messages.convention_package_nullName, null); |
557 |
return new Status(IStatus.ERROR, JavaCore.PLUGIN_ID, -1, Messages.convention_package_nullName, null); |
Lines 379-385
Link Here
|
379 |
while (st.hasMoreTokens()) { |
579 |
while (st.hasMoreTokens()) { |
380 |
String typeName = st.nextToken(); |
580 |
String typeName = st.nextToken(); |
381 |
typeName = typeName.trim(); // grammar allows spaces |
581 |
typeName = typeName.trim(); // grammar allows spaces |
382 |
char[] scannedID = scannedIdentifier(typeName); |
582 |
char[] scannedID = scannedIdentifier(typeName, sourceLevel, complianceLevel); |
383 |
if (scannedID == null) { |
583 |
if (scannedID == null) { |
384 |
return new Status(IStatus.ERROR, JavaCore.PLUGIN_ID, -1, Messages.bind(Messages.convention_illegalIdentifier, typeName), null); |
584 |
return new Status(IStatus.ERROR, JavaCore.PLUGIN_ID, -1, Messages.bind(Messages.convention_illegalIdentifier, typeName), null); |
385 |
} |
585 |
} |
Lines 465-475
Link Here
|
465 |
* the given name is valid as a type variable name, otherwise a status |
665 |
* the given name is valid as a type variable name, otherwise a status |
466 |
* object indicating what is wrong with the name |
666 |
* object indicating what is wrong with the name |
467 |
* @since 3.1 |
667 |
* @since 3.1 |
|
|
668 |
* @deprecated Use {@link #validateTypeVariableName(String id, String sourceLevel, String complianceLevel)} instead |
468 |
*/ |
669 |
*/ |
469 |
public static IStatus validateTypeVariableName(String name) { |
670 |
public static IStatus validateTypeVariableName(String name) { |
470 |
return validateIdentifier(name); |
671 |
return validateIdentifier(name, CompilerOptions.VERSION_1_3,CompilerOptions.VERSION_1_3); |
471 |
} |
672 |
} |
472 |
|
673 |
|
|
|
674 |
/** |
675 |
* Validate the given type variable name for the given source and compliance levels. |
676 |
* <p> |
677 |
* Syntax of a type variable name corresponds to a Java identifier (JLS3 4.3). |
678 |
* For example, <code>"E"</code>. |
679 |
* |
680 |
* @param name the name of a type variable |
681 |
* @param sourceLevel the source level |
682 |
* @param complianceLevel the compliance level |
683 |
* @return a status object with code <code>IStatus.OK</code> if |
684 |
* the given name is valid as a type variable name, otherwise a status |
685 |
* object indicating what is wrong with the name |
686 |
* @since 3.3 |
687 |
*/ |
688 |
public static IStatus validateTypeVariableName(String name, String sourceLevel, String complianceLevel) { |
689 |
return validateIdentifier(name, sourceLevel, complianceLevel); |
690 |
} |
691 |
|
473 |
/** |
692 |
/** |
474 |
* Validate that all compiler options of the given project match keys and values |
693 |
* Validate that all compiler options of the given project match keys and values |
475 |
* described in {@link JavaCore#getDefaultOptions()} method. |
694 |
* described in {@link JavaCore#getDefaultOptions()} method. |