View | Details | Raw Unified | Return to bug 161621
Collapse All | Expand All

(-)model/org/eclipse/jdt/core/IPackageFragment.java (-1 / +1 lines)
Lines 100-106 Link Here
100
	 * 
100
	 * 
101
	 * @param name the given name
101
	 * @param name the given name
102
	 * @return the compilation unit with the specified name in this package
102
	 * @return the compilation unit with the specified name in this package
103
	 * @see JavaConventions#validateCompilationUnitName(String)
103
	 * @see JavaConventions#validateCompilationUnitName(String name, String sourceLevel, String complianceLevel)
104
	 */
104
	 */
105
	ICompilationUnit getCompilationUnit(String name);
105
	ICompilationUnit getCompilationUnit(String name);
106
	/**
106
	/**
(-)model/org/eclipse/jdt/core/ICompilationUnit.java (-1 / +1 lines)
Lines 378-384 Link Here
378
 *
378
 *
379
 * @param name the simple name of the requested type in the compilation unit
379
 * @param name the simple name of the requested type in the compilation unit
380
 * @return a handle onto the corresponding type. The type may or may not exist.
380
 * @return a handle onto the corresponding type. The type may or may not exist.
381
 * @see JavaConventions#validateCompilationUnitName(String name)
381
 * @see JavaConventions#validateCompilationUnitName(String name, String sourceLevel, String complianceLevel)
382
 */
382
 */
