use of org.eclipse.n4js.json.JSON.JSONNumericLiteral in project n4js by eclipse.
the class JSONSemanticSequencer method sequence.
@Override
public void sequence(ISerializationContext context, EObject semanticObject) {
EPackage epackage = semanticObject.eClass().getEPackage();
ParserRule rule = context.getParserRule();
Action action = context.getAssignedAction();
Set<Parameter> parameters = context.getEnabledBooleanParameters();
if (epackage == JSONPackage.eINSTANCE)
switch(semanticObject.eClass().getClassifierID()) {
case JSONPackage.JSON_ARRAY:
sequence_JSONArray(context, (JSONArray) semanticObject);
return;
case JSONPackage.JSON_BOOLEAN_LITERAL:
sequence_JSONBooleanLiteral(context, (JSONBooleanLiteral) semanticObject);
return;
case JSONPackage.JSON_DOCUMENT:
sequence_JSONDocument(context, (JSONDocument) semanticObject);
return;
case JSONPackage.JSON_NULL_LITERAL:
sequence_JSONNullLiteral(context, (JSONNullLiteral) semanticObject);
return;
case JSONPackage.JSON_NUMERIC_LITERAL:
sequence_JSONNumericLiteral(context, (JSONNumericLiteral) semanticObject);
return;
case JSONPackage.JSON_OBJECT:
sequence_JSONObject(context, (JSONObject) semanticObject);
return;
case JSONPackage.JSON_STRING_LITERAL:
sequence_JSONStringLiteral(context, (JSONStringLiteral) semanticObject);
return;
case JSONPackage.NAME_VALUE_PAIR:
sequence_NameValuePair(context, (NameValuePair) semanticObject);
return;
}
if (errorAcceptor != null)
errorAcceptor.accept(diagnosticProvider.createInvalidContextOrTypeDiagnostic(semanticObject, context));
}
use of org.eclipse.n4js.json.JSON.JSONNumericLiteral in project n4js by eclipse.
the class ProjectDescriptionLoader method copy.
private JSONValue copy(JsonElement jsonElement) {
if (jsonElement.isJsonNull()) {
return JSONFactory.eINSTANCE.createJSONNullLiteral();
}
if (jsonElement.isJsonPrimitive()) {
JsonPrimitive primitive = jsonElement.getAsJsonPrimitive();
if (primitive.isBoolean()) {
JSONBooleanLiteral result = JSONFactory.eINSTANCE.createJSONBooleanLiteral();
result.setBooleanValue(primitive.getAsBoolean());
return result;
}
if (primitive.isNumber()) {
JSONNumericLiteral result = JSONFactory.eINSTANCE.createJSONNumericLiteral();
result.setValue(primitive.getAsBigDecimal());
return result;
}
if (primitive.isString()) {
JSONStringLiteral result = JSONFactory.eINSTANCE.createJSONStringLiteral();
result.setValue(primitive.getAsString());
return result;
}
throw new IllegalArgumentException(jsonElement.toString());
}
if (jsonElement.isJsonObject()) {
JsonObject object = jsonElement.getAsJsonObject();
JSONObject result = JSONFactory.eINSTANCE.createJSONObject();
for (Map.Entry<String, JsonElement> entry : object.entrySet()) {
NameValuePair pair = JSONFactory.eINSTANCE.createNameValuePair();
pair.setName(entry.getKey());
pair.setValue(copy(entry.getValue()));
result.getNameValuePairs().add(pair);
}
return result;
}
if (jsonElement.isJsonArray()) {
JsonArray array = jsonElement.getAsJsonArray();
JSONArray result = JSONFactory.eINSTANCE.createJSONArray();
for (JsonElement arrayElement : array) {
result.getElements().add(copy(arrayElement));
}
return result;
}
throw new IllegalArgumentException(jsonElement.toString());
}
Aggregations