### Eclipse Workspace Patch 1.0
#P org.eclipse.jdt.core
Index: model/org/eclipse/jdt/core/IPackageFragment.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/core/IPackageFragment.java,v
retrieving revision 1.32
diff -u -r1.32 IPackageFragment.java
--- model/org/eclipse/jdt/core/IPackageFragment.java 29 Mar 2006 03:08:46 -0000 1.32
+++ model/org/eclipse/jdt/core/IPackageFragment.java 6 Nov 2006 12:26:29 -0000
@@ -100,7 +100,7 @@
*
* @param name the given name
* @return the compilation unit with the specified name in this package
- * @see JavaConventions#validateCompilationUnitName(String)
+ * @see JavaConventions#validateCompilationUnitName(String name, String sourceLevel, String complianceLevel)
*/
ICompilationUnit getCompilationUnit(String name);
/**
Index: model/org/eclipse/jdt/core/ICompilationUnit.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/core/ICompilationUnit.java,v
retrieving revision 1.57
diff -u -r1.57 ICompilationUnit.java
--- model/org/eclipse/jdt/core/ICompilationUnit.java 29 Mar 2006 03:08:46 -0000 1.57
+++ model/org/eclipse/jdt/core/ICompilationUnit.java 6 Nov 2006 12:26:28 -0000
@@ -378,7 +378,7 @@
*
* @param name the simple name of the requested type in the compilation unit
* @return a handle onto the corresponding type. The type may or may not exist.
- * @see JavaConventions#validateCompilationUnitName(String name)
+ * @see JavaConventions#validateCompilationUnitName(String name, String sourceLevel, String complianceLevel)
*/
IType getType(String name);
/**
Index: model/org/eclipse/jdt/core/JavaConventions.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/core/JavaConventions.java,v
retrieving revision 1.113
diff -u -r1.113 JavaConventions.java
--- model/org/eclipse/jdt/core/JavaConventions.java 23 Jun 2006 13:44:54 -0000 1.113
+++ model/org/eclipse/jdt/core/JavaConventions.java 6 Nov 2006 12:26:30 -0000
@@ -19,6 +19,8 @@
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.jdt.core.compiler.*;
+import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
+import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
import org.eclipse.jdt.internal.compiler.lookup.TypeConstants;
import org.eclipse.jdt.internal.compiler.parser.Scanner;
import org.eclipse.jdt.internal.compiler.parser.ScannerHelper;
@@ -36,10 +38,11 @@
*/
public final class JavaConventions {
- private final static char DOT= '.';
+ private static final char DOT= '.';
private static final String PACKAGE_INFO = new String(TypeConstants.PACKAGE_INFO_NAME);
- private final static Scanner SCANNER = new Scanner();
-
+ private static final Scanner[] SCANNERS = new Scanner[5];
+ private static final int[][] MAP_INDEXES = { { 0 }, { 0, 1 }, { 2, 3, 4 }, { 2, 3, 4, 4 } };
+
private JavaConventions() {
// Not instantiable
}
@@ -73,10 +76,10 @@
/*
* Returns the current identifier extracted by the scanner (without unicode
- * escapes) from the given id.
+ * escapes) from the given id and for the given source and compliance levels.
* Returns null
if the id was not valid
*/
- private static synchronized char[] scannedIdentifier(String id) {
+ private static synchronized char[] scannedIdentifier(String id, String sourceLevel, String complianceLevel) {
if (id == null) {
return null;
}
@@ -84,19 +87,42 @@
if (!trimmed.equals(id)) {
return null;
}
+
+ // Get scanner for given source and compliance levels
+ long lSourceLevel = CompilerOptions.versionToJdkLevel(sourceLevel);
+ long lComplianceLevel = CompilerOptions.versionToJdkLevel(complianceLevel);
+ int sourceIndex = ((int)(lSourceLevel>>> 16)) - ClassFileConstants.MAJOR_VERSION_1_3 ;
+ int complianceIndex = ((int)(lComplianceLevel >>> 16)) - ClassFileConstants.MAJOR_VERSION_1_3;
+ if (complianceIndex < 0) complianceIndex = 0;
+ if (sourceIndex < 0) sourceIndex = 0;
+ if (sourceIndex > complianceIndex) sourceIndex = complianceIndex;
+ int index = MAP_INDEXES[complianceIndex][sourceIndex];
+ if (SCANNERS[index] == null) {
+ SCANNERS[index] = new Scanner(
+ false /*comment*/,
+ false /*whitespace*/,
+ false /*nls*/,
+ lSourceLevel,
+ lComplianceLevel,
+ null/*taskTag*/,
+ null/*taskPriorities*/,
+ true /*taskCaseSensitive*/);
+ }
+ Scanner scanner = SCANNERS[index];
+
try {
- SCANNER.setSource(id.toCharArray());
- int token = SCANNER.getNextToken();
+ scanner.setSource(id.toCharArray());
+ int token = scanner.getNextToken();
char[] currentIdentifier;
try {
- currentIdentifier = SCANNER.getCurrentIdentifierSource();
+ currentIdentifier = scanner.getCurrentIdentifierSource();
} catch (ArrayIndexOutOfBoundsException e) {
return null;
}
- int nextToken= SCANNER.getNextToken();
+ int nextToken= scanner.getNextToken();
if (token == TerminalTokens.TokenNameIdentifier
&& nextToken == TerminalTokens.TokenNameEOF
- && SCANNER.startPosition == SCANNER.source.length) { // to handle case where we had an ArrayIndexOutOfBoundsException
+ && scanner.startPosition == scanner.source.length) { // to handle case where we had an ArrayIndexOutOfBoundsException
// while reading the last token
return currentIdentifier;
} else {
@@ -125,8 +151,34 @@
* @return a status object with code IStatus.OK
if
* the given name is valid as a compilation unit name, otherwise a status
* object indicating what is wrong with the name
+ * @deprecated Use {@link #validateCompilationUnitName(String id, String sourceLevel, String complianceLevel)} instead
*/
public static IStatus validateCompilationUnitName(String name) {
+ return validateCompilationUnitName(name,CompilerOptions.VERSION_1_3,CompilerOptions.VERSION_1_3);
+ }
+
+ /**
+ * Validate the given compilation unit name for the given source and compliance levels.
+ *
+ * A compilation unit name must obey the following rules: + *
IStatus.OK
if
+ * the given name is valid as a compilation unit name, otherwise a status
+ * object indicating what is wrong with the name
+ * @since 3.3
+ */
+ public static IStatus validateCompilationUnitName(String name, String sourceLevel, String complianceLevel) {
if (name == null) {
return new Status(IStatus.ERROR, JavaCore.PLUGIN_ID, -1, Messages.convention_unit_nullName, null);
}
@@ -144,7 +196,7 @@
// file in which to store package annotations and
// the package-level spec (replaces package.html)
if (!identifier.equals(PACKAGE_INFO)) {
- IStatus status = validateIdentifier(identifier);
+ IStatus status = validateIdentifier(identifier, sourceLevel, complianceLevel);
if (!status.isOK()) {
return status;
}
@@ -173,8 +225,33 @@
* the given name is valid as a .class file name, otherwise a status
* object indicating what is wrong with the name
* @since 2.0
+ * @deprecated Use {@link #validateClassFileName(String id, String sourceLevel, String complianceLevel)} instead
*/
public static IStatus validateClassFileName(String name) {
+ return validateClassFileName(name, CompilerOptions.VERSION_1_3, CompilerOptions.VERSION_1_3);
+ }
+
+ /**
+ * Validate the given .class file name for the given source and compliance levels.
+ * + * A .class file name must obey the following rules: + *
".class"
suffix
+ * IStatus.OK
if
+ * the given name is valid as a .class file name, otherwise a status
+ * object indicating what is wrong with the name
+ * @since 3.3
+ */
+ public static IStatus validateClassFileName(String name, String sourceLevel, String complianceLevel) {
if (name == null) {
return new Status(IStatus.ERROR, JavaCore.PLUGIN_ID, -1, Messages.convention_classFile_nullName, null); }
if (!org.eclipse.jdt.internal.compiler.util.Util.isClassFileName(name)) {
@@ -191,7 +268,7 @@
// file in which to store package annotations and
// the package-level spec (replaces package.html)
if (!identifier.equals(PACKAGE_INFO)) {
- IStatus status = validateIdentifier(identifier);
+ IStatus status = validateIdentifier(identifier, sourceLevel, complianceLevel);
if (!status.isOK()) {
return status;
}
@@ -213,9 +290,28 @@
* @return a status object with code IStatus.OK
if
* the given name is valid as a field name, otherwise a status
* object indicating what is wrong with the name
+ * @deprecated Use {@link #validateFieldName(String id, String sourceLevel, String complianceLevel)} instead
*/
public static IStatus validateFieldName(String name) {
- return validateIdentifier(name);
+ return validateIdentifier(name, CompilerOptions.VERSION_1_3,CompilerOptions.VERSION_1_3);
+ }
+
+ /**
+ * Validate the given field name for the given source and compliance levels.
+ *
+ * Syntax of a field name corresponds to VariableDeclaratorId (JLS2 8.3).
+ * For example, "x"
.
+ *
+ * @param name the name of a field
+ * @param sourceLevel the source level
+ * @param complianceLevel the compliance level
+ * @return a status object with code IStatus.OK
if
+ * the given name is valid as a field name, otherwise a status
+ * object indicating what is wrong with the name
+ * @since 3.3
+ */
+ public static IStatus validateFieldName(String name, String sourceLevel, String complianceLevel) {
+ return validateIdentifier(name, sourceLevel, complianceLevel);
}
/**
@@ -229,9 +325,29 @@
* @return a status object with code IStatus.OK
if
* the given identifier is a valid Java identifier, otherwise a status
* object indicating what is wrong with the identifier
+ * @deprecated Use {@link #validateIdentifier(String id, String sourceLevel, String complianceLevel)} instead
*/
public static IStatus validateIdentifier(String id) {
- if (scannedIdentifier(id) != null) {
+ return validateIdentifier(id,CompilerOptions.VERSION_1_3,CompilerOptions.VERSION_1_3);
+ }
+
+ /**
+ * Validate the given Java identifier for the given source and compliance levels
+ * The identifier must not have the same spelling as a Java keyword,
+ * boolean literal ("true"
, "false"
), or null literal ("null"
).
+ * See section 3.8 of the Java Language Specification, Second Edition (JLS2).
+ * A valid identifier can act as a simple type name, method name or field name.
+ *
+ * @param id the Java identifier
+ * @param sourceLevel the source level
+ * @param complianceLevel the compliance level
+ * @return a status object with code IStatus.OK
if
+ * the given identifier is a valid Java identifier, otherwise a status
+ * object indicating what is wrong with the identifier
+ * @since 3.3
+ */
+ public static IStatus validateIdentifier(String id, String sourceLevel, String complianceLevel) {
+ if (scannedIdentifier(id, sourceLevel, complianceLevel) != null) {
return JavaModelStatus.VERIFIED_OK;
} else {
return new Status(IStatus.ERROR, JavaCore.PLUGIN_ID, -1, Messages.bind(Messages.convention_illegalIdentifier, id), null);
@@ -249,19 +365,39 @@
* @return a status object with code IStatus.OK
if
* the given name is valid as an import declaration, otherwise a status
* object indicating what is wrong with the name
+ * @deprecated Use {@link #validateImportDeclaration(String id, String sourceLevel, String complianceLevel)} instead
*/
public static IStatus validateImportDeclaration(String name) {
+ return validateImportDeclaration(name,CompilerOptions.VERSION_1_3,CompilerOptions.VERSION_1_3);
+ }
+
+ /**
+ * Validate the given import declaration name for the given source and compliance levels.
+ *
+ * The name of an import corresponds to a fully qualified type name
+ * or an on-demand package name as defined by ImportDeclaration (JLS2 7.5).
+ * For example, "java.util.*"
or "java.util.Hashtable"
.
+ *
+ * @param name the import declaration
+ * @param sourceLevel the source level
+ * @param complianceLevel the compliance level
+ * @return a status object with code IStatus.OK
if
+ * the given name is valid as an import declaration, otherwise a status
+ * object indicating what is wrong with the name
+ * @since 3.3
+ */
+ public static IStatus validateImportDeclaration(String name, String sourceLevel, String complianceLevel) {
if (name == null || name.length() == 0) {
return new Status(IStatus.ERROR, JavaCore.PLUGIN_ID, -1, Messages.convention_import_nullImport, null);
}
if (name.charAt(name.length() - 1) == '*') {
if (name.charAt(name.length() - 2) == '.') {
- return validatePackageName(name.substring(0, name.length() - 2));
+ return validatePackageName(name.substring(0, name.length() - 2), sourceLevel, complianceLevel);
} else {
return new Status(IStatus.ERROR, JavaCore.PLUGIN_ID, -1, Messages.convention_import_unqualifiedImport, null);
}
}
- return validatePackageName(name);
+ return validatePackageName(name, sourceLevel, complianceLevel);
}
/**
@@ -276,8 +412,29 @@
* indicating why the given name is discouraged,
* otherwise a status object indicating what is wrong with
* the name
+ * @deprecated Use {@link #validateJavaTypeName(String id, String sourceLevel, String complianceLevel)} instead
*/
public static IStatus validateJavaTypeName(String name) {
+ return validateJavaTypeName(name, CompilerOptions.VERSION_1_3,CompilerOptions.VERSION_1_3);
+ }
+
+ /**
+ * Validate the given Java type name, either simple or qualified, for the given source and compliance levels.
+ * For example, "java.lang.Object"
, or "Object"
.
+ *
+ *
+ * @param name the name of a type
+ * @param sourceLevel the source level
+ * @param complianceLevel the compliance level
+ * @return a status object with code IStatus.OK
if
+ * the given name is valid as a Java type name,
+ * a status with code IStatus.WARNING
+ * indicating why the given name is discouraged,
+ * otherwise a status object indicating what is wrong with
+ * the name
+ * @since 3.3
+ */
+ public static IStatus validateJavaTypeName(String name, String sourceLevel, String complianceLevel) {
if (name == null) {
return new Status(IStatus.ERROR, JavaCore.PLUGIN_ID, -1, Messages.convention_type_nullName, null);
}
@@ -289,16 +446,16 @@
char[] scannedID;
if (index == -1) {
// simple name
- scannedID = scannedIdentifier(name);
+ scannedID = scannedIdentifier(name, sourceLevel, complianceLevel);
} else {
// qualified name
String pkg = name.substring(0, index).trim();
- IStatus status = validatePackageName(pkg);
+ IStatus status = validatePackageName(pkg, sourceLevel, complianceLevel);
if (!status.isOK()) {
return status;
}
String type = name.substring(index + 1).trim();
- scannedID = scannedIdentifier(type);
+ scannedID = scannedIdentifier(type, sourceLevel, complianceLevel);
}
if (scannedID != null) {
@@ -329,10 +486,29 @@
* @return a status object with code IStatus.OK
if
* the given name is valid as a method name, otherwise a status
* object indicating what is wrong with the name
+ * @deprecated Use {@link #validateMethodName(String id, String sourceLevel, String complianceLevel)} instead
*/
public static IStatus validateMethodName(String name) {
-
- return validateIdentifier(name);
+ return validateMethodName(name, CompilerOptions.VERSION_1_3,CompilerOptions.VERSION_1_3);
+ }
+
+ /**
+ * Validate the given method name for the given source and compliance levels.
+ * The special names "<init>" and "<clinit>" are not valid.
+ *
+ * The syntax for a method name is defined by Identifier
+ * of MethodDeclarator (JLS2 8.4). For example "println".
+ *
+ * @param name the name of a method
+ * @param sourceLevel the source level
+ * @param complianceLevel the compliance level
+ * @return a status object with code IStatus.OK
if
+ * the given name is valid as a method name, otherwise a status
+ * object indicating what is wrong with the name
+ * @since 3.3
+ */
+ public static IStatus validateMethodName(String name, String sourceLevel, String complianceLevel) {
+ return validateIdentifier(name, sourceLevel,complianceLevel);
}
/**
@@ -350,8 +526,32 @@
* @return a status object with code IStatus.OK
if
* the given name is valid as a package name, otherwise a status
* object indicating what is wrong with the name
+ * @deprecated Use {@link #validatePackageName(String id, String sourceLevel, String complianceLevel)} instead
*/
public static IStatus validatePackageName(String name) {
+ return validatePackageName(name, CompilerOptions.VERSION_1_3,CompilerOptions.VERSION_1_3);
+ }
+
+ /**
+ * Validate the given package name for the given source and compliance levels.
+ *
+ * The syntax of a package name corresponds to PackageName as
+ * defined by PackageDeclaration (JLS2 7.4). For example, "java.lang"
.
+ *
+ * Note that the given name must be a non-empty package name (that is, attempting to
+ * validate the default package will return an error status.)
+ * Also it must not contain any characters or substrings that are not valid
+ * on the file system on which workspace root is located.
+ *
+ * @param name the name of a package
+ * @param sourceLevel the source level
+ * @param complianceLevel the compliance level
+ * @return a status object with code IStatus.OK
if
+ * the given name is valid as a package name, otherwise a status
+ * object indicating what is wrong with the name
+ * @since 3.3
+ */
+ public static IStatus validatePackageName(String name, String sourceLevel, String complianceLevel) {
if (name == null) {
return new Status(IStatus.ERROR, JavaCore.PLUGIN_ID, -1, Messages.convention_package_nullName, null);
@@ -379,7 +579,7 @@
while (st.hasMoreTokens()) {
String typeName = st.nextToken();
typeName = typeName.trim(); // grammar allows spaces
- char[] scannedID = scannedIdentifier(typeName);
+ char[] scannedID = scannedIdentifier(typeName, sourceLevel, complianceLevel);
if (scannedID == null) {
return new Status(IStatus.ERROR, JavaCore.PLUGIN_ID, -1, Messages.bind(Messages.convention_illegalIdentifier, typeName), null);
}
@@ -465,11 +665,30 @@
* the given name is valid as a type variable name, otherwise a status
* object indicating what is wrong with the name
* @since 3.1
+ * @deprecated Use {@link #validateTypeVariableName(String id, String sourceLevel, String complianceLevel)} instead
*/
public static IStatus validateTypeVariableName(String name) {
- return validateIdentifier(name);
+ return validateIdentifier(name, CompilerOptions.VERSION_1_3,CompilerOptions.VERSION_1_3);
}
-
+
+ /**
+ * Validate the given type variable name for the given source and compliance levels.
+ *
+ * Syntax of a type variable name corresponds to a Java identifier (JLS3 4.3).
+ * For example, "E"
.
+ *
+ * @param name the name of a type variable
+ * @param sourceLevel the source level
+ * @param complianceLevel the compliance level
+ * @return a status object with code IStatus.OK
if
+ * the given name is valid as a type variable name, otherwise a status
+ * object indicating what is wrong with the name
+ * @since 3.3
+ */
+ public static IStatus validateTypeVariableName(String name, String sourceLevel, String complianceLevel) {
+ return validateIdentifier(name, sourceLevel, complianceLevel);
+ }
+
/**
* Validate that all compiler options of the given project match keys and values
* described in {@link JavaCore#getDefaultOptions()} method.
Index: model/org/eclipse/jdt/internal/core/CreatePackageDeclarationOperation.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/CreatePackageDeclarationOperation.java,v
retrieving revision 1.25
diff -u -r1.25 CreatePackageDeclarationOperation.java
--- model/org/eclipse/jdt/internal/core/CreatePackageDeclarationOperation.java 8 Apr 2005 20:30:28 -0000 1.25
+++ model/org/eclipse/jdt/internal/core/CreatePackageDeclarationOperation.java 6 Nov 2006 12:26:33 -0000
@@ -16,8 +16,10 @@
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IJavaModelStatus;
import org.eclipse.jdt.core.IJavaModelStatusConstants;
+import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.JavaConventions;
+import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.core.dom.AST;
import org.eclipse.jdt.core.dom.ASTNode;
@@ -120,7 +122,8 @@
if (!status.isOK()) {
return status;
}
- if (JavaConventions.validatePackageName(this.name).getSeverity() == IStatus.ERROR) {
+ IJavaProject project = getParentElement().getJavaProject();
+ if (JavaConventions.validatePackageName(this.name, project.getOption(JavaCore.COMPILER_SOURCE, true), project.getOption(JavaCore.COMPILER_COMPLIANCE, true)).getSeverity() == IStatus.ERROR) {
return new JavaModelStatus(IJavaModelStatusConstants.INVALID_NAME, this.name);
}
return JavaModelStatus.VERIFIED_OK;
Index: model/org/eclipse/jdt/internal/core/CreateImportOperation.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/CreateImportOperation.java,v
retrieving revision 1.29
diff -u -r1.29 CreateImportOperation.java
--- model/org/eclipse/jdt/internal/core/CreateImportOperation.java 20 Jun 2006 11:33:13 -0000 1.29
+++ model/org/eclipse/jdt/internal/core/CreateImportOperation.java 6 Nov 2006 12:26:33 -0000
@@ -19,8 +19,10 @@
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IJavaModelStatus;
import org.eclipse.jdt.core.IJavaModelStatusConstants;
+import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.JavaConventions;
+import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.core.compiler.CharOperation;
import org.eclipse.jdt.core.dom.AST;
@@ -165,7 +167,8 @@
if (!status.isOK()) {
return status;
}
- if (JavaConventions.validateImportDeclaration(this.importName).getSeverity() == IStatus.ERROR) {
+ IJavaProject project = getParentElement().getJavaProject();
+ if (JavaConventions.validateImportDeclaration(this.importName, project.getOption(JavaCore.COMPILER_SOURCE, true), project.getOption(JavaCore.COMPILER_COMPLIANCE, true)).getSeverity() == IStatus.ERROR) {
return new JavaModelStatus(IJavaModelStatusConstants.INVALID_NAME, this.importName);
}
return JavaModelStatus.VERIFIED_OK;
Index: model/org/eclipse/jdt/internal/core/ClassFile.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/ClassFile.java,v
retrieving revision 1.127
diff -u -r1.127 ClassFile.java
--- model/org/eclipse/jdt/internal/core/ClassFile.java 23 Jun 2006 11:16:24 -0000 1.127
+++ model/org/eclipse/jdt/internal/core/ClassFile.java 6 Nov 2006 12:26:30 -0000
@@ -560,7 +560,8 @@
} catch (JavaModelException e) {
return e.getJavaModelStatus();
}
- return JavaConventions.validateClassFileName(getElementName());
+ IJavaProject project = getJavaProject();
+ return JavaConventions.validateClassFileName(getElementName(), project.getOption(JavaCore.COMPILER_SOURCE, true), project.getOption(JavaCore.COMPILER_COMPLIANCE, true));
}
/**
* Opens and returns buffer on the source code associated with this class file.
Index: model/org/eclipse/jdt/internal/core/PackageFragment.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/PackageFragment.java,v
retrieving revision 1.78
diff -u -r1.78 PackageFragment.java
--- model/org/eclipse/jdt/internal/core/PackageFragment.java 4 May 2006 09:33:30 -0000 1.78
+++ model/org/eclipse/jdt/internal/core/PackageFragment.java 6 Nov 2006 12:26:40 -0000
@@ -27,10 +27,12 @@
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IJavaModelStatusConstants;
+import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.IPackageFragment;
import org.eclipse.jdt.core.IPackageFragmentRoot;
import org.eclipse.jdt.core.IParent;
import org.eclipse.jdt.core.ISourceManipulation;
+import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.core.WorkingCopyOwner;
import org.eclipse.jdt.internal.compiler.util.SuffixConstants;
@@ -79,17 +81,23 @@
char[][] inclusionPatterns = root.fullInclusionPatternChars();
char[][] exclusionPatterns = root.fullExclusionPatternChars();
IResource[] members = ((IContainer) underlyingResource).members();
- for (int i = 0, max = members.length; i < max; i++) {
- IResource child = members[i];
- if (child.getType() != IResource.FOLDER
- && !Util.isExcluded(child, inclusionPatterns, exclusionPatterns)) {
- IJavaElement childElement;
- if (kind == IPackageFragmentRoot.K_SOURCE && Util.isValidCompilationUnitName(child.getName())) {
- childElement = new CompilationUnit(this, child.getName(), DefaultWorkingCopyOwner.PRIMARY);
- vChildren.add(childElement);
- } else if (kind == IPackageFragmentRoot.K_BINARY && Util.isValidClassFileName(child.getName())) {
- childElement = getClassFile(child.getName());
- vChildren.add(childElement);
+ int length = members.length;
+ if (length > 0) {
+ IJavaProject project = getJavaProject();
+ String sourceLevel = project.getOption(JavaCore.COMPILER_SOURCE, true);
+ String complianceLevel = project.getOption(JavaCore.COMPILER_COMPLIANCE, true);
+ for (int i = 0; i < length; i++) {
+ IResource child = members[i];
+ if (child.getType() != IResource.FOLDER
+ && !Util.isExcluded(child, inclusionPatterns, exclusionPatterns)) {
+ IJavaElement childElement;
+ if (kind == IPackageFragmentRoot.K_SOURCE && Util.isValidCompilationUnitName(child.getName(), sourceLevel, complianceLevel)) {
+ childElement = new CompilationUnit(this, child.getName(), DefaultWorkingCopyOwner.PRIMARY);
+ vChildren.add(childElement);
+ } else if (kind == IPackageFragmentRoot.K_BINARY && Util.isValidClassFileName(child.getName(), sourceLevel, complianceLevel)) {
+ childElement = getClassFile(child.getName());
+ vChildren.add(childElement);
+ }
}
}
}
Index: model/org/eclipse/jdt/internal/core/SourceMapper.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/SourceMapper.java,v
retrieving revision 1.127
diff -u -r1.127 SourceMapper.java
--- model/org/eclipse/jdt/internal/core/SourceMapper.java 29 Sep 2006 17:13:16 -0000 1.127
+++ model/org/eclipse/jdt/internal/core/SourceMapper.java 6 Nov 2006 12:26:43 -0000
@@ -38,6 +38,7 @@
import org.eclipse.jdt.core.IClassFile;
import org.eclipse.jdt.core.IField;
import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.IMember;
import org.eclipse.jdt.core.IMethod;
import org.eclipse.jdt.core.IPackageFragmentRoot;
@@ -45,6 +46,7 @@
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.ITypeParameter;
import org.eclipse.jdt.core.JavaConventions;
+import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.core.Signature;
import org.eclipse.jdt.core.compiler.CategorizedProblem;
@@ -365,6 +367,9 @@
if (root.isArchive()) {
JarPackageFragmentRoot jarPackageFragmentRoot = (JarPackageFragmentRoot) root;
+ IJavaProject project = jarPackageFragmentRoot.getJavaProject();
+ String sourceLevel = null;
+ String complianceLevel = null;
JavaModelManager manager = JavaModelManager.getJavaModelManager();
ZipFile zip = null;
try {
@@ -377,7 +382,11 @@
if (index != -1 && Util.isClassFileName(entryName)) {
String firstLevelPackageName = entryName.substring(0, index);
if (!firstLevelPackageNames.contains(firstLevelPackageName)) {
- IStatus status = JavaConventions.validatePackageName(firstLevelPackageName);
+ if (sourceLevel == null) {
+ sourceLevel = project.getOption(JavaCore.COMPILER_SOURCE, true);
+ complianceLevel = project.getOption(JavaCore.COMPILER_COMPLIANCE, true);
+ }
+ IStatus status = JavaConventions.validatePackageName(firstLevelPackageName, sourceLevel, complianceLevel);
if (status.isOK() || status.getSeverity() == IStatus.WARNING) {
firstLevelPackageNames.add(firstLevelPackageName);
}
Index: model/org/eclipse/jdt/internal/core/CommitWorkingCopyOperation.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/CommitWorkingCopyOperation.java,v
retrieving revision 1.54
diff -u -r1.54 CommitWorkingCopyOperation.java
--- model/org/eclipse/jdt/internal/core/CommitWorkingCopyOperation.java 29 Mar 2006 03:08:47 -0000 1.54
+++ model/org/eclipse/jdt/internal/core/CommitWorkingCopyOperation.java 6 Nov 2006 12:26:30 -0000
@@ -18,12 +18,13 @@
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.jobs.ISchedulingRule;
-//import org.eclipse.jdt.core.*;
import org.eclipse.jdt.core.IBuffer;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IJavaModelStatus;
import org.eclipse.jdt.core.IJavaModelStatusConstants;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.internal.core.util.Messages;
import org.eclipse.jdt.internal.core.util.Util;
@@ -83,7 +84,8 @@
PackageFragmentRoot root = (PackageFragmentRoot)workingCopy.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT);
boolean isIncluded = !Util.isExcluded(workingCopy);
IFile resource = (IFile)workingCopy.getResource();
- if (isPrimary || (root.validateOnClasspath().isOK() && isIncluded && resource.isAccessible() && Util.isValidCompilationUnitName(workingCopy.getElementName()))) {
+ IJavaProject project = root.getJavaProject();
+ if (isPrimary || (root.validateOnClasspath().isOK() && isIncluded && resource.isAccessible() && Util.isValidCompilationUnitName(workingCopy.getElementName(), project.getOption(JavaCore.COMPILER_SOURCE, true), project.getOption(JavaCore.COMPILER_COMPLIANCE, true)))) {
// force opening so that the delta builder can get the old info
if (!isPrimary && !primary.isOpen()) {
Index: model/org/eclipse/jdt/internal/core/DeltaProcessor.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/DeltaProcessor.java,v
retrieving revision 1.289
diff -u -r1.289 DeltaProcessor.java
--- model/org/eclipse/jdt/internal/core/DeltaProcessor.java 20 Oct 2006 14:35:34 -0000 1.289
+++ model/org/eclipse/jdt/internal/core/DeltaProcessor.java 6 Nov 2006 12:26:35 -0000
@@ -1230,15 +1230,17 @@
if (parentType == NON_JAVA_RESOURCE && !Util.isExcluded(res.getParent(), rootInfo.inclusionPatterns, rootInfo.exclusionPatterns))
// 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)
return NON_JAVA_RESOURCE;
- if (Util.isValidFolderNameForPackage(res.getName())) {
+ if (Util.isValidFolderNameForPackage(res.getName(), rootInfo.project.getOption(JavaCore.COMPILER_SOURCE, true), rootInfo.project.getOption(JavaCore.COMPILER_COMPLIANCE, true))) {
return IJavaElement.PACKAGE_FRAGMENT;
}
return NON_JAVA_RESOURCE;
}
String fileName = res.getName();
- if (Util.isValidCompilationUnitName(fileName)) {
+ String sourceLevel = rootInfo.project.getOption(JavaCore.COMPILER_SOURCE, true);
+ String complianceLevel = rootInfo.project.getOption(JavaCore.COMPILER_COMPLIANCE, true);
+ if (Util.isValidCompilationUnitName(fileName, sourceLevel, complianceLevel)) {
return IJavaElement.COMPILATION_UNIT;
- } else if (Util.isValidClassFileName(fileName)) {
+ } else if (Util.isValidClassFileName(fileName, sourceLevel, complianceLevel)) {
return IJavaElement.CLASS_FILE;
} else if (this.rootInfo(res.getFullPath(), kind) != null) {
// case of proj=src=bin and resource is a jar file on the classpath
@@ -1419,8 +1421,11 @@
* Returns whether the given resource is in one of the given output folders and if
* it is filtered out from this output folder.
*/
- private boolean isResFilteredFromOutput(OutputsInfo info, IResource res, int elementType) {
+ private boolean isResFilteredFromOutput(RootInfo rootInfo, OutputsInfo info, IResource res, int elementType) {
if (info != null) {
+ JavaProject javaProject = null;
+ String sourceLevel = null;
+ String complianceLevel = null;
IPath resPath = res.getFullPath();
for (int i = 0; i < info.outputCount; i++) {
if (info.paths[i].isPrefixOf(resPath)) {
@@ -1431,10 +1436,24 @@
}
// case of .class file under project and no source folder
// proj=bin
- if (elementType == IJavaElement.JAVA_PROJECT
- && res instanceof IFile
- && Util.isValidClassFileName(res.getName())) {
- return true;
+ if (elementType == IJavaElement.JAVA_PROJECT && res instanceof IFile) {
+ if (sourceLevel == null) {
+ // Get java project to use its source and compliance levels
+ javaProject = rootInfo == null ?
+ (JavaProject)this.createElement(res.getProject(), IJavaElement.JAVA_PROJECT, null) :
+ rootInfo.project;
+ if (javaProject == null) {
+ // Cannot get any project => use workspace options
+ sourceLevel = this.manager.getOption(JavaCore.COMPILER_SOURCE);
+ complianceLevel = this.manager.getOption(JavaCore.COMPILER_COMPLIANCE);
+ } else {
+ sourceLevel = javaProject.getOption(JavaCore.COMPILER_SOURCE, true);
+ complianceLevel = javaProject.getOption(JavaCore.COMPILER_COMPLIANCE, true);
+ }
+ }
+ if (Util.isValidClassFileName(res.getName(), sourceLevel, complianceLevel)) {
+ return true;
+ }
}
} else {
return true;
@@ -2024,7 +2043,7 @@
);
// is childRes in the output folder and is it filtered out ?
- boolean isResFilteredFromOutput = this.isResFilteredFromOutput(outputsInfo, childRes, childType);
+ boolean isResFilteredFromOutput = this.isResFilteredFromOutput(rootInfo, outputsInfo, childRes, childType);
boolean isNestedRoot = rootInfo != null && childRootInfo != null;
if (!isResFilteredFromOutput
Index: model/org/eclipse/jdt/internal/core/CreateCompilationUnitOperation.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/CreateCompilationUnitOperation.java,v
retrieving revision 1.38
diff -u -r1.38 CreateCompilationUnitOperation.java
--- model/org/eclipse/jdt/internal/core/CreateCompilationUnitOperation.java 10 May 2006 18:03:47 -0000 1.38
+++ model/org/eclipse/jdt/internal/core/CreateCompilationUnitOperation.java 6 Nov 2006 12:26:33 -0000
@@ -15,9 +15,6 @@
import java.io.InputStream;
import org.eclipse.core.resources.*;
-import org.eclipse.core.resources.IContainer;
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.NullProgressMonitor;
@@ -29,9 +26,10 @@
import org.eclipse.jdt.core.IJavaElementDelta;
import org.eclipse.jdt.core.IJavaModelStatus;
import org.eclipse.jdt.core.IJavaModelStatusConstants;
+import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.IPackageFragment;
import org.eclipse.jdt.core.JavaConventions;
-//import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.internal.core.util.Messages;
import org.eclipse.jdt.internal.core.util.Util;
@@ -163,7 +161,8 @@
if (getParentElement() == null) {
return new JavaModelStatus(IJavaModelStatusConstants.NO_ELEMENTS_TO_PROCESS);
}
- if (JavaConventions.validateCompilationUnitName(fName).getSeverity() == IStatus.ERROR) {
+ IJavaProject project = getParentElement().getJavaProject();
+ if (JavaConventions.validateCompilationUnitName(fName, project.getOption(JavaCore.COMPILER_SOURCE, true), project.getOption(JavaCore.COMPILER_COMPLIANCE, true)).getSeverity() == IStatus.ERROR) {
return new JavaModelStatus(IJavaModelStatusConstants.INVALID_NAME, fName);
}
if (fSource == null) {
Index: model/org/eclipse/jdt/internal/core/PackageFragmentRoot.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/PackageFragmentRoot.java,v
retrieving revision 1.119
diff -u -r1.119 PackageFragmentRoot.java
--- model/org/eclipse/jdt/internal/core/PackageFragmentRoot.java 13 Jun 2006 13:00:41 -0000 1.119
+++ model/org/eclipse/jdt/internal/core/PackageFragmentRoot.java 6 Nov 2006 12:26:41 -0000
@@ -237,34 +237,39 @@
JavaModelManager manager = JavaModelManager.getJavaModelManager();
IResource[] members = folder.members();
boolean hasIncluded = isIncluded;
- for (int i = 0, max = members.length; i < max; i++) {
- IResource member = members[i];
- String memberName = member.getName();
+ int length = members.length;
+ if (length >0) {
+ String sourceLevel = javaProject.getOption(JavaCore.COMPILER_SOURCE, true);
+ String complianceLevel = javaProject.getOption(JavaCore.COMPILER_COMPLIANCE, true);
+ for (int i = 0; i < length; i++) {
+ IResource member = members[i];
+ String memberName = member.getName();
- switch(member.getType()) {
+ switch(member.getType()) {
- case IResource.FOLDER:
- // recurse into sub folders even even parent not included as a sub folder could be included
- // (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=65637)
- if (Util.isValidFolderNameForPackage(memberName)) {
- // eliminate binary output only if nested inside direct subfolders
- if (javaProject.contains(member)) {
- String[] newNames = Util.arrayConcat(pkgName, manager.intern(memberName));
- boolean isMemberIncluded = !Util.isExcluded(member, inclusionPatterns, exclusionPatterns);
- computeFolderChildren((IFolder) member, isMemberIncluded, newNames, vChildren, inclusionPatterns, exclusionPatterns);
- }
- }
- break;
- case IResource.FILE:
- // inclusion filter may only include files, in which case we still want to include the immediate parent package (lazily)
- if (!hasIncluded
- && Util.isValidCompilationUnitName(memberName)
+ case IResource.FOLDER:
+ // recurse into sub folders even even parent not included as a sub folder could be included
+ // (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=65637)
+ if (Util.isValidFolderNameForPackage(memberName, sourceLevel, complianceLevel)) {
+ // eliminate binary output only if nested inside direct subfolders
+ if (javaProject.contains(member)) {
+ String[] newNames = Util.arrayConcat(pkgName, manager.intern(memberName));
+ boolean isMemberIncluded = !Util.isExcluded(member, inclusionPatterns, exclusionPatterns);
+ computeFolderChildren((IFolder) member, isMemberIncluded, newNames, vChildren, inclusionPatterns, exclusionPatterns);
+ }
+ }
+ break;
+ case IResource.FILE:
+ // inclusion filter may only include files, in which case we still want to include the immediate parent package (lazily)
+ if (!hasIncluded
+ && Util.isValidCompilationUnitName(memberName, sourceLevel, complianceLevel)
&& !Util.isExcluded(member, inclusionPatterns, exclusionPatterns)) {
- hasIncluded = true;
- IPackageFragment pkg = getPackageFragment(pkgName);
- vChildren.add(pkg);
- }
- break;
+ hasIncluded = true;
+ IPackageFragment pkg = getPackageFragment(pkgName);
+ vChildren.add(pkg);
+ }
+ break;
+ }
}
}
} catch(IllegalArgumentException e){
Index: model/org/eclipse/jdt/internal/core/MultiOperation.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/MultiOperation.java,v
retrieving revision 1.16
diff -u -r1.16 MultiOperation.java
--- model/org/eclipse/jdt/internal/core/MultiOperation.java 23 Feb 2005 02:47:29 -0000 1.16
+++ model/org/eclipse/jdt/internal/core/MultiOperation.java 6 Nov 2006 12:26:40 -0000
@@ -266,23 +266,25 @@
protected void verifyRenaming(IJavaElement element) throws JavaModelException {
String newName = getNewNameFor(element);
boolean isValid = true;
-
+ IJavaProject project = element.getJavaProject();
+ String sourceLevel = project.getOption(JavaCore.COMPILER_SOURCE, true);
+ String complianceLevel = project.getOption(JavaCore.COMPILER_COMPLIANCE, true);
switch (element.getElementType()) {
case IJavaElement.PACKAGE_FRAGMENT :
if (((IPackageFragment) element).isDefaultPackage()) {
// don't allow renaming of default package (see PR #1G47GUM)
throw new JavaModelException(new JavaModelStatus(IJavaModelStatusConstants.NAME_COLLISION, element));
}
- isValid = JavaConventions.validatePackageName(newName).getSeverity() != IStatus.ERROR;
+ isValid = JavaConventions.validatePackageName(newName, sourceLevel, complianceLevel).getSeverity() != IStatus.ERROR;
break;
case IJavaElement.COMPILATION_UNIT :
- isValid = JavaConventions.validateCompilationUnitName(newName).getSeverity() != IStatus.ERROR;
+ isValid = JavaConventions.validateCompilationUnitName(newName,sourceLevel, complianceLevel).getSeverity() != IStatus.ERROR;
break;
case IJavaElement.INITIALIZER :
isValid = false; //cannot rename initializers
break;
default :
- isValid = JavaConventions.validateIdentifier(newName).getSeverity() != IStatus.ERROR;
+ isValid = JavaConventions.validateIdentifier(newName, sourceLevel, complianceLevel).getSeverity() != IStatus.ERROR;
break;
}
Index: model/org/eclipse/jdt/internal/core/CompilationUnit.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/CompilationUnit.java,v
retrieving revision 1.233
diff -u -r1.233 CompilationUnit.java
--- model/org/eclipse/jdt/internal/core/CompilationUnit.java 17 Jul 2006 11:40:27 -0000 1.233
+++ model/org/eclipse/jdt/internal/core/CompilationUnit.java 6 Nov 2006 12:26:32 -0000
@@ -963,7 +963,8 @@
if (!resource.isAccessible())
return new JavaModelStatus(IJavaModelStatusConstants.ELEMENT_DOES_NOT_EXIST, this);
}
- return JavaConventions.validateCompilationUnitName(getElementName());
+ IJavaProject project = getJavaProject();
+ return JavaConventions.validateCompilationUnitName(getElementName(),project.getOption(JavaCore.COMPILER_SOURCE, true), project.getOption(JavaCore.COMPILER_COMPLIANCE, true));
}
/*
* @see ICompilationUnit#isWorkingCopy()
Index: model/org/eclipse/jdt/internal/core/JavaProjectElementInfo.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JavaProjectElementInfo.java,v
retrieving revision 1.41
diff -u -r1.41 JavaProjectElementInfo.java
--- model/org/eclipse/jdt/internal/core/JavaProjectElementInfo.java 13 Jun 2006 13:00:42 -0000 1.41
+++ model/org/eclipse/jdt/internal/core/JavaProjectElementInfo.java 6 Nov 2006 12:26:40 -0000
@@ -123,58 +123,63 @@
int resourcesCounter = 0;
try {
IResource[] members = ((IContainer) project.getResource()).members();
- for (int i = 0, max = members.length; i < max; i++) {
- IResource res = members[i];
- switch (res.getType()) {
- case IResource.FILE :
- IPath resFullPath = res.getFullPath();
- String resName = res.getName();
+ int length = members.length;
+ if (length > 0) {
+ String sourceLevel = project.getOption(JavaCore.COMPILER_SOURCE, true);
+ String complianceLevel = project.getOption(JavaCore.COMPILER_COMPLIANCE, true);
+ for (int i = 0; i < length; i++) {
+ IResource res = members[i];
+ switch (res.getType()) {
+ case IResource.FILE :
+ IPath resFullPath = res.getFullPath();
+ String resName = res.getName();
- // ignore a jar file on the classpath
- if (org.eclipse.jdt.internal.compiler.util.Util.isArchiveFileName(resName) && this.isClasspathEntryOrOutputLocation(resFullPath, classpath, projectOutput)) {
+ // ignore a jar file on the classpath
+ if (org.eclipse.jdt.internal.compiler.util.Util.isArchiveFileName(resName) && this.isClasspathEntryOrOutputLocation(resFullPath, classpath, projectOutput)) {
+ break;
+ }
+ // ignore .java file if src == project
+ if (srcIsProject
+ && Util.isValidCompilationUnitName(resName, sourceLevel, complianceLevel)
+ && !Util.isExcluded(res, inclusionPatterns, exclusionPatterns)) {
+ break;
+ }
+ // ignore .class file if bin == project
+ if (binIsProject && Util.isValidClassFileName(resName, sourceLevel, complianceLevel)) {
+ break;
+ }
+ // else add non java resource
+ if (resources.length == resourcesCounter) {
+ // resize
+ System.arraycopy(
+ resources,
+ 0,
+ (resources = new IResource[resourcesCounter * 2]),
+ 0,
+ resourcesCounter);
+ }
+ resources[resourcesCounter++] = res;
break;
- }
- // ignore .java file if src == project
- if (srcIsProject
- && Util.isValidCompilationUnitName(resName)
- && !Util.isExcluded(res, inclusionPatterns, exclusionPatterns)) {
- break;
- }
- // ignore .class file if bin == project
- if (binIsProject && Util.isValidClassFileName(resName)) {
- break;
- }
- // else add non java resource
- if (resources.length == resourcesCounter) {
- // resize
- System.arraycopy(
- resources,
- 0,
- (resources = new IResource[resourcesCounter * 2]),
- 0,
- resourcesCounter);
- }
- resources[resourcesCounter++] = res;
- break;
- case IResource.FOLDER :
- resFullPath = res.getFullPath();
+ case IResource.FOLDER :
+ resFullPath = res.getFullPath();
- // ignore non-excluded folders on the classpath or that correspond to an output location
- if ((srcIsProject && !Util.isExcluded(res, inclusionPatterns, exclusionPatterns) && Util.isValidFolderNameForPackage(res.getName()))
- || this.isClasspathEntryOrOutputLocation(resFullPath, classpath, projectOutput)) {
- break;
- }
- // else add non java resource
- if (resources.length == resourcesCounter) {
- // resize
- System.arraycopy(
- resources,
- 0,
- (resources = new IResource[resourcesCounter * 2]),
- 0,
- resourcesCounter);
- }
- resources[resourcesCounter++] = res;
+ // ignore non-excluded folders on the classpath or that correspond to an output location
+ if ((srcIsProject && !Util.isExcluded(res, inclusionPatterns, exclusionPatterns) && Util.isValidFolderNameForPackage(res.getName(), sourceLevel, complianceLevel))
+ || this.isClasspathEntryOrOutputLocation(resFullPath, classpath, projectOutput)) {
+ break;
+ }
+ // else add non java resource
+ if (resources.length == resourcesCounter) {
+ // resize
+ System.arraycopy(
+ resources,
+ 0,
+ (resources = new IResource[resourcesCounter * 2]),
+ 0,
+ resourcesCounter);
+ }
+ resources[resourcesCounter++] = res;
+ }
}
}
if (resources.length != resourcesCounter) {
Index: model/org/eclipse/jdt/internal/core/CreatePackageFragmentOperation.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/CreatePackageFragmentOperation.java,v
retrieving revision 1.32
diff -u -r1.32 CreatePackageFragmentOperation.java
--- model/org/eclipse/jdt/internal/core/CreatePackageFragmentOperation.java 10 May 2006 18:03:48 -0000 1.32
+++ model/org/eclipse/jdt/internal/core/CreatePackageFragmentOperation.java 6 Nov 2006 12:26:33 -0000
@@ -19,9 +19,11 @@
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IJavaModelStatus;
import org.eclipse.jdt.core.IJavaModelStatusConstants;
+import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.IPackageFragment;
import org.eclipse.jdt.core.IPackageFragmentRoot;
import org.eclipse.jdt.core.JavaConventions;
+import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.core.compiler.CharOperation;
import org.eclipse.jdt.internal.core.util.Messages;
@@ -120,12 +122,14 @@
* @see JavaConventions
*/
public IJavaModelStatus verify() {
- if (getParentElement() == null) {
+ IJavaElement parentElement = getParentElement();
+ if (parentElement == null) {
return new JavaModelStatus(IJavaModelStatusConstants.NO_ELEMENTS_TO_PROCESS);
}
String packageName = this.pkgName == null ? null : Util.concatWith(this.pkgName, '.');
- if (this.pkgName == null || (this.pkgName.length > 0 && JavaConventions.validatePackageName(packageName).getSeverity() == IStatus.ERROR)) {
+ IJavaProject project = parentElement.getJavaProject();
+ 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)) {
return new JavaModelStatus(IJavaModelStatusConstants.INVALID_NAME, packageName);
}
IPackageFragmentRoot root = (IPackageFragmentRoot) getParentElement();
Index: model/org/eclipse/jdt/internal/core/JavaModelManager.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JavaModelManager.java,v
retrieving revision 1.343
diff -u -r1.343 JavaModelManager.java
--- model/org/eclipse/jdt/internal/core/JavaModelManager.java 3 Nov 2006 15:12:30 -0000 1.343
+++ model/org/eclipse/jdt/internal/core/JavaModelManager.java 6 Nov 2006 12:26:40 -0000
@@ -805,31 +805,36 @@
org.eclipse.jdt.internal.core.util.Util.isJavaLikeFileName(resourcePath.lastSegment())
? project.getRawClasspath() // JAVA file can only live inside SRC folder (on the raw path)
: ((JavaProject)project).getResolvedClasspath();
-
- for (int i = 0; i < entries.length; i++) {
- IClasspathEntry entry = entries[i];
- if (entry.getEntryKind() == IClasspathEntry.CPE_PROJECT) continue;
- IPath rootPath = entry.getPath();
- if (rootPath.equals(resourcePath)) {
- return project.getPackageFragmentRoot(resource);
- } else if (rootPath.isPrefixOf(resourcePath)) {
- // allow creation of package fragment if it contains a .java file that is included
- if (!Util.isExcluded(resource, ((ClasspathEntry)entry).fullInclusionPatternChars(), ((ClasspathEntry)entry).fullExclusionPatternChars())) {
- // given we have a resource child of the root, it cannot be a JAR pkg root
- PackageFragmentRoot root =(PackageFragmentRoot) ((JavaProject) project).getFolderPackageFragmentRoot(rootPath);
- if (root == null) return null;
- IPath pkgPath = resourcePath.removeFirstSegments(rootPath.segmentCount());
-
- if (resource.getType() == IResource.FILE) {
- // if the resource is a file, then remove the last segment which
- // is the file name in the package
- pkgPath = pkgPath.removeLastSegments(1);
- }
- String[] pkgName = pkgPath.segments();
- if (pkgName.length != 0 && JavaConventions.validatePackageName(Util.packageName(pkgPath)).getSeverity() == IStatus.ERROR) {
- return null;
+
+ int length = entries.length;
+ if (length > 0) {
+ String sourceLevel = project.getOption(JavaCore.COMPILER_SOURCE, true);
+ String complianceLevel = project.getOption(JavaCore.COMPILER_COMPLIANCE, true);
+ for (int i = 0; i < length; i++) {
+ IClasspathEntry entry = entries[i];
+ if (entry.getEntryKind() == IClasspathEntry.CPE_PROJECT) continue;
+ IPath rootPath = entry.getPath();
+ if (rootPath.equals(resourcePath)) {
+ return project.getPackageFragmentRoot(resource);
+ } else if (rootPath.isPrefixOf(resourcePath)) {
+ // allow creation of package fragment if it contains a .java file that is included
+ if (!Util.isExcluded(resource, ((ClasspathEntry)entry).fullInclusionPatternChars(), ((ClasspathEntry)entry).fullExclusionPatternChars())) {
+ // given we have a resource child of the root, it cannot be a JAR pkg root
+ PackageFragmentRoot root =(PackageFragmentRoot) ((JavaProject) project).getFolderPackageFragmentRoot(rootPath);
+ if (root == null) return null;
+ IPath pkgPath = resourcePath.removeFirstSegments(rootPath.segmentCount());
+
+ if (resource.getType() == IResource.FILE) {
+ // if the resource is a file, then remove the last segment which
+ // is the file name in the package
+ pkgPath = pkgPath.removeLastSegments(1);
+ }
+ String[] pkgName = pkgPath.segments();
+ if (pkgName.length != 0 && JavaConventions.validatePackageName(Util.packageName(pkgPath, sourceLevel, complianceLevel), sourceLevel, complianceLevel).getSeverity() == IStatus.ERROR) {
+ return null;
+ }
+ return root.getPackageFragment(pkgName);
}
- return root.getPackageFragment(pkgName);
}
}
}
Index: model/org/eclipse/jdt/internal/core/PackageFragmentRootInfo.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/PackageFragmentRootInfo.java,v
retrieving revision 1.37
diff -u -r1.37 PackageFragmentRootInfo.java
--- model/org/eclipse/jdt/internal/core/PackageFragmentRootInfo.java 13 Jun 2006 13:00:43 -0000 1.37
+++ model/org/eclipse/jdt/internal/core/PackageFragmentRootInfo.java 6 Nov 2006 12:26:41 -0000
@@ -16,9 +16,6 @@
import org.eclipse.core.runtime.IPath;
import org.eclipse.jdt.core.*;
-import org.eclipse.jdt.core.IPackageFragmentRoot;
-import org.eclipse.jdt.core.IJavaProject;
-import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.internal.core.util.Util;
/**
@@ -62,37 +59,41 @@
try {
IClasspathEntry[] classpath = project.getResolvedClasspath();
IResource[] members = folder.members();
- nextResource: for (int i = 0, max = members.length; i < max; i++) {
- IResource member = members[i];
- switch (member.getType()) {
- case IResource.FILE :
- String fileName = member.getName();
+ int length = members.length;
+ if (length > 0) {
+ String sourceLevel = project.getOption(JavaCore.COMPILER_SOURCE, true);
+ String complianceLevel = project.getOption(JavaCore.COMPILER_COMPLIANCE, true);
+ nextResource: for (int i = 0; i < length; i++) {
+ IResource member = members[i];
+ switch (member.getType()) {
+ case IResource.FILE :
+ String fileName = member.getName();
- // ignore .java files that are not excluded
- if (Util.isValidCompilationUnitName(fileName) && !Util.isExcluded(member, inclusionPatterns, exclusionPatterns))
- continue nextResource;
- // ignore .class files
- if (Util.isValidClassFileName(fileName))
- continue nextResource;
- // ignore .zip or .jar file on classpath
- if (org.eclipse.jdt.internal.compiler.util.Util.isArchiveFileName(fileName) && isClasspathEntry(member.getFullPath(), classpath))
- continue nextResource;
- break;
-
- case IResource.FOLDER :
- // ignore valid packages or excluded folders that correspond to a nested pkg fragment root
- if (Util.isValidFolderNameForPackage(member.getName())
- && (!Util.isExcluded(member, inclusionPatterns, exclusionPatterns)
- || isClasspathEntry(member.getFullPath(), classpath)))
- continue nextResource;
- break;
- }
- if (nonJavaResources.length == nonJavaResourcesCounter) {
- // resize
- System.arraycopy(nonJavaResources, 0, (nonJavaResources = new IResource[nonJavaResourcesCounter * 2]), 0, nonJavaResourcesCounter);
- }
- nonJavaResources[nonJavaResourcesCounter++] = member;
-
+ // ignore .java files that are not excluded
+ if (Util.isValidCompilationUnitName(fileName, sourceLevel, complianceLevel) && !Util.isExcluded(member, inclusionPatterns, exclusionPatterns))
+ continue nextResource;
+ // ignore .class files
+ if (Util.isValidClassFileName(fileName, sourceLevel, complianceLevel))
+ continue nextResource;
+ // ignore .zip or .jar file on classpath
+ if (org.eclipse.jdt.internal.compiler.util.Util.isArchiveFileName(fileName) && isClasspathEntry(member.getFullPath(), classpath))
+ continue nextResource;
+ break;
+
+ case IResource.FOLDER :
+ // ignore valid packages or excluded folders that correspond to a nested pkg fragment root
+ if (Util.isValidFolderNameForPackage(member.getName(), sourceLevel, complianceLevel)
+ && (!Util.isExcluded(member, inclusionPatterns, exclusionPatterns)
+ || isClasspathEntry(member.getFullPath(), classpath)))
+ continue nextResource;
+ break;
+ }
+ if (nonJavaResources.length == nonJavaResourcesCounter) {
+ // resize
+ System.arraycopy(nonJavaResources, 0, (nonJavaResources = new IResource[nonJavaResourcesCounter * 2]), 0, nonJavaResourcesCounter);
+ }
+ nonJavaResources[nonJavaResourcesCounter++] = member;
+ }
}
if (nonJavaResources.length != nonJavaResourcesCounter) {
System.arraycopy(nonJavaResources, 0, (nonJavaResources = new IResource[nonJavaResourcesCounter]), 0, nonJavaResourcesCounter);
Index: model/org/eclipse/jdt/internal/core/JarPackageFragmentRoot.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JarPackageFragmentRoot.java,v
retrieving revision 1.62
diff -u -r1.62 JarPackageFragmentRoot.java
--- model/org/eclipse/jdt/internal/core/JarPackageFragmentRoot.java 28 Jun 2006 11:12:31 -0000 1.62
+++ model/org/eclipse/jdt/internal/core/JarPackageFragmentRoot.java 6 Nov 2006 12:26:35 -0000
@@ -225,8 +225,9 @@
existingLength--;
}
JavaModelManager manager = JavaModelManager.getJavaModelManager();
+ IJavaProject project = getJavaProject();
for (int i = existingLength; i < length; i++) {
- if (Util.isValidFolderNameForPackage(pkgName[i])) {
+ if (Util.isValidFolderNameForPackage(pkgName[i], project.getOption(JavaCore.COMPILER_SOURCE, true), project.getOption(JavaCore.COMPILER_COMPLIANCE, true))) {
System.arraycopy(existing, 0, existing = new String[i+1], 0, i);
existing[i] = manager.intern(pkgName[i]);
packageFragToTypes.put(existing, new ArrayList[] { EMPTY_LIST, EMPTY_LIST });
Index: model/org/eclipse/jdt/internal/core/util/Util.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/util/Util.java,v
retrieving revision 1.98
diff -u -r1.98 Util.java
--- model/org/eclipse/jdt/internal/core/util/Util.java 27 Jun 2006 09:53:36 -0000 1.98
+++ model/org/eclipse/jdt/internal/core/util/Util.java 6 Nov 2006 12:26:44 -0000
@@ -1277,6 +1277,7 @@
return isExcluded(path, inclusionPatterns, exclusionPatterns, resourceType == IResource.FOLDER || resourceType == IResource.PROJECT);
}
+
/**
* Validate the given .class file name.
* A .class file name must obey the following rules:
@@ -1287,14 +1288,17 @@
*
*
IStatus.OK
if
* the given name is valid as a .class file name, otherwise a status
* object indicating what is wrong with the name
*/
- public static boolean isValidClassFileName(String name) {
- return JavaConventions.validateClassFileName(name).getSeverity() != IStatus.ERROR;
+ public static boolean isValidClassFileName(String name, String sourceLevel, String complianceLevel) {
+ return JavaConventions.validateClassFileName(name, sourceLevel, complianceLevel).getSeverity() != IStatus.ERROR;
}
+
/**
* Validate the given compilation unit name.
* A compilation unit name must obey the following rules:
@@ -1305,20 +1309,25 @@
*
*
* @param name the name of a compilation unit
+ * @param sourceLevel the source level
+ * @param complianceLevel the compliance level
* @return a status object with code IStatus.OK
if
* the given name is valid as a compilation unit name, otherwise a status
* object indicating what is wrong with the name
*/
- public static boolean isValidCompilationUnitName(String name) {
- return JavaConventions.validateCompilationUnitName(name).getSeverity() != IStatus.ERROR;
+ public static boolean isValidCompilationUnitName(String name, String sourceLevel, String complianceLevel) {
+ return JavaConventions.validateCompilationUnitName(name, sourceLevel, complianceLevel).getSeverity() != IStatus.ERROR;
}
-
+
/**
* Returns true if the given folder name is valid for a package,
* false if it is not.
+ * @param folderName the name of the folder
+ * @param sourceLevel the source level
+ * @param complianceLevel the compliance level
*/
- public static boolean isValidFolderNameForPackage(String folderName) {
- return JavaConventions.validateIdentifier(folderName).getSeverity() != IStatus.ERROR;
+ public static boolean isValidFolderNameForPackage(String folderName, String sourceLevel, String complianceLevel) {
+ return JavaConventions.validateIdentifier(folderName, sourceLevel, complianceLevel).getSeverity() != IStatus.ERROR;
}
/**
@@ -1467,12 +1476,15 @@
/**
* Converts the given relative path into a package name.
* Returns null if the path is not a valid package name.
+ * @param pkgPath the package path
+ * @param sourceLevel the source level
+ * @param complianceLevel the compliance level
*/
- public static String packageName(IPath pkgPath) {
+ public static String packageName(IPath pkgPath, String sourceLevel, String complianceLevel) {
StringBuffer pkgName = new StringBuffer(IPackageFragment.DEFAULT_PACKAGE_NAME);
for (int j = 0, max = pkgPath.segmentCount(); j < max; j++) {
String segment = pkgPath.segment(j);
- if (!isValidFolderNameForPackage(segment)) {
+ if (!isValidFolderNameForPackage(segment, sourceLevel, complianceLevel)) {
return null;
}
pkgName.append(segment);
#P org.eclipse.jdt.core.tests.model
Index: src/org/eclipse/jdt/core/tests/dom/ASTConverterJavadocTest.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverterJavadocTest.java,v
retrieving revision 1.72
diff -u -r1.72 ASTConverterJavadocTest.java
--- src/org/eclipse/jdt/core/tests/dom/ASTConverterJavadocTest.java 23 Jun 2006 07:57:38 -0000 1.72
+++ src/org/eclipse/jdt/core/tests/dom/ASTConverterJavadocTest.java 6 Nov 2006 12:26:52 -0000
@@ -1343,8 +1343,13 @@
// Create DOM AST nodes hierarchy
List unitComments = null;
+ String sourceLevel = null;
+ String complianceLevel = null;
if (currentProject != null) {
if (astLevel == AST.JLS3) {
+ complianceLevel = currentProject.getOption(JavaCore.COMPILER_COMPLIANCE, true);
+ sourceLevel = currentProject.getOption(JavaCore.COMPILER_SOURCE, true);
+ currentProject.setOption(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_5);
currentProject.setOption(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_5);
}
}
@@ -1403,6 +1408,10 @@
}
*/
+ if (sourceLevel != null) {
+ currentProject.setOption(JavaCore.COMPILER_COMPLIANCE, complianceLevel);
+ currentProject.setOption(JavaCore.COMPILER_SOURCE, sourceLevel);
+ }
// Return compilation unit for possible further verifications
return compilUnit;
}
Index: src/org/eclipse/jdt/core/tests/model/JavaConventionTests.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaConventionTests.java,v
retrieving revision 1.19
diff -u -r1.19 JavaConventionTests.java
--- src/org/eclipse/jdt/core/tests/model/JavaConventionTests.java 3 Nov 2006 17:55:45 -0000 1.19
+++ src/org/eclipse/jdt/core/tests/model/JavaConventionTests.java 6 Nov 2006 12:26:52 -0000
@@ -15,8 +15,11 @@
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.*;
import org.eclipse.jdt.core.*;
+import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
public class JavaConventionTests extends AbstractJavaModelTests {
+ private final static String sourceLevel = CompilerOptions.VERSION_1_3;
+ private final static String complianceLevel = CompilerOptions.VERSION_1_3;
public JavaConventionTests(String name) {
super(name);
}
@@ -78,26 +81,26 @@
public void testInvalidIdentifier() {
String[] invalidIds = new String[] {" s\\u0069ze", " s\\u0069ze ", "", "1java", "Foo Bar", "#@$!", "Foo-Bar", "if", "InvalidEscapeSequence\\g", "true", "false", "null", null, " untrimmmed "};
for (int i = 0; i < invalidIds.length; i++) {
- assertTrue("identifier not recognized as invalid: " + invalidIds[i], !JavaConventions.validateIdentifier(invalidIds[i]).isOK());
+ assertTrue("identifier not recognized as invalid: " + invalidIds[i], !JavaConventions.validateIdentifier(invalidIds[i], sourceLevel, complianceLevel).isOK());
}
}
/**
* @see JavaConventions
*/
public void testInvalidImportDeclaration1() {
- assertTrue("import not reconized as invalid; java.math.", !JavaConventions.validateImportDeclaration("java.math.").isOK());
+ assertTrue("import not reconized as invalid; java.math.", !JavaConventions.validateImportDeclaration("java.math.", sourceLevel, complianceLevel).isOK());
}
/**
* @see JavaConventions
*/
public void testInvalidImportDeclaration2() {
- assertTrue("import not reconized as invalid; java.math*", !JavaConventions.validateImportDeclaration("java.math*").isOK());
+ assertTrue("import not reconized as invalid; java.math*", !JavaConventions.validateImportDeclaration("java.math*", sourceLevel, complianceLevel).isOK());
}
/**
* @see JavaConventions
*/
public void testInvalidImportDeclaration3() {
- assertTrue("import not reconized as invalid; empty string", !JavaConventions.validateImportDeclaration("").isOK());
+ assertTrue("import not reconized as invalid; empty string", !JavaConventions.validateImportDeclaration("", sourceLevel, complianceLevel).isOK());
}
/**
* Test for package fragment root overlap
@@ -140,18 +143,18 @@
public void testValidCompilationUnitName() {
String[] invalidNames = new String[] {"java/lang/Object.java", "Object.class", ".java", "Object.javaaa", "A.B.java"};
for (int i = 0; i < invalidNames.length; i++) {
- assertTrue("compilation unit name not recognized as invalid: " + invalidNames[i], !JavaConventions.validateCompilationUnitName(invalidNames[i]).isOK());
+ assertTrue("compilation unit name not recognized as invalid: " + invalidNames[i], !JavaConventions.validateCompilationUnitName(invalidNames[i], sourceLevel, complianceLevel).isOK());
}
String[] validNames = new String[] {"Object.java", "OBJECT.java", "object.java", "package-info.java"};
for (int i = 0; i < validNames.length; i++) {
- assertTrue("compilation unit name not recognized as valid: " + validNames[i], JavaConventions.validateCompilationUnitName(validNames[i]).isOK());
+ assertTrue("compilation unit name not recognized as valid: " + validNames[i], JavaConventions.validateCompilationUnitName(validNames[i], sourceLevel, complianceLevel).isOK());
}
}
/**
* @see JavaConventions
*/
public void testValidFieldName() {
- assertTrue("unicode field name not handled", JavaConventions.validateFieldName("s\\u0069ze").isOK());
+ assertTrue("unicode field name not handled", JavaConventions.validateFieldName("s\\u0069ze", sourceLevel, complianceLevel).isOK());
}
/**
* @see JavaConventions
@@ -159,20 +162,20 @@
public void testValidIdentifier() {
String[] validIds = new String[] {"s\\u0069ze", "Object", "An_Extremly_Long_Class_Name_With_Words_Separated_By_Undescores"};
for (int i = 0; i < validIds.length; i++) {
- assertTrue("identifier not recognized as valid: " + validIds[i], JavaConventions.validateIdentifier(validIds[i]).isOK());
+ assertTrue("identifier not recognized as valid: " + validIds[i], JavaConventions.validateIdentifier(validIds[i], sourceLevel, complianceLevel).isOK());
}
}
/**
* @see JavaConventions
*/
public void testValidImportDeclaration() {
- assertTrue("import not reconized as valid", JavaConventions.validateImportDeclaration("java.math.*").isOK());
+ assertTrue("import not reconized as valid", JavaConventions.validateImportDeclaration("java.math.*", sourceLevel, complianceLevel).isOK());
}
/**
* @see JavaConventions
*/
public void testValidMethodName() {
- assertTrue("unicode method name not handled", JavaConventions.validateMethodName("getSiz\\u0065").isOK());
+ assertTrue("unicode method name not handled", JavaConventions.validateMethodName("getSiz\\u0065", sourceLevel, complianceLevel).isOK());
}
/**
* @see JavaConventions
@@ -180,44 +183,44 @@
public void testValidPackageName() {
String pkgName= "org.eclipse.jdt.core.t\\u0065sts.MyPackage";
- assertTrue("unicode package name not handled", JavaConventions.validatePackageName(pkgName).isOK());
+ assertTrue("unicode package name not handled", JavaConventions.validatePackageName(pkgName, sourceLevel, complianceLevel).isOK());
- assertTrue("package name not recognized as invalid1", !JavaConventions.validatePackageName("").isOK());
- assertTrue("package name not recognized as valid1", JavaConventions.validatePackageName("java . lang").isOK());
- assertTrue("package name not recognized as invalid2", !JavaConventions.validatePackageName(" java . lang").isOK());
- assertTrue("package name not recognized as invalid3", !JavaConventions.validatePackageName("java . lang ").isOK());
- assertTrue("package name not recognized as invalid4", !JavaConventions.validatePackageName(null).isOK());
- assertTrue("package name not recognized as unconventional1", JavaConventions.validatePackageName("Java.lang").getSeverity() == IStatus.WARNING);
- assertTrue("package name not recognized as valid2", JavaConventions.validatePackageName("java.Lang").isOK());
- assertTrue("package name not recognized as invalid5", JavaConventions.validatePackageName("Test.sample&plugin").getSeverity() == IStatus.ERROR);
- assertTrue("package name not recognized as unconventional2", JavaConventions.validatePackageName("Test.sample").getSeverity() == IStatus.WARNING);
+ assertTrue("package name not recognized as invalid1", !JavaConventions.validatePackageName("", sourceLevel, complianceLevel).isOK());
+ assertTrue("package name not recognized as valid1", JavaConventions.validatePackageName("java . lang", sourceLevel, complianceLevel).isOK());
+ assertTrue("package name not recognized as invalid2", !JavaConventions.validatePackageName(" java . lang", sourceLevel, complianceLevel).isOK());
+ assertTrue("package name not recognized as invalid3", !JavaConventions.validatePackageName("java . lang ", sourceLevel, complianceLevel).isOK());
+ assertTrue("package name not recognized as invalid4", !JavaConventions.validatePackageName(null, sourceLevel, complianceLevel).isOK());
+ assertTrue("package name not recognized as unconventional1", JavaConventions.validatePackageName("Java.lang", sourceLevel, complianceLevel).getSeverity() == IStatus.WARNING);
+ assertTrue("package name not recognized as valid2", JavaConventions.validatePackageName("java.Lang", sourceLevel, complianceLevel).isOK());
+ assertTrue("package name not recognized as invalid5", JavaConventions.validatePackageName("Test.sample&plugin", sourceLevel, complianceLevel).getSeverity() == IStatus.ERROR);
+ assertTrue("package name not recognized as unconventional2", JavaConventions.validatePackageName("Test.sample", sourceLevel, complianceLevel).getSeverity() == IStatus.WARNING);
}
/**
* @see JavaConventions
*/
public void testValidTypeName() {
// regression tests for 1G5HVPB: ITPJCORE:WINNT - validateJavaTypeName accepts type names ending with \
- assertTrue("type name should not contain slashes (1)", JavaConventions.validateJavaTypeName("Object\\").getSeverity() == IStatus.ERROR);
- assertTrue("type name should not contain slashes (2)", JavaConventions.validateJavaTypeName("Object/").getSeverity() == IStatus.ERROR);
- assertTrue("type name should not contain slashes (3)", JavaConventions.validateJavaTypeName("\\Object").getSeverity() == IStatus.ERROR);
- assertTrue("type name should not contain slashes (4)", JavaConventions.validateJavaTypeName("java\\lang\\Object").getSeverity() == IStatus.ERROR);
+ assertTrue("type name should not contain slashes (1)", JavaConventions.validateJavaTypeName("Object\\", sourceLevel, complianceLevel).getSeverity() == IStatus.ERROR);
+ assertTrue("type name should not contain slashes (2)", JavaConventions.validateJavaTypeName("Object/", sourceLevel, complianceLevel).getSeverity() == IStatus.ERROR);
+ assertTrue("type name should not contain slashes (3)", JavaConventions.validateJavaTypeName("\\Object", sourceLevel, complianceLevel).getSeverity() == IStatus.ERROR);
+ assertTrue("type name should not contain slashes (4)", JavaConventions.validateJavaTypeName("java\\lang\\Object", sourceLevel, complianceLevel).getSeverity() == IStatus.ERROR);
// regression test for 1G52ZIF: ITPJUI:WINNT - Wizards should strongly discourage the use of non-standard names
- assertTrue("discouraged type names not handled", JavaConventions.validateJavaTypeName("alowercasetypename").getSeverity() == IStatus.WARNING);
+ assertTrue("discouraged type names not handled", JavaConventions.validateJavaTypeName("alowercasetypename", sourceLevel, complianceLevel).getSeverity() == IStatus.WARNING);
// other tests
- assertTrue("unicode type name not handled", JavaConventions.validateJavaTypeName("P\\u0065a").getSeverity() == IStatus.OK);
- assertTrue("qualified type names not handled", JavaConventions.validateJavaTypeName("java . lang\t.Object").getSeverity() == IStatus.OK);
- assertTrue("simple qualified type names not handled", JavaConventions.validateJavaTypeName("java.lang.Object").getSeverity() == IStatus.OK);
- assertTrue("simple type names not handled", JavaConventions.validateJavaTypeName("Object").getSeverity() == IStatus.OK);
- assertTrue("discouraged type names not handled", JavaConventions.validateJavaTypeName("Object$SubType").getSeverity() == IStatus.WARNING);
- assertTrue("invalid type name not recognized", JavaConventions.validateJavaTypeName("==?==").getSeverity() == IStatus.ERROR);
+ assertTrue("unicode type name not handled", JavaConventions.validateJavaTypeName("P\\u0065a", sourceLevel, complianceLevel).getSeverity() == IStatus.OK);
+ assertTrue("qualified type names not handled", JavaConventions.validateJavaTypeName("java . lang\t.Object", sourceLevel, complianceLevel).getSeverity() == IStatus.OK);
+ assertTrue("simple qualified type names not handled", JavaConventions.validateJavaTypeName("java.lang.Object", sourceLevel, complianceLevel).getSeverity() == IStatus.OK);
+ assertTrue("simple type names not handled", JavaConventions.validateJavaTypeName("Object", sourceLevel, complianceLevel).getSeverity() == IStatus.OK);
+ assertTrue("discouraged type names not handled", JavaConventions.validateJavaTypeName("Object$SubType", sourceLevel, complianceLevel).getSeverity() == IStatus.WARNING);
+ assertTrue("invalid type name not recognized", JavaConventions.validateJavaTypeName("==?==", sourceLevel, complianceLevel).getSeverity() == IStatus.ERROR);
}
/**
* @see JavaConventions
*/
public void testValidTypeVariableName() {
- assertTrue("E sould be a valid variable name", JavaConventions.validateTypeVariableName("E").isOK());
+ assertTrue("E sould be a valid variable name", JavaConventions.validateTypeVariableName("E", sourceLevel, complianceLevel).isOK());
}
/**
* @see JavaConventions
@@ -225,7 +228,7 @@
public void testValidUnicodeImportDeclaration() {
String pkgName= "com.\\u0069bm.jdt.core.tests.MyPackag\\u0065";
- assertTrue("import not reconized as valid", JavaConventions.validateImportDeclaration(pkgName).isOK());
+ assertTrue("import not reconized as valid", JavaConventions.validateImportDeclaration(pkgName, sourceLevel, complianceLevel).isOK());
}
/**
@@ -234,7 +237,7 @@
public void testValidUnicodePackageName() {
String pkgName= "com.\\u0069bm.jdt.core.tests.MyPackag\\u0065";
- assertTrue("unicode package name not handled", JavaConventions.validatePackageName(pkgName).isOK());
+ assertTrue("unicode package name not handled", JavaConventions.validatePackageName(pkgName, sourceLevel, complianceLevel).isOK());
assertTrue("Parameter modified", pkgName.equals("com.\\u0069bm.jdt.core.tests.MyPackag\\u0065"));
}