use of org.eclipse.n4js.utils.ProjectDescriptionUtils.ProjectNameInfo in project n4js by eclipse.
the class PackageJsonValidatorExtension method checkName.
/**
* Validates the project/package name.
*/
@CheckProperty(property = NAME)
public void checkName(JSONValue projectNameValue) {
// first check for the type of the name value
if (!checkIsType(projectNameValue, JSONPackage.Literals.JSON_STRING_LITERAL, "as package name")) {
return;
}
final JSONStringLiteral projectNameLiteral = (JSONStringLiteral) projectNameValue;
final String projectName = projectNameLiteral.getValue();
final String projectNameWithoutScope = ProjectDescriptionUtils.getPlainPackageName(projectName);
final String scopeName = ProjectDescriptionUtils.getScopeName(projectName);
// make sure the name conforms to the IDENTIFIER_PATTERN
if (!ProjectDescriptionUtils.isValidPlainPackageName(projectNameWithoutScope)) {
addIssue(IssueCodes.getMessageForPKGJ_INVALID_PROJECT_NAME(projectNameWithoutScope), projectNameValue, IssueCodes.PKGJ_INVALID_PROJECT_NAME);
}
if (scopeName != null) {
String scopeNameWithoutPrefix = scopeName.substring(1);
if (!ProjectDescriptionUtils.isValidScopeName(scopeNameWithoutPrefix)) {
String msg = IssueCodes.getMessageForPKGJ_INVALID_SCOPE_NAME(scopeNameWithoutPrefix);
addIssue(msg, projectNameValue, IssueCodes.PKGJ_INVALID_SCOPE_NAME);
}
}
// compute names of project folder, parent folder, Eclipse project folder
final URI projectUri = projectNameValue.eResource().getURI().trimSegments(1);
final ProjectNameInfo nameInfo = ProjectNameInfo.of(projectUri);
// make sure the project name equals the name of the project folder
if (!projectNameWithoutScope.equals(nameInfo.projectFolderName)) {
String msg = IssueCodes.getMessageForPKGJ_PACKAGE_NAME_MISMATCH(projectNameWithoutScope, nameInfo.projectFolderName);
addIssue(msg, projectNameLiteral, IssueCodes.PKGJ_PACKAGE_NAME_MISMATCH);
}
// (i.e. the folder containing the project folder)
if (scopeName != null && !scopeName.equals(nameInfo.parentFolderName)) {
String msg = IssueCodes.getMessageForPKGJ_SCOPE_NAME_MISMATCH(scopeName, nameInfo.parentFolderName);
addIssue(msg, projectNameLiteral, IssueCodes.PKGJ_SCOPE_NAME_MISMATCH);
}
}
Aggregations