Search in sources :

Example 16 with JSONValue

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);
        }
    }
}
Also used : JSONValue(org.eclipse.n4js.json.JSON.JSONValue) ProjectType(org.eclipse.n4js.packagejson.projectDescription.ProjectType) EObject(org.eclipse.emf.ecore.EObject) JSONStringLiteral(org.eclipse.n4js.json.JSON.JSONStringLiteral)

Example 17 with JSONValue

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;
}
Also used : JSONValue(org.eclipse.n4js.json.JSON.JSONValue) EObject(org.eclipse.emf.ecore.EObject) ArrayList(java.util.ArrayList) Either(org.eclipse.lsp4j.jsonrpc.messages.Either) JSONDocument(org.eclipse.n4js.json.JSON.JSONDocument)

Example 18 with JSONValue

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;
}
Also used : JSONValue(org.eclipse.n4js.json.JSON.JSONValue) ENotificationImpl(org.eclipse.emf.ecore.impl.ENotificationImpl)

Example 19 with JSONValue

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;
}
Also used : JSONValue(org.eclipse.n4js.json.JSON.JSONValue) ENotificationImpl(org.eclipse.emf.ecore.impl.ENotificationImpl)

Example 20 with JSONValue

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);
    }
}
Also used : JSONValue(org.eclipse.n4js.json.JSON.JSONValue) JSONObject(org.eclipse.n4js.json.JSON.JSONObject)

Aggregations

JSONValue (org.eclipse.n4js.json.JSON.JSONValue)27 NameValuePair (org.eclipse.n4js.json.JSON.NameValuePair)19 JSONObject (org.eclipse.n4js.json.JSON.JSONObject)17 EObject (org.eclipse.emf.ecore.EObject)7 JSONStringLiteral (org.eclipse.n4js.json.JSON.JSONStringLiteral)7 JSONDocument (org.eclipse.n4js.json.JSON.JSONDocument)6 ArrayList (java.util.ArrayList)4 List (java.util.List)4 URI (org.eclipse.emf.common.util.URI)4 ImmutableMultimap (com.google.common.collect.ImmutableMultimap)3 Multimap (com.google.common.collect.Multimap)3 Inject (com.google.inject.Inject)3 Collection (java.util.Collection)3 HashSet (java.util.HashSet)3 Map (java.util.Map)3 Collectors (java.util.stream.Collectors)3 EClass (org.eclipse.emf.ecore.EClass)3 Resource (org.eclipse.emf.ecore.resource.Resource)3 N4JSGlobals (org.eclipse.n4js.N4JSGlobals)3 JSONArray (org.eclipse.n4js.json.JSON.JSONArray)3