use of org.eclipse.n4js.packagejson.projectDescription.ProjectType in project n4js by eclipse.
the class JSONIdeContentProposalProvider method proposeProjectTypes.
private void proposeProjectTypes(ContentAssistContext context, IIdeContentProposalAcceptor acceptor, List<String> namePath) {
if (namePath.size() >= 2) {
String n4js = namePath.get(namePath.size() - 2);
String projectType = namePath.get(namePath.size() - 1);
if (PackageJsonProperties.PROJECT_TYPE.name.equals(projectType) || PackageJsonProperties.N4JS.name.equals(n4js)) {
for (ProjectType type : ProjectType.values()) {
String asString = PackageJsonUtils.getProjectTypeStringRepresentation(type);
if (asString.equals(asString.toUpperCase())) {
asString = asString.toLowerCase();
}
ContentAssistEntry entryForProjectType = getProposalCreator().createProposal('"' + asString + '"', context, ContentAssistEntry.KIND_KEYWORD, null);
if (entryForProjectType != null) {
acceptor.accept(entryForProjectType, getProposalPriorities().getDefaultPriority(entryForProjectType));
}
}
}
}
}
use of org.eclipse.n4js.packagejson.projectDescription.ProjectType in project n4js by eclipse.
the class PackageJsonHelper method convertN4jsPairs.
private void convertN4jsPairs(ProjectDescriptionBuilder target, List<NameValuePair> n4jsPairs) {
for (NameValuePair pair : n4jsPairs) {
PackageJsonProperties property = PackageJsonProperties.valueOfNameValuePairOrNull(pair);
if (property == null) {
continue;
}
JSONValue value = pair.getValue();
switch(property) {
case PROJECT_TYPE:
ProjectType projectType = parseProjectType(asNonEmptyStringOrNull(value));
if (projectType != null) {
target.setType(projectType);
}
break;
case VENDOR_ID:
target.setVendorId(asNonEmptyStringOrNull(value));
break;
case VENDOR_NAME:
target.setVendorName(asNonEmptyStringOrNull(value));
break;
case OUTPUT:
target.setOutputPath(asNonEmptyStringOrNull(value));
break;
case SOURCES:
target.getSourceContainers().addAll(asSourceContainerDescriptionsOrEmpty(value));
break;
case MODULE_FILTERS:
target.getModuleFilters().addAll(asModuleFiltersInObjectOrEmpty(value));
break;
case MAIN_MODULE:
target.setMainModule(asNonEmptyStringOrNull(value));
break;
case TESTED_PROJECTS:
target.getTestedProjects().addAll(asProjectReferencesInArrayOrEmpty(value));
break;
case IMPLEMENTATION_ID:
target.setImplementationId(asNonEmptyStringOrNull(value));
break;
case IMPLEMENTED_PROJECTS:
target.getImplementedProjects().addAll(asProjectReferencesInArrayOrEmpty(value));
break;
case EXTENDED_RUNTIME_ENVIRONMENT:
target.setExtendedRuntimeEnvironment(asProjectReferenceOrNull(value));
break;
case PROVIDED_RUNTIME_LIBRARIES:
target.getProvidedRuntimeLibraries().addAll(asProjectReferencesInArrayOrEmpty(value));
break;
case REQUIRED_RUNTIME_LIBRARIES:
target.getRequiredRuntimeLibraries().addAll(asProjectReferencesInArrayOrEmpty(value));
break;
case DEFINES_PACKAGE:
target.setDefinesPackage(asStringOrNull(value));
break;
case GENERATOR:
convertN4jsPairs(target, asNameValuePairsOrEmpty(value));
break;
case GENERATOR_SOURCE_MAPS:
target.setGeneratorEnabledSourceMaps(asBooleanOrDefault(value, (Boolean) PackageJsonProperties.GENERATOR_SOURCE_MAPS.defaultValue));
break;
case GENERATOR_DTS:
target.setGeneratorEnabledDts(asBooleanOrDefault(value, (Boolean) PackageJsonProperties.GENERATOR_DTS.defaultValue));
break;
case GENERATOR_REWRITE_MODULE_SPECIFIERS:
for (NameValuePair nvp : asNameValuePairsOrEmpty(value)) {
String n = nvp.getName();
String v = asStringOrNull(nvp.getValue());
if (n != null && v != null) {
// note: we allow empty strings
target.getGeneratorRewriteModuleSpecifiers().put(n, v);
}
}
break;
case GENERATOR_REWRITE_CJS_IMPORTS:
target.setGeneratorEnabledRewriteCjsImports(asBooleanOrDefault(value, (Boolean) PackageJsonProperties.GENERATOR_REWRITE_CJS_IMPORTS.defaultValue));
break;
default:
break;
}
}
}
use of org.eclipse.n4js.packagejson.projectDescription.ProjectType in project n4js by eclipse.
the class N4JSResourceValidator method isValidFileTypeForProjectType.
private boolean isValidFileTypeForProjectType(Resource resource, N4JSProjectConfigSnapshot project) {
final ResourceType resourceType = ResourceType.getResourceType(resource);
final ProjectType projectType = project.getType();
if (resourceType == ResourceType.JS || resourceType == ResourceType.JSX || resourceType == ResourceType.N4JS || resourceType == ResourceType.N4JSX) {
// we have a .js or .n4js file ...
if (projectType == ProjectType.RUNTIME_LIBRARY || projectType == ProjectType.DEFINITION) {
// --> invalid!
return false;
}
}
return true;
}
use of org.eclipse.n4js.packagejson.projectDescription.ProjectType in project n4js by eclipse.
the class PackageJsonValidatorExtension method checkProjectType.
/**
* Check the projectType value structure and limitations.
*/
@CheckProperty(property = PROJECT_TYPE)
public void checkProjectType(JSONValue projectTypeValue) {
if (!checkIsType(projectTypeValue, JSONPackage.Literals.JSON_STRING_LITERAL)) {
return;
}
if (!checkIsNonEmptyString((JSONStringLiteral) projectTypeValue, PROJECT_TYPE)) {
return;
}
// check whether the given value represents a valid project type
final String projectTypeString = ((JSONStringLiteral) projectTypeValue).getValue();
final ProjectType type = PackageJsonUtils.parseProjectType(projectTypeString);
// check type can be parsed successfully
if (type == null) {
addIssue(IssueCodes.getMessageForPKGJ_INVALID_PROJECT_TYPE(projectTypeString), projectTypeValue, IssueCodes.PKGJ_INVALID_PROJECT_TYPE);
return;
}
// check limitations of specific project types
final boolean isDefType = type == ProjectType.DEFINITION;
final JSONValue propDefinesPck = getSingleDocumentValue(DEFINES_PACKAGE);
final boolean hasDefPck = propDefinesPck != null;
if (isDefType != hasDefPck) {
EObject issueObj = propDefinesPck == null ? projectTypeValue : propDefinesPck.eContainer();
String not = propDefinesPck == null ? "" : "not ";
String msg = IssueCodes.getMessageForPKGJ_DEFINES_PROPERTY(type.toString(), not, "definesPackage");
addIssue(msg, issueObj, IssueCodes.PKGJ_DEFINES_PROPERTY);
}
if (isRequiresOutputAndSourceFolder(type)) {
// make sure non-validation projects always declare an output and at least one source folder
final boolean hasSources = getSingleDocumentValue(SOURCES) != null;
final boolean hasOutput = getSingleDocumentValue(OUTPUT) != null;
if (!hasSources || !hasOutput) {
String msg = IssueCodes.getMessageForPKGJ_PROJECT_TYPE_MANDATORY_OUTPUT_AND_SOURCES(projectTypeString);
addIssue(msg, projectTypeValue, IssueCodes.PKGJ_PROJECT_TYPE_MANDATORY_OUTPUT_AND_SOURCES);
}
}
}
use of org.eclipse.n4js.packagejson.projectDescription.ProjectType in project n4js by eclipse.
the class PackageJsonValidatorExtension method internalCheckOutput.
/**
* Checks the given {@code outputPath} for validity.
*
* @param astOutputValue
* If present, the ast representation. May be {@code null} if {@code outputPath} is a default value.
*/
private void internalCheckOutput(String outputPath, Optional<JSONValue> astOutputValue) {
final Resource resource = getDocument().eResource();
final URI absoluteOutputLocation = getResourceRelativeURI(resource, outputPath);
// forbid output folder for 'definition' projects
final ProjectType projectType = getProjectType();
if (projectType == ProjectType.DEFINITION && astOutputValue.isPresent()) {
String message = IssueCodes.getMessageForPKGJ_DEFINES_PROPERTY(projectType.name(), "not ", "output");
addIssue(message, astOutputValue.get().eContainer(), IssueCodes.PKGJ_DEFINES_PROPERTY);
}
// do not perform check for projects which do not require an output folder
if (!isRequiresOutputAndSourceFolder(projectType)) {
return;
}
final Multimap<SourceContainerType, List<JSONStringLiteral>> sourceContainers = getSourceContainers();
for (Entry<SourceContainerType, List<JSONStringLiteral>> sourceContainerType : sourceContainers.entries()) {
// iterate over all source container paths (in terms of string literals)
for (JSONStringLiteral sourceContainerSpecifier : sourceContainerType.getValue()) {
// compute absolute source container location
final URI absoluteSourceLocation = getResourceRelativeURI(resource, sourceContainerSpecifier.getValue());
// obtain descriptive name of the current source container type
final String srcFrgmtName = PackageJsonUtils.getSourceContainerTypeStringRepresentation(sourceContainerType.getKey());
// handle case that source container is nested within output directory (or equal)
if (isContainedOrEqual(absoluteSourceLocation, absoluteOutputLocation)) {
final String containingFolder = ("A " + srcFrgmtName + " folder");
final String nestedFolder = astOutputValue.isPresent() ? "the output folder" : "the default output folder \"" + OUTPUT.defaultValue + "\"";
final String message = IssueCodes.getMessageForOUTPUT_AND_SOURCES_FOLDER_NESTING(containingFolder, nestedFolder);
addIssue(message, sourceContainerSpecifier, IssueCodes.OUTPUT_AND_SOURCES_FOLDER_NESTING);
}
// if "output" AST element is available (outputPath is not a default value)
if (astOutputValue.isPresent()) {
// handle case that output path is nested within a source folder (or equal)
if (isContainedOrEqual(absoluteOutputLocation, absoluteSourceLocation)) {
final String containingFolder = "The output folder";
final String nestedFolder = ("a " + srcFrgmtName + " folder");
final String message = IssueCodes.getMessageForOUTPUT_AND_SOURCES_FOLDER_NESTING(containingFolder, nestedFolder);
addIssue(message, astOutputValue.get(), IssueCodes.OUTPUT_AND_SOURCES_FOLDER_NESTING);
}
}
}
}
}
Aggregations