383
IType getType(String name);
383
IType getType(String name);
384
/**
384
/**
(-)model/org/eclipse/jdt/core/JavaConventions.java (-24 / +243 lines)
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 "&lt;init&gt;" and "&lt;clinit&gt;" 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.
(-)model/org/eclipse/jdt/internal/core/CreatePackageDeclarationOperation.java (-1 / +4 lines)
Lines 16-23 Link Here
16
import org.eclipse.jdt.core.IJavaElement;
16
import org.eclipse.jdt.core.IJavaElement;
17
import org.eclipse.jdt.core.IJavaModelStatus;
17
import org.eclipse.jdt.core.IJavaModelStatus;
18
import org.eclipse.jdt.core.IJavaModelStatusConstants;
18
import org.eclipse.jdt.core.IJavaModelStatusConstants;
19
import org.eclipse.jdt.core.IJavaProject;
19
import org.eclipse.jdt.core.IType;
20
import org.eclipse.jdt.core.IType;
20
import org.eclipse.jdt.core.JavaConventions;
21
import org.eclipse.jdt.core.JavaConventions;
22
import org.eclipse.jdt.core.JavaCore;
21
import org.eclipse.jdt.core.JavaModelException;
23
import org.eclipse.jdt.core.JavaModelException;
22
import org.eclipse.jdt.core.dom.AST;
24
import org.eclipse.jdt.core.dom.AST;
23
import org.eclipse.jdt.core.dom.ASTNode;
25
import org.eclipse.jdt.core.dom.ASTNode;
Lines 120-126 Link Here
120
	if (!status.isOK()) {
122
	if (!status.isOK()) {
121
		return status;
123
		return status;
122
	}
124
	}
123
	if (JavaConventions.validatePackageName(this.name).getSeverity() == IStatus.ERROR) {
125
	IJavaProject project = getParentElement().getJavaProject();
126
	if (JavaConventions.validatePackageName(this.name, project.getOption(JavaCore.COMPILER_SOURCE, true), project.getOption(JavaCore.COMPILER_COMPLIANCE, true)).getSeverity() == IStatus.ERROR) {
124
		return new JavaModelStatus(IJavaModelStatusConstants.INVALID_NAME, this.name);
127
		return new JavaModelStatus(IJavaModelStatusConstants.INVALID_NAME, this.name);
125
	}
128
	}
126
	return JavaModelStatus.VERIFIED_OK;
129
	return JavaModelStatus.VERIFIED_OK;
(-)model/org/eclipse/jdt/internal/core/CreateImportOperation.java (-1 / +4 lines)
Lines 19-26 Link Here
19
import org.eclipse.jdt.core.IJavaElement;
19
import org.eclipse.jdt.core.IJavaElement;
20
import org.eclipse.jdt.core.IJavaModelStatus;
20
import org.eclipse.jdt.core.IJavaModelStatus;
21
import org.eclipse.jdt.core.IJavaModelStatusConstants;
21
import org.eclipse.jdt.core.IJavaModelStatusConstants;
22
import org.eclipse.jdt.core.IJavaProject;
22
import org.eclipse.jdt.core.IType;
23
import org.eclipse.jdt.core.IType;
23
import org.eclipse.jdt.core.JavaConventions;
24
import org.eclipse.jdt.core.JavaConventions;
25
import org.eclipse.jdt.core.JavaCore;
24
import org.eclipse.jdt.core.JavaModelException;
26
import org.eclipse.jdt.core.JavaModelException;
25
import org.eclipse.jdt.core.compiler.CharOperation;
27
import org.eclipse.jdt.core.compiler.CharOperation;
26
import org.eclipse.jdt.core.dom.AST;
28
import org.eclipse.jdt.core.dom.AST;
Lines 165-171 Link Here
165
	if (!status.isOK()) {
167
	if (!status.isOK()) {
166
		return status;
168
		return status;
167
	}
169
	}
168
	if (JavaConventions.validateImportDeclaration(this.importName).getSeverity() == IStatus.ERROR) {
170
	IJavaProject project = getParentElement().getJavaProject();
171
	if (JavaConventions.validateImportDeclaration(this.importName, project.getOption(JavaCore.COMPILER_SOURCE, true), project.getOption(JavaCore.COMPILER_COMPLIANCE, true)).getSeverity() == IStatus.ERROR) {
169
		return new JavaModelStatus(IJavaModelStatusConstants.INVALID_NAME, this.importName);
172
		return new JavaModelStatus(IJavaModelStatusConstants.INVALID_NAME, this.importName);
170
	}
173
	}
171
	return JavaModelStatus.VERIFIED_OK;
174
	return JavaModelStatus.VERIFIED_OK;
(-)model/org/eclipse/jdt/internal/core/ClassFile.java (-1 / +2 lines)
Lines 560-566 Link Here
560
	} catch (JavaModelException e) {
560
	} catch (JavaModelException e) {
561
		return e.getJavaModelStatus();
561
		return e.getJavaModelStatus();
562
	}
562
	}
563
	return JavaConventions.validateClassFileName(getElementName());
563
	IJavaProject project = getJavaProject();
564
	return JavaConventions.validateClassFileName(getElementName(), project.getOption(JavaCore.COMPILER_SOURCE, true), project.getOption(JavaCore.COMPILER_COMPLIANCE, true));
564
}
565
}
565
/**
566
/**
566
 * Opens and returns buffer on the source code associated with this class file.
567
 * Opens and returns buffer on the source code associated with this class file.
(-)model/org/eclipse/jdt/internal/core/PackageFragment.java (-11 / +19 lines)
Lines 27-36 Link Here
27
import org.eclipse.jdt.core.ICompilationUnit;
27
import org.eclipse.jdt.core.ICompilationUnit;
28
import org.eclipse.jdt.core.IJavaElement;
28
import org.eclipse.jdt.core.IJavaElement;
29
import org.eclipse.jdt.core.IJavaModelStatusConstants;
29
import org.eclipse.jdt.core.IJavaModelStatusConstants;
30
import org.eclipse.jdt.core.IJavaProject;
30
import org.eclipse.jdt.core.IPackageFragment;
31
import org.eclipse.jdt.core.IPackageFragment;
31
import org.eclipse.jdt.core.IPackageFragmentRoot;
32
import org.eclipse.jdt.core.IPackageFragmentRoot;
32
import org.eclipse.jdt.core.IParent;
33
import org.eclipse.jdt.core.IParent;
33
import org.eclipse.jdt.core.ISourceManipulation;
34
import org.eclipse.jdt.core.ISourceManipulation;
35
import org.eclipse.jdt.core.JavaCore;
34
import org.eclipse.jdt.core.JavaModelException;
36
import org.eclipse.jdt.core.JavaModelException;
35
import org.eclipse.jdt.core.WorkingCopyOwner;
37
import org.eclipse.jdt.core.WorkingCopyOwner;
36
import org.eclipse.jdt.internal.compiler.util.SuffixConstants;
38
import org.eclipse.jdt.internal.compiler.util.SuffixConstants;
Lines 79-95 Link Here
79
		char[][] inclusionPatterns = root.fullInclusionPatternChars();
81
		char[][] inclusionPatterns = root.fullInclusionPatternChars();
80
		char[][] exclusionPatterns = root.fullExclusionPatternChars();
82
		char[][] exclusionPatterns = root.fullExclusionPatternChars();
81
		IResource[] members = ((IContainer) underlyingResource).members();
83
		IResource[] members = ((IContainer) underlyingResource).members();
82
		for (int i = 0, max = members.length; i < max; i++) {
84
		int length = members.length;
83
			IResource child = members[i];
85
		if (length > 0) {
84
			if (child.getType() != IResource.FOLDER
86
			IJavaProject project = getJavaProject();
85
					&& !Util.isExcluded(child, inclusionPatterns, exclusionPatterns)) {
87
			String sourceLevel = project.getOption(JavaCore.COMPILER_SOURCE, true);
86
				IJavaElement childElement;
88
			String complianceLevel = project.getOption(JavaCore.COMPILER_COMPLIANCE, true);
87
				if (kind == IPackageFragmentRoot.K_SOURCE && Util.isValidCompilationUnitName(child.getName())) {
89
			for (int i = 0; i < length; i++) {
88
					childElement = new CompilationUnit(this, child.getName(), DefaultWorkingCopyOwner.PRIMARY);
90
				IResource child = members[i];
89
					vChildren.add(childElement);
91
				if (child.getType() != IResource.FOLDER
90
				} else if (kind == IPackageFragmentRoot.K_BINARY && Util.isValidClassFileName(child.getName())) {
92
						&& !Util.isExcluded(child, inclusionPatterns, exclusionPatterns)) {
91
					childElement = getClassFile(child.getName());
93
					IJavaElement childElement;
92
					vChildren.add(childElement);
94
					if (kind == IPackageFragmentRoot.K_SOURCE && Util.isValidCompilationUnitName(child.getName(), sourceLevel, complianceLevel)) {
95
						childElement = new CompilationUnit(this, child.getName(), DefaultWorkingCopyOwner.PRIMARY);
96
						vChildren.add(childElement);
97
					} else if (kind == IPackageFragmentRoot.K_BINARY && Util.isValidClassFileName(child.getName(), sourceLevel, complianceLevel)) {
98
						childElement = getClassFile(child.getName());
99
						vChildren.add(childElement);
100
					}
93
				}
101
				}
94
			}
102
			}
95
		}
103
		}
(-)model/org/eclipse/jdt/internal/core/SourceMapper.java (-1 / +10 lines)
Lines 38-43 Link Here
38
import org.eclipse.jdt.core.IClassFile;
38
import org.eclipse.jdt.core.IClassFile;
39
import org.eclipse.jdt.core.IField;
39
import org.eclipse.jdt.core.IField;
40
import org.eclipse.jdt.core.IJavaElement;
40
import org.eclipse.jdt.core.IJavaElement;
41
import org.eclipse.jdt.core.IJavaProject;
41
import org.eclipse.jdt.core.IMember;
42
import org.eclipse.jdt.core.IMember;
42
import org.eclipse.jdt.core.IMethod;
43
import org.eclipse.jdt.core.IMethod;
43
import org.eclipse.jdt.core.IPackageFragmentRoot;
44
import org.eclipse.jdt.core.IPackageFragmentRoot;
Lines 45-50 Link Here
45
import org.eclipse.jdt.core.IType;
46
import org.eclipse.jdt.core.IType;
46
import org.eclipse.jdt.core.ITypeParameter;
47
import org.eclipse.jdt.core.ITypeParameter;
47
import org.eclipse.jdt.core.JavaConventions;
48
import org.eclipse.jdt.core.JavaConventions;
49
import org.eclipse.jdt.core.JavaCore;
48
import org.eclipse.jdt.core.JavaModelException;
50
import org.eclipse.jdt.core.JavaModelException;
49
import org.eclipse.jdt.core.Signature;
51
import org.eclipse.jdt.core.Signature;
50
import org.eclipse.jdt.core.compiler.CategorizedProblem;
52
import org.eclipse.jdt.core.compiler.CategorizedProblem;
Lines 365-370 Link Here
365
367
366
		if (root.isArchive()) {
368
		if (root.isArchive()) {
367
			JarPackageFragmentRoot jarPackageFragmentRoot = (JarPackageFragmentRoot) root;
369
			JarPackageFragmentRoot jarPackageFragmentRoot = (JarPackageFragmentRoot) root;
370
			IJavaProject project = jarPackageFragmentRoot.getJavaProject();
371
			String sourceLevel = null;
372
			String complianceLevel = null;
368
			JavaModelManager manager = JavaModelManager.getJavaModelManager();
373
			JavaModelManager manager = JavaModelManager.getJavaModelManager();
369
			ZipFile zip = null;
374
			ZipFile zip = null;
370
			try {
375
			try {
Lines 377-383 Link Here
377
						if (index != -1 && Util.isClassFileName(entryName)) {
382
						if (index != -1 && Util.isClassFileName(entryName)) {
378
							String firstLevelPackageName = entryName.substring(0, index);
383
							String firstLevelPackageName = entryName.substring(0, index);
379
							if (!firstLevelPackageNames.contains(firstLevelPackageName)) {
384
							if (!firstLevelPackageNames.contains(firstLevelPackageName)) {
380
								IStatus status = JavaConventions.validatePackageName(firstLevelPackageName);
385
								if (sourceLevel == null) {
386
									sourceLevel = project.getOption(JavaCore.COMPILER_SOURCE, true);
387
									complianceLevel = project.getOption(JavaCore.COMPILER_COMPLIANCE, true);
388
								}
389
								IStatus status = JavaConventions.validatePackageName(firstLevelPackageName, sourceLevel, complianceLevel);
381
								if (status.isOK() || status.getSeverity() == IStatus.WARNING) {
390
								if (status.isOK() || status.getSeverity() == IStatus.WARNING) {
382
									firstLevelPackageNames.add(firstLevelPackageName);
391
									firstLevelPackageNames.add(firstLevelPackageName);
383
								}
392
								}
(-)model/org/eclipse/jdt/internal/core/CommitWorkingCopyOperation.java (-2 / +4 lines)
Lines 18-29 Link Here
18
import org.eclipse.core.resources.IWorkspace;
18
import org.eclipse.core.resources.IWorkspace;
19
import org.eclipse.core.runtime.CoreException;
19
import org.eclipse.core.runtime.CoreException;
20
import org.eclipse.core.runtime.jobs.ISchedulingRule;
20
import org.eclipse.core.runtime.jobs.ISchedulingRule;
21
//import org.eclipse.jdt.core.*;
22
import org.eclipse.jdt.core.IBuffer;
21
import org.eclipse.jdt.core.IBuffer;
23
import org.eclipse.jdt.core.ICompilationUnit;
22
import org.eclipse.jdt.core.ICompilationUnit;
24
import org.eclipse.jdt.core.IJavaElement;
23
import org.eclipse.jdt.core.IJavaElement;
25
import org.eclipse.jdt.core.IJavaModelStatus;
24
import org.eclipse.jdt.core.IJavaModelStatus;
26
import org.eclipse.jdt.core.IJavaModelStatusConstants;
25
import org.eclipse.jdt.core.IJavaModelStatusConstants;
26
import org.eclipse.jdt.core.IJavaProject;
27
import org.eclipse.jdt.core.JavaCore;
27
import org.eclipse.jdt.core.JavaModelException;
28
import org.eclipse.jdt.core.JavaModelException;
28
import org.eclipse.jdt.internal.core.util.Messages;
29
import org.eclipse.jdt.internal.core.util.Messages;
29
import org.eclipse.jdt.internal.core.util.Util;
30
import org.eclipse.jdt.internal.core.util.Util;
Lines 83-89 Link Here
83
			PackageFragmentRoot root = (PackageFragmentRoot)workingCopy.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT);
84
			PackageFragmentRoot root = (PackageFragmentRoot)workingCopy.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT);
84
			boolean isIncluded = !Util.isExcluded(workingCopy);
85
			boolean isIncluded = !Util.isExcluded(workingCopy);
85
			IFile resource = (IFile)workingCopy.getResource();
86
			IFile resource = (IFile)workingCopy.getResource();
86
			if (isPrimary || (root.validateOnClasspath().isOK() && isIncluded && resource.isAccessible() && Util.isValidCompilationUnitName(workingCopy.getElementName()))) {
87
			IJavaProject project = root.getJavaProject();
88
			if (isPrimary || (root.validateOnClasspath().isOK() && isIncluded && resource.isAccessible() && Util.isValidCompilationUnitName(workingCopy.getElementName(), project.getOption(JavaCore.COMPILER_SOURCE, true), project.getOption(JavaCore.COMPILER_COMPLIANCE, true)))) {
87
				
89
				
88
				// force opening so that the delta builder can get the old info
90
				// force opening so that the delta builder can get the old info
89
				if (!isPrimary && !primary.isOpen()) {
91
				if (!isPrimary && !primary.isOpen()) {
(-)model/org/eclipse/jdt/internal/core/DeltaProcessor.java (-9 / +28 lines)
Lines 1230-1244 Link Here
1230
					if (parentType == NON_JAVA_RESOURCE && !Util.isExcluded(res.getParent(), rootInfo.inclusionPatterns, rootInfo.exclusionPatterns))
1230
					if (parentType == NON_JAVA_RESOURCE && !Util.isExcluded(res.getParent(), rootInfo.inclusionPatterns, rootInfo.exclusionPatterns))
1231
						// parent is a non-Java resource because it doesn't have a valid package name (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=130982)
1231
						// parent is a non-Java resource because it doesn't have a valid package name (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=130982)
1232
						return NON_JAVA_RESOURCE;
1232
						return NON_JAVA_RESOURCE;
1233
					if (Util.isValidFolderNameForPackage(res.getName())) {
1233
					if (Util.isValidFolderNameForPackage(res.getName(), rootInfo.project.getOption(JavaCore.COMPILER_SOURCE, true), rootInfo.project.getOption(JavaCore.COMPILER_COMPLIANCE, true))) {
1234
						return IJavaElement.PACKAGE_FRAGMENT;
1234
						return IJavaElement.PACKAGE_FRAGMENT;
1235
					}
1235
					}
1236
					return NON_JAVA_RESOURCE;
1236
					return NON_JAVA_RESOURCE;
1237
				}
1237
				}
1238
				String fileName = res.getName();
1238
				String fileName = res.getName();
1239
				if (Util.isValidCompilationUnitName(fileName)) {
1239
				String sourceLevel = rootInfo.project.getOption(JavaCore.COMPILER_SOURCE, true);
1240
				String complianceLevel = rootInfo.project.getOption(JavaCore.COMPILER_COMPLIANCE, true);
1241
				if (Util.isValidCompilationUnitName(fileName, sourceLevel, complianceLevel)) {
1240
					return IJavaElement.COMPILATION_UNIT;
1242
					return IJavaElement.COMPILATION_UNIT;
1241
				} else if (Util.isValidClassFileName(fileName)) {
1243
				} else if (Util.isValidClassFileName(fileName, sourceLevel, complianceLevel)) {
1242
					return IJavaElement.CLASS_FILE;
1244
					return IJavaElement.CLASS_FILE;
1243
				} else if (this.rootInfo(res.getFullPath(), kind) != null) {
1245
				} else if (this.rootInfo(res.getFullPath(), kind) != null) {
1244
					// case of proj=src=bin and resource is a jar file on the classpath
1246
					// case of proj=src=bin and resource is a jar file on the classpath
Lines 1419-1426 Link Here
1419
	 * Returns whether the given resource is in one of the given output folders and if
1421
	 * Returns whether the given resource is in one of the given output folders and if
1420
	 * it is filtered out from this output folder.
1422
	 * it is filtered out from this output folder.
1421
	 */
