use of org.eclipse.n4js.json.JSON.JSONValue 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.json.JSON.JSONValue in project n4js by eclipse.
the class JSONHierarchicalSymbolService method getSymbols.
@Override
public List<Either<SymbolInformation, DocumentSymbol>> getSymbols(XtextResource resource, CancelIndicator cancelIndicator) {
List<Either<SymbolInformation, DocumentSymbol>> result = new ArrayList<>();
for (EObject content : resource.getContents()) {
if (content instanceof JSONDocument) {
JSONDocument document = (JSONDocument) content;
JSONValue rootValue = document.getContent();
getSymbols(rootValue, symbol -> result.add(Either.forRight(symbol)), cancelIndicator);
}
}
return result;
}
use of org.eclipse.n4js.json.JSON.JSONValue in project n4js by eclipse.
the class JSONDocumentImpl method basicSetContent.
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public NotificationChain basicSetContent(JSONValue newContent, NotificationChain msgs) {
JSONValue oldContent = content;
content = newContent;
if (eNotificationRequired()) {
ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, JSONPackage.JSON_DOCUMENT__CONTENT, oldContent, newContent);
if (msgs == null)
msgs = notification;
else
msgs.add(notification);
}
return msgs;
}
use of org.eclipse.n4js.json.JSON.JSONValue in project n4js by eclipse.
the class NameValuePairImpl method basicSetValue.
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public NotificationChain basicSetValue(JSONValue newValue, NotificationChain msgs) {
JSONValue oldValue = value;
value = newValue;
if (eNotificationRequired()) {
ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, JSONPackage.NAME_VALUE_PAIR__VALUE, oldValue, newValue);
if (msgs == null)
msgs = notification;
else
msgs.add(notification);
}
return msgs;
}
use of org.eclipse.n4js.json.JSON.JSONValue in project n4js by eclipse.
the class JSONModelUtils method merge.
/**
* Like {@link #merge(JSONObject, JSONObject, boolean, boolean)}, but for {@link JSONDocument}.
*/
public static void merge(JSONDocument target, JSONDocument source, boolean copy, boolean recursive) {
JSONValue targetContent = target.getContent();
JSONValue sourceContent = source.getContent();
if (sourceContent instanceof JSONObject && targetContent instanceof JSONObject) {
merge((JSONObject) targetContent, (JSONObject) sourceContent, copy, recursive);
} else {
target.setContent(copy ? EcoreUtil.copy(sourceContent) : sourceContent);
}
}
Aggregations