mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2024-12-22 08:14:09 -08:00
Get rid of Gson library
This commit is contained in:
parent
43a55769d8
commit
ca76ea45cf
|
@ -34,7 +34,12 @@ public abstract class PublishTeaVMPlugin implements Plugin<Project> {
|
||||||
public void apply(Project target) {
|
public void apply(Project target) {
|
||||||
target.getPlugins().apply(PublishingPlugin.class);
|
target.getPlugins().apply(PublishingPlugin.class);
|
||||||
target.getPlugins().apply(MavenPublishPlugin.class);
|
target.getPlugins().apply(MavenPublishPlugin.class);
|
||||||
|
|
||||||
|
var publish = Boolean.parseBoolean(target.getProviders().gradleProperty("teavm.mavenCentral.publish")
|
||||||
|
.getOrElse("false"));
|
||||||
|
if (publish) {
|
||||||
target.getPlugins().apply(SigningPlugin.class);
|
target.getPlugins().apply(SigningPlugin.class);
|
||||||
|
}
|
||||||
|
|
||||||
var extension = new ExtensionImpl();
|
var extension = new ExtensionImpl();
|
||||||
target.getExtensions().add(PublishTeaVMExtension.class, EXTENSION_NAME, extension);
|
target.getExtensions().add(PublishTeaVMExtension.class, EXTENSION_NAME, extension);
|
||||||
|
@ -45,8 +50,6 @@ public abstract class PublishTeaVMPlugin implements Plugin<Project> {
|
||||||
customizePublication(target, publication, extension);
|
customizePublication(target, publication, extension);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
var publish = Boolean.parseBoolean(target.getProviders().gradleProperty("teavm.mavenCentral.publish")
|
|
||||||
.getOrElse("false"));
|
|
||||||
if (publish) {
|
if (publish) {
|
||||||
var signing = target.getExtensions().getByType(SigningExtension.class);
|
var signing = target.getExtensions().getByType(SigningExtension.class);
|
||||||
publishing.getPublications().configureEach(signing::sign);
|
publishing.getPublications().configureEach(signing::sign);
|
||||||
|
|
|
@ -29,7 +29,6 @@ dependencies {
|
||||||
api(project(":jso:impl"))
|
api(project(":jso:impl"))
|
||||||
api(project(":metaprogramming:impl"))
|
api(project(":metaprogramming:impl"))
|
||||||
api(libs.commons.io)
|
api(libs.commons.io)
|
||||||
api(libs.gson)
|
|
||||||
api(libs.jzlib)
|
api(libs.jzlib)
|
||||||
api(libs.jodaTime)
|
api(libs.jodaTime)
|
||||||
|
|
||||||
|
|
|
@ -15,24 +15,28 @@
|
||||||
*/
|
*/
|
||||||
package org.teavm.classlib.impl.unicode;
|
package org.teavm.classlib.impl.unicode;
|
||||||
|
|
||||||
import com.google.gson.JsonElement;
|
|
||||||
import com.google.gson.JsonObject;
|
|
||||||
import com.google.gson.JsonParser;
|
|
||||||
import java.io.BufferedInputStream;
|
import java.io.BufferedInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.LinkedHashSet;
|
import java.util.LinkedHashSet;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.zip.ZipEntry;
|
import java.util.zip.ZipEntry;
|
||||||
import java.util.zip.ZipInputStream;
|
import java.util.zip.ZipInputStream;
|
||||||
|
import org.teavm.common.json.JsonObjectValue;
|
||||||
|
import org.teavm.common.json.JsonParser;
|
||||||
|
import org.teavm.common.json.JsonValue;
|
||||||
|
import org.teavm.common.json.JsonValueParserVisitor;
|
||||||
|
import org.teavm.common.json.JsonValueProvider;
|
||||||
|
import org.teavm.common.json.JsonVisitingConsumer;
|
||||||
|
import org.teavm.common.json.JsonVisitor;
|
||||||
|
|
||||||
public class CLDRReader {
|
public class CLDRReader {
|
||||||
private static final String[] weekdayKeys = { "sun", "mon", "tue", "wed", "thu", "fri", "sat" };
|
private static final String[] weekdayKeys = { "sun", "mon", "tue", "wed", "thu", "fri", "sat" };
|
||||||
|
@ -132,7 +136,7 @@ public class CLDRReader {
|
||||||
readTimeZones(localeName, localeInfo, input);
|
readTimeZones(localeName, localeInfo, input);
|
||||||
break;
|
break;
|
||||||
case "ca-gregorian.json": {
|
case "ca-gregorian.json": {
|
||||||
JsonObject root = (JsonObject) new JsonParser().parse(new InputStreamReader(input));
|
var root = (JsonObjectValue) parse(input);
|
||||||
readEras(localeName, localeInfo, root);
|
readEras(localeName, localeInfo, root);
|
||||||
readAmPms(localeName, localeInfo, root);
|
readAmPms(localeName, localeInfo, root);
|
||||||
readMonths(localeName, localeInfo, root);
|
readMonths(localeName, localeInfo, root);
|
||||||
|
@ -158,50 +162,49 @@ public class CLDRReader {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void readLanguages(String localeCode, CLDRLocale locale, InputStream input) {
|
private void readLanguages(String localeCode, CLDRLocale locale, InputStream input) {
|
||||||
JsonObject root = (JsonObject) new JsonParser().parse(new InputStreamReader(input));
|
var root = parse(input).asObject();
|
||||||
JsonObject languagesJson = root.get("main").getAsJsonObject().get(localeCode).getAsJsonObject()
|
var languagesJson = root.get("main").asObject().get(localeCode).asObject()
|
||||||
.get("localeDisplayNames").getAsJsonObject().get("languages").getAsJsonObject();
|
.get("localeDisplayNames").asObject().get("languages").asObject();
|
||||||
for (Map.Entry<String, JsonElement> property : languagesJson.entrySet()) {
|
for (var property : languagesJson.entrySet()) {
|
||||||
String language = property.getKey();
|
String language = property.getKey();
|
||||||
if (availableLanguages.contains(language)) {
|
if (availableLanguages.contains(language)) {
|
||||||
locale.languages.put(language, property.getValue().getAsString());
|
locale.languages.put(language, property.getValue().asString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void readCountries(String localeCode, CLDRLocale locale, InputStream input) {
|
private void readCountries(String localeCode, CLDRLocale locale, InputStream input) {
|
||||||
JsonObject root = (JsonObject) new JsonParser().parse(new InputStreamReader(input));
|
var root = parse(input).asObject();
|
||||||
JsonObject countriesJson = root.get("main").getAsJsonObject().get(localeCode).getAsJsonObject()
|
var countriesJson = root.get("main").asObject().get(localeCode).asObject()
|
||||||
.get("localeDisplayNames").getAsJsonObject().get("territories").getAsJsonObject();
|
.get("localeDisplayNames").asObject().get("territories").asObject();
|
||||||
for (Map.Entry<String, JsonElement> property : countriesJson.entrySet()) {
|
for (var property : countriesJson.entrySet()) {
|
||||||
String country = property.getKey();
|
String country = property.getKey();
|
||||||
if (availableCountries.contains(country)) {
|
if (availableCountries.contains(country)) {
|
||||||
locale.territories.put(country, property.getValue().getAsString());
|
locale.territories.put(country, property.getValue().asString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void readTimeZones(String localeCode, CLDRLocale locale, InputStream input) {
|
private void readTimeZones(String localeCode, CLDRLocale locale, InputStream input) {
|
||||||
JsonObject root = (JsonObject) new JsonParser().parse(new InputStreamReader(input));
|
var root = parse(input).asObject();
|
||||||
JsonObject zonesJson = root.get("main").getAsJsonObject().get(localeCode).getAsJsonObject()
|
var zonesJson = root.get("main").asObject().get(localeCode).asObject()
|
||||||
.get("dates").getAsJsonObject().get("timeZoneNames").getAsJsonObject().get("zone")
|
.get("dates").asObject().get("timeZoneNames").asObject().get("zone")
|
||||||
.getAsJsonObject();
|
.asObject();
|
||||||
List<CLDRTimeZone> timeZones = new ArrayList<>();
|
var timeZones = new ArrayList<CLDRTimeZone>();
|
||||||
for (Map.Entry<String, JsonElement> area : zonesJson.entrySet()) {
|
for (var area : zonesJson.entrySet()) {
|
||||||
String areaName = area.getKey();
|
var areaName = area.getKey();
|
||||||
for (Map.Entry<String, JsonElement> location : area.getValue().getAsJsonObject().entrySet()) {
|
for (var location : area.getValue().asObject().entrySet()) {
|
||||||
String locationName = location.getKey();
|
var locationName = location.getKey();
|
||||||
JsonElement city = location.getValue().getAsJsonObject().get("exemplarCity");
|
var city = location.getValue().asObject().get("exemplarCity");
|
||||||
if (city != null) {
|
if (city != null) {
|
||||||
CLDRTimeZone tz = new CLDRTimeZone(areaName, locationName, city.getAsString());
|
var tz = new CLDRTimeZone(areaName, locationName, city.asString());
|
||||||
timeZones.add(tz);
|
timeZones.add(tz);
|
||||||
} else {
|
} else {
|
||||||
for (Map.Entry<String, JsonElement> sublocation : location.getValue()
|
for (var sublocation : location.getValue().asObject().entrySet()) {
|
||||||
.getAsJsonObject().entrySet()) {
|
city = location.getValue().asObject().get("exemplarCity");
|
||||||
city = location.getValue().getAsJsonObject().get("exemplarCity");
|
|
||||||
if (city != null) {
|
if (city != null) {
|
||||||
CLDRTimeZone tz = new CLDRTimeZone(areaName, locationName + "/" + sublocation.getKey(),
|
var tz = new CLDRTimeZone(areaName, locationName + "/" + sublocation.getKey(),
|
||||||
city.getAsString());
|
city.asString());
|
||||||
timeZones.add(tz);
|
timeZones.add(tz);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -212,156 +215,155 @@ public class CLDRReader {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void readCurrencies(String localeCode, CLDRLocale locale, InputStream input) {
|
private void readCurrencies(String localeCode, CLDRLocale locale, InputStream input) {
|
||||||
JsonObject root = (JsonObject) new JsonParser().parse(new InputStreamReader(input));
|
var root = parse(input).asObject();
|
||||||
JsonObject currenciesJson = root.get("main").getAsJsonObject().get(localeCode).getAsJsonObject()
|
var currenciesJson = root.get("main").asObject().get(localeCode).asObject()
|
||||||
.get("numbers").getAsJsonObject().get("currencies").getAsJsonObject();
|
.get("numbers").asObject().get("currencies").asObject();
|
||||||
for (Map.Entry<String, JsonElement> currencyEntry : currenciesJson.entrySet()) {
|
for (var currencyEntry : currenciesJson.entrySet()) {
|
||||||
String currencyCode = currencyEntry.getKey();
|
var currencyCode = currencyEntry.getKey();
|
||||||
JsonObject currencyJson = currencyEntry.getValue().getAsJsonObject();
|
var currencyJson = currencyEntry.getValue().asObject();
|
||||||
CLDRCurrency currency = new CLDRCurrency();
|
var currency = new CLDRCurrency();
|
||||||
currency.name = currencyJson.get("displayName").getAsString();
|
currency.name = currencyJson.get("displayName").asString();
|
||||||
if (currencyJson.has("symbol")) {
|
if (currencyJson.has("symbol")) {
|
||||||
currency.symbol = currencyJson.get("symbol").getAsString();
|
currency.symbol = currencyJson.get("symbol").asString();
|
||||||
}
|
}
|
||||||
locale.currencies.put(currencyCode, currency);
|
locale.currencies.put(currencyCode, currency);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void readNumbers(String localeCode, CLDRLocale locale, InputStream input) {
|
private void readNumbers(String localeCode, CLDRLocale locale, InputStream input) {
|
||||||
JsonObject root = (JsonObject) new JsonParser().parse(new InputStreamReader(input));
|
var root = parse(input).asObject();
|
||||||
JsonObject numbersJson = root.get("main").getAsJsonObject().get(localeCode).getAsJsonObject()
|
var numbersJson = root.get("main").asObject().get(localeCode).asObject()
|
||||||
.get("numbers").getAsJsonObject();
|
.get("numbers").asObject();
|
||||||
String numbering = numbersJson.get("defaultNumberingSystem").getAsString();
|
String numbering = numbersJson.get("defaultNumberingSystem").asString();
|
||||||
JsonObject symbolsJson = numbersJson.get("symbols-numberSystem-" + numbering).getAsJsonObject();
|
var symbolsJson = numbersJson.get("symbols-numberSystem-" + numbering).asObject();
|
||||||
locale.decimalData.decimalSeparator = symbolsJson.get("decimal").getAsString().charAt(0);
|
locale.decimalData.decimalSeparator = symbolsJson.get("decimal").asString().charAt(0);
|
||||||
locale.decimalData.groupingSeparator = symbolsJson.get("group").getAsString().charAt(0);
|
locale.decimalData.groupingSeparator = symbolsJson.get("group").asString().charAt(0);
|
||||||
locale.decimalData.listSeparator = symbolsJson.get("list").getAsString().charAt(0);
|
locale.decimalData.listSeparator = symbolsJson.get("list").asString().charAt(0);
|
||||||
locale.decimalData.percent = symbolsJson.get("percentSign").getAsString().charAt(0);
|
locale.decimalData.percent = symbolsJson.get("percentSign").asString().charAt(0);
|
||||||
locale.decimalData.minusSign = symbolsJson.get("minusSign").getAsString().charAt(0);
|
locale.decimalData.minusSign = symbolsJson.get("minusSign").asString().charAt(0);
|
||||||
locale.decimalData.exponentSeparator = symbolsJson.get("exponential").getAsString();
|
locale.decimalData.exponentSeparator = symbolsJson.get("exponential").asString();
|
||||||
locale.decimalData.perMille = symbolsJson.get("perMille").getAsString().charAt(0);
|
locale.decimalData.perMille = symbolsJson.get("perMille").asString().charAt(0);
|
||||||
locale.decimalData.infinity = symbolsJson.get("infinity").getAsString();
|
locale.decimalData.infinity = symbolsJson.get("infinity").asString();
|
||||||
locale.decimalData.nan = symbolsJson.get("nan").getAsString();
|
locale.decimalData.nan = symbolsJson.get("nan").asString();
|
||||||
|
|
||||||
JsonObject numberJson = numbersJson.get("decimalFormats-numberSystem-" + numbering).getAsJsonObject();
|
var numberJson = numbersJson.get("decimalFormats-numberSystem-" + numbering).asObject();
|
||||||
locale.numberFormat = numberJson.get("standard").getAsString();
|
locale.numberFormat = numberJson.get("standard").asString();
|
||||||
|
|
||||||
JsonObject percentJson = numbersJson.get("percentFormats-numberSystem-" + numbering).getAsJsonObject();
|
var percentJson = numbersJson.get("percentFormats-numberSystem-" + numbering).asObject();
|
||||||
locale.percentFormat = percentJson.get("standard").getAsString();
|
locale.percentFormat = percentJson.get("standard").asString();
|
||||||
|
|
||||||
JsonObject currencyJson = numbersJson.get("currencyFormats-numberSystem-" + numbering).getAsJsonObject();
|
var currencyJson = numbersJson.get("currencyFormats-numberSystem-" + numbering).asObject();
|
||||||
locale.currencyFormat = currencyJson.get("standard").getAsString();
|
locale.currencyFormat = currencyJson.get("standard").asString();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void readEras(String localeCode, CLDRLocale locale, JsonObject root) {
|
private void readEras(String localeCode, CLDRLocale locale, JsonObjectValue root) {
|
||||||
JsonObject erasJson = root.get("main").getAsJsonObject().get(localeCode).getAsJsonObject()
|
var erasJson = root.get("main").asObject().get(localeCode).asObject()
|
||||||
.get("dates").getAsJsonObject().get("calendars").getAsJsonObject()
|
.get("dates").asObject().get("calendars").asObject()
|
||||||
.get("gregorian").getAsJsonObject().get("eras").getAsJsonObject().get("eraAbbr").getAsJsonObject();
|
.get("gregorian").asObject().get("eras").asObject().get("eraAbbr").asObject();
|
||||||
String bc = erasJson.get("0").getAsString();
|
var bc = erasJson.get("0").asString();
|
||||||
String ac = erasJson.get("1").getAsString();
|
var ac = erasJson.get("1").asString();
|
||||||
locale.eras = new String[] { bc, ac };
|
locale.eras = new String[] { bc, ac };
|
||||||
}
|
}
|
||||||
|
|
||||||
private void readAmPms(String localeCode, CLDRLocale locale, JsonObject root) {
|
private void readAmPms(String localeCode, CLDRLocale locale, JsonObjectValue root) {
|
||||||
JsonObject ampmJson = root.get("main").getAsJsonObject().get(localeCode).getAsJsonObject()
|
var ampmJson = root.get("main").asObject().get(localeCode).asObject()
|
||||||
.get("dates").getAsJsonObject().get("calendars").getAsJsonObject()
|
.get("dates").asObject().get("calendars").asObject()
|
||||||
.get("gregorian").getAsJsonObject().get("dayPeriods").getAsJsonObject()
|
.get("gregorian").asObject().get("dayPeriods").asObject()
|
||||||
.get("format").getAsJsonObject().get("abbreviated").getAsJsonObject();
|
.get("format").asObject().get("abbreviated").asObject();
|
||||||
String am = ampmJson.get("am").getAsString();
|
String am = ampmJson.get("am").asString();
|
||||||
String pm = ampmJson.get("pm").getAsString();
|
String pm = ampmJson.get("pm").asString();
|
||||||
locale.dayPeriods = new String[] { am, pm };
|
locale.dayPeriods = new String[] { am, pm };
|
||||||
}
|
}
|
||||||
|
|
||||||
private void readMonths(String localeCode, CLDRLocale locale, JsonObject root) {
|
private void readMonths(String localeCode, CLDRLocale locale, JsonObjectValue root) {
|
||||||
JsonObject monthsJson = root.get("main").getAsJsonObject().get(localeCode).getAsJsonObject()
|
var monthsJson = root.get("main").asObject().get(localeCode).asObject()
|
||||||
.get("dates").getAsJsonObject().get("calendars").getAsJsonObject()
|
.get("dates").asObject().get("calendars").asObject()
|
||||||
.get("gregorian").getAsJsonObject().get("months").getAsJsonObject()
|
.get("gregorian").asObject().get("months").asObject()
|
||||||
.get("format").getAsJsonObject().get("wide").getAsJsonObject();
|
.get("format").asObject().get("wide").asObject();
|
||||||
locale.months = new String[12];
|
locale.months = new String[12];
|
||||||
for (int i = 0; i < 12; ++i) {
|
for (int i = 0; i < 12; ++i) {
|
||||||
locale.months[i] = monthsJson.get(String.valueOf(i + 1)).getAsString();
|
locale.months[i] = monthsJson.get(String.valueOf(i + 1)).asString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void readShortMonths(String localeCode, CLDRLocale locale, JsonObject root) {
|
private void readShortMonths(String localeCode, CLDRLocale locale, JsonObjectValue root) {
|
||||||
JsonObject monthsJson = root.get("main").getAsJsonObject().get(localeCode).getAsJsonObject()
|
var monthsJson = root.get("main").asObject().get(localeCode).asObject()
|
||||||
.get("dates").getAsJsonObject().get("calendars").getAsJsonObject()
|
.get("dates").asObject().get("calendars").asObject()
|
||||||
.get("gregorian").getAsJsonObject().get("months").getAsJsonObject()
|
.get("gregorian").asObject().get("months").asObject()
|
||||||
.get("format").getAsJsonObject().get("abbreviated").getAsJsonObject();
|
.get("format").asObject().get("abbreviated").asObject();
|
||||||
locale.shortMonths = new String[12];
|
locale.shortMonths = new String[12];
|
||||||
for (int i = 0; i < 12; ++i) {
|
for (int i = 0; i < 12; ++i) {
|
||||||
locale.shortMonths[i] = monthsJson.get(String.valueOf(i + 1)).getAsString();
|
locale.shortMonths[i] = monthsJson.get(String.valueOf(i + 1)).asString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void readWeekdays(String localeCode, CLDRLocale locale, JsonObject root) {
|
private void readWeekdays(String localeCode, CLDRLocale locale, JsonObjectValue root) {
|
||||||
JsonObject weekdaysJson = root.get("main").getAsJsonObject().get(localeCode).getAsJsonObject()
|
var weekdaysJson = root.get("main").asObject().get(localeCode).asObject()
|
||||||
.get("dates").getAsJsonObject().get("calendars").getAsJsonObject()
|
.get("dates").asObject().get("calendars").asObject()
|
||||||
.get("gregorian").getAsJsonObject().get("days").getAsJsonObject()
|
.get("gregorian").asObject().get("days").asObject()
|
||||||
.get("format").getAsJsonObject().get("wide").getAsJsonObject();
|
.get("format").asObject().get("wide").asObject();
|
||||||
locale.weekdays = new String[7];
|
locale.weekdays = new String[7];
|
||||||
for (int i = 0; i < 7; ++i) {
|
for (int i = 0; i < 7; ++i) {
|
||||||
locale.weekdays[i] = weekdaysJson.get(weekdayKeys[i]).getAsString();
|
locale.weekdays[i] = weekdaysJson.get(weekdayKeys[i]).asString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void readShortWeekdays(String localeCode, CLDRLocale locale, JsonObject root) {
|
private void readShortWeekdays(String localeCode, CLDRLocale locale, JsonObjectValue root) {
|
||||||
JsonObject weekdaysJson = root.get("main").getAsJsonObject().get(localeCode).getAsJsonObject()
|
var weekdaysJson = root.get("main").asObject().get(localeCode).asObject()
|
||||||
.get("dates").getAsJsonObject().get("calendars").getAsJsonObject()
|
.get("dates").asObject().get("calendars").asObject()
|
||||||
.get("gregorian").getAsJsonObject().get("days").getAsJsonObject()
|
.get("gregorian").asObject().get("days").asObject()
|
||||||
.get("format").getAsJsonObject().get("abbreviated").getAsJsonObject();
|
.get("format").asObject().get("abbreviated").asObject();
|
||||||
locale.shortWeekdays = new String[7];
|
locale.shortWeekdays = new String[7];
|
||||||
for (int i = 0; i < 7; ++i) {
|
for (int i = 0; i < 7; ++i) {
|
||||||
locale.shortWeekdays[i] = weekdaysJson.get(weekdayKeys[i]).getAsString();
|
locale.shortWeekdays[i] = weekdaysJson.get(weekdayKeys[i]).asString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void readDateFormats(String localeCode, CLDRLocale locale, JsonObject root) {
|
private void readDateFormats(String localeCode, CLDRLocale locale, JsonObjectValue root) {
|
||||||
JsonObject formatsJson = root.get("main").getAsJsonObject().get(localeCode).getAsJsonObject()
|
var formatsJson = root.get("main").asObject().get(localeCode).asObject()
|
||||||
.get("dates").getAsJsonObject().get("calendars").getAsJsonObject()
|
.get("dates").asObject().get("calendars").asObject()
|
||||||
.get("gregorian").getAsJsonObject().get("dateFormats").getAsJsonObject();
|
.get("gregorian").asObject().get("dateFormats").asObject();
|
||||||
locale.dateFormats = new CLDRDateFormats(formatsJson.get("short").getAsString(),
|
locale.dateFormats = new CLDRDateFormats(formatsJson.get("short").asString(),
|
||||||
formatsJson.get("medium").getAsString(), formatsJson.get("long").getAsString(),
|
formatsJson.get("medium").asString(), formatsJson.get("long").asString(),
|
||||||
formatsJson.get("full").getAsString());
|
formatsJson.get("full").asString());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void readTimeFormats(String localeCode, CLDRLocale locale, JsonObject root) {
|
private void readTimeFormats(String localeCode, CLDRLocale locale, JsonObjectValue root) {
|
||||||
JsonObject formatsJson = root.get("main").getAsJsonObject().get(localeCode).getAsJsonObject()
|
var formatsJson = root.get("main").asObject().get(localeCode).asObject()
|
||||||
.get("dates").getAsJsonObject().get("calendars").getAsJsonObject()
|
.get("dates").asObject().get("calendars").asObject()
|
||||||
.get("gregorian").getAsJsonObject().get("timeFormats").getAsJsonObject();
|
.get("gregorian").asObject().get("timeFormats").asObject();
|
||||||
locale.timeFormats = new CLDRDateFormats(formatsJson.get("short").getAsString(),
|
locale.timeFormats = new CLDRDateFormats(formatsJson.get("short").asString(),
|
||||||
formatsJson.get("medium").getAsString(), formatsJson.get("long").getAsString(),
|
formatsJson.get("medium").asString(), formatsJson.get("long").asString(),
|
||||||
formatsJson.get("full").getAsString());
|
formatsJson.get("full").asString());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void readDateTimeFormats(String localeCode, CLDRLocale locale, JsonObject root) {
|
private void readDateTimeFormats(String localeCode, CLDRLocale locale, JsonObjectValue root) {
|
||||||
JsonObject formatsJson = root.get("main").getAsJsonObject().get(localeCode).getAsJsonObject()
|
var formatsJson = root.get("main").asObject().get(localeCode).asObject()
|
||||||
.get("dates").getAsJsonObject().get("calendars").getAsJsonObject()
|
.get("dates").asObject().get("calendars").asObject()
|
||||||
.get("gregorian").getAsJsonObject().get("dateTimeFormats").getAsJsonObject();
|
.get("gregorian").asObject().get("dateTimeFormats").asObject();
|
||||||
locale.dateTimeFormats = new CLDRDateFormats(formatsJson.get("short").getAsString(),
|
locale.dateTimeFormats = new CLDRDateFormats(formatsJson.get("short").asString(),
|
||||||
formatsJson.get("medium").getAsString(), formatsJson.get("long").getAsString(),
|
formatsJson.get("medium").asString(), formatsJson.get("long").asString(),
|
||||||
formatsJson.get("full").getAsString());
|
formatsJson.get("full").asString());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void readWeekData(InputStream input) {
|
private void readWeekData(InputStream input) {
|
||||||
JsonObject root = (JsonObject) new JsonParser().parse(new InputStreamReader(input));
|
var root = parse(input).asObject();
|
||||||
JsonObject weekJson = root.get("supplemental").getAsJsonObject().get("weekData").getAsJsonObject();
|
var weekJson = root.get("supplemental").asObject().get("weekData").asObject();
|
||||||
JsonObject minDaysJson = weekJson.get("minDays").getAsJsonObject();
|
var minDaysJson = weekJson.get("minDays").asObject();
|
||||||
for (Map.Entry<String, JsonElement> property : minDaysJson.entrySet()) {
|
for (var property : minDaysJson.entrySet()) {
|
||||||
minDaysMap.put(property.getKey(), property.getValue().getAsInt());
|
minDaysMap.put(property.getKey(), Integer.parseInt(property.getValue().asString()));
|
||||||
}
|
}
|
||||||
JsonObject firstDayJson = weekJson.get("firstDay").getAsJsonObject();
|
var firstDayJson = weekJson.get("firstDay").asObject();
|
||||||
for (Map.Entry<String, JsonElement> property : firstDayJson.entrySet()) {
|
for (var property : firstDayJson.entrySet()) {
|
||||||
firstDayMap.put(property.getKey(), getNumericDay(property.getValue().getAsString()));
|
firstDayMap.put(property.getKey(), getNumericDay(property.getValue().asString()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void readLikelySubtags(InputStream input) {
|
private void readLikelySubtags(InputStream input) {
|
||||||
JsonObject root = (JsonObject) new JsonParser().parse(new InputStreamReader(input));
|
var root = parse(input).asObject();
|
||||||
JsonObject likelySubtagsJson = root.get("supplemental").getAsJsonObject().get("likelySubtags")
|
var likelySubtagsJson = root.get("supplemental").asObject().get("likelySubtags").asObject();
|
||||||
.getAsJsonObject();
|
for (var property : likelySubtagsJson.entrySet()) {
|
||||||
for (Map.Entry<String, JsonElement> property : likelySubtagsJson.entrySet()) {
|
likelySubtags.put(property.getKey(), property.getValue().asString());
|
||||||
likelySubtags.put(property.getKey(), property.getValue().getAsString());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -420,4 +422,21 @@ public class CLDRReader {
|
||||||
ensureInitialized();
|
ensureInitialized();
|
||||||
return Collections.unmodifiableMap(likelySubtags);
|
return Collections.unmodifiableMap(likelySubtags);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private JsonValue parse(InputStream input) {
|
||||||
|
var provider = new JsonValueProvider();
|
||||||
|
var visitor = JsonValueParserVisitor.create(provider);
|
||||||
|
parse(visitor, input);
|
||||||
|
return provider.getValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void parse(JsonVisitor visitor, InputStream input) {
|
||||||
|
var consumer = new JsonVisitingConsumer(visitor);
|
||||||
|
var parser = new JsonParser(consumer);
|
||||||
|
try {
|
||||||
|
parser.parse(new InputStreamReader(input, StandardCharsets.UTF_8));
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,27 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2023 Alexey Andreev.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.teavm.classlib.impl.unicode;
|
||||||
|
|
||||||
|
import org.teavm.common.json.JsonPropertyVisitor;
|
||||||
|
|
||||||
|
class NumbersJsonParser extends JsonPropertyVisitor {
|
||||||
|
CLDRLocale locale;
|
||||||
|
|
||||||
|
NumbersJsonParser() {
|
||||||
|
super(true);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -26,13 +26,13 @@ import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import org.teavm.backend.c.util.json.JsonAllErrorVisitor;
|
import org.teavm.common.json.JsonAllErrorVisitor;
|
||||||
import org.teavm.backend.c.util.json.JsonArrayVisitor;
|
import org.teavm.common.json.JsonArrayVisitor;
|
||||||
import org.teavm.backend.c.util.json.JsonErrorReporter;
|
import org.teavm.common.json.JsonErrorReporter;
|
||||||
import org.teavm.backend.c.util.json.JsonParser;
|
import org.teavm.common.json.JsonParser;
|
||||||
import org.teavm.backend.c.util.json.JsonPropertyVisitor;
|
import org.teavm.common.json.JsonPropertyVisitor;
|
||||||
import org.teavm.backend.c.util.json.JsonVisitingConsumer;
|
import org.teavm.common.json.JsonVisitingConsumer;
|
||||||
import org.teavm.backend.c.util.json.JsonVisitor;
|
import org.teavm.common.json.JsonVisitor;
|
||||||
|
|
||||||
public class Deobfuscator {
|
public class Deobfuscator {
|
||||||
private Map<Integer, CallSite> callSites = new HashMap<>();
|
private Map<Integer, CallSite> callSites = new HashMap<>();
|
||||||
|
|
|
@ -32,14 +32,14 @@ import java.util.Collection;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import org.teavm.backend.c.util.json.JsonAllErrorVisitor;
|
import org.teavm.common.json.JsonAllErrorVisitor;
|
||||||
import org.teavm.backend.c.util.json.JsonArrayVisitor;
|
import org.teavm.common.json.JsonArrayVisitor;
|
||||||
import org.teavm.backend.c.util.json.JsonErrorReporter;
|
import org.teavm.common.json.JsonErrorReporter;
|
||||||
import org.teavm.backend.c.util.json.JsonObjectVisitor;
|
import org.teavm.common.json.JsonObjectVisitor;
|
||||||
import org.teavm.backend.c.util.json.JsonParser;
|
import org.teavm.common.json.JsonParser;
|
||||||
import org.teavm.backend.c.util.json.JsonPropertyVisitor;
|
import org.teavm.common.json.JsonPropertyVisitor;
|
||||||
import org.teavm.backend.c.util.json.JsonVisitingConsumer;
|
import org.teavm.common.json.JsonVisitingConsumer;
|
||||||
import org.teavm.backend.c.util.json.JsonVisitor;
|
import org.teavm.common.json.JsonVisitor;
|
||||||
|
|
||||||
public final class HeapDumpConverter {
|
public final class HeapDumpConverter {
|
||||||
private static byte[] buffer = new byte[8];
|
private static byte[] buffer = new byte[8];
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2019 Alexey Andreev.
|
* Copyright 2023 Alexey Andreev.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -13,7 +13,7 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package org.teavm.backend.c.util.json;
|
package org.teavm.common.json;
|
||||||
|
|
||||||
public class JsonAllErrorVisitor extends JsonVisitor {
|
public class JsonAllErrorVisitor extends JsonVisitor {
|
||||||
@Override
|
@Override
|
35
core/src/main/java/org/teavm/common/json/JsonArrayValue.java
Normal file
35
core/src/main/java/org/teavm/common/json/JsonArrayValue.java
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2023 Alexey Andreev.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.teavm.common.json;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class JsonArrayValue extends JsonValue {
|
||||||
|
private List<JsonValue> elements = new ArrayList<>();
|
||||||
|
|
||||||
|
public int size() {
|
||||||
|
return elements.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
public JsonValue get(int index) {
|
||||||
|
return elements.get(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void add(JsonValue element) {
|
||||||
|
elements.add(element);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2019 Alexey Andreev.
|
* Copyright 2023 Alexey Andreev.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -13,7 +13,7 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package org.teavm.backend.c.util.json;
|
package org.teavm.common.json;
|
||||||
|
|
||||||
public class JsonArrayVisitor extends JsonAllErrorVisitor {
|
public class JsonArrayVisitor extends JsonAllErrorVisitor {
|
||||||
private JsonVisitor itemVisitor;
|
private JsonVisitor itemVisitor;
|
|
@ -0,0 +1,28 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2023 Alexey Andreev.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.teavm.common.json;
|
||||||
|
|
||||||
|
public class JsonBooleanValue extends JsonValue {
|
||||||
|
private boolean innerValue;
|
||||||
|
|
||||||
|
public JsonBooleanValue(boolean value) {
|
||||||
|
this.innerValue = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean asBoolean() {
|
||||||
|
return innerValue;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2019 Alexey Andreev.
|
* Copyright 2023 Alexey Andreev.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -13,7 +13,7 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package org.teavm.backend.c.util.json;
|
package org.teavm.common.json;
|
||||||
|
|
||||||
public abstract class JsonConsumer {
|
public abstract class JsonConsumer {
|
||||||
public void enterObject(JsonErrorReporter reporter) {
|
public void enterObject(JsonErrorReporter reporter) {
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2019 Alexey Andreev.
|
* Copyright 2023 Alexey Andreev.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -13,7 +13,7 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package org.teavm.backend.c.util.json;
|
package org.teavm.common.json;
|
||||||
|
|
||||||
public abstract class JsonErrorReporter {
|
public abstract class JsonErrorReporter {
|
||||||
public abstract void error(String message);
|
public abstract void error(String message);
|
29
core/src/main/java/org/teavm/common/json/JsonFloatValue.java
Normal file
29
core/src/main/java/org/teavm/common/json/JsonFloatValue.java
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2023 Alexey Andreev.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.teavm.common.json;
|
||||||
|
|
||||||
|
public class JsonFloatValue extends JsonNumericValue {
|
||||||
|
private double number;
|
||||||
|
|
||||||
|
public JsonFloatValue(double number) {
|
||||||
|
this.number = number;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double asNumber() {
|
||||||
|
return number;
|
||||||
|
}
|
||||||
|
}
|
34
core/src/main/java/org/teavm/common/json/JsonIntValue.java
Normal file
34
core/src/main/java/org/teavm/common/json/JsonIntValue.java
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2023 Alexey Andreev.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.teavm.common.json;
|
||||||
|
|
||||||
|
public class JsonIntValue extends JsonNumericValue {
|
||||||
|
private long number;
|
||||||
|
|
||||||
|
public JsonIntValue(long number) {
|
||||||
|
this.number = number;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double asNumber() {
|
||||||
|
return number;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long asIntNumber() {
|
||||||
|
return number;
|
||||||
|
}
|
||||||
|
}
|
19
core/src/main/java/org/teavm/common/json/JsonNullValue.java
Normal file
19
core/src/main/java/org/teavm/common/json/JsonNullValue.java
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2023 Alexey Andreev.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.teavm.common.json;
|
||||||
|
|
||||||
|
public class JsonNullValue extends JsonValue {
|
||||||
|
}
|
|
@ -0,0 +1,20 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2023 Alexey Andreev.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.teavm.common.json;
|
||||||
|
|
||||||
|
public abstract class JsonNumericValue extends JsonValue {
|
||||||
|
public abstract double asNumber();
|
||||||
|
}
|
|
@ -0,0 +1,45 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2023 Alexey Andreev.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.teavm.common.json;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
public class JsonObjectValue extends JsonValue {
|
||||||
|
private Map<String, JsonValue> properties = new HashMap<>();
|
||||||
|
|
||||||
|
public void put(String name, JsonValue value) {
|
||||||
|
properties.put(name, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public JsonValue get(String name) {
|
||||||
|
return properties.get(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean has(String name) {
|
||||||
|
return properties.containsKey(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Set<Map.Entry<String, JsonValue>> entrySet() {
|
||||||
|
return properties.entrySet();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public JsonObjectValue asObject() {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2019 Alexey Andreev.
|
* Copyright 2023 Alexey Andreev.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -13,12 +13,12 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package org.teavm.backend.c.util.json;
|
package org.teavm.common.json;
|
||||||
|
|
||||||
public class JsonObjectVisitor extends JsonVisitor {
|
public class JsonObjectVisitor extends JsonVisitor {
|
||||||
private JsonPropertyVisitor propertyVisitor;
|
private JsonVisitor propertyVisitor;
|
||||||
|
|
||||||
public JsonObjectVisitor(JsonPropertyVisitor propertyVisitor) {
|
public JsonObjectVisitor(JsonVisitor propertyVisitor) {
|
||||||
this.propertyVisitor = propertyVisitor;
|
this.propertyVisitor = propertyVisitor;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2019 Alexey Andreev.
|
* Copyright 2023 Alexey Andreev.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -13,7 +13,7 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package org.teavm.backend.c.util.json;
|
package org.teavm.common.json;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.Reader;
|
import java.io.Reader;
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2019 Alexey Andreev.
|
* Copyright 2023 Alexey Andreev.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -13,7 +13,7 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package org.teavm.backend.c.util.json;
|
package org.teavm.common.json;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -26,8 +26,9 @@ public class JsonPropertyVisitor extends JsonAllErrorVisitor {
|
||||||
this.skipNonExistentProperties = skipNonExistentProperties;
|
this.skipNonExistentProperties = skipNonExistentProperties;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addProperty(String propertyName, JsonVisitor visitor) {
|
public JsonPropertyVisitor addProperty(String propertyName, JsonVisitor visitor) {
|
||||||
properties.put(propertyName, visitor);
|
properties.put(propertyName, visitor);
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
|
@ -0,0 +1,29 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2023 Alexey Andreev.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.teavm.common.json;
|
||||||
|
|
||||||
|
public class JsonStringValue extends JsonValue {
|
||||||
|
private String text;
|
||||||
|
|
||||||
|
public JsonStringValue(String text) {
|
||||||
|
this.text = text;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String asString() {
|
||||||
|
return text;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2019 Alexey Andreev.
|
* Copyright 2023 Alexey Andreev.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -13,7 +13,7 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package org.teavm.backend.c.util.json;
|
package org.teavm.common.json;
|
||||||
|
|
||||||
public class JsonSyntaxException extends RuntimeException {
|
public class JsonSyntaxException extends RuntimeException {
|
||||||
private final int lineNumber;
|
private final int lineNumber;
|
30
core/src/main/java/org/teavm/common/json/JsonValue.java
Normal file
30
core/src/main/java/org/teavm/common/json/JsonValue.java
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2023 Alexey Andreev.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.teavm.common.json;
|
||||||
|
|
||||||
|
public abstract class JsonValue {
|
||||||
|
public JsonObjectValue asObject() {
|
||||||
|
throw new IllegalStateException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String asString() {
|
||||||
|
throw new IllegalStateException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public long asIntNumber() {
|
||||||
|
throw new IllegalStateException();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,90 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2023 Alexey Andreev.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.teavm.common.json;
|
||||||
|
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
|
public abstract class JsonValueParserVisitor extends JsonAllErrorVisitor {
|
||||||
|
public abstract void consume(JsonValue value);
|
||||||
|
|
||||||
|
public static JsonValueParserVisitor create(Consumer<JsonValue> consumer) {
|
||||||
|
return new JsonValueParserVisitor() {
|
||||||
|
@Override
|
||||||
|
public void consume(JsonValue value) {
|
||||||
|
consumer.accept(value);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public JsonVisitor object(JsonErrorReporter reporter) {
|
||||||
|
var jsonObject = new JsonObjectValue();
|
||||||
|
consume(jsonObject);
|
||||||
|
return new JsonAllErrorVisitor() {
|
||||||
|
@Override
|
||||||
|
public JsonVisitor property(JsonErrorReporter reporter, String name) {
|
||||||
|
return new JsonValueParserVisitor() {
|
||||||
|
@Override
|
||||||
|
public void consume(JsonValue value) {
|
||||||
|
jsonObject.put(name, value);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public JsonVisitor array(JsonErrorReporter reporter) {
|
||||||
|
var jsonArray = new JsonArrayValue();
|
||||||
|
consume(jsonArray);
|
||||||
|
return new JsonAllErrorVisitor() {
|
||||||
|
@Override
|
||||||
|
public JsonVisitor array(JsonErrorReporter reporter) {
|
||||||
|
return new JsonValueParserVisitor() {
|
||||||
|
@Override
|
||||||
|
public void consume(JsonValue value) {
|
||||||
|
jsonArray.add(value);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void stringValue(JsonErrorReporter reporter, String value) {
|
||||||
|
consume(new JsonStringValue(value));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void intValue(JsonErrorReporter reporter, long value) {
|
||||||
|
consume(new JsonIntValue(value));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void floatValue(JsonErrorReporter reporter, double value) {
|
||||||
|
consume(new JsonFloatValue(value));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void nullValue(JsonErrorReporter reporter) {
|
||||||
|
consume(new JsonNullValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void booleanValue(JsonErrorReporter reporter, boolean value) {
|
||||||
|
consume(new JsonBooleanValue(value));
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,31 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2023 Alexey Andreev.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.teavm.common.json;
|
||||||
|
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
|
public class JsonValueProvider implements Consumer<JsonValue> {
|
||||||
|
private JsonValue value;
|
||||||
|
|
||||||
|
public JsonValue getValue() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void accept(JsonValue jsonValue) {
|
||||||
|
value = jsonValue;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2019 Alexey Andreev.
|
* Copyright 2023 Alexey Andreev.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -13,7 +13,7 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package org.teavm.backend.c.util.json;
|
package org.teavm.common.json;
|
||||||
|
|
||||||
import java.util.ArrayDeque;
|
import java.util.ArrayDeque;
|
||||||
import java.util.Deque;
|
import java.util.Deque;
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2019 Alexey Andreev.
|
* Copyright 2023 Alexey Andreev.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -13,7 +13,7 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package org.teavm.backend.c.util.json;
|
package org.teavm.common.json;
|
||||||
|
|
||||||
public abstract class JsonVisitor {
|
public abstract class JsonVisitor {
|
||||||
public JsonVisitor object(JsonErrorReporter reporter) {
|
public JsonVisitor object(JsonErrorReporter reporter) {
|
|
@ -30,7 +30,6 @@ asm-analysis = { module = "org.ow2.asm:asm-analysis", version.ref = "asm" }
|
||||||
jackson-annotations = { module = "com.fasterxml.jackson.core:jackson-annotations", version.ref = "jackson" }
|
jackson-annotations = { module = "com.fasterxml.jackson.core:jackson-annotations", version.ref = "jackson" }
|
||||||
jackson-databind = { module = "com.fasterxml.jackson.core:jackson-databind", version.ref = "jackson" }
|
jackson-databind = { module = "com.fasterxml.jackson.core:jackson-databind", version.ref = "jackson" }
|
||||||
|
|
||||||
gson = "com.google.code.gson:gson:2.10.1"
|
|
||||||
jzlib = "com.jcraft:jzlib:1.1.3"
|
jzlib = "com.jcraft:jzlib:1.1.3"
|
||||||
jodaTime = "joda-time:joda-time:2.12.2"
|
jodaTime = "joda-time:joda-time:2.12.2"
|
||||||
htmlunit = "net.sourceforge.htmlunit:htmlunit:2.70.0"
|
htmlunit = "net.sourceforge.htmlunit:htmlunit:2.70.0"
|
||||||
|
|
Loading…
Reference in New Issue
Block a user