1423
	 */
1422
	private boolean isResFilteredFromOutput(OutputsInfo info, IResource res, int elementType) {
1424
	private boolean isResFilteredFromOutput(RootInfo rootInfo, OutputsInfo info, IResource res, int elementType) {
1423
		if (info != null) {
1425
		if (info != null) {
1426
			JavaProject javaProject = null;
1427
			String sourceLevel = null;
1428
			String complianceLevel = null;
1424
			IPath resPath = res.getFullPath();
1429
			IPath resPath = res.getFullPath();
1425
			for (int i = 0;  i < info.outputCount; i++) {
1430
			for (int i = 0;  i < info.outputCount; i++) {
1426
				if (info.paths[i].isPrefixOf(resPath)) {
1431
				if (info.paths[i].isPrefixOf(resPath)) {
Lines 1431-1440 Link Here
1431
						}
1436
						}
1432
						// case of .class file under project and no source folder
1437
						// case of .class file under project and no source folder
1433
						// proj=bin
1438
						// proj=bin
1434
						if (elementType == IJavaElement.JAVA_PROJECT 
1439
						if (elementType == IJavaElement.JAVA_PROJECT && res instanceof IFile) {
1435
								&& res instanceof IFile 
1440
							if (sourceLevel == null) {
1436
								&& Util.isValidClassFileName(res.getName())) {
1441
								// Get java project to use its source and compliance levels
1437
							return true;
1442
								javaProject = rootInfo == null ?
1443
									(JavaProject)this.createElement(res.getProject(), IJavaElement.JAVA_PROJECT, null) :
1444
									rootInfo.project;
1445
								if (javaProject == null) {
1446
									// Cannot get any project => use workspace options
1447
									sourceLevel = this.manager.getOption(JavaCore.COMPILER_SOURCE);
1448
									complianceLevel = this.manager.getOption(JavaCore.COMPILER_COMPLIANCE);
1449
								} else {
1450
									sourceLevel = javaProject.getOption(JavaCore.COMPILER_SOURCE, true);
1451
									complianceLevel = javaProject.getOption(JavaCore.COMPILER_COMPLIANCE, true);
1452
								}
1453
							}
1454
							if (Util.isValidClassFileName(res.getName(), sourceLevel, complianceLevel)) {
1455
								return true;
1456
							}
1438
						}
1457
						}
1439
					} else {
1458
					} else {
1440
						return true;
1459
						return true;
Lines 2024-2030 Link Here
2024
					);
2043
					);
2025
						
2044
						
2026
				// is childRes in the output folder and is it filtered out ?
2045
				// is childRes in the output folder and is it filtered out ?
2027
				boolean isResFilteredFromOutput = this.isResFilteredFromOutput(outputsInfo, childRes, childType);
2046
				boolean isResFilteredFromOutput = this.isResFilteredFromOutput(rootInfo, outputsInfo, childRes, childType);
2028
2047
2029
				boolean isNestedRoot = rootInfo != null && childRootInfo != null;
2048
				boolean isNestedRoot = rootInfo != null && childRootInfo != null;
2030
				if (!isResFilteredFromOutput 
2049
				if (!isResFilteredFromOutput 
(-)model/org/eclipse/jdt/internal/core/CreateCompilationUnitOperation.java (-5 / +4 lines)
Lines 15-23 Link Here
15
import java.io.InputStream;
15
import java.io.InputStream;
16
16
17
import org.eclipse.core.resources.*;
17
import org.eclipse.core.resources.*;
18
import org.eclipse.core.resources.IContainer;
19
import org.eclipse.core.resources.IFile;
20
import org.eclipse.core.resources.IWorkspace;
21
import org.eclipse.core.runtime.CoreException;
18
import org.eclipse.core.runtime.CoreException;
22
import org.eclipse.core.runtime.IStatus;
19
import org.eclipse.core.runtime.IStatus;
23
import org.eclipse.core.runtime.NullProgressMonitor;
20
import org.eclipse.core.runtime.NullProgressMonitor;
Lines 29-37 Link Here
29
import org.eclipse.jdt.core.IJavaElementDelta;
26
import org.eclipse.jdt.core.IJavaElementDelta;
30
import org.eclipse.jdt.core.IJavaModelStatus;
27
import org.eclipse.jdt.core.IJavaModelStatus;
31
import org.eclipse.jdt.core.IJavaModelStatusConstants;
28
import org.eclipse.jdt.core.IJavaModelStatusConstants;
29
import org.eclipse.jdt.core.IJavaProject;
32
import org.eclipse.jdt.core.IPackageFragment;
30
import org.eclipse.jdt.core.IPackageFragment;
33
import org.eclipse.jdt.core.JavaConventions;
31
import org.eclipse.jdt.core.JavaConventions;
34
//import org.eclipse.jdt.core.JavaCore;
32
import org.eclipse.jdt.core.JavaCore;
35
import org.eclipse.jdt.core.JavaModelException;
33
import org.eclipse.jdt.core.JavaModelException;
36
import org.eclipse.jdt.internal.core.util.Messages;
34
import org.eclipse.jdt.internal.core.util.Messages;
37
import org.eclipse.jdt.internal.core.util.Util;
35
import org.eclipse.jdt.internal.core.util.Util;
Lines 163-169 Link Here
163
	if (getParentElement() == null) {
161
	if (getParentElement() == null) {
164
		return new JavaModelStatus(IJavaModelStatusConstants.NO_ELEMENTS_TO_PROCESS);
162
		return new JavaModelStatus(IJavaModelStatusConstants.NO_ELEMENTS_TO_PROCESS);
165
	}
163
	}
166
	if (JavaConventions.validateCompilationUnitName(fName).getSeverity() == IStatus.ERROR) {
164
	IJavaProject project = getParentElement().getJavaProject();
165
	if (JavaConventions.validateCompilationUnitName(fName, project.getOption(JavaCore.COMPILER_SOURCE, true), project.getOption(JavaCore.COMPILER_COMPLIANCE, true)).getSeverity() == IStatus.ERROR) {
167
		return new JavaModelStatus(IJavaModelStatusConstants.INVALID_NAME, fName);
166
		return new JavaModelStatus(IJavaModelStatusConstants.INVALID_NAME, fName);
168
	}
167
	}
169
	if (fSource == null) {
168
	if (fSource == null) {
(-)model/org/eclipse/jdt/internal/core/PackageFragmentRoot.java (-25 / +30 lines)
Lines 237-270 Link Here
237
		JavaModelManager manager = JavaModelManager.getJavaModelManager();
237
		JavaModelManager manager = JavaModelManager.getJavaModelManager();
238
		IResource[] members = folder.members();
238
		IResource[] members = folder.members();
239
		boolean hasIncluded = isIncluded;
239
		boolean hasIncluded = isIncluded;
240
		for (int i = 0, max = members.length; i < max; i++) {
240
		int length = members.length;
241
			IResource member = members[i];
241
		if (length >0) {
242
			String memberName = member.getName();
242
			String sourceLevel = javaProject.getOption(JavaCore.COMPILER_SOURCE, true);
243
			String complianceLevel = javaProject.getOption(JavaCore.COMPILER_COMPLIANCE, true);
244
			for (int i = 0; i < length; i++) {
245
				IResource member = members[i];
246
				String memberName = member.getName();
243
			
247
			
244
			switch(member.getType()) {
248
				switch(member.getType()) {
245
			    
249
			    
246
			    case IResource.FOLDER:
250
			    	case IResource.FOLDER:
247
					// recurse into sub folders even even parent not included as a sub folder could be included
251
			    		// recurse into sub folders even even parent not included as a sub folder could be included
248
					// (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=65637)
252
			    		// (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=65637)
249
					if (Util.isValidFolderNameForPackage(memberName)) {
253
			    		if (Util.isValidFolderNameForPackage(memberName, sourceLevel, complianceLevel)) {
250
						// eliminate binary output only if nested inside direct subfolders
254
			    			// eliminate binary output only if nested inside direct subfolders
251
						if (javaProject.contains(member)) {
255
			    			if (javaProject.contains(member)) {
252
							String[] newNames = Util.arrayConcat(pkgName, manager.intern(memberName));
256
			    				String[] newNames = Util.arrayConcat(pkgName, manager.intern(memberName));
253
							boolean isMemberIncluded = !Util.isExcluded(member, inclusionPatterns, exclusionPatterns);
257
			    				boolean isMemberIncluded = !Util.isExcluded(member, inclusionPatterns, exclusionPatterns);
254
							computeFolderChildren((IFolder) member, isMemberIncluded, newNames, vChildren, inclusionPatterns, exclusionPatterns);
258
			    				computeFolderChildren((IFolder) member, isMemberIncluded, newNames, vChildren, inclusionPatterns, exclusionPatterns);
255
						}
259
			    			}
256
					}
260
			    		}
257
			    	break;
261
			    		break;
258
			    case IResource.FILE:
262
			    	case IResource.FILE:
259
			        // inclusion filter may only include files, in which case we still want to include the immediate parent package (lazily)
263
			    		// inclusion filter may only include files, in which case we still want to include the immediate parent package (lazily)
260
					if (!hasIncluded
264
			    		if (!hasIncluded
261
								&& Util.isValidCompilationUnitName(memberName)
265
			    				&& Util.isValidCompilationUnitName(memberName, sourceLevel, complianceLevel)
262
								&& !Util.isExcluded(member, inclusionPatterns, exclusionPatterns)) {
266
								&& !Util.isExcluded(member, inclusionPatterns, exclusionPatterns)) {
263
						hasIncluded = true;
267
			    			hasIncluded = true;
264
					    IPackageFragment pkg = getPackageFragment(pkgName);
268
			    			IPackageFragment pkg = getPackageFragment(pkgName);
265
					    vChildren.add(pkg); 
269
			    			vChildren.add(pkg); 
266
					}
270
			    		}
267
			        break;
271
			    		break;
272
				}
268
			}
273
			}
269
		}
274
		}
270
	} catch(IllegalArgumentException e){
275
	} catch(IllegalArgumentException e){
(-)model/org/eclipse/jdt/internal/core/MultiOperation.java (-4 / +6 lines)
Lines 266-288 Link Here
266
	protected void verifyRenaming(IJavaElement element) throws JavaModelException {
266
	protected void verifyRenaming(IJavaElement element) throws JavaModelException {
267
		String newName = getNewNameFor(element);
267
		String newName = getNewNameFor(element);
268
		boolean isValid = true;
268
		boolean isValid = true;
269
	
269
	    IJavaProject project = element.getJavaProject();
270
	    String sourceLevel = project.getOption(JavaCore.COMPILER_SOURCE, true);
271
	    String complianceLevel = project.getOption(JavaCore.COMPILER_COMPLIANCE, true);
270
		switch (element.getElementType()) {
272
		switch (element.getElementType()) {
271
			case IJavaElement.PACKAGE_FRAGMENT :
273
			case IJavaElement.PACKAGE_FRAGMENT :
272
				if (((IPackageFragment) element).isDefaultPackage()) {
274
				if (((IPackageFragment) element).isDefaultPackage()) {
273
					// don't allow renaming of default package (see PR #1G47GUM)
275
					// don't allow renaming of default package (see PR #1G47GUM)
274
					throw new JavaModelException(new JavaModelStatus(IJavaModelStatusConstants.NAME_COLLISION, element));
276
					throw new JavaModelException(new JavaModelStatus(IJavaModelStatusConstants.NAME_COLLISION, element));
275
				}
277
				}
276
				isValid = JavaConventions.validatePackageName(newName).getSeverity() != IStatus.ERROR;
278
				isValid = JavaConventions.validatePackageName(newName, sourceLevel, complianceLevel).getSeverity() != IStatus.ERROR;
277
				break;
279
				break;
278
			case IJavaElement.COMPILATION_UNIT :
280
			case IJavaElement.COMPILATION_UNIT :
279
				isValid = JavaConventions.validateCompilationUnitName(newName).getSeverity() != IStatus.ERROR;
281
				isValid = JavaConventions.validateCompilationUnitName(newName,sourceLevel, complianceLevel).getSeverity() != IStatus.ERROR;
280
				break;
282
				break;
281
			case IJavaElement.INITIALIZER :
283
			case IJavaElement.INITIALIZER :
282
				isValid = false; //cannot rename initializers
284
				isValid = false; //cannot rename initializers
283
				break;
285
				break;
284
			default :
286
			default :
285
				isValid = JavaConventions.validateIdentifier(newName).getSeverity() != IStatus.ERROR;
287
				isValid = JavaConventions.validateIdentifier(newName, sourceLevel, complianceLevel).getSeverity() != IStatus.ERROR;
286
				break;
288
				break;
287
		}
289
		}
288
	
290
	
(-)model/org/eclipse/jdt/internal/core/CompilationUnit.java (-1 / +2 lines)
Lines 963-969 Link Here
963
		if (!resource.isAccessible())
963
		if (!resource.isAccessible())
964
			return new JavaModelStatus(IJavaModelStatusConstants.ELEMENT_DOES_NOT_EXIST, this);
964
			return new JavaModelStatus(IJavaModelStatusConstants.ELEMENT_DOES_NOT_EXIST, this);
965
	}
965
	}
966
	return JavaConventions.validateCompilationUnitName(getElementName());
966
	IJavaProject project = getJavaProject();
967
	return JavaConventions.validateCompilationUnitName(getElementName(),project.getOption(JavaCore.COMPILER_SOURCE, true), project.getOption(JavaCore.COMPILER_COMPLIANCE, true));
967
}
968
}
968
/*
969
/*
969
 * @see ICompilationUnit#isWorkingCopy()
970
 * @see ICompilationUnit#isWorkingCopy()
(-)model/org/eclipse/jdt/internal/core/JavaProjectElementInfo.java (-49 / +54 lines)
Lines 123-180 Link Here
123
		int resourcesCounter = 0;
123
		int resourcesCounter = 0;
124
		try {
124
		try {
125
			IResource[] members = ((IContainer) project.getResource()).members();
125
			IResource[] members = ((IContainer) project.getResource()).members();
126
			for (int i = 0, max = members.length; i < max; i++) {
126
			int length = members.length;
127
				IResource res = members[i];
127
			if (length > 0) {
128
				switch (res.getType()) {
128
				String sourceLevel = project.getOption(JavaCore.COMPILER_SOURCE, true);
129
					case IResource.FILE :
129
				String complianceLevel = project.getOption(JavaCore.COMPILER_COMPLIANCE, true);
130
						IPath resFullPath = res.getFullPath();
130
				for (int i = 0; i < length; i++) {
131
						String resName = res.getName();
131
					IResource res = members[i];
132
					switch (res.getType()) {
133
						case IResource.FILE :
134
							IPath resFullPath = res.getFullPath();
135
							String resName = res.getName();
132
						
136
						
133
						// ignore a jar file on the classpath
137
							// ignore a jar file on the classpath
134
						if (org.eclipse.jdt.internal.compiler.util.Util.isArchiveFileName(resName) && this.isClasspathEntryOrOutputLocation(resFullPath, classpath, projectOutput)) {
138
							if (org.eclipse.jdt.internal.compiler.util.Util.isArchiveFileName(resName) && this.isClasspathEntryOrOutputLocation(resFullPath, classpath, projectOutput)) {
139
								break;
140
							}
141
							// ignore .java file if src == project
142
							if (srcIsProject 
143
									&& Util.isValidCompilationUnitName(resName, sourceLevel, complianceLevel)
144
									&& !Util.isExcluded(res, inclusionPatterns, exclusionPatterns)) {
145
								break;
146
							}
147
							// ignore .class file if bin == project
148
							if (binIsProject && Util.isValidClassFileName(resName, sourceLevel, complianceLevel)) {
149
								break;
150
							}
151
							// else add non java resource
152
							if (resources.length == resourcesCounter) {
153
								// resize
154
								System.arraycopy(
155
										resources,
156
										0,
157
										(resources = new IResource[resourcesCounter * 2]),
158
										0,
159
										resourcesCounter);
160
							}
161
							resources[resourcesCounter++] = res;
135
							break;
162
							break;
136
						}
163
						case IResource.FOLDER :
137
						// ignore .java file if src == project
164
							resFullPath = res.getFullPath();
138
						if (srcIsProject 
139
							&& Util.isValidCompilationUnitName(resName)
140
							&& !Util.isExcluded(res, inclusionPatterns, exclusionPatterns)) {
141
							break;
142
						}
143
						// ignore .class file if bin == project
144
						if (binIsProject && Util.isValidClassFileName(resName)) {
145
							break;
146
						}
147
						// else add non java resource
148
						if (resources.length == resourcesCounter) {
149
							// resize
150
							System.arraycopy(
151
								resources,
152
								0,
153
								(resources = new IResource[resourcesCounter * 2]),
154
								0,
155
								resourcesCounter);
156
						}
157
						resources[resourcesCounter++] = res;
158
						break;
159
					case IResource.FOLDER :
160
						resFullPath = res.getFullPath();
161
						
165
						
162
						// ignore non-excluded folders on the classpath or that correspond to an output location
166
							// ignore non-excluded folders on the classpath or that correspond to an output location
163
						if ((srcIsProject && !Util.isExcluded(res, inclusionPatterns, exclusionPatterns) && Util.isValidFolderNameForPackage(res.getName()))
167
							if ((srcIsProject && !Util.isExcluded(res, inclusionPatterns, exclusionPatterns) && Util.isValidFolderNameForPackage(res.getName(), sourceLevel, complianceLevel))
164
								|| this.isClasspathEntryOrOutputLocation(resFullPath, classpath, projectOutput)) {
168
									|| this.isClasspathEntryOrOutputLocation(resFullPath, classpath, projectOutput)) {
165
							break;
169
								break;
166
						}
170
							}
167
						// else add non java resource
171
							// else add non java resource
168
						if (resources.length == resourcesCounter) {
172
							if (resources.length == resourcesCounter) {
169
							// resize
173
								// resize
170
							System.arraycopy(
174
								System.arraycopy(
171
								resources,
175
										resources,
172
								0,
176
										0,
173
								(resources = new IResource[resourcesCounter * 2]),
177
										(resources = new IResource[resourcesCounter * 2]),
174
								0,
178
										0,
175
								resourcesCounter);
179
										resourcesCounter);
176
						}
180
							}
177
						resources[resourcesCounter++] = res;
181
							resources[resourcesCounter++] = res;
182
					}
178
				}
183
				}
179
			}
184
			}
180
			if (resources.length != resourcesCounter) {
185
			if (resources.length != resourcesCounter) {
(-)model/org/eclipse/jdt/internal/core/CreatePackageFragmentOperation.java (-2 / +6 lines)
Lines 19-27 Link Here
19
import org.eclipse.jdt.core.IJavaElement;
19
import org.eclipse.jdt.core.IJavaElement;
20
import org.eclipse.jdt.core.IJavaModelStatus;
20
import org.eclipse.jdt.core.IJavaModelStatus;
21
import org.eclipse.jdt.core.IJavaModelStatusConstants;
21
import org.eclipse.jdt.core.IJavaModelStatusConstants;
22
import org.eclipse.jdt.core.IJavaProject;
22
import org.eclipse.jdt.core.IPackageFragment;
23
import org.eclipse.jdt.core.IPackageFragment;
23
import org.eclipse.jdt.core.IPackageFragmentRoot;
24
import org.eclipse.jdt.core.IPackageFragmentRoot;
24
import org.eclipse.jdt.core.JavaConventions;
25
import org.eclipse.jdt.core.JavaConventions;
26
import org.eclipse.jdt.core.JavaCore;
25
import org.eclipse.jdt.core.JavaModelException;
27
import org.eclipse.jdt.core.JavaModelException;
26
import org.eclipse.jdt.core.compiler.CharOperation;
28
import org.eclipse.jdt.core.compiler.CharOperation;
27
import org.eclipse.jdt.internal.core.util.Messages;
29
import org.eclipse.jdt.internal.core.util.Messages;
Lines 120-131 Link Here
120
 * @see JavaConventions
122
 * @see JavaConventions
121
 */
123
 */
122
public IJavaModelStatus verify() {
124
public IJavaModelStatus verify() {
123
	if (getParentElement() == null) {
125
	IJavaElement parentElement = getParentElement();
126
	if (parentElement == null) {
124
		return new JavaModelStatus(IJavaModelStatusConstants.NO_ELEMENTS_TO_PROCESS);
127
		return new JavaModelStatus(IJavaModelStatusConstants.NO_ELEMENTS_TO_PROCESS);
125
	}
128
	}
126
	
129
	
127
	String packageName = this.pkgName == null ? null : Util.concatWith(this.pkgName, '.');
130
	String packageName = this.pkgName == null ? null : Util.concatWith(this.pkgName, '.');
128
	if (this.pkgName == null || (this.pkgName.length > 0 && JavaConventions.validatePackageName(packageName).getSeverity() == IStatus.ERROR)) {
131
	IJavaProject project = parentElement.getJavaProject();
132
	if (this.pkgName == null || (this.pkgName.length > 0 && JavaConventions.validatePackageName(packageName, project.getOption(JavaCore.COMPILER_SOURCE, true), project.getOption(JavaCore.COMPILER_COMPLIANCE, true)).getSeverity() == IStatus.ERROR)) {
129
		return new JavaModelStatus(IJavaModelStatusConstants.INVALID_NAME, packageName);
133
		return new JavaModelStatus(IJavaModelStatusConstants.INVALID_NAME, packageName);
130
	}
134
	}
131
	IPackageFragmentRoot root = (IPackageFragmentRoot) getParentElement();
135
	IPackageFragmentRoot root = (IPackageFragmentRoot) getParentElement();
(-)model/org/eclipse/jdt/internal/core/JavaModelManager.java (-24 / +29 lines)
Lines 805-835 Link Here
805
				org.eclipse.jdt.internal.core.util.Util.isJavaLikeFileName(resourcePath.lastSegment())
805
				org.eclipse.jdt.internal.core.util.Util.isJavaLikeFileName(resourcePath.lastSegment())
806
					? project.getRawClasspath() // JAVA file can only live inside SRC folder (on the raw path)
806
					? project.getRawClasspath() // JAVA file can only live inside SRC folder (on the raw path)
807
					: ((JavaProject)project).getResolvedClasspath();
807
					: ((JavaProject)project).getResolvedClasspath();
808
				
808
			
809
			for (int i = 0; i < entries.length; i++) {
809
			int length	= entries.length;
810
				IClasspathEntry entry = entries[i];
810
			if (length > 0) {
811
				if (entry.getEntryKind() == IClasspathEntry.CPE_PROJECT) continue;
811
				String sourceLevel = project.getOption(JavaCore.COMPILER_SOURCE, true);
812
				IPath rootPath = entry.getPath();
812
				String complianceLevel = project.getOption(JavaCore.COMPILER_COMPLIANCE, true);
813
				if (rootPath.equals(resourcePath)) {
813
				for (int i = 0; i < length; i++) {
814
					return project.getPackageFragmentRoot(resource);
814
					IClasspathEntry entry = entries[i];
815
				} else if (rootPath.isPrefixOf(resourcePath)) {
815
					if (entry.getEntryKind() == IClasspathEntry.CPE_PROJECT) continue;
816
					// allow creation of package fragment if it contains a .java file that is included
816
					IPath rootPath = entry.getPath();
817
					if (!Util.isExcluded(resource, ((ClasspathEntry)entry).fullInclusionPatternChars(), ((ClasspathEntry)entry).fullExclusionPatternChars())) {
817
					if (rootPath.equals(resourcePath)) {
818
						// given we have a resource child of the root, it cannot be a JAR pkg root
818
						return project.getPackageFragmentRoot(resource);
819
						PackageFragmentRoot root =(PackageFragmentRoot) ((JavaProject) project).getFolderPackageFragmentRoot(rootPath);
819
					} else if (rootPath.isPrefixOf(resourcePath)) {
820
						if (root == null) return null;
820
						// allow creation of package fragment if it contains a .java file that is included
821
						IPath pkgPath = resourcePath.removeFirstSegments(rootPath.segmentCount());
821
						if (!Util.isExcluded(resource, ((ClasspathEntry)entry).fullInclusionPatternChars(), ((ClasspathEntry)entry).fullExclusionPatternChars())) {
822
	
822
							// given we have a resource child of the root, it cannot be a JAR pkg root
823
						if (resource.getType() == IResource.FILE) {
823
							PackageFragmentRoot root =(PackageFragmentRoot) ((JavaProject) project).getFolderPackageFragmentRoot(rootPath);
824
							// if the resource is a file, then remove the last segment which
824
							if (root == null) return null;
825
							// is the file name in the package
825
							IPath pkgPath = resourcePath.removeFirstSegments(rootPath.segmentCount());
826
							pkgPath = pkgPath.removeLastSegments(1);
826
	
827
						}
827
							if (resource.getType() == IResource.FILE) {
828
						String[] pkgName = pkgPath.segments();
828
								// if the resource is a file, then remove the last segment which
829
						if (pkgName.length != 0 && JavaConventions.validatePackageName(Util.packageName(pkgPath)).getSeverity() == IStatus.ERROR) {
829
								// is the file name in the package
830
							return null;
830
								pkgPath = pkgPath.removeLastSegments(1);
831
							}
832
							String[] pkgName = pkgPath.segments();
833
							if (pkgName.length != 0 && JavaConventions.validatePackageName(Util.packageName(pkgPath, sourceLevel, complianceLevel), sourceLevel, complianceLevel).getSeverity() == IStatus.ERROR) {
834
								return null;
835
							}
836
							return root.getPackageFragment(pkgName);
831
						}
837
						}
832
						return root.getPackageFragment(pkgName);
833
					}
838
					}
834
				}
839
				}
835
			}
840
			}
(-)model/org/eclipse/jdt/internal/core/PackageFragmentRootInfo.java (-33 / +34 lines)
Lines 16-24 Link Here
16
import org.eclipse.core.runtime.IPath;
16
import org.eclipse.core.runtime.IPath;
17
17
18
import org.eclipse.jdt.core.*;
18
import org.eclipse.jdt.core.*;
19
import org.eclipse.jdt.core.IPackageFragmentRoot;
20
import org.eclipse.jdt.core.IJavaProject;
21
import org.eclipse.jdt.core.JavaModelException;
22
import org.eclipse.jdt.internal.core.util.Util;
19
import org.eclipse.jdt.internal.core.util.Util;
23
20
24
/**
21
/**
Lines 62-98 Link Here
62
	try {
59
	try {
63
		IClasspathEntry[] classpath = project.getResolvedClasspath();
60
		IClasspathEntry[] classpath = project.getResolvedClasspath();
64
		IResource[] members = folder.members();
61
		IResource[] members = folder.members();
65
		nextResource: for (int i = 0, max = members.length; i < max; i++) {
62
		int length = members.length;
66
			IResource member = members[i];
63
		if (length > 0) {
67
			switch (member.getType()) {
64
			String sourceLevel = project.getOption(JavaCore.COMPILER_SOURCE, true);
68
				case IResource.FILE :
65
			String complianceLevel = project.getOption(JavaCore.COMPILER_COMPLIANCE, true);
69
					String fileName = member.getName();
66
			nextResource: for (int i = 0; i < length; i++) {
67
				IResource member = members[i];
68
				switch (member.getType()) {
69
					case IResource.FILE :
70
						String fileName = member.getName();
70
					
71
					
71
					// ignore .java files that are not excluded
72
						// ignore .java files that are not excluded
72
					if (Util.isValidCompilationUnitName(fileName) && !Util.isExcluded(member, inclusionPatterns, exclusionPatterns)) 
73
						if (Util.isValidCompilationUnitName(fileName, sourceLevel, complianceLevel) && !Util.isExcluded(member, inclusionPatterns, exclusionPatterns)) 
73
						continue nextResource;
74
							continue nextResource;
74
					// ignore .class files
75
						// ignore .class files
75
					if (Util.isValidClassFileName(fileName)) 
76
						if (Util.isValidClassFileName(fileName, sourceLevel, complianceLevel)) 
76
						continue nextResource;
77
							continue nextResource;
77
					// ignore .zip or .jar file on classpath
78
						// ignore .zip or .jar file on classpath
78
					if (org.eclipse.jdt.internal.compiler.util.Util.isArchiveFileName(fileName) && isClasspathEntry(member.getFullPath(), classpath)) 
79
						if (org.eclipse.jdt.internal.compiler.util.Util.isArchiveFileName(fileName) && isClasspathEntry(member.getFullPath(), classpath)) 
79
						continue nextResource;
80
							continue nextResource;
80
					break;
81
						break;
81
82
82
				case IResource.FOLDER :
83
					case IResource.FOLDER :
83
					// ignore valid packages or excluded folders that correspond to a nested pkg fragment root
84
						// ignore valid packages or excluded folders that correspond to a nested pkg fragment root
84
					if (Util.isValidFolderNameForPackage(member.getName())
85
						if (Util.isValidFolderNameForPackage(member.getName(), sourceLevel, complianceLevel)
85
							&& (!Util.isExcluded(member, inclusionPatterns, exclusionPatterns) 
86
								&& (!Util.isExcluded(member, inclusionPatterns, exclusionPatterns) 
86
								|| isClasspathEntry(member.getFullPath(), classpath)))
87
										|| isClasspathEntry(member.getFullPath(), classpath)))
87
						continue nextResource;
88
							continue nextResource;
88
					break;
89
						break;
89
			}
90
				}
90
			if (nonJavaResources.length == nonJavaResourcesCounter) {
91
				if (nonJavaResources.length == nonJavaResourcesCounter) {
91
				// resize
92
					// resize
92
				System.arraycopy(nonJavaResources, 0, (nonJavaResources = new IResource[nonJavaResourcesCounter * 2]), 0, nonJavaResourcesCounter);
93
					System.arraycopy(nonJavaResources, 0, (nonJavaResources = new IResource[nonJavaResourcesCounter * 2]), 0, nonJavaResourcesCounter);
93
			}
94
				}
94
			nonJavaResources[nonJavaResourcesCounter++] = member;
95
				nonJavaResources[nonJavaResourcesCounter++] = member;
95
96
			}	
96
		}
97
		}
97
		if (nonJavaResources.length != nonJavaResourcesCounter) {
98
		if (nonJavaResources.length != nonJavaResourcesCounter) {
98
			System.arraycopy(nonJavaResources, 0, (nonJavaResources = new IResource[nonJavaResourcesCounter]), 0, nonJavaResourcesCounter);
99
			System.arraycopy(nonJavaResources, 0, (nonJavaResources = new IResource[nonJavaResourcesCounter]), 0, nonJavaResourcesCounter);
(-)model/org/eclipse/jdt/internal/core/JarPackageFragmentRoot.java (-1 / +2 lines)
Lines 225-232 Link Here
225
			existingLength--;
225
			existingLength--;
226
		}
226
		}
227
		JavaModelManager manager = JavaModelManager.getJavaModelManager();
227
		JavaModelManager manager = JavaModelManager.getJavaModelManager();
228
		IJavaProject project = getJavaProject();
228
		for (int i = existingLength; i < length; i++) {
229
		for (int i = existingLength; i < length; i++) {
229
			if (Util.isValidFolderNameForPackage(pkgName[i])) {
230
			if (Util.isValidFolderNameForPackage(pkgName[i], project.getOption(JavaCore.COMPILER_SOURCE, true), project.getOption(JavaCore.COMPILER_COMPLIANCE, true))) {
230
				System.arraycopy(existing, 0, existing = new String[i+1], 0, i);
231
				System.arraycopy(existing, 0, existing = new String[i+1], 0, i);
231
				existing[i] = manager.intern(pkgName[i]);
232
				existing[i] = manager.intern(pkgName[i]);
232
				packageFragToTypes.put(existing, new ArrayList[] { EMPTY_LIST, EMPTY_LIST });
233
				packageFragToTypes.put(existing, new ArrayList[] { EMPTY_LIST, EMPTY_LIST });
(-)model/org/eclipse/jdt/internal/core/util/Util.java (-9 / +21 lines)
Lines 1277-1282 Link Here
1277
		return isExcluded(path, inclusionPatterns, exclusionPatterns, resourceType == IResource.FOLDER || resourceType == IResource.PROJECT);
1277
		return isExcluded(path, inclusionPatterns, exclusionPatterns, resourceType == IResource.FOLDER || resourceType == IResource.PROJECT);
1278
	}
1278
	}
1279
1279
1280
1280
	/**
1281
	/**
1281
	 * Validate the given .class file name.
1282
	 * Validate the given .class file name.
1282
	 * A .class file name must obey the following rules:
1283
	 * A .class file name must obey the following rules:
Lines 1287-1300 Link Here
1287
	 * </ul>
1288
	 * </ul>
1288
	 * </p>
1289
	 * </p>
1289
	 * @param name the name of a .class file
1290
	 * @param name the name of a .class file
1291
	 * @param sourceLevel the source level
1292
	 * @param complianceLevel the compliance level
1290
	 * @return a status object with code <code>IStatus.OK</code> if
1293
	 * @return a status object with code <code>IStatus.OK</code> if
1291
	 *		the given name is valid as a .class file name, otherwise a status 
1294
	 *		the given name is valid as a .class file name, otherwise a status 
1292
	 *		object indicating what is wrong with the name
1295
	 *		object indicating what is wrong with the name
1293
	 */
1296
	 */
1294
	public static boolean isValidClassFileName(String name) {
1297
	public static boolean isValidClassFileName(String name, String sourceLevel, String complianceLevel) {
1295
		return JavaConventions.validateClassFileName(name).getSeverity() != IStatus.ERROR;
1298
		return JavaConventions.validateClassFileName(name, sourceLevel, complianceLevel).getSeverity() != IStatus.ERROR;
1296
	}
1299
	}
1297
1300
1301
1298
	/**
1302
	/**
1299
	 * Validate the given compilation unit name.
1303
	 * Validate the given compilation unit name.
1300
	 * A compilation unit name must obey the following rules:
1304
	 * A compilation unit name must obey the following rules:
Lines 1305-1324 Link Here
1305
	 * </ul>
1309
	 * </ul>
1306
	 * </p>
1310
	 * </p>
1307
	 * @param name the name of a compilation unit
1311
	 * @param name the name of a compilation unit
1312
	 * @param sourceLevel the source level
1313
	 * @param complianceLevel the compliance level
1308
	 * @return a status object with code <code>IStatus.OK</code> if
1314
	 * @return a status object with code <code>IStatus.OK</code> if
1309
	 *		the given name is valid as a compilation unit name, otherwise a status 
1315
	 *		the given name is valid as a compilation unit name, otherwise a status 
1310
	 *		object indicating what is wrong with the name
1316
	 *		object indicating what is wrong with the name
1311
	 */
1317
	 */
1312
	public static boolean isValidCompilationUnitName(String name) {
1318
	public static boolean isValidCompilationUnitName(String name, String sourceLevel, String complianceLevel) {
1313
		return JavaConventions.validateCompilationUnitName(name).getSeverity() != IStatus.ERROR;
1319
		return JavaConventions.validateCompilationUnitName(name, sourceLevel, complianceLevel).getSeverity() != IStatus.ERROR;
1314
	}
1320
	}
1315
	
1321
1316
	/**
1322
	/**
1317
	 * Returns true if the given folder name is valid for a package,
1323
	 * Returns true if the given folder name is valid for a package,
1318
	 * false if it is not.
1324
	 * false if it is not.
1325
	 * @param folderName the name of the folder
1326
	 * @param sourceLevel the source level
1327
	 * @param complianceLevel the compliance level
1319
	 */
1328
	 */
1320
	public static boolean isValidFolderNameForPackage(String folderName) {
1329
	public static boolean isValidFolderNameForPackage(String folderName, String sourceLevel, String complianceLevel) {
1321
		return JavaConventions.validateIdentifier(folderName).getSeverity() != IStatus.ERROR;
1330
		return JavaConventions.validateIdentifier(folderName, sourceLevel, complianceLevel).getSeverity() != IStatus.ERROR;
1322
	}	
1331
	}	
1323
1332
1324
	/**
1333
	/**
Lines 1467-1478 Link Here
1467
	/**
1476
	/**
1468
	 * Converts the given relative path into a package name.
1477
	 * Converts the given relative path into a package name.
1469
	 * Returns null if the path is not a valid package name.
1478
	 * Returns null if the path is not a valid package name.
1479
	 * @param pkgPath the package path
1480
	 * @param sourceLevel the source level
1481
	 * @param complianceLevel the compliance level
1470
	 */
1482
	 */
1471
	public static String packageName(IPath pkgPath) {
1483
	public static String packageName(IPath pkgPath, String sourceLevel, String complianceLevel) {
1472
		StringBuffer pkgName = new StringBuffer(IPackageFragment.DEFAULT_PACKAGE_NAME);
1484
		StringBuffer pkgName = new StringBuffer(IPackageFragment.DEFAULT_PACKAGE_NAME);
1473
		for (int j = 0, max = pkgPath.segmentCount(); j < max; j++) {
1485
		for (int j = 0, max = pkgPath.segmentCount(); j < max; j++) {
1474
			String segment = pkgPath.segment(j);
1486
			String segment = pkgPath.segment(j);
1475
			if (!isValidFolderNameForPackage(segment)) {
1487
			if (!isValidFolderNameForPackage(segment, sourceLevel, complianceLevel)) {
1476
				return null;
1488
				return null;
1477
			}
1489
			}
1478
			pkgName.append(segment);
1490
			pkgName.append(segment);
(-)src/org/eclipse/jdt/core/tests/dom/ASTConverterJavadocTest.java (+9 lines)
Lines 1343-1350 Link Here
1343
1343
1344
		// Create DOM AST nodes hierarchy		
1344
		// Create DOM AST nodes hierarchy		
1345
		List unitComments = null;
1345
		List unitComments = null;
1346
		String sourceLevel = null;
1347
		String complianceLevel = null;
1346
		if (currentProject != null) {
1348
		if (currentProject != null) {
1347
			if (astLevel == AST.JLS3) {
1349
			if (astLevel == AST.JLS3) {
1350
				complianceLevel = currentProject.getOption(JavaCore.COMPILER_COMPLIANCE, true);
1351
				sourceLevel = currentProject.getOption(JavaCore.COMPILER_SOURCE, true);
1352
				currentProject.setOption(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_5);
1348
				currentProject.setOption(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_5);
1353
				currentProject.setOption(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_5);
1349
			}
1354
			}
1350
		}
1355
		}
Lines 1403-1408 Link Here
1403
		}
1408
		}
1404
		*/
1409
		*/
1405
1410
1411
		if (sourceLevel != null) {
1412
			currentProject.setOption(JavaCore.COMPILER_COMPLIANCE, complianceLevel);
1413
			currentProject.setOption(JavaCore.COMPILER_SOURCE, sourceLevel);
1414
		}
1406
		// Return compilation unit for possible further verifications
1415
		// Return compilation unit for possible further verifications
1407
		return compilUnit;
1416
		return compilUnit;
1408
	}
1417
	}
(-)src/org/eclipse/jdt/core/tests/model/JavaConventionTests.java (-34 / +37 lines)
Lines 15-22 Link Here
15
import org.eclipse.core.resources.IResource;
15
import org.eclipse.core.resources.IResource;
16
import org.eclipse.core.runtime.*;
16
import org.eclipse.core.runtime.*;
17
import org.eclipse.jdt.core.*;
17
import org.eclipse.jdt.core.*;
18
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
18
19
19
public class JavaConventionTests extends AbstractJavaModelTests {
20
public class JavaConventionTests extends AbstractJavaModelTests {
21
	private final static String sourceLevel = CompilerOptions.VERSION_1_3; 
22
	private final static String complianceLevel = CompilerOptions.VERSION_1_3;
20
	public JavaConventionTests(String name) {
23
	public JavaConventionTests(String name) {
21
		super(name);
24
		super(name);
22
	}
25
	}
Lines 78-103 Link Here
78
	public void testInvalidIdentifier() {
81
	public void testInvalidIdentifier() {
79
		String[] invalidIds = new String[] {" s\\u0069ze", " s\\u0069ze ", "", "1java", "Foo Bar", "#@$!", "Foo-Bar", "if", "InvalidEscapeSequence\\g", "true", "false", "null", null, " untrimmmed "};
82
		String[] invalidIds = new String[] {" s\\u0069ze", " s\\u0069ze ", "", "1java", "Foo Bar", "#@$!", "Foo-Bar", "if", "InvalidEscapeSequence\\g", "true", "false", "null", null, " untrimmmed "};
80
		for (int i = 0; i < invalidIds.length; i++) {
83
		for (int i = 0; i < invalidIds.length; i++) {
81
			assertTrue("identifier not recognized as invalid: " + invalidIds[i], !JavaConventions.validateIdentifier(invalidIds[i]).isOK());
84
			assertTrue("identifier not recognized as invalid: " + invalidIds[i], !JavaConventions.validateIdentifier(invalidIds[i], sourceLevel, complianceLevel).isOK());
82
		}
85
		}
83
	}
86
	}
84
	/**
87
	/**
85
	 * @see JavaConventions
88
	 * @see JavaConventions
86
	 */
89
	 */
87
	public void testInvalidImportDeclaration1() {
90
	public void testInvalidImportDeclaration1() {
88
		assertTrue("import not reconized as invalid; java.math.", !JavaConventions.validateImportDeclaration("java.math.").isOK());
91
		assertTrue("import not reconized as invalid; java.math.", !JavaConventions.validateImportDeclaration("java.math.", sourceLevel, complianceLevel).isOK());
89
	}
92
	}
90
	/**
93
	/**
91
	 * @see JavaConventions
94
	 * @see JavaConventions
92
	 */
95
	 */
93
	public void testInvalidImportDeclaration2() {
96
	public void testInvalidImportDeclaration2() {
94
		assertTrue("import not reconized as invalid; java.math*", !JavaConventions.validateImportDeclaration("java.math*").isOK());
97
		assertTrue("import not reconized as invalid; java.math*", !JavaConventions.validateImportDeclaration("java.math*", sourceLevel, complianceLevel).isOK());
95
	}
98
	}
96
	/**
99
	/**
97
	 * @see JavaConventions
100
	 * @see JavaConventions
98
	 */
101
	 */
99
	public void testInvalidImportDeclaration3() {
102
	public void testInvalidImportDeclaration3() {
100
		assertTrue("import not reconized as invalid; empty string", !JavaConventions.validateImportDeclaration("").isOK());
103
		assertTrue("import not reconized as invalid; empty string", !JavaConventions.validateImportDeclaration("", sourceLevel, complianceLevel).isOK());
101
	}
104
	}
102
	/**
105
	/**
103
	 * Test for package fragment root overlap
106
	 * Test for package fragment root overlap
Lines 140-157 Link Here
140
	public void testValidCompilationUnitName() {
143
	public void testValidCompilationUnitName() {
141
		String[] invalidNames = new String[] {"java/lang/Object.java", "Object.class", ".java", "Object.javaaa", "A.B.java"};
144
		String[] invalidNames = new String[] {"java/lang/Object.java", "Object.class", ".java", "Object.javaaa", "A.B.java"};
142
		for (int i = 0; i < invalidNames.length; i++) {
145
		for (int i = 0; i < invalidNames.length; i++) {
143
			assertTrue("compilation unit name not recognized as invalid: " + invalidNames[i], !JavaConventions.validateCompilationUnitName(invalidNames[i]).isOK());
146
			assertTrue("compilation unit name not recognized as invalid: " + invalidNames[i], !JavaConventions.validateCompilationUnitName(invalidNames[i], sourceLevel, complianceLevel).isOK());
144
		}
147
		}
145
		String[] validNames = new String[] {"Object.java", "OBJECT.java", "object.java", "package-info.java"};
148
		String[] validNames = new String[] {"Object.java", "OBJECT.java", "object.java", "package-info.java"};
146
		for (int i = 0; i < validNames.length; i++) {
149
		for (int i = 0; i < validNames.length; i++) {
147
			assertTrue("compilation unit name not recognized as valid: " + validNames[i], JavaConventions.validateCompilationUnitName(validNames[i]).isOK());
150
			assertTrue("compilation unit name not recognized as valid: " + validNames[i], JavaConventions.validateCompilationUnitName(validNames[i], sourceLevel, complianceLevel).isOK());
148
		}
151
		}
149
	}
152
	}
150
	/**
153
	/**
151
	 * @see JavaConventions
154
	 * @see JavaConventions
152
	 */
155
	 */
153
	public void testValidFieldName() {
156
	public void testValidFieldName() {
154
		assertTrue("unicode field name not handled", JavaConventions.validateFieldName("s\\u0069ze").isOK());
157
		assertTrue("unicode field name not handled", JavaConventions.validateFieldName("s\\u0069ze", sourceLevel, complianceLevel).isOK());
155
	}
158
	}
156
	/**
159
	/**
157
	 * @see JavaConventions
160
	 * @see JavaConventions
Lines 159-178 Link Here
159
	public void testValidIdentifier() {
162
	public void testValidIdentifier() {
160
		String[] validIds = new String[] {"s\\u0069ze", "Object", "An_Extremly_Long_Class_Name_With_Words_Separated_By_Undescores"};
163
		String[] validIds = new String[] {"s\\u0069ze", "Object", "An_Extremly_Long_Class_Name_With_Words_Separated_By_Undescores"};
161
		for (int i = 0; i < validIds.length; i++) {
164
		for (int i = 0; i < validIds.length; i++) {
162
			assertTrue("identifier not recognized as valid: " + validIds[i], JavaConventions.validateIdentifier(validIds[i]).isOK());
165
			assertTrue("identifier not recognized as valid: " + validIds[i], JavaConventions.validateIdentifier(validIds[i], sourceLevel, complianceLevel).isOK());
163
		}
166
		}
164
	}
167
	}
165
	/**
168
	/**
166
	 * @see JavaConventions
169
	 * @see JavaConventions
167
	 */
170
	 */
168
	public void testValidImportDeclaration() {
171
	public void testValidImportDeclaration() {
169
		assertTrue("import not reconized as valid", JavaConventions.validateImportDeclaration("java.math.*").isOK());
172
		assertTrue("import not reconized as valid", JavaConventions.validateImportDeclaration("java.math.*", sourceLevel, complianceLevel).isOK());
170
	}
173
	}
171
	/**
174
	/**
172
	 * @see JavaConventions
175
	 * @see JavaConventions
173
	 */
176
	 */
174
	public void testValidMethodName() {
177
	public void testValidMethodName() {
175
		assertTrue("unicode method name not handled", JavaConventions.validateMethodName("getSiz\\u0065").isOK());
178
		assertTrue("unicode method name not handled", JavaConventions.validateMethodName("getSiz\\u0065", sourceLevel, complianceLevel).isOK());
176
	}
179
	}
177
	/**
180
	/**
178
	 * @see JavaConventions
181
	 * @see JavaConventions
Lines 180-223 Link Here
180
	public void testValidPackageName() {
183
	public void testValidPackageName() {
181
		
184
		
182
		String pkgName= "org.eclipse.jdt.core.t\\u0065sts.MyPackage";
185
		String pkgName= "org.eclipse.jdt.core.t\\u0065sts.MyPackage";
183
		assertTrue("unicode package name not handled", JavaConventions.validatePackageName(pkgName).isOK());
186
		assertTrue("unicode package name not handled", JavaConventions.validatePackageName(pkgName, sourceLevel, complianceLevel).isOK());
184
	
187
	
185
		assertTrue("package name not recognized as invalid1", !JavaConventions.validatePackageName("").isOK());
188
		assertTrue("package name not recognized as invalid1", !JavaConventions.validatePackageName("", sourceLevel, complianceLevel).isOK());
186
		assertTrue("package name not recognized as valid1", JavaConventions.validatePackageName("java . lang").isOK());
189
		assertTrue("package name not recognized as valid1", JavaConventions.validatePackageName("java . lang", sourceLevel, complianceLevel).isOK());
187
		assertTrue("package name not recognized as invalid2", !JavaConventions.validatePackageName("   java . lang").isOK());
190
		assertTrue("package name not recognized as invalid2", !JavaConventions.validatePackageName("   java . lang", sourceLevel, complianceLevel).isOK());
188
		assertTrue("package name not recognized as invalid3", !JavaConventions.validatePackageName("java . lang  ").isOK());
191
		assertTrue("package name not recognized as invalid3", !JavaConventions.validatePackageName("java . lang  ", sourceLevel, complianceLevel).isOK());
189
		assertTrue("package name not recognized as invalid4", !JavaConventions.validatePackageName(null).isOK());
192
		assertTrue("package name not recognized as invalid4", !JavaConventions.validatePackageName(null, sourceLevel, complianceLevel).isOK());
190
		assertTrue("package name not recognized as unconventional1", JavaConventions.validatePackageName("Java.lang").getSeverity() == IStatus.WARNING);
193
		assertTrue("package name not recognized as unconventional1", JavaConventions.validatePackageName("Java.lang", sourceLevel, complianceLevel).getSeverity() == IStatus.WARNING);
191
		assertTrue("package name not recognized as valid2", JavaConventions.validatePackageName("java.Lang").isOK());
194
		assertTrue("package name not recognized as valid2", JavaConventions.validatePackageName("java.Lang", sourceLevel, complianceLevel).isOK());
192
		assertTrue("package name not recognized as invalid5", JavaConventions.validatePackageName("Test.sample&plugin").getSeverity() == IStatus.ERROR);
195
		assertTrue("package name not recognized as invalid5", JavaConventions.validatePackageName("Test.sample&plugin", sourceLevel, complianceLevel).getSeverity() == IStatus.ERROR);
193
		assertTrue("package name not recognized as unconventional2", JavaConventions.validatePackageName("Test.sample").getSeverity() == IStatus.WARNING);
196
		assertTrue("package name not recognized as unconventional2", JavaConventions.validatePackageName("Test.sample", sourceLevel, complianceLevel).getSeverity() == IStatus.WARNING);
194
	}
197
	}
195
	/**
198
	/**
196
	 * @see JavaConventions
199
	 * @see JavaConventions
197
	 */
200
	 */
198
	public void testValidTypeName() {
201
	public void testValidTypeName() {
199
		// regression tests for 1G5HVPB: ITPJCORE:WINNT - validateJavaTypeName accepts type names ending with \
202
		// regression tests for 1G5HVPB: ITPJCORE:WINNT - validateJavaTypeName accepts type names ending with \
200
		assertTrue("type name should not contain slashes (1)", JavaConventions.validateJavaTypeName("Object\\").getSeverity() == IStatus.ERROR);
203
		assertTrue("type name should not contain slashes (1)", JavaConventions.validateJavaTypeName("Object\\", sourceLevel, complianceLevel).getSeverity() == IStatus.ERROR);
201
		assertTrue("type name should not contain slashes (2)", JavaConventions.validateJavaTypeName("Object/").getSeverity() == IStatus.ERROR);
204
		assertTrue("type name should not contain slashes (2)", JavaConventions.validateJavaTypeName("Object/", sourceLevel, complianceLevel).getSeverity() == IStatus.ERROR);
202
		assertTrue("type name should not contain slashes (3)", JavaConventions.validateJavaTypeName("\\Object").getSeverity() == IStatus.ERROR);
205
		assertTrue("type name should not contain slashes (3)", JavaConventions.validateJavaTypeName("\\Object", sourceLevel, complianceLevel).getSeverity() == IStatus.ERROR);
203
		assertTrue("type name should not contain slashes (4)", JavaConventions.validateJavaTypeName("java\\lang\\Object").getSeverity() == IStatus.ERROR);
206
		assertTrue("type name should not contain slashes (4)", JavaConventions.validateJavaTypeName("java\\lang\\Object", sourceLevel, complianceLevel).getSeverity() == IStatus.ERROR);
204
	
207
	
205
		// regression test for 1G52ZIF: ITPJUI:WINNT - Wizards should strongly discourage the use of non-standard names
208
		// regression test for 1G52ZIF: ITPJUI:WINNT - Wizards should strongly discourage the use of non-standard names
206
		assertTrue("discouraged type names not handled", JavaConventions.validateJavaTypeName("alowercasetypename").getSeverity() == IStatus.WARNING);
209
		assertTrue("discouraged type names not handled", JavaConventions.validateJavaTypeName("alowercasetypename", sourceLevel, complianceLevel).getSeverity() == IStatus.WARNING);
207
	
210
	
208
		// other tests
211
		// other tests
209
		assertTrue("unicode type name not handled", JavaConventions.validateJavaTypeName("P\\u0065a").getSeverity() == IStatus.OK);
212
		assertTrue("unicode type name not handled", JavaConventions.validateJavaTypeName("P\\u0065a", sourceLevel, complianceLevel).getSeverity() == IStatus.OK);
210
		assertTrue("qualified type names not handled", JavaConventions.validateJavaTypeName("java  .  lang\t.Object").getSeverity() == IStatus.OK);
213
		assertTrue("qualified type names not handled", JavaConventions.validateJavaTypeName("java  .  lang\t.Object", sourceLevel, complianceLevel).getSeverity() == IStatus.OK);
211
		assertTrue("simple qualified type names not handled", JavaConventions.validateJavaTypeName("java.lang.Object").getSeverity() == IStatus.OK);
214
		assertTrue("simple qualified type names not handled", JavaConventions.validateJavaTypeName("java.lang.Object", sourceLevel, complianceLevel).getSeverity() == IStatus.OK);
212
		assertTrue("simple type names not handled", JavaConventions.validateJavaTypeName("Object").getSeverity() == IStatus.OK);
215
		assertTrue("simple type names not handled", JavaConventions.validateJavaTypeName("Object", sourceLevel, complianceLevel).getSeverity() == IStatus.OK);
213
		assertTrue("discouraged type names not handled", JavaConventions.validateJavaTypeName("Object$SubType").getSeverity() == IStatus.WARNING);
216
		assertTrue("discouraged type names not handled", JavaConventions.validateJavaTypeName("Object$SubType", sourceLevel, complianceLevel).getSeverity() == IStatus.WARNING);
214
		assertTrue("invalid type name not recognized", JavaConventions.validateJavaTypeName("==?==").getSeverity() == IStatus.ERROR);
217
		assertTrue("invalid type name not recognized", JavaConventions.validateJavaTypeName("==?==", sourceLevel, complianceLevel).getSeverity() == IStatus.ERROR);
215
	}
218
	}
216
	/**
219
	/**
217
	 * @see JavaConventions
220
	 * @see JavaConventions
218
	 */
221
	 */
219
	public void testValidTypeVariableName() {
222
	public void testValidTypeVariableName() {
220
		assertTrue("E sould be a valid variable name", JavaConventions.validateTypeVariableName("E").isOK());
223
		assertTrue("E sould be a valid variable name", JavaConventions.validateTypeVariableName("E", sourceLevel, complianceLevel).isOK());
221
	}
224
	}
222
	/**
225
	/**
223
	 * @see JavaConventions
226
	 * @see JavaConventions
Lines 225-231 Link Here
225
	public void testValidUnicodeImportDeclaration() {
228
	public void testValidUnicodeImportDeclaration() {
226
		
229
		
227
		String pkgName= "com.\\u0069bm.jdt.core.tests.MyPackag\\u0065";
230
		String pkgName= "com.\\u0069bm.jdt.core.tests.MyPackag\\u0065";
228
		assertTrue("import not reconized as valid", JavaConventions.validateImportDeclaration(pkgName).isOK());
231
		assertTrue("import not reconized as valid", JavaConventions.validateImportDeclaration(pkgName, sourceLevel, complianceLevel).isOK());
229
	
232
	
230
	}
233
	}
231
	/**
234
	/**
Lines 234-240 Link Here
234
	public void testValidUnicodePackageName() {
237
	public void testValidUnicodePackageName() {
235
		
238
		
236
		String pkgName= "com.\\u0069bm.jdt.core.tests.MyPackag\\u0065";
239
		String pkgName= "com.\\u0069bm.jdt.core.tests.MyPackag\\u0065";
237
		assertTrue("unicode package name not handled", JavaConventions.validatePackageName(pkgName).isOK());
240
		assertTrue("unicode package name not handled", JavaConventions.validatePackageName(pkgName, sourceLevel, complianceLevel).isOK());
238
		assertTrue("Parameter modified", pkgName.equals("com.\\u0069bm.jdt.core.tests.MyPackag\\u0065"));
241
		assertTrue("Parameter modified", pkgName.equals("com.\\u0069bm.jdt.core.tests.MyPackag\\u0065"));
239
	
242
	
240
	}
243
	}

Return to bug 161621