use of org.eclipse.n4js.packagejson.projectDescription.SourceContainerType in project n4js by eclipse.
the class PackageJsonValidatorExtension method createInSourceContainerTypeClause.
/**
* Constructs in-clause (e.g. "in external, test") for sections in which a source container path can be declared.
*
* If the source container type of {@code issueTarget} is the only section (e.g. external) in which
* {@code duplicates} appear, the in-clause is empty. Otherwise the in-clause lists all source container types for
* which duplicates have been declared.
*/
private String createInSourceContainerTypeClause(JSONStringLiteral issueTarget, List<JSONStringLiteral> duplicates) {
final SourceContainerType targetContainerType = getSourceContainerType(issueTarget);
final Set<SourceContainerType> otherTypes = duplicates.stream().filter(d -> d != issueTarget).map(d -> getSourceContainerType(d)).collect(Collectors.toSet());
// if issueTarget's type is the only type for which there have been declared duplicate paths
if (otherTypes.size() == 1 && otherTypes.iterator().next() == targetContainerType) {
// do not use an in-clause
return "";
}
// otherwise list all other types for which the path of issueTarget has been declared as well
return " in " + otherTypes.stream().map(PackageJsonUtils::getSourceContainerTypeStringRepresentation).collect(Collectors.joining(", "));
}
use of org.eclipse.n4js.packagejson.projectDescription.SourceContainerType in project n4js by eclipse.
the class PackageJsonValidatorExtension method doGetSourceContainers.
/**
* Validates the correct structure of a {@link PackageJsonProperties#SOURCES} section and returns a map between the
* declared source container types and corresponding {@link JSONStringLiteral}s that specify the various source
* container paths.
*/
private Multimap<SourceContainerType, List<JSONStringLiteral>> doGetSourceContainers() {
final Collection<JSONValue> sourcesValues = getDocumentValues(SOURCES);
// first check whether n4js.sources section has been defined at all
if (sourcesValues.isEmpty()) {
// return an empty map
return ImmutableMultimap.<SourceContainerType, List<JSONStringLiteral>>of();
}
// first check type of all occuring 'sources' sections
if (!checkIsType(sourcesValues, JSONPackage.Literals.JSON_OBJECT, "as source container section")) {
// return an empty map
return ImmutableMultimap.<SourceContainerType, List<JSONStringLiteral>>of();
}
// only consider the first n4js.sources section for further validation (in case of duplicates)
final JSONValue sourcesValue = sourcesValues.iterator().next();
final JSONObject sourceContainerObject = (JSONObject) sourcesValue;
final Multimap<SourceContainerType, List<JSONStringLiteral>> sourceContainerValues = HashMultimap.create();
for (NameValuePair pair : sourceContainerObject.getNameValuePairs()) {
final String sourceContainerType = pair.getName();
// compute type of source container sub-section
final SourceContainerType containerType = PackageJsonUtils.parseSourceContainerType(pair.getName());
// check that sourceContainerType represents a valid source container type
if (containerType == null) {
addIssue(IssueCodes.getMessageForPKGJ_INVALID_SOURCE_CONTAINER_TYPE(sourceContainerType), pair, JSONPackage.Literals.NAME_VALUE_PAIR__NAME, IssueCodes.PKGJ_INVALID_SOURCE_CONTAINER_TYPE);
continue;
}
// check type of RHS (list of source paths)
if (!checkIsType(pair.getValue(), JSONPackage.Literals.JSON_ARRAY, "as source container list")) {
continue;
}
final JSONArray sourceContainerSpecifiers = (JSONArray) pair.getValue();
// collect all source container paths in this list
final List<JSONStringLiteral> specifierLiterals = new ArrayList<>();
for (JSONValue specifier : sourceContainerSpecifiers.getElements()) {
if (!checkIsType(specifier, JSONPackage.Literals.JSON_STRING_LITERAL, "as source container specifier")) {
continue;
}
specifierLiterals.add((JSONStringLiteral) specifier);
}
// This may override a value in case of a duplicate containerType (e.g. two external sections).
// However, this will also issue an appropriate warning for a duplicate key and
// is therefore not handled here.
sourceContainerValues.put(containerType, specifierLiterals);
}
return sourceContainerValues;
}
Aggregations