public final class JavaConventions extends Object
This class provides static methods and constants only.
Modifier and Type | Method and Description |
---|---|
static boolean |
isOverlappingRoots(IPath rootPath1,
IPath rootPath2)
Deprecated.
Overlapping roots are allowed in 2.1
|
static IStatus |
validateClassFileName(String name)
Deprecated.
|
static 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,
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 code
IStatus.OK if the entry is fine (that is, if the
given classpath entry denotes a valid element to be referenced onto a classpath). |
static IStatus |
validateCompilationUnitName(String name)
Deprecated.
|
static IStatus |
validateCompilationUnitName(String name,
String sourceLevel,
String complianceLevel)
Validate the given compilation unit name for the given source and compliance levels.
|
static IStatus |
validateFieldName(String name)
Deprecated.
|
static IStatus |
validateFieldName(String name,
String sourceLevel,
String complianceLevel)
Validate the given field name for the given source and compliance levels.
|
static IStatus |
validateIdentifier(String id)
Deprecated.
|
static 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 IStatus |
validateImportDeclaration(String name)
Deprecated.
|
static IStatus |
validateImportDeclaration(String name,
String sourceLevel,
String complianceLevel)
Validate the given import declaration name for the given source and compliance levels.
|
static IStatus |
validateJavaTypeName(String name)
Deprecated.
|
static IStatus |
validateJavaTypeName(String name,
String sourceLevel,
String complianceLevel)
Validate the given Java type name, either simple or qualified, for the given source and compliance levels.
|
static IStatus |
validateMethodName(String name)
Deprecated.
|
static IStatus |
validateMethodName(String name,
String sourceLevel,
String complianceLevel)
Validate the given method name for the given source and compliance levels.
|
static IStatus |
validatePackageName(String name)
Deprecated.
|
static IStatus |
validatePackageName(String name,
String sourceLevel,
String complianceLevel)
Validate the given package name for the given source and compliance levels.
|
static IStatus |
validateTypeVariableName(String name)
Deprecated.
|
static IStatus |
validateTypeVariableName(String name,
String sourceLevel,
String complianceLevel)
Validate the given type variable name for the given source and compliance levels.
|
public static boolean isOverlappingRoots(IPath rootPath1, IPath rootPath2)
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.
rootPath1
- the first root pathrootPath2
- the second root pathpublic static IStatus validateCompilationUnitName(String name)
validateCompilationUnitName(String id, String sourceLevel, String complianceLevel)
insteadA compilation unit name must obey the following rules:
Java-like extensions
name
- the name of a compilation unitIStatus.OK
if
the given name is valid as a compilation unit name, otherwise a status
object indicating what is wrong with the namepublic static IStatus validateCompilationUnitName(String name, String sourceLevel, String complianceLevel)
A compilation unit name must obey the following rules:
Java-like extensions
name
- the name of a compilation unitsourceLevel
- the source levelcomplianceLevel
- the compliance levelIStatus.OK
if
the given name is valid as a compilation unit name, otherwise a status
object indicating what is wrong with the namepublic static IStatus validateClassFileName(String name)
validateClassFileName(String id, String sourceLevel, String complianceLevel)
insteadA .class file name must obey the following rules:
".class"
suffix
name
- the name of a .class fileIStatus.OK
if
the given name is valid as a .class file name, otherwise a status
object indicating what is wrong with the namepublic static IStatus validateClassFileName(String name, String sourceLevel, String complianceLevel)
A .class file name must obey the following rules:
".class"
suffix
name
- the name of a .class filesourceLevel
- the source levelcomplianceLevel
- the compliance levelIStatus.OK
if
the given name is valid as a .class file name, otherwise a status
object indicating what is wrong with the namepublic static IStatus validateFieldName(String name)
validateFieldName(String id, String sourceLevel, String complianceLevel)
instead
Syntax of a field name corresponds to VariableDeclaratorId (JLS2 8.3).
For example, "x"
.
name
- the name of a fieldIStatus.OK
if
the given name is valid as a field name, otherwise a status
object indicating what is wrong with the namepublic static IStatus validateFieldName(String name, String sourceLevel, String complianceLevel)
Syntax of a field name corresponds to VariableDeclaratorId (JLS2 8.3).
For example, "x"
.
name
- the name of a fieldsourceLevel
- the source levelcomplianceLevel
- the compliance levelIStatus.OK
if
the given name is valid as a field name, otherwise a status
object indicating what is wrong with the namepublic static IStatus validateIdentifier(String id)
validateIdentifier(String id, String sourceLevel, String complianceLevel)
instead"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.id
- the Java identifierIStatus.OK
if
the given identifier is a valid Java identifier, otherwise a status
object indicating what is wrong with the identifierpublic static IStatus validateIdentifier(String id, String sourceLevel, String complianceLevel)
"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.id
- the Java identifiersourceLevel
- the source levelcomplianceLevel
- the compliance levelIStatus.OK
if
the given identifier is a valid Java identifier, otherwise a status
object indicating what is wrong with the identifierpublic static IStatus validateImportDeclaration(String name)
validateImportDeclaration(String id, String sourceLevel, String complianceLevel)
instead
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"
.
name
- the import declarationIStatus.OK
if
the given name is valid as an import declaration, otherwise a status
object indicating what is wrong with the namepublic static IStatus validateImportDeclaration(String name, String sourceLevel, String complianceLevel)
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"
.
name
- the import declarationsourceLevel
- the source levelcomplianceLevel
- the compliance levelIStatus.OK
if
the given name is valid as an import declaration, otherwise a status
object indicating what is wrong with the namepublic static IStatus validateJavaTypeName(String name)
validateJavaTypeName(String id, String sourceLevel, String complianceLevel)
instead"java.lang.Object"
, or "Object"
.
name
- the name of a typeIStatus.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 namepublic static IStatus validateJavaTypeName(String name, String sourceLevel, String complianceLevel)
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 named JavaCore#VERSION_1_x
, x being set
between '1' and '8'.
name
- the name of a typesourceLevel
- the source levelcomplianceLevel
- the compliance levelIStatus.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 nameJavaCore.VERSION_1_1
,
JavaCore.VERSION_1_2
,
JavaCore.VERSION_1_3
,
JavaCore.VERSION_1_4
,
JavaCore.VERSION_1_5
,
JavaCore.VERSION_1_6
,
JavaCore.VERSION_1_7
,
JavaCore.VERSION_1_8
public static IStatus validateMethodName(String name)
validateMethodName(String id, String sourceLevel, String complianceLevel)
insteadThe syntax for a method name is defined by Identifier of MethodDeclarator (JLS2 8.4). For example "println".
name
- the name of a methodIStatus.OK
if
the given name is valid as a method name, otherwise a status
object indicating what is wrong with the namepublic static IStatus validateMethodName(String name, String sourceLevel, String complianceLevel)
The syntax for a method name is defined by Identifier of MethodDeclarator (JLS2 8.4). For example "println".
name
- the name of a methodsourceLevel
- the source levelcomplianceLevel
- the compliance levelIStatus.OK
if
the given name is valid as a method name, otherwise a status
object indicating what is wrong with the namepublic static IStatus validatePackageName(String name)
validatePackageName(String id, String sourceLevel, String complianceLevel)
instead
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.
name
- the name of a packageIStatus.OK
if
the given name is valid as a package name, otherwise a status
object indicating what is wrong with the namepublic static IStatus validatePackageName(String name, String sourceLevel, String complianceLevel)
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.
name
- the name of a packagesourceLevel
- the source levelcomplianceLevel
- the compliance levelIStatus.OK
if
the given name is valid as a package name, otherwise a status
object indicating what is wrong with the namepublic static IJavaModelStatus validateClasspath(IJavaProject javaProject, IClasspathEntry[] rawClasspath, IPath projectOutputLocation)
JavaCore.CORE_OUTPUT_LOCATION_OVERLAPPING_ANOTHER_SOURCE
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).
javaProject
- the given java projectrawClasspath
- the given classpathprojectOutputLocation
- the given output locationIStatus.OK
if
the given classpath and output location are compatible, otherwise a status
object indicating what is wrong with the classpath or output locationpublic static IJavaModelStatus validateClasspathEntry(IJavaProject project, IClasspathEntry entry, boolean checkSourceAttachment)
IStatus.OK
if the entry is fine (that is, if the
given classpath entry denotes a valid element to be referenced onto a classpath).project
- the given java projectentry
- the given classpath entrycheckSourceAttachment
- a flag to determine if source attachment should be checkedIStatus.OK
if the entry is finepublic static IStatus validateTypeVariableName(String name)
validateTypeVariableName(String id, String sourceLevel, String complianceLevel)
instead
Syntax of a type variable name corresponds to a Java identifier (JLS3 4.3).
For example, "E"
.
name
- the name of a type variableIStatus.OK
if
the given name is valid as a type variable name, otherwise a status
object indicating what is wrong with the namepublic static IStatus validateTypeVariableName(String name, String sourceLevel, String complianceLevel)
Syntax of a type variable name corresponds to a Java identifier (JLS3 4.3).
For example, "E"
.
name
- the name of a type variablesourceLevel
- the source levelcomplianceLevel
- the compliance levelIStatus.OK
if
the given name is valid as a type variable name, otherwise a status
object indicating what is wrong with the name
Copyright (c) 2000, 2015 Eclipse Contributors and others. All rights reserved.Guidelines for using Eclipse APIs.