Class JavaConventions
This class provides static methods and constants only.
- Restriction:
- This class is not intended to be instantiated by clients.
-
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
isOverlappingRoots
(org.eclipse.core.runtime.IPath rootPath1, org.eclipse.core.runtime.IPath rootPath2) Deprecated.Overlapping roots are allowed in 2.1static org.eclipse.core.runtime.IStatus
validateClassFileName
(String name) Deprecated.static org.eclipse.core.runtime.IStatus
validateClassFileName
(String name, String sourceLevel, String complianceLevel) Validate the given .class file name for the given source and compliance levels.static IJavaModelStatus
validateClasspath
(IJavaProject javaProject, IClasspathEntry[] rawClasspath, org.eclipse.core.runtime.IPath projectOutputLocation) Validate a given classpath and output location for a project, using the following rules: Classpath entries cannot collide with each other; that is, all entry paths must be unique.static IJavaModelStatus
validateClasspathEntry
(IJavaProject project, IClasspathEntry entry, boolean checkSourceAttachment) Returns a Java model status describing the problem related to this classpath entry if any, a status object with codeIStatus.OK
if the entry is fine (that is, if the given classpath entry denotes a valid element to be referenced onto a classpath).static org.eclipse.core.runtime.IStatus
Deprecated.static org.eclipse.core.runtime.IStatus
validateCompilationUnitName
(String name, String sourceLevel, String complianceLevel) Validate the given compilation unit name for the given source and compliance levels.static org.eclipse.core.runtime.IStatus
validateFieldName
(String name) Deprecated.static org.eclipse.core.runtime.IStatus
validateFieldName
(String name, String sourceLevel, String complianceLevel) Validate the given field name for the given source and compliance levels.static org.eclipse.core.runtime.IStatus
Deprecated.static org.eclipse.core.runtime.IStatus
validateIdentifier
(String id, String sourceLevel, String complianceLevel) 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"
).static org.eclipse.core.runtime.IStatus
Deprecated.static org.eclipse.core.runtime.IStatus
validateImportDeclaration
(String name, String sourceLevel, String complianceLevel) Validate the given import declaration name for the given source and compliance levels.static org.eclipse.core.runtime.IStatus
validateJavaTypeName
(String name) Deprecated.static org.eclipse.core.runtime.IStatus
validateJavaTypeName
(String name, String sourceLevel, String complianceLevel) static org.eclipse.core.runtime.IStatus
validateJavaTypeName
(String name, String sourceLevel, String complianceLevel, String previewEnabled) Validate the given Java type name, either simple or qualified, for the given source level, compliance levels and the preview flag.static org.eclipse.core.runtime.IStatus
validateMethodName
(String name) Deprecated.static org.eclipse.core.runtime.IStatus
validateMethodName
(String name, String sourceLevel, String complianceLevel) Validate the given method name for the given source and compliance levels.static org.eclipse.core.runtime.IStatus
validateModuleName
(String name, String sourceLevel, String complianceLevel) Validate the given module name for the given source and compliance levels.static org.eclipse.core.runtime.IStatus
validatePackageName
(String name) Deprecated.static org.eclipse.core.runtime.IStatus
validatePackageName
(String name, String sourceLevel, String complianceLevel) Validate the given package name for the given source and compliance levels.static org.eclipse.core.runtime.IStatus
Deprecated.static org.eclipse.core.runtime.IStatus
validateTypeVariableName
(String name, String sourceLevel, String complianceLevel) Validate the given type variable name for the given source and compliance levels.
-
Method Details
-
isOverlappingRoots
public static boolean isOverlappingRoots(org.eclipse.core.runtime.IPath rootPath1, org.eclipse.core.runtime.IPath rootPath2) Deprecated.Overlapping roots are allowed in 2.1Returns whether the given package fragment root paths are considered to overlap.Two root paths overlap if one is a prefix of the other, or they point to the same location. However, a JAR is allowed to be nested in a root.
- Parameters:
rootPath1
- the first root pathrootPath2
- the second root path- Returns:
- true if the given package fragment root paths are considered to overlap, false otherwise
-
validateCompilationUnitName
Deprecated.Validate the given compilation unit name.A compilation unit name must obey the following rules:
- it must not be null
- it must be suffixed by a dot ('.') followed by one of the
Java-like extensions
- its prefix must be a valid identifier
- it must not contain any characters or substrings that are not valid on the file system on which workspace root is located.
- Parameters:
name
- the name of a compilation unit- Returns:
- 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
-
validateCompilationUnitName
public static org.eclipse.core.runtime.IStatus validateCompilationUnitName(String name, String sourceLevel, String complianceLevel) Validate the given compilation unit name for the given source and compliance levels.A compilation unit name must obey the following rules:
- it must not be null
- it must be suffixed by a dot ('.') followed by one of the
Java-like extensions
- its prefix must be a valid identifier
- it must not contain any characters or substrings that are not valid on the file system on which workspace root is located.
- Parameters:
name
- the name of a compilation unitsourceLevel
- the source levelcomplianceLevel
- the compliance level- Returns:
- 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 - Since:
- 3.3
-
validateClassFileName
Deprecated.Validate the given .class file name.A .class file name must obey the following rules:
- it must not be null
- it must include the
".class"
suffix - its prefix must be a valid identifier
- it must not contain any characters or substrings that are not valid on the file system on which workspace root is located.
- Parameters:
name
- the name of a .class file- Returns:
- a status object with code
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:
- 2.0
-
validateClassFileName
public static org.eclipse.core.runtime.IStatus validateClassFileName(String name, String sourceLevel, String complianceLevel) Validate the given .class file name for the given source and compliance levels.A .class file name must obey the following rules:
- it must not be null
- it must include the
".class"
suffix - its prefix must be a valid identifier
- it must not contain any characters or substrings that are not valid on the file system on which workspace root is located.
- Parameters:
name
- the name of a .class filesourceLevel
- the source levelcomplianceLevel
- the compliance level- Returns:
- a status object with code
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
-
validateFieldName
Deprecated.Validate the given field name.Syntax of a field name corresponds to VariableDeclaratorId (JLS2 8.3). For example,
"x"
.- Parameters:
name
- the name of a field- Returns:
- 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
-
validateFieldName
public static org.eclipse.core.runtime.IStatus validateFieldName(String name, String sourceLevel, String complianceLevel) 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"
.- Parameters:
name
- the name of a fieldsourceLevel
- the source levelcomplianceLevel
- the compliance level- Returns:
- 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
-
validateIdentifier
Deprecated.Validate the given Java identifier. 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.- Parameters:
id
- the Java identifier- Returns:
- 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
-
validateIdentifier
public static org.eclipse.core.runtime.IStatus validateIdentifier(String id, String sourceLevel, String complianceLevel) 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.- Parameters:
id
- the Java identifiersourceLevel
- the source levelcomplianceLevel
- the compliance level- Returns:
- 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
-
validateImportDeclaration
Deprecated.Validate the given import declaration name.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"
.- Parameters:
name
- the import declaration- Returns:
- 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
-
validateImportDeclaration
public static org.eclipse.core.runtime.IStatus validateImportDeclaration(String name, String sourceLevel, String complianceLevel) 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"
.- Parameters:
name
- the import declarationsourceLevel
- the source levelcomplianceLevel
- the compliance level- Returns:
- 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
-
validateJavaTypeName
Deprecated.Validate the given Java type name, either simple or qualified. For example,"java.lang.Object"
, or"Object"
.- Parameters:
name
- the name of a type- Returns:
- a status object with code
IStatus.OK
if the given name is valid as a Java type name, a status with codeIStatus.WARNING
indicating why the given name is discouraged, otherwise a status object indicating what is wrong with the name
-
validateJavaTypeName
public static org.eclipse.core.runtime.IStatus validateJavaTypeName(String name, String sourceLevel, String complianceLevel) Deprecated.Validate the given Java type name, either simple or qualified, for the given source and compliance levels.For example,
"java.lang.Object"
, or"Object"
.The source level and compliance level values should be taken from the constant defined inside
JavaCore
class. The constants are namedJavaCore#VERSION_1_x
, x being set between '1' and '8'.- Parameters:
name
- the name of a typesourceLevel
- the source levelcomplianceLevel
- the compliance level- Returns:
- a status object with code
IStatus.OK
if the given name is valid as a Java type name, a status with codeIStatus.WARNING
indicating why the given name is discouraged, otherwise a status object indicating what is wrong with the name - Since:
- 3.3
- See Also:
-
validateJavaTypeName
public static org.eclipse.core.runtime.IStatus validateJavaTypeName(String name, String sourceLevel, String complianceLevel, String previewEnabled) Validate the given Java type name, either simple or qualified, for the given source level, compliance levels and the preview flag.For example,
"java.lang.Object"
, or"Object"
.The source level and compliance level values should be taken from the constant defined inside
JavaCore
class. The constants are namedJavaCore#VERSION_1_x
, x being set between '1' and '8'.The preview flag should be one of
JavaCore.ENABLED
,JavaCore.DISABLED
or null. When null is passed, the preview is considered to be disabled.- Parameters:
name
- the name of a typesourceLevel
- the source levelcomplianceLevel
- the compliance levelpreviewEnabled
- preview flag- Returns:
- a status object with code
IStatus.OK
if the given name is valid as a Java type name, a status with codeIStatus.WARNING
indicating why the given name is discouraged, otherwise a status object indicating what is wrong with the name - Since:
- 3.22
- See Also:
-
validateMethodName
Deprecated.Validate the given method name. 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".
- Parameters:
name
- the name of a method- Returns:
- 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
-
validateMethodName
public static org.eclipse.core.runtime.IStatus validateMethodName(String name, String sourceLevel, String complianceLevel) 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".
- Parameters:
name
- the name of a methodsourceLevel
- the source levelcomplianceLevel
- the compliance level- Returns:
- 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
-
validatePackageName
Deprecated.Validate the given package name.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.
- Parameters:
name
- the name of a package- Returns:
- 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
-
validatePackageName
public static org.eclipse.core.runtime.IStatus validatePackageName(String name, String sourceLevel, String complianceLevel) 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.
- Parameters:
name
- the name of a packagesourceLevel
- the source levelcomplianceLevel
- the compliance level- Returns:
- 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
-
validateModuleName
public static org.eclipse.core.runtime.IStatus validateModuleName(String name, String sourceLevel, String complianceLevel) Validate the given module name for the given source and compliance levels.The syntax of a module name corresponds to ModuleName as defined by ModuleDeclaration (JLS 7.6). For example,
"java.base"
.Note that the given name must not be empty. Also each segment of the module name (separated by ".") must be a valid Java identifier as per JLS 3.8.
- Parameters:
name
- name of a modulesourceLevel
- the source levelcomplianceLevel
- the compliance level- Returns:
- a status object with code
IStatus.OK
if the given name is valid as a module name, otherwise a status object indicating what is wrong with the name - Since:
- 3.14
-
validateClasspath
public static IJavaModelStatus validateClasspath(IJavaProject javaProject, IClasspathEntry[] rawClasspath, org.eclipse.core.runtime.IPath projectOutputLocation) Validate a given classpath and output location for a project, using the following rules:- Classpath entries cannot collide with each other; that is, all entry paths must be unique.
- The project output location path cannot be null, must be absolute and located inside the project.
- Specific output locations (specified on source entries) can be null, if not they must be located inside the project,
- A project entry cannot refer to itself directly (that is, a project cannot prerequisite itself).
- Classpath entries or output locations cannot coincide or be nested in each other, except for the following scenarios listed below:
- A source folder can coincide with its own output location, in which case this output can then contain library archives.
However, a specific output location cannot coincide with any library or a distinct source folder than the one referring to it.
Note: Since 3.8, this behavior can be overridden by configuringJavaCore.CORE_OUTPUT_LOCATION_OVERLAPPING_ANOTHER_SOURCE
- A source/library folder can be nested in any source folder as long as the nested folder is excluded from the enclosing one.
- An output location can be nested in a source folder, if the source folder coincides with the project itself, or if the output location is excluded from the source folder.
- A source folder can coincide with its own output location, in which case this output can then contain library archives.
However, a specific output location cannot coincide with any library or a distinct source folder than the one referring to it.
This validation is intended to anticipate classpath issues prior to assigning it to a project. In particular, it will automatically be performed during the classpath setting operation (if validation fails, the classpath setting will not complete).
- Parameters:
javaProject
- the given java projectrawClasspath
- the given classpathprojectOutputLocation
- the given output location- Returns:
- a status object with code
IStatus.OK
if the given classpath and output location are compatible, otherwise a status object indicating what is wrong with the classpath or output location - Since:
- 2.0
-
validateClasspathEntry
public static IJavaModelStatus validateClasspathEntry(IJavaProject project, IClasspathEntry entry, boolean checkSourceAttachment) Returns a Java model status describing the problem related to this classpath entry if any, a status object with codeIStatus.OK
if the entry is fine (that is, if the given classpath entry denotes a valid element to be referenced onto a classpath).- Parameters:
project
- the given java projectentry
- the given classpath entrycheckSourceAttachment
- a flag to determine if source attachment should be checked- Returns:
- a java model status describing the problem related to this classpath entry if any, a status object with code
IStatus.OK
if the entry is fine - Since:
- 2.0
-
validateTypeVariableName
Deprecated.Validate the given type variable name.Syntax of a type variable name corresponds to a Java identifier (JLS3 4.3). For example,
"E"
.- Parameters:
name
- the name of a type variable- Returns:
- 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.1
-
validateTypeVariableName
public static org.eclipse.core.runtime.IStatus validateTypeVariableName(String name, String sourceLevel, String complianceLevel) 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"
.- Parameters:
name
- the name of a type variablesourceLevel
- the source levelcomplianceLevel
- the compliance level- Returns:
- 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
-