From ae3eee86cd437f884bfb579559f2a640c847bd6e Mon Sep 17 00:00:00 2001 From: Piotr Tomiak Date: Thu, 5 Feb 2026 10:44:29 +0100 Subject: [PATCH] WEB-76699 MDN: move generation module to the tools directory. GitOrigin-RevId: 9beab73f45aafae904837c110233c5d5bf2960d2 --- xml/xml-psi-impl/intellij.xml.psi.impl.iml | 1 - xml/xml-psi-impl/mdn-doc-gen/.gitignore | 2 - .../mdn-doc-gen/baseline-server/index.mjs | 40 - .../baseline-server/package-lock.json | 84 - .../mdn-doc-gen/baseline-server/package.json | 14 - .../mdn-doc-gen/bcd-gen/gen/pom.xml | 84 - xml/xml-psi-impl/mdn-doc-gen/bcd-gen/pom.xml | 52 - .../mdn-doc-gen/bcd-gen/resources/bcd.json | 306 ---- .../gen/com/intellij/bcd/json/Bcd.java | 90 - .../gen/com/intellij/bcd/json/Browsers.java | 31 - .../intellij/bcd/json/CompatStatement.java | 160 -- .../com/intellij/bcd/json/FlagStatement.java | 147 -- .../gen/com/intellij/bcd/json/Identifier.java | 44 - .../gen/com/intellij/bcd/json/ImplUrl.java | 50 - .../gen/com/intellij/bcd/json/Meta.java | 31 - .../gen/com/intellij/bcd/json/Notes.java | 50 - .../bcd/json/SimpleSupportStatement.java | 228 --- .../gen/com/intellij/bcd/json/SpecUrl.java | 50 - .../com/intellij/bcd/json/StatusBlock.java | 102 -- .../com/intellij/bcd/json/SupportBlock.java | 31 - .../intellij/bcd/json/SupportStatement.java | 66 - .../com/intellij/bcd/json/VersionAdded.java | 61 - .../com/intellij/bcd/json/VersionRemoved.java | 61 - .../com/intellij/bcd/json/Webextensions.java | 31 - .../intellij.documenation.mdn.gen.iml | 43 - .../mdn-doc-gen/src/BaseLineService.kt | 113 -- xml/xml-psi-impl/mdn-doc-gen/src/BcdUtil.kt | 32 - .../src/GenerateMdnDocumentation.kt | 1549 ----------------- .../mdn-doc-gen/src/MdnDocUpdateTestSuite.kt | 44 - .../mdn-doc-gen/src/prepare-mdn.sh | 39 - 30 files changed, 3636 deletions(-) delete mode 100644 xml/xml-psi-impl/mdn-doc-gen/.gitignore delete mode 100644 xml/xml-psi-impl/mdn-doc-gen/baseline-server/index.mjs delete mode 100644 xml/xml-psi-impl/mdn-doc-gen/baseline-server/package-lock.json delete mode 100644 xml/xml-psi-impl/mdn-doc-gen/baseline-server/package.json delete mode 100644 xml/xml-psi-impl/mdn-doc-gen/bcd-gen/gen/pom.xml delete mode 100644 xml/xml-psi-impl/mdn-doc-gen/bcd-gen/pom.xml delete mode 100644 xml/xml-psi-impl/mdn-doc-gen/bcd-gen/resources/bcd.json delete mode 100644 xml/xml-psi-impl/mdn-doc-gen/gen/com/intellij/bcd/json/Bcd.java delete mode 100644 xml/xml-psi-impl/mdn-doc-gen/gen/com/intellij/bcd/json/Browsers.java delete mode 100644 xml/xml-psi-impl/mdn-doc-gen/gen/com/intellij/bcd/json/CompatStatement.java delete mode 100644 xml/xml-psi-impl/mdn-doc-gen/gen/com/intellij/bcd/json/FlagStatement.java delete mode 100644 xml/xml-psi-impl/mdn-doc-gen/gen/com/intellij/bcd/json/Identifier.java delete mode 100644 xml/xml-psi-impl/mdn-doc-gen/gen/com/intellij/bcd/json/ImplUrl.java delete mode 100644 xml/xml-psi-impl/mdn-doc-gen/gen/com/intellij/bcd/json/Meta.java delete mode 100644 xml/xml-psi-impl/mdn-doc-gen/gen/com/intellij/bcd/json/Notes.java delete mode 100644 xml/xml-psi-impl/mdn-doc-gen/gen/com/intellij/bcd/json/SimpleSupportStatement.java delete mode 100644 xml/xml-psi-impl/mdn-doc-gen/gen/com/intellij/bcd/json/SpecUrl.java delete mode 100644 xml/xml-psi-impl/mdn-doc-gen/gen/com/intellij/bcd/json/StatusBlock.java delete mode 100644 xml/xml-psi-impl/mdn-doc-gen/gen/com/intellij/bcd/json/SupportBlock.java delete mode 100644 xml/xml-psi-impl/mdn-doc-gen/gen/com/intellij/bcd/json/SupportStatement.java delete mode 100644 xml/xml-psi-impl/mdn-doc-gen/gen/com/intellij/bcd/json/VersionAdded.java delete mode 100644 xml/xml-psi-impl/mdn-doc-gen/gen/com/intellij/bcd/json/VersionRemoved.java delete mode 100644 xml/xml-psi-impl/mdn-doc-gen/gen/com/intellij/bcd/json/Webextensions.java delete mode 100644 xml/xml-psi-impl/mdn-doc-gen/intellij.documenation.mdn.gen.iml delete mode 100644 xml/xml-psi-impl/mdn-doc-gen/src/BaseLineService.kt delete mode 100644 xml/xml-psi-impl/mdn-doc-gen/src/BcdUtil.kt delete mode 100644 xml/xml-psi-impl/mdn-doc-gen/src/GenerateMdnDocumentation.kt delete mode 100644 xml/xml-psi-impl/mdn-doc-gen/src/MdnDocUpdateTestSuite.kt delete mode 100755 xml/xml-psi-impl/mdn-doc-gen/src/prepare-mdn.sh diff --git a/xml/xml-psi-impl/intellij.xml.psi.impl.iml b/xml/xml-psi-impl/intellij.xml.psi.impl.iml index c06a14601910..4d6dc74448a2 100644 --- a/xml/xml-psi-impl/intellij.xml.psi.impl.iml +++ b/xml/xml-psi-impl/intellij.xml.psi.impl.iml @@ -7,7 +7,6 @@ - diff --git a/xml/xml-psi-impl/mdn-doc-gen/.gitignore b/xml/xml-psi-impl/mdn-doc-gen/.gitignore deleted file mode 100644 index 98deafc457a3..000000000000 --- a/xml/xml-psi-impl/mdn-doc-gen/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -work/ -baseline-server/node_modules/ \ No newline at end of file diff --git a/xml/xml-psi-impl/mdn-doc-gen/baseline-server/index.mjs b/xml/xml-psi-impl/mdn-doc-gen/baseline-server/index.mjs deleted file mode 100644 index 361d5c0b7da0..000000000000 --- a/xml/xml-psi-impl/mdn-doc-gen/baseline-server/index.mjs +++ /dev/null @@ -1,40 +0,0 @@ -import data from "../work/browser-compat-data.json" with { type: "json" }; -import { computeBaseline } from "compute-baseline"; -import { Compat } from "compute-baseline/browser-compat-data"; -import * as readline from 'readline'; - -const compat = new Compat(data); - -// Create readline interface to read from stdin -const rl = readline.createInterface({ - input: process.stdin, - output: process.stdout, - terminal: false -}); - -// Process each line from stdin -rl.on('line', (line) => { - if (line.trim()) { - try { - const result = computeBaseline({ - compatKeys: [line], - checkAncestors: true - }, compat); - - // Output the result as a single line to stdout - console.log(JSON.stringify(result)); - } catch (e) { - if ((e.message?.indexOf("is unindexable at") ?? -1) > 0) { - console.error(e.message) - } else { - console.error(e) - } - console.log("\"null\"") - } - } -}); - -// Handle end of input -rl.on('close', () => { - process.exit(0); -}); diff --git a/xml/xml-psi-impl/mdn-doc-gen/baseline-server/package-lock.json b/xml/xml-psi-impl/mdn-doc-gen/baseline-server/package-lock.json deleted file mode 100644 index c4e8041214e4..000000000000 --- a/xml/xml-psi-impl/mdn-doc-gen/baseline-server/package-lock.json +++ /dev/null @@ -1,84 +0,0 @@ -{ - "name": "baseline-server", - "lockfileVersion": 3, - "requires": true, - "packages": { - "": { - "name": "baseline-server", - "dependencies": { - "compute-baseline": "0.3.1" - }, - "devDependencies": { - "@types/node": "20.10.0" - } - }, - "node_modules/@js-temporal/polyfill": { - "version": "0.4.4", - "resolved": "https://registry.npmjs.org/@js-temporal/polyfill/-/polyfill-0.4.4.tgz", - "integrity": "sha512-2X6bvghJ/JAoZO52lbgyAPFj8uCflhTo2g7nkFzEQdXd/D8rEeD4HtmTEpmtGCva260fcd66YNXBOYdnmHqSOg==", - "license": "ISC", - "dependencies": { - "jsbi": "^4.3.0", - "tslib": "^2.4.1" - }, - "engines": { - "node": ">=12" - } - }, - "node_modules/@mdn/browser-compat-data": { - "version": "6.0.12", - "resolved": "https://registry.npmjs.org/@mdn/browser-compat-data/-/browser-compat-data-6.0.12.tgz", - "integrity": "sha512-lQ6p212jKeJBG+L7UYRKchTCcnQbp6yOj5swKxGLjvuW4SmbgWgd/WyA1Dxq1GGT86C7jVTEaKry36LmsBp8SQ==", - "license": "CC0-1.0", - "peer": true - }, - "node_modules/@types/node": { - "version": "20.10.0", - "resolved": "https://registry.npmjs.org/@types/node/-/node-20.10.0.tgz", - "integrity": "sha512-D0WfRmU9TQ8I9PFx9Yc+EBHw+vSpIub4IDvQivcp26PtPrdMGAq5SDcpXEo/epqa/DXotVpekHiLNTg3iaKXBQ==", - "dev": true, - "license": "MIT", - "dependencies": { - "undici-types": "~5.26.4" - } - }, - "node_modules/compare-versions": { - "version": "6.1.1", - "resolved": "https://registry.npmjs.org/compare-versions/-/compare-versions-6.1.1.tgz", - "integrity": "sha512-4hm4VPpIecmlg59CHXnRDnqGplJFrbLG4aFEl5vl6cK1u76ws3LLvX7ikFnTDl5vo39sjWD6AaDPYodJp/NNHg==", - "license": "MIT" - }, - "node_modules/compute-baseline": { - "version": "0.3.1", - "resolved": "https://registry.npmjs.org/compute-baseline/-/compute-baseline-0.3.1.tgz", - "integrity": "sha512-fehgbBh5UG4H5AemyVXWaviTwUbcPduhaD9iHWfkIy5fv2xFou/Zfs5z0VISXJyUEDzThe84MMofNOZ/qd0K6g==", - "license": "Apache-2.0", - "dependencies": { - "@js-temporal/polyfill": "^0.4.4", - "compare-versions": "^6.1.1" - }, - "peerDependencies": { - "@mdn/browser-compat-data": "^6.0.1" - } - }, - "node_modules/jsbi": { - "version": "4.3.2", - "resolved": "https://registry.npmjs.org/jsbi/-/jsbi-4.3.2.tgz", - "integrity": "sha512-9fqMSQbhJykSeii05nxKl4m6Eqn2P6rOlYiS+C5Dr/HPIU/7yZxu5qzbs40tgaFORiw2Amd0mirjxatXYMkIew==", - "license": "Apache-2.0" - }, - "node_modules/tslib": { - "version": "2.8.1", - "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.8.1.tgz", - "integrity": "sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w==", - "license": "0BSD" - }, - "node_modules/undici-types": { - "version": "5.26.5", - "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-5.26.5.tgz", - "integrity": "sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==", - "dev": true, - "license": "MIT" - } - } -} diff --git a/xml/xml-psi-impl/mdn-doc-gen/baseline-server/package.json b/xml/xml-psi-impl/mdn-doc-gen/baseline-server/package.json deleted file mode 100644 index f43b90309304..000000000000 --- a/xml/xml-psi-impl/mdn-doc-gen/baseline-server/package.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "name": "baseline-server", - "private": "true", - "type": "module", - "scripts": { - "start": "node index.mjs" - }, - "dependencies": { - "compute-baseline": "0.3.1" - }, - "devDependencies": { - "@types/node": "20.10.0" - } -} diff --git a/xml/xml-psi-impl/mdn-doc-gen/bcd-gen/gen/pom.xml b/xml/xml-psi-impl/mdn-doc-gen/bcd-gen/gen/pom.xml deleted file mode 100644 index b2f5d5b06349..000000000000 --- a/xml/xml-psi-impl/mdn-doc-gen/bcd-gen/gen/pom.xml +++ /dev/null @@ -1,84 +0,0 @@ - - 4.0.0 - - intellij.bcd - 1.0.0 - bcd-gen-root - - bcd-gen - pom - - - - - org.apache.maven.plugins - maven-clean-plugin - 2.4.1 - - - compile - - - - ${basedir}/../../gen/com/intellij/bcd/json/ - - **/* - - false - - - - - clean - - - - - - org.jsonschema2pojo - jsonschema2pojo-maven-plugin - 1.0.2 - - JACKSON2 - true - false - false - 1.8 - com.intellij.bcd.json - ${basedir}/../resources/bcd.json - JSONSCHEMA - ${basedir}/../../gen/ - com.intellij.polySymbols.webTypes.gen.WebTypesRuleFactory - - - - intellij.polySymbols - web-types-ext - 1.0.0 - - - com.fasterxml.jackson.core - jackson-databind - ${jackson2x.version} - - - com.fasterxml.jackson.dataformat - jackson-dataformat-yaml - ${jackson2x.version} - - - - - compile - - generate - - - - - - - \ No newline at end of file diff --git a/xml/xml-psi-impl/mdn-doc-gen/bcd-gen/pom.xml b/xml/xml-psi-impl/mdn-doc-gen/bcd-gen/pom.xml deleted file mode 100644 index 3d584cdb3efc..000000000000 --- a/xml/xml-psi-impl/mdn-doc-gen/bcd-gen/pom.xml +++ /dev/null @@ -1,52 +0,0 @@ - - 4.0.0 - intellij.bcd - bcd-gen-root - pom - 1.0.0 - - - gen - ../../../../platform/polySymbols/web-types-gen/ext - - - - - - UTF-8 - 2.12.0 - - - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.8.1 - - 11 - 11 - - - - - - - - - com.fasterxml.jackson.core - jackson-databind - ${jackson2x.version} - - - com.fasterxml.jackson.dataformat - jackson-dataformat-yaml - ${jackson2x.version} - - - - - \ No newline at end of file diff --git a/xml/xml-psi-impl/mdn-doc-gen/bcd-gen/resources/bcd.json b/xml/xml-psi-impl/mdn-doc-gen/bcd-gen/resources/bcd.json deleted file mode 100644 index 45804bac4b99..000000000000 --- a/xml/xml-psi-impl/mdn-doc-gen/bcd-gen/resources/bcd.json +++ /dev/null @@ -1,306 +0,0 @@ -{ - "$schema": "http://json-schema.org/schema#", - - "definitions": { - "simple_support_statement": { - "type": "object", - "properties": { - "version_added": { - "description": "A string (indicating which browser version added this feature), the value true (indicating support added in an unknown version), the value false (indicating the feature is not supported), or the value null (indicating support is unknown).", - "anyOf": [ - { - "type": "string", - "pattern": "^(≤?(\\d+)(\\.\\d+)*|preview)$" - }, - { - "type": "boolean", - "nullable": true - } - ], - "tsType": "VersionValue" - }, - "version_removed": { - "description": "A string, indicating which browser version removed this feature, or the value true, indicating that the feature was removed in an unknown version.", - "anyOf": [ - { - "type": "string", - "pattern": "^(≤?(\\d+)(\\.\\d+)*|preview)$" - }, - { - "type": "boolean", - "const": true - } - ], - "tsType": "VersionValue" - }, - "prefix": { - "type": "string", - "description": "A prefix to add to the sub-feature name (defaults to empty string). If applicable, leading and trailing '-' must be included." - }, - "alternative_name": { - "type": "string", - "description": "An alternative name for the feature, for cases where a feature is implemented under an entirely different name and not just prefixed." - }, - "flags": { - "type": "array", - "description": "An optional array of objects describing flags that must be configured for this browser to support this feature.", - "minItems": 1, - "items": { - "$ref": "#/definitions/flag_statement" - }, - "tsType": "FlagStatement[]" - }, - "impl_url": { - "anyOf": [ - { - "$ref": "#/definitions/impl_url_value" - }, - { - "type": "array", - "minItems": 2, - "items": { - "$ref": "#/definitions/impl_url_value" - } - } - ], - "description": "An optional changeset/commit URL for the revision which implemented the feature in the source code, or the URL to the bug tracking the implementation, for the associated browser.", - "tsType": "string | string[]", - "errorMessage": { - "pattern": "impl_url must be a link to a browser commit or bug URL. URLs must be in shortened form (ex. bugs.chromium.org -> crbug.com). Note: `npm run fix` may resolve these issues." - } - }, - "partial_implementation": { - "const": true, - "description": "A boolean value indicating whether or not the implementation of the sub-feature deviates from the specification in a way that may cause compatibility problems. It defaults to false (no interoperability problems expected). If set to true, it is recommended that you add a note explaining how it diverges from the standard (such as that it implements an old version of the standard, for example)." - }, - "notes": { - "description": "A string or array of strings containing additional information.", - "anyOf": [ - { - "type": "string" - }, - { - "type": "array", - "minItems": 2, - "items": { - "type": "string" - } - } - ], - "tsType": "string | string[]" - } - }, - "required": ["version_added"], - "dependencies": { - "partial_implementation": { - "if": { - "properties": { "partial_implementation": { "const": true } } - }, - "then": { "required": ["notes"] } - } - }, - "additionalProperties": false - }, - - "flag_statement": { - "type": "object", - "properties": { - "type": { - "type": "string", - "description": "An enum that indicates the flag type.", - "enum": ["preference", "runtime_flag"] - }, - "name": { - "type": "string", - "description": "A string giving the name of the flag or preference that must be configured." - }, - "value_to_set": { - "type": "string", - "description": "A string giving the value which the specified flag must be set to for this feature to work." - } - }, - "additionalProperties": false, - "required": ["type", "name"] - }, - - "support_statement": { - "anyOf": [ - { "$ref": "#/definitions/simple_support_statement" }, - { - "type": "array", - "minItems": 2, - "items": { - "$ref": "#/definitions/simple_support_statement" - } - }, - { - "type": "string", - "const": "mirror" - } - ], - "tsType": "SimpleSupportStatement | SimpleSupportStatement[]" - }, - - "status_block": { - "type": "object", - "properties": { - "experimental": { - "type": "boolean", - "description": "A boolean value that indicates whether this functionality is intended to be an addition to the Web platform. Set to false, it means the functionality is mature, and no significant incompatible changes are expected in the future." - }, - "standard_track": { - "type": "boolean", - "description": "A boolean value indicating whether the feature is part of an active specification or specification process." - }, - "deprecated": { - "type": "boolean", - "description": "A boolean value that indicates whether the feature is no longer recommended. It might be removed in the future or might only be kept for compatibility purposes. Avoid using this functionality." - } - }, - "required": ["experimental", "standard_track", "deprecated"], - "additionalProperties": false - }, - - "support_block": { - "type": "object", - "propertyNames": { - "enum": [ - "chrome", - "chrome_android", - "deno", - "edge", - "firefox", - "firefox_android", - "ie", - "nodejs", - "oculus", - "opera", - "opera_android", - "safari", - "safari_ios", - "samsunginternet_android", - "webview_android" - ] - }, - "additionalProperties": { - "$ref": "#/definitions/support_statement" - }, - "tsType": "Partial>" - }, - - "spec_url_value": { - "type": "string", - "pattern": "(^https://[^#]+#.+)|(^https://registry.khronos.org/webgl/extensions/[^/]+/)" - }, - - "impl_url_value": { - "type": "string", - "pattern": "^https://(trac.webkit.org/changeset/|hg.mozilla.org/mozilla-central/rev/|crrev.com/|bugzil.la/|crbug.com/|webkit.org/b/)" - }, - - "compat_statement": { - "type": "object", - "properties": { - "description": { - "type": "string", - "description": "A string containing a human-readable description of the feature." - }, - "mdn_url": { - "type": "string", - "pattern": "^https://developer\\.mozilla\\.org/docs/", - "description": "A URL that points to an MDN reference page documenting the feature. The URL should be language-agnostic." - }, - "spec_url": { - "anyOf": [ - { - "$ref": "#/definitions/spec_url_value" - }, - { - "type": "array", - "minItems": 2, - "items": { - "$ref": "#/definitions/spec_url_value" - } - } - ], - "description": "An optional URL or array of URLs, each of which is for a specific part of a specification in which this feature is defined. Each URL must contain a fragment identifier.", - "tsType": "string | string[]" - }, - "source_file": { - "type": "string", - "description": "The path to the file that defines this feature in browser-compat-data, relative to the repository root. Useful for guiding potential contributors towards the correct file to edit. This is automatically generated at build time and should never manually be specified." - }, - "support": { - "$ref": "#/definitions/support_block", - "description": "The data for the support of each browser, containing a `support_statement` object for each browser identifier with information about versions, prefixes, or alternate names, as well as notes." - }, - "status": { - "$ref": "#/definitions/status_block", - "description": "An object containing information about the stability of the feature." - } - }, - "required": ["support"], - "additionalProperties": false - }, - - "identifier": { - "type": "object", - "properties": { - "__compat": { - "type": "object", - "$ref": "#/definitions/compat_statement", - "required": ["status"], - "description": "A feature is described by an identifier containing the `__compat` property.\n\nIn other words, identifiers without `__compat` aren't necessarily features, but help to nest the features properly.\n\nWhen an identifier has a `__compat` block, it represents its basic support, indicating that a minimal implementation of a functionality is included.\n\nWhat it represents exactly depends of the evolution of the feature over time, both in terms of specifications and of browser support.", - "tsType": "CompatStatement" - } - }, - "additionalProperties": { - "$ref": "#/definitions/identifier" - }, - "errorMessage": { - "additionalProperties": "Feature names can only contain alphanumerical characters or the following symbols: _-$@" - }, - "tsType": "{[key: string]: Identifier} & {__compat?: CompatStatement};" - }, - - "webextensions_identifier": { - "type": "object", - "properties": { - "__compat": { "$ref": "#/definitions/compat_statement" } - }, - "additionalProperties": { - "$ref": "#/definitions/webextensions_identifier", - "tsType": "Identifier" - }, - "errorMessage": { - "additionalProperties": "Feature names can only contain alphanumerical characters or the following symbols: _-$@" - }, - "tsType": "{[key: string]: Identifier} & {__compat?: CompatStatement}" - } - }, - - "title": "CompatDataFile", - "type": "object", - "properties": { - "__compat": { - "$ref": "#/definitions/compat_statement" - }, - "__meta": { - "type": "object" - }, - "browsers": { - "type": "object" - }, - "webextensions": { - "type": "object" - } - }, - "additionalProperties": { - "$ref": "#/definitions/identifier" - }, - "errorMessage": { - "additionalProperties": "Feature names can only contain alphanumerical characters or the following symbols: _-$@" - }, - "maxProperties": 1, - "minProperties": 1 -} diff --git a/xml/xml-psi-impl/mdn-doc-gen/gen/com/intellij/bcd/json/Bcd.java b/xml/xml-psi-impl/mdn-doc-gen/gen/com/intellij/bcd/json/Bcd.java deleted file mode 100644 index 312df7a612ff..000000000000 --- a/xml/xml-psi-impl/mdn-doc-gen/gen/com/intellij/bcd/json/Bcd.java +++ /dev/null @@ -1,90 +0,0 @@ - -package com.intellij.bcd.json; - -import java.util.HashMap; -import java.util.Map; -import com.fasterxml.jackson.annotation.JsonAnyGetter; -import com.fasterxml.jackson.annotation.JsonAnySetter; -import com.fasterxml.jackson.annotation.JsonIgnore; -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonPropertyOrder; - - -/** - * CompatDataFile - *

- * - * - */ -@JsonInclude(JsonInclude.Include.NON_NULL) -@JsonPropertyOrder({ - "__compat", - "__meta", - "browsers", - "webextensions" -}) -public class Bcd { - - @JsonProperty("__compat") - private CompatStatement compat; - @JsonProperty("__meta") - private Meta meta; - @JsonProperty("browsers") - private Browsers browsers; - @JsonProperty("webextensions") - private Webextensions webextensions; - @JsonIgnore - private Map additionalProperties = new HashMap(); - - @JsonProperty("__compat") - public CompatStatement getCompat() { - return compat; - } - - @JsonProperty("__compat") - public void setCompat(CompatStatement compat) { - this.compat = compat; - } - - @JsonProperty("__meta") - public Meta getMeta() { - return meta; - } - - @JsonProperty("__meta") - public void setMeta(Meta meta) { - this.meta = meta; - } - - @JsonProperty("browsers") - public Browsers getBrowsers() { - return browsers; - } - - @JsonProperty("browsers") - public void setBrowsers(Browsers browsers) { - this.browsers = browsers; - } - - @JsonProperty("webextensions") - public Webextensions getWebextensions() { - return webextensions; - } - - @JsonProperty("webextensions") - public void setWebextensions(Webextensions webextensions) { - this.webextensions = webextensions; - } - - @JsonAnyGetter - public Map getAdditionalProperties() { - return this.additionalProperties; - } - - @JsonAnySetter - public void setAdditionalProperty(String name, Identifier value) { - this.additionalProperties.put(name, value); - } - -} diff --git a/xml/xml-psi-impl/mdn-doc-gen/gen/com/intellij/bcd/json/Browsers.java b/xml/xml-psi-impl/mdn-doc-gen/gen/com/intellij/bcd/json/Browsers.java deleted file mode 100644 index c2634b2c0743..000000000000 --- a/xml/xml-psi-impl/mdn-doc-gen/gen/com/intellij/bcd/json/Browsers.java +++ /dev/null @@ -1,31 +0,0 @@ - -package com.intellij.bcd.json; - -import java.util.HashMap; -import java.util.Map; -import com.fasterxml.jackson.annotation.JsonAnyGetter; -import com.fasterxml.jackson.annotation.JsonAnySetter; -import com.fasterxml.jackson.annotation.JsonIgnore; -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonPropertyOrder; - -@JsonInclude(JsonInclude.Include.NON_NULL) -@JsonPropertyOrder({ - -}) -public class Browsers { - - @JsonIgnore - private Map additionalProperties = new HashMap(); - - @JsonAnyGetter - public Map getAdditionalProperties() { - return this.additionalProperties; - } - - @JsonAnySetter - public void setAdditionalProperty(String name, Object value) { - this.additionalProperties.put(name, value); - } - -} diff --git a/xml/xml-psi-impl/mdn-doc-gen/gen/com/intellij/bcd/json/CompatStatement.java b/xml/xml-psi-impl/mdn-doc-gen/gen/com/intellij/bcd/json/CompatStatement.java deleted file mode 100644 index d58786dac979..000000000000 --- a/xml/xml-psi-impl/mdn-doc-gen/gen/com/intellij/bcd/json/CompatStatement.java +++ /dev/null @@ -1,160 +0,0 @@ - -package com.intellij.bcd.json; - -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonPropertyDescription; -import com.fasterxml.jackson.annotation.JsonPropertyOrder; - -@JsonInclude(JsonInclude.Include.NON_NULL) -@JsonPropertyOrder({ - "description", - "mdn_url", - "spec_url", - "source_file", - "support", - "status" -}) -public class CompatStatement { - - /** - * A string containing a human-readable description of the feature. - * - */ - @JsonProperty("description") - @JsonPropertyDescription("A string containing a human-readable description of the feature.") - private String description; - /** - * A URL that points to an MDN reference page documenting the feature. The URL should be language-agnostic. - * - */ - @JsonProperty("mdn_url") - @JsonPropertyDescription("A URL that points to an MDN reference page documenting the feature. The URL should be language-agnostic.") - private String mdnUrl; - /** - * An optional URL or array of URLs, each of which is for a specific part of a specification in which this feature is defined. Each URL must contain a fragment identifier. - * - */ - @JsonProperty("spec_url") - @JsonPropertyDescription("An optional URL or array of URLs, each of which is for a specific part of a specification in which this feature is defined. Each URL must contain a fragment identifier.") - private SpecUrl specUrl; - /** - * The path to the file that defines this feature in browser-compat-data, relative to the repository root. Useful for guiding potential contributors towards the correct file to edit. This is automatically generated at build time and should never manually be specified. - * - */ - @JsonProperty("source_file") - @JsonPropertyDescription("The path to the file that defines this feature in browser-compat-data, relative to the repository root. Useful for guiding potential contributors towards the correct file to edit. This is automatically generated at build time and should never manually be specified.") - private String sourceFile; - /** - * - * (Required) - * - */ - @JsonProperty("support") - private SupportBlock support; - @JsonProperty("status") - private StatusBlock status; - - /** - * A string containing a human-readable description of the feature. - * - */ - @JsonProperty("description") - public String getDescription() { - return description; - } - - /** - * A string containing a human-readable description of the feature. - * - */ - @JsonProperty("description") - public void setDescription(String description) { - this.description = description; - } - - /** - * A URL that points to an MDN reference page documenting the feature. The URL should be language-agnostic. - * - */ - @JsonProperty("mdn_url") - public String getMdnUrl() { - return mdnUrl; - } - - /** - * A URL that points to an MDN reference page documenting the feature. The URL should be language-agnostic. - * - */ - @JsonProperty("mdn_url") - public void setMdnUrl(String mdnUrl) { - this.mdnUrl = mdnUrl; - } - - /** - * An optional URL or array of URLs, each of which is for a specific part of a specification in which this feature is defined. Each URL must contain a fragment identifier. - * - */ - @JsonProperty("spec_url") - public SpecUrl getSpecUrl() { - return specUrl; - } - - /** - * An optional URL or array of URLs, each of which is for a specific part of a specification in which this feature is defined. Each URL must contain a fragment identifier. - * - */ - @JsonProperty("spec_url") - public void setSpecUrl(SpecUrl specUrl) { - this.specUrl = specUrl; - } - - /** - * The path to the file that defines this feature in browser-compat-data, relative to the repository root. Useful for guiding potential contributors towards the correct file to edit. This is automatically generated at build time and should never manually be specified. - * - */ - @JsonProperty("source_file") - public String getSourceFile() { - return sourceFile; - } - - /** - * The path to the file that defines this feature in browser-compat-data, relative to the repository root. Useful for guiding potential contributors towards the correct file to edit. This is automatically generated at build time and should never manually be specified. - * - */ - @JsonProperty("source_file") - public void setSourceFile(String sourceFile) { - this.sourceFile = sourceFile; - } - - /** - * - * (Required) - * - */ - @JsonProperty("support") - public SupportBlock getSupport() { - return support; - } - - /** - * - * (Required) - * - */ - @JsonProperty("support") - public void setSupport(SupportBlock support) { - this.support = support; - } - - @JsonProperty("status") - public StatusBlock getStatus() { - return status; - } - - @JsonProperty("status") - public void setStatus(StatusBlock status) { - this.status = status; - } - -} diff --git a/xml/xml-psi-impl/mdn-doc-gen/gen/com/intellij/bcd/json/FlagStatement.java b/xml/xml-psi-impl/mdn-doc-gen/gen/com/intellij/bcd/json/FlagStatement.java deleted file mode 100644 index fb689080d340..000000000000 --- a/xml/xml-psi-impl/mdn-doc-gen/gen/com/intellij/bcd/json/FlagStatement.java +++ /dev/null @@ -1,147 +0,0 @@ - -package com.intellij.bcd.json; - -import java.util.HashMap; -import java.util.Map; -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonPropertyDescription; -import com.fasterxml.jackson.annotation.JsonPropertyOrder; -import com.fasterxml.jackson.annotation.JsonValue; - -@JsonInclude(JsonInclude.Include.NON_NULL) -@JsonPropertyOrder({ - "type", - "name", - "value_to_set" -}) -public class FlagStatement { - - /** - * An enum that indicates the flag type. - * (Required) - * - */ - @JsonProperty("type") - @JsonPropertyDescription("An enum that indicates the flag type.") - private FlagStatement.Type type; - /** - * A string giving the name of the flag or preference that must be configured. - * (Required) - * - */ - @JsonProperty("name") - @JsonPropertyDescription("A string giving the name of the flag or preference that must be configured.") - private String name; - /** - * A string giving the value which the specified flag must be set to for this feature to work. - * - */ - @JsonProperty("value_to_set") - @JsonPropertyDescription("A string giving the value which the specified flag must be set to for this feature to work.") - private String valueToSet; - - /** - * An enum that indicates the flag type. - * (Required) - * - */ - @JsonProperty("type") - public FlagStatement.Type getType() { - return type; - } - - /** - * An enum that indicates the flag type. - * (Required) - * - */ - @JsonProperty("type") - public void setType(FlagStatement.Type type) { - this.type = type; - } - - /** - * A string giving the name of the flag or preference that must be configured. - * (Required) - * - */ - @JsonProperty("name") - public String getName() { - return name; - } - - /** - * A string giving the name of the flag or preference that must be configured. - * (Required) - * - */ - @JsonProperty("name") - public void setName(String name) { - this.name = name; - } - - /** - * A string giving the value which the specified flag must be set to for this feature to work. - * - */ - @JsonProperty("value_to_set") - public String getValueToSet() { - return valueToSet; - } - - /** - * A string giving the value which the specified flag must be set to for this feature to work. - * - */ - @JsonProperty("value_to_set") - public void setValueToSet(String valueToSet) { - this.valueToSet = valueToSet; - } - - - /** - * An enum that indicates the flag type. - * - */ - public enum Type { - - PREFERENCE("preference"), - RUNTIME_FLAG("runtime_flag"); - private final String value; - private final static Map CONSTANTS = new HashMap(); - - static { - for (FlagStatement.Type c: values()) { - CONSTANTS.put(c.value, c); - } - } - - private Type(String value) { - this.value = value; - } - - @Override - public String toString() { - return this.value; - } - - @JsonValue - public String value() { - return this.value; - } - - @JsonCreator - public static FlagStatement.Type fromValue(String value) { - FlagStatement.Type constant = CONSTANTS.get(value); - if (constant == null) { - throw new IllegalArgumentException(value); - } else { - return constant; - } - } - - } - -} diff --git a/xml/xml-psi-impl/mdn-doc-gen/gen/com/intellij/bcd/json/Identifier.java b/xml/xml-psi-impl/mdn-doc-gen/gen/com/intellij/bcd/json/Identifier.java deleted file mode 100644 index f4ba2bd5a8d1..000000000000 --- a/xml/xml-psi-impl/mdn-doc-gen/gen/com/intellij/bcd/json/Identifier.java +++ /dev/null @@ -1,44 +0,0 @@ - -package com.intellij.bcd.json; - -import java.util.HashMap; -import java.util.Map; -import com.fasterxml.jackson.annotation.JsonAnyGetter; -import com.fasterxml.jackson.annotation.JsonAnySetter; -import com.fasterxml.jackson.annotation.JsonIgnore; -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonPropertyOrder; - -@JsonInclude(JsonInclude.Include.NON_NULL) -@JsonPropertyOrder({ - "__compat" -}) -public class Identifier { - - @JsonProperty("__compat") - private CompatStatement compat; - @JsonIgnore - private Map additionalProperties = new HashMap(); - - @JsonProperty("__compat") - public CompatStatement getCompat() { - return compat; - } - - @JsonProperty("__compat") - public void setCompat(CompatStatement compat) { - this.compat = compat; - } - - @JsonAnyGetter - public Map getAdditionalProperties() { - return this.additionalProperties; - } - - @JsonAnySetter - public void setAdditionalProperty(String name, Identifier value) { - this.additionalProperties.put(name, value); - } - -} diff --git a/xml/xml-psi-impl/mdn-doc-gen/gen/com/intellij/bcd/json/ImplUrl.java b/xml/xml-psi-impl/mdn-doc-gen/gen/com/intellij/bcd/json/ImplUrl.java deleted file mode 100644 index 8a4b32c68d0d..000000000000 --- a/xml/xml-psi-impl/mdn-doc-gen/gen/com/intellij/bcd/json/ImplUrl.java +++ /dev/null @@ -1,50 +0,0 @@ - -package com.intellij.bcd.json; - -import java.io.IOException; -import java.util.ArrayList; -import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.core.JsonToken; -import com.fasterxml.jackson.databind.DeserializationContext; -import com.fasterxml.jackson.databind.JsonDeserializer; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; - -@JsonDeserialize(using = ImplUrl.MyDeserializer.class) -public class ImplUrl - extends ArrayList -{ - - - public static class MyDeserializer - extends JsonDeserializer - { - - - @Override - public ImplUrl deserialize(JsonParser parser, DeserializationContext deserializationContext) - throws IOException - { - ImplUrl result = new ImplUrl(); - JsonToken token = parser.currentToken(); - if (token == JsonToken.START_ARRAY) { - while (parser.nextToken()!= JsonToken.END_ARRAY) { - token = parser.currentToken(); - if (token == JsonToken.VALUE_STRING) { - result.add(parser.readValueAs(String.class)); - } else { - deserializationContext.handleUnexpectedToken(String.class, parser); - } - } - } else { - if (token == JsonToken.VALUE_STRING) { - result.add(parser.readValueAs(String.class)); - } else { - deserializationContext.handleUnexpectedToken(String.class, parser); - } - } - return result; - } - - } - -} diff --git a/xml/xml-psi-impl/mdn-doc-gen/gen/com/intellij/bcd/json/Meta.java b/xml/xml-psi-impl/mdn-doc-gen/gen/com/intellij/bcd/json/Meta.java deleted file mode 100644 index 0e60b79024ca..000000000000 --- a/xml/xml-psi-impl/mdn-doc-gen/gen/com/intellij/bcd/json/Meta.java +++ /dev/null @@ -1,31 +0,0 @@ - -package com.intellij.bcd.json; - -import java.util.HashMap; -import java.util.Map; -import com.fasterxml.jackson.annotation.JsonAnyGetter; -import com.fasterxml.jackson.annotation.JsonAnySetter; -import com.fasterxml.jackson.annotation.JsonIgnore; -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonPropertyOrder; - -@JsonInclude(JsonInclude.Include.NON_NULL) -@JsonPropertyOrder({ - -}) -public class Meta { - - @JsonIgnore - private Map additionalProperties = new HashMap(); - - @JsonAnyGetter - public Map getAdditionalProperties() { - return this.additionalProperties; - } - - @JsonAnySetter - public void setAdditionalProperty(String name, Object value) { - this.additionalProperties.put(name, value); - } - -} diff --git a/xml/xml-psi-impl/mdn-doc-gen/gen/com/intellij/bcd/json/Notes.java b/xml/xml-psi-impl/mdn-doc-gen/gen/com/intellij/bcd/json/Notes.java deleted file mode 100644 index 6bd7f353930f..000000000000 --- a/xml/xml-psi-impl/mdn-doc-gen/gen/com/intellij/bcd/json/Notes.java +++ /dev/null @@ -1,50 +0,0 @@ - -package com.intellij.bcd.json; - -import java.io.IOException; -import java.util.ArrayList; -import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.core.JsonToken; -import com.fasterxml.jackson.databind.DeserializationContext; -import com.fasterxml.jackson.databind.JsonDeserializer; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; - -@JsonDeserialize(using = Notes.MyDeserializer.class) -public class Notes - extends ArrayList -{ - - - public static class MyDeserializer - extends JsonDeserializer - { - - - @Override - public Notes deserialize(JsonParser parser, DeserializationContext deserializationContext) - throws IOException - { - Notes result = new Notes(); - JsonToken token = parser.currentToken(); - if (token == JsonToken.START_ARRAY) { - while (parser.nextToken()!= JsonToken.END_ARRAY) { - token = parser.currentToken(); - if (token == JsonToken.VALUE_STRING) { - result.add(parser.readValueAs(String.class)); - } else { - deserializationContext.handleUnexpectedToken(String.class, parser); - } - } - } else { - if (token == JsonToken.VALUE_STRING) { - result.add(parser.readValueAs(String.class)); - } else { - deserializationContext.handleUnexpectedToken(String.class, parser); - } - } - return result; - } - - } - -} diff --git a/xml/xml-psi-impl/mdn-doc-gen/gen/com/intellij/bcd/json/SimpleSupportStatement.java b/xml/xml-psi-impl/mdn-doc-gen/gen/com/intellij/bcd/json/SimpleSupportStatement.java deleted file mode 100644 index d7fa114c9bd2..000000000000 --- a/xml/xml-psi-impl/mdn-doc-gen/gen/com/intellij/bcd/json/SimpleSupportStatement.java +++ /dev/null @@ -1,228 +0,0 @@ - -package com.intellij.bcd.json; - -import java.util.ArrayList; -import java.util.List; -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonPropertyDescription; -import com.fasterxml.jackson.annotation.JsonPropertyOrder; - -@JsonInclude(JsonInclude.Include.NON_NULL) -@JsonPropertyOrder({ - "version_added", - "version_removed", - "prefix", - "alternative_name", - "flags", - "impl_url", - "partial_implementation", - "notes" -}) -public class SimpleSupportStatement { - - /** - * A string (indicating which browser version added this feature), the value true (indicating support added in an unknown version), the value false (indicating the feature is not supported), or the value null (indicating support is unknown). - * (Required) - * - */ - @JsonProperty("version_added") - @JsonPropertyDescription("A string (indicating which browser version added this feature), the value true (indicating support added in an unknown version), the value false (indicating the feature is not supported), or the value null (indicating support is unknown).") - private VersionAdded versionAdded; - /** - * A string, indicating which browser version removed this feature, or the value true, indicating that the feature was removed in an unknown version. - * - */ - @JsonProperty("version_removed") - @JsonPropertyDescription("A string, indicating which browser version removed this feature, or the value true, indicating that the feature was removed in an unknown version.") - private VersionRemoved versionRemoved; - /** - * A prefix to add to the sub-feature name (defaults to empty string). If applicable, leading and trailing '-' must be included. - * - */ - @JsonProperty("prefix") - @JsonPropertyDescription("A prefix to add to the sub-feature name (defaults to empty string). If applicable, leading and trailing '-' must be included.") - private String prefix; - /** - * An alternative name for the feature, for cases where a feature is implemented under an entirely different name and not just prefixed. - * - */ - @JsonProperty("alternative_name") - @JsonPropertyDescription("An alternative name for the feature, for cases where a feature is implemented under an entirely different name and not just prefixed.") - private String alternativeName; - /** - * An optional array of objects describing flags that must be configured for this browser to support this feature. - * - */ - @JsonProperty("flags") - @JsonPropertyDescription("An optional array of objects describing flags that must be configured for this browser to support this feature.") - private List flags = new ArrayList(); - /** - * An optional changeset/commit URL for the revision which implemented the feature in the source code, or the URL to the bug tracking the implementation, for the associated browser. - * - */ - @JsonProperty("impl_url") - @JsonPropertyDescription("An optional changeset/commit URL for the revision which implemented the feature in the source code, or the URL to the bug tracking the implementation, for the associated browser.") - private ImplUrl implUrl; - /** - * A boolean value indicating whether or not the implementation of the sub-feature deviates from the specification in a way that may cause compatibility problems. It defaults to false (no interoperability problems expected). If set to true, it is recommended that you add a note explaining how it diverges from the standard (such as that it implements an old version of the standard, for example). - * - */ - @JsonProperty("partial_implementation") - @JsonPropertyDescription("A boolean value indicating whether or not the implementation of the sub-feature deviates from the specification in a way that may cause compatibility problems. It defaults to false (no interoperability problems expected). If set to true, it is recommended that you add a note explaining how it diverges from the standard (such as that it implements an old version of the standard, for example).") - private Object partialImplementation; - /** - * A string or array of strings containing additional information. - * - */ - @JsonProperty("notes") - @JsonPropertyDescription("A string or array of strings containing additional information.") - private Notes notes; - - /** - * A string (indicating which browser version added this feature), the value true (indicating support added in an unknown version), the value false (indicating the feature is not supported), or the value null (indicating support is unknown). - * (Required) - * - */ - @JsonProperty("version_added") - public VersionAdded getVersionAdded() { - return versionAdded; - } - - /** - * A string (indicating which browser version added this feature), the value true (indicating support added in an unknown version), the value false (indicating the feature is not supported), or the value null (indicating support is unknown). - * (Required) - * - */ - @JsonProperty("version_added") - public void setVersionAdded(VersionAdded versionAdded) { - this.versionAdded = versionAdded; - } - - /** - * A string, indicating which browser version removed this feature, or the value true, indicating that the feature was removed in an unknown version. - * - */ - @JsonProperty("version_removed") - public VersionRemoved getVersionRemoved() { - return versionRemoved; - } - - /** - * A string, indicating which browser version removed this feature, or the value true, indicating that the feature was removed in an unknown version. - * - */ - @JsonProperty("version_removed") - public void setVersionRemoved(VersionRemoved versionRemoved) { - this.versionRemoved = versionRemoved; - } - - /** - * A prefix to add to the sub-feature name (defaults to empty string). If applicable, leading and trailing '-' must be included. - * - */ - @JsonProperty("prefix") - public String getPrefix() { - return prefix; - } - - /** - * A prefix to add to the sub-feature name (defaults to empty string). If applicable, leading and trailing '-' must be included. - * - */ - @JsonProperty("prefix") - public void setPrefix(String prefix) { - this.prefix = prefix; - } - - /** - * An alternative name for the feature, for cases where a feature is implemented under an entirely different name and not just prefixed. - * - */ - @JsonProperty("alternative_name") - public String getAlternativeName() { - return alternativeName; - } - - /** - * An alternative name for the feature, for cases where a feature is implemented under an entirely different name and not just prefixed. - * - */ - @JsonProperty("alternative_name") - public void setAlternativeName(String alternativeName) { - this.alternativeName = alternativeName; - } - - /** - * An optional array of objects describing flags that must be configured for this browser to support this feature. - * - */ - @JsonProperty("flags") - public List getFlags() { - return flags; - } - - /** - * An optional array of objects describing flags that must be configured for this browser to support this feature. - * - */ - @JsonProperty("flags") - public void setFlags(List flags) { - this.flags = flags; - } - - /** - * An optional changeset/commit URL for the revision which implemented the feature in the source code, or the URL to the bug tracking the implementation, for the associated browser. - * - */ - @JsonProperty("impl_url") - public ImplUrl getImplUrl() { - return implUrl; - } - - /** - * An optional changeset/commit URL for the revision which implemented the feature in the source code, or the URL to the bug tracking the implementation, for the associated browser. - * - */ - @JsonProperty("impl_url") - public void setImplUrl(ImplUrl implUrl) { - this.implUrl = implUrl; - } - - /** - * A boolean value indicating whether or not the implementation of the sub-feature deviates from the specification in a way that may cause compatibility problems. It defaults to false (no interoperability problems expected). If set to true, it is recommended that you add a note explaining how it diverges from the standard (such as that it implements an old version of the standard, for example). - * - */ - @JsonProperty("partial_implementation") - public Object getPartialImplementation() { - return partialImplementation; - } - - /** - * A boolean value indicating whether or not the implementation of the sub-feature deviates from the specification in a way that may cause compatibility problems. It defaults to false (no interoperability problems expected). If set to true, it is recommended that you add a note explaining how it diverges from the standard (such as that it implements an old version of the standard, for example). - * - */ - @JsonProperty("partial_implementation") - public void setPartialImplementation(Object partialImplementation) { - this.partialImplementation = partialImplementation; - } - - /** - * A string or array of strings containing additional information. - * - */ - @JsonProperty("notes") - public Notes getNotes() { - return notes; - } - - /** - * A string or array of strings containing additional information. - * - */ - @JsonProperty("notes") - public void setNotes(Notes notes) { - this.notes = notes; - } - -} diff --git a/xml/xml-psi-impl/mdn-doc-gen/gen/com/intellij/bcd/json/SpecUrl.java b/xml/xml-psi-impl/mdn-doc-gen/gen/com/intellij/bcd/json/SpecUrl.java deleted file mode 100644 index 46f8d3745145..000000000000 --- a/xml/xml-psi-impl/mdn-doc-gen/gen/com/intellij/bcd/json/SpecUrl.java +++ /dev/null @@ -1,50 +0,0 @@ - -package com.intellij.bcd.json; - -import java.io.IOException; -import java.util.ArrayList; -import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.core.JsonToken; -import com.fasterxml.jackson.databind.DeserializationContext; -import com.fasterxml.jackson.databind.JsonDeserializer; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; - -@JsonDeserialize(using = SpecUrl.MyDeserializer.class) -public class SpecUrl - extends ArrayList -{ - - - public static class MyDeserializer - extends JsonDeserializer - { - - - @Override - public SpecUrl deserialize(JsonParser parser, DeserializationContext deserializationContext) - throws IOException - { - SpecUrl result = new SpecUrl(); - JsonToken token = parser.currentToken(); - if (token == JsonToken.START_ARRAY) { - while (parser.nextToken()!= JsonToken.END_ARRAY) { - token = parser.currentToken(); - if (token == JsonToken.VALUE_STRING) { - result.add(parser.readValueAs(String.class)); - } else { - deserializationContext.handleUnexpectedToken(String.class, parser); - } - } - } else { - if (token == JsonToken.VALUE_STRING) { - result.add(parser.readValueAs(String.class)); - } else { - deserializationContext.handleUnexpectedToken(String.class, parser); - } - } - return result; - } - - } - -} diff --git a/xml/xml-psi-impl/mdn-doc-gen/gen/com/intellij/bcd/json/StatusBlock.java b/xml/xml-psi-impl/mdn-doc-gen/gen/com/intellij/bcd/json/StatusBlock.java deleted file mode 100644 index a38a9760be90..000000000000 --- a/xml/xml-psi-impl/mdn-doc-gen/gen/com/intellij/bcd/json/StatusBlock.java +++ /dev/null @@ -1,102 +0,0 @@ - -package com.intellij.bcd.json; - -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonPropertyDescription; -import com.fasterxml.jackson.annotation.JsonPropertyOrder; - -@JsonInclude(JsonInclude.Include.NON_NULL) -@JsonPropertyOrder({ - "experimental", - "standard_track", - "deprecated" -}) -public class StatusBlock { - - /** - * A boolean value that indicates whether this functionality is intended to be an addition to the Web platform. Set to false, it means the functionality is mature, and no significant incompatible changes are expected in the future. - * (Required) - * - */ - @JsonProperty("experimental") - @JsonPropertyDescription("A boolean value that indicates whether this functionality is intended to be an addition to the Web platform. Set to false, it means the functionality is mature, and no significant incompatible changes are expected in the future.") - private Boolean experimental; - /** - * A boolean value indicating whether the feature is part of an active specification or specification process. - * (Required) - * - */ - @JsonProperty("standard_track") - @JsonPropertyDescription("A boolean value indicating whether the feature is part of an active specification or specification process.") - private Boolean standardTrack; - /** - * A boolean value that indicates whether the feature is no longer recommended. It might be removed in the future or might only be kept for compatibility purposes. Avoid using this functionality. - * (Required) - * - */ - @JsonProperty("deprecated") - @JsonPropertyDescription("A boolean value that indicates whether the feature is no longer recommended. It might be removed in the future or might only be kept for compatibility purposes. Avoid using this functionality.") - private Boolean deprecated; - - /** - * A boolean value that indicates whether this functionality is intended to be an addition to the Web platform. Set to false, it means the functionality is mature, and no significant incompatible changes are expected in the future. - * (Required) - * - */ - @JsonProperty("experimental") - public Boolean getExperimental() { - return experimental; - } - - /** - * A boolean value that indicates whether this functionality is intended to be an addition to the Web platform. Set to false, it means the functionality is mature, and no significant incompatible changes are expected in the future. - * (Required) - * - */ - @JsonProperty("experimental") - public void setExperimental(Boolean experimental) { - this.experimental = experimental; - } - - /** - * A boolean value indicating whether the feature is part of an active specification or specification process. - * (Required) - * - */ - @JsonProperty("standard_track") - public Boolean getStandardTrack() { - return standardTrack; - } - - /** - * A boolean value indicating whether the feature is part of an active specification or specification process. - * (Required) - * - */ - @JsonProperty("standard_track") - public void setStandardTrack(Boolean standardTrack) { - this.standardTrack = standardTrack; - } - - /** - * A boolean value that indicates whether the feature is no longer recommended. It might be removed in the future or might only be kept for compatibility purposes. Avoid using this functionality. - * (Required) - * - */ - @JsonProperty("deprecated") - public Boolean getDeprecated() { - return deprecated; - } - - /** - * A boolean value that indicates whether the feature is no longer recommended. It might be removed in the future or might only be kept for compatibility purposes. Avoid using this functionality. - * (Required) - * - */ - @JsonProperty("deprecated") - public void setDeprecated(Boolean deprecated) { - this.deprecated = deprecated; - } - -} diff --git a/xml/xml-psi-impl/mdn-doc-gen/gen/com/intellij/bcd/json/SupportBlock.java b/xml/xml-psi-impl/mdn-doc-gen/gen/com/intellij/bcd/json/SupportBlock.java deleted file mode 100644 index 51091bb5c1d8..000000000000 --- a/xml/xml-psi-impl/mdn-doc-gen/gen/com/intellij/bcd/json/SupportBlock.java +++ /dev/null @@ -1,31 +0,0 @@ - -package com.intellij.bcd.json; - -import java.util.HashMap; -import java.util.Map; -import com.fasterxml.jackson.annotation.JsonAnyGetter; -import com.fasterxml.jackson.annotation.JsonAnySetter; -import com.fasterxml.jackson.annotation.JsonIgnore; -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonPropertyOrder; - -@JsonInclude(JsonInclude.Include.NON_NULL) -@JsonPropertyOrder({ - -}) -public class SupportBlock { - - @JsonIgnore - private Map additionalProperties = new HashMap(); - - @JsonAnyGetter - public Map getAdditionalProperties() { - return this.additionalProperties; - } - - @JsonAnySetter - public void setAdditionalProperty(String name, SupportStatement value) { - this.additionalProperties.put(name, value); - } - -} diff --git a/xml/xml-psi-impl/mdn-doc-gen/gen/com/intellij/bcd/json/SupportStatement.java b/xml/xml-psi-impl/mdn-doc-gen/gen/com/intellij/bcd/json/SupportStatement.java deleted file mode 100644 index 995c8009e073..000000000000 --- a/xml/xml-psi-impl/mdn-doc-gen/gen/com/intellij/bcd/json/SupportStatement.java +++ /dev/null @@ -1,66 +0,0 @@ - -package com.intellij.bcd.json; - -import java.io.IOException; -import java.util.List; -import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.core.JsonToken; -import com.fasterxml.jackson.databind.DeserializationContext; -import com.fasterxml.jackson.databind.JsonDeserializer; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; - -@JsonDeserialize(using = SupportStatement.MyDeserializer.class) -public class SupportStatement { - - /** - * Type: {@code SimpleSupportStatement | List | String} - * - */ - private Object value; - - /** - * Type: {@code SimpleSupportStatement | List | String} - * - */ - public Object getValue() { - return value; - } - - /** - * Type: {@code SimpleSupportStatement | List | String} - * - */ - public void setValue(Object value) { - this.value = value; - } - - public static class MyDeserializer - extends JsonDeserializer - { - - - @Override - public SupportStatement deserialize(JsonParser parser, DeserializationContext deserializationContext) - throws IOException - { - SupportStatement result = new SupportStatement(); - JsonToken token = parser.currentToken(); - if (token == JsonToken.START_OBJECT) { - result.value = parser.readValueAs(SimpleSupportStatement.class); - } else { - if (token == JsonToken.START_ARRAY) { - result.value = parser.getCodec().readValue(parser, deserializationContext.getTypeFactory().constructParametricType(List.class, SimpleSupportStatement.class)); - } else { - if (token == JsonToken.VALUE_STRING) { - result.value = parser.readValueAs(String.class); - } else { - deserializationContext.handleUnexpectedToken(Object.class, parser); - } - } - } - return result; - } - - } - -} diff --git a/xml/xml-psi-impl/mdn-doc-gen/gen/com/intellij/bcd/json/VersionAdded.java b/xml/xml-psi-impl/mdn-doc-gen/gen/com/intellij/bcd/json/VersionAdded.java deleted file mode 100644 index 219dc8b6bc71..000000000000 --- a/xml/xml-psi-impl/mdn-doc-gen/gen/com/intellij/bcd/json/VersionAdded.java +++ /dev/null @@ -1,61 +0,0 @@ - -package com.intellij.bcd.json; - -import java.io.IOException; -import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.core.JsonToken; -import com.fasterxml.jackson.databind.DeserializationContext; -import com.fasterxml.jackson.databind.JsonDeserializer; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; - -@JsonDeserialize(using = VersionAdded.MyDeserializer.class) -public class VersionAdded { - - /** - * Type: {@code String | Boolean} - * - */ - private Object value; - - /** - * Type: {@code String | Boolean} - * - */ - public Object getValue() { - return value; - } - - /** - * Type: {@code String | Boolean} - * - */ - public void setValue(Object value) { - this.value = value; - } - - public static class MyDeserializer - extends JsonDeserializer - { - - - @Override - public VersionAdded deserialize(JsonParser parser, DeserializationContext deserializationContext) - throws IOException - { - VersionAdded result = new VersionAdded(); - JsonToken token = parser.currentToken(); - if (token == JsonToken.VALUE_STRING) { - result.value = parser.readValueAs(String.class); - } else { - if ((token == JsonToken.VALUE_TRUE)||(token == JsonToken.VALUE_FALSE)) { - result.value = parser.readValueAs(Boolean.class); - } else { - deserializationContext.handleUnexpectedToken(Object.class, parser); - } - } - return result; - } - - } - -} diff --git a/xml/xml-psi-impl/mdn-doc-gen/gen/com/intellij/bcd/json/VersionRemoved.java b/xml/xml-psi-impl/mdn-doc-gen/gen/com/intellij/bcd/json/VersionRemoved.java deleted file mode 100644 index 31093631c4b3..000000000000 --- a/xml/xml-psi-impl/mdn-doc-gen/gen/com/intellij/bcd/json/VersionRemoved.java +++ /dev/null @@ -1,61 +0,0 @@ - -package com.intellij.bcd.json; - -import java.io.IOException; -import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.core.JsonToken; -import com.fasterxml.jackson.databind.DeserializationContext; -import com.fasterxml.jackson.databind.JsonDeserializer; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; - -@JsonDeserialize(using = VersionRemoved.MyDeserializer.class) -public class VersionRemoved { - - /** - * Type: {@code String | Boolean} - * - */ - private Object value; - - /** - * Type: {@code String | Boolean} - * - */ - public Object getValue() { - return value; - } - - /** - * Type: {@code String | Boolean} - * - */ - public void setValue(Object value) { - this.value = value; - } - - public static class MyDeserializer - extends JsonDeserializer - { - - - @Override - public VersionRemoved deserialize(JsonParser parser, DeserializationContext deserializationContext) - throws IOException - { - VersionRemoved result = new VersionRemoved(); - JsonToken token = parser.currentToken(); - if (token == JsonToken.VALUE_STRING) { - result.value = parser.readValueAs(String.class); - } else { - if ((token == JsonToken.VALUE_TRUE)||(token == JsonToken.VALUE_FALSE)) { - result.value = parser.readValueAs(Boolean.class); - } else { - deserializationContext.handleUnexpectedToken(Object.class, parser); - } - } - return result; - } - - } - -} diff --git a/xml/xml-psi-impl/mdn-doc-gen/gen/com/intellij/bcd/json/Webextensions.java b/xml/xml-psi-impl/mdn-doc-gen/gen/com/intellij/bcd/json/Webextensions.java deleted file mode 100644 index 08d967095243..000000000000 --- a/xml/xml-psi-impl/mdn-doc-gen/gen/com/intellij/bcd/json/Webextensions.java +++ /dev/null @@ -1,31 +0,0 @@ - -package com.intellij.bcd.json; - -import java.util.HashMap; -import java.util.Map; -import com.fasterxml.jackson.annotation.JsonAnyGetter; -import com.fasterxml.jackson.annotation.JsonAnySetter; -import com.fasterxml.jackson.annotation.JsonIgnore; -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonPropertyOrder; - -@JsonInclude(JsonInclude.Include.NON_NULL) -@JsonPropertyOrder({ - -}) -public class Webextensions { - - @JsonIgnore - private Map additionalProperties = new HashMap(); - - @JsonAnyGetter - public Map getAdditionalProperties() { - return this.additionalProperties; - } - - @JsonAnySetter - public void setAdditionalProperty(String name, Object value) { - this.additionalProperties.put(name, value); - } - -} diff --git a/xml/xml-psi-impl/mdn-doc-gen/intellij.documenation.mdn.gen.iml b/xml/xml-psi-impl/mdn-doc-gen/intellij.documenation.mdn.gen.iml deleted file mode 100644 index 3a22e55063bd..000000000000 --- a/xml/xml-psi-impl/mdn-doc-gen/intellij.documenation.mdn.gen.iml +++ /dev/null @@ -1,43 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/xml/xml-psi-impl/mdn-doc-gen/src/BaseLineService.kt b/xml/xml-psi-impl/mdn-doc-gen/src/BaseLineService.kt deleted file mode 100644 index bc4b6a2a8f63..000000000000 --- a/xml/xml-psi-impl/mdn-doc-gen/src/BaseLineService.kt +++ /dev/null @@ -1,113 +0,0 @@ -import com.google.gson.GsonBuilder -import com.google.gson.JsonObject -import com.intellij.lang.javascript.JSStringUtil -import com.intellij.openapi.application.PathManager -import com.intellij.openapi.util.io.FileUtil -import java.io.BufferedReader -import java.io.BufferedWriter -import java.io.File -import java.io.IOException - -object BaseLineService { - private val logger = com.intellij.openapi.diagnostic.Logger.getInstance(BaseLineService::class.java) - private var process: Process? = null - private var writer: BufferedWriter? = null - private var reader: BufferedReader? = null - private val gson = GsonBuilder().create() - - @Synchronized - fun start() { - if (process != null) { - return - } - - try { - val baselineServerPath = FileUtil.toSystemDependentName( - "${PathManager.getCommunityHomePath()}/xml/xml-psi-impl/mdn-doc-gen/baseline-server" - ) - - val processBuilder = ProcessBuilder("node", "index.mjs") - processBuilder.directory(File(baselineServerPath)) - processBuilder.redirectError(ProcessBuilder.Redirect.INHERIT) - - process = processBuilder.start() - writer = process!!.outputStream.bufferedWriter() - reader = process!!.inputStream.bufferedReader() - - // Add shutdown hook to ensure process is terminated when JVM exits - Runtime.getRuntime().addShutdownHook(Thread { - stop() - }) - } - catch (e: Exception) { - logger.error("Failed to start BaseLineService", e) - stop() - throw e - } - } - - @Synchronized - fun stop() { - try { - try { - writer?.close() - } - catch (_: IOException) { - } - try { - reader?.close() - } - catch (_: IOException) { - } - process?.let { - if (it.isAlive) { - it.destroy() - it.waitFor(5, java.util.concurrent.TimeUnit.SECONDS) - if (it.isAlive) { - it.destroyForcibly() - } - } - } - } - catch (e: Exception) { - logger.error("Error stopping BaseLineService", e) - } - finally { - writer = null - reader = null - process = null - logger.info("BaseLineService stopped") - } - } - - @Synchronized - fun computeBaseline(compatKey: String): JsonObject? { - if (process == null || writer == null || reader == null) { - start() - } - - try { - // Write the compatKey to stdin - writer!!.write(compatKey) - writer!!.newLine() - writer!!.flush() - - // Read the response from stdout - val response = reader!!.readLine() ?: return null - - // Parse the JSON response - val json = JSStringUtil.unquoteAndUnescapeString(response) - if (json == "null") - return null - return gson.fromJson(json, JsonObject::class.java) - } - catch (e: Exception) { - logger.error("Error computing baseline for key: $compatKey", e) - if (e is IOException) { - stop() - start() - } - return null - } - } -} diff --git a/xml/xml-psi-impl/mdn-doc-gen/src/BcdUtil.kt b/xml/xml-psi-impl/mdn-doc-gen/src/BcdUtil.kt deleted file mode 100644 index c77af7009eca..000000000000 --- a/xml/xml-psi-impl/mdn-doc-gen/src/BcdUtil.kt +++ /dev/null @@ -1,32 +0,0 @@ -import com.fasterxml.jackson.databind.DeserializationFeature -import com.fasterxml.jackson.databind.ObjectMapper -import com.fasterxml.jackson.databind.type.TypeFactory -import com.intellij.bcd.json.Bcd -import com.intellij.bcd.json.Identifier -import java.io.File -import java.io.InputStream - -fun readBcd(path: String): Bcd = - File(path).inputStream().readBcd() - -fun Bcd.resolve(path: String): Identifier = - tryResolve(path) ?: throw RuntimeException("Failed to resolve $path") - -fun Bcd.tryResolve(path: String): Identifier? { - val segments = path.split('.', '/') - if (segments.isEmpty()) return null - var result = this.additionalProperties[segments[0]] - ?: return null - for (segment in segments.subList(1, segments.size)) { - result = result.additionalProperties[segment] - ?: return null - } - return result -} - - -private val objectMapper = ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false) - .setTypeFactory(TypeFactory.defaultInstance().withClassLoader(Bcd::class.java.classLoader)) - -private fun InputStream.readBcd(): Bcd = - objectMapper.readValue(this, Bcd::class.java) \ No newline at end of file diff --git a/xml/xml-psi-impl/mdn-doc-gen/src/GenerateMdnDocumentation.kt b/xml/xml-psi-impl/mdn-doc-gen/src/GenerateMdnDocumentation.kt deleted file mode 100644 index a9f9cb96deca..000000000000 --- a/xml/xml-psi-impl/mdn-doc-gen/src/GenerateMdnDocumentation.kt +++ /dev/null @@ -1,1549 +0,0 @@ -// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. -import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper -import com.google.gson.* -import com.google.gson.stream.JsonReader -import com.intellij.application.options.CodeStyle -import com.intellij.bcd.json.* -import com.intellij.documentation.mdn.* -import com.intellij.ide.highlighter.HtmlFileType -import com.intellij.lang.html.HTMLLanguage -import com.intellij.lang.javascript.index.JSIndexKeys -import com.intellij.lang.javascript.library.JSCorePredefinedLibrariesProvider -import com.intellij.lang.javascript.psi.JSPsiElementBase -import com.intellij.lang.javascript.psi.types.JSNamedTypeFactory -import com.intellij.lang.javascript.psi.types.JSTypeContext -import com.intellij.lang.javascript.psi.types.JSTypeSourceFactory -import com.intellij.openapi.application.PathManager -import com.intellij.openapi.util.io.FileUtil -import com.intellij.openapi.util.text.StringUtil -import com.intellij.psi.* -import com.intellij.psi.codeStyle.CodeStyleSettingsManager -import com.intellij.psi.codeStyle.CommonCodeStyleSettings -import com.intellij.psi.formatter.xml.HtmlCodeStyleSettings -import com.intellij.psi.impl.source.html.HtmlFileImpl -import com.intellij.psi.stubs.StubIndex -import com.intellij.psi.util.PsiTreeUtil -import com.intellij.psi.xml.* -import com.intellij.testFramework.fixtures.BasePlatformTestCase -import com.intellij.util.applyIf -import com.intellij.util.asSafely -import com.intellij.util.text.CharSequenceSubSequence -import com.intellij.util.text.NameUtilCore -import com.intellij.xml.util.Html5TagAndAttributeNamesProvider -import java.io.File -import java.io.FileReader -import java.lang.reflect.Type -import java.nio.file.Path -import java.util.* -import java.util.function.BiFunction - -val htmlSpecialMappings = mapOf( - "heading_elements" to setOf("h1", "h2", "h3", "h4", "h5", "h6") -) - -/** - * When adding a known property here, ensure that there is appropriate key in XmlPsiBundle. - */ -const val defaultBcdContext = "\$default_context" - -val jsRuntimesMap = MdnJavaScriptRuntime.entries.associateBy { it.mdnId } - -val BROWSER_COMPAT_DATA_PATH = PathManager.getCommunityHomePath() + "/xml/xml-psi-impl/mdn-doc-gen/work/browser-compat-data.json" -val MDN_CONTENT_ROOT = PathManager.getCommunityHomePath() + "/xml/xml-psi-impl/mdn-doc-gen/work/mdn-content/files" -val YARI_BUILD_PATH = PathManager.getCommunityHomePath() + "/xml/xml-psi-impl/mdn-doc-gen/work/yari/client/build" -const val BUILT_LANG = "en-us" -const val WEB_DOCS = "docs/web" -const val MDN_DOCS_URL_PREFIX = "\$MDN_URL\$" -const val OUTPUT_DIR = "xml/xml-psi-impl/resources-gen/com/intellij/documentation/mdn/" -const val BUNDLE_OUTPUT_DIR = "xml/xml-psi-impl/resources-gen/messages/" - - -private val LICENSE = MdnNameWithUrl( - "CC-BY-SA 2.5", - "https://creativecommons.org/licenses/by-sa/2.5/", -) - -private val AUTHOR = MdnNameWithUrl( - "Mozilla Contributors", - "https://github.com/mdn/content", -) - -const val SEE_REFERENCE = "\$SEE_REFERENCE\$" -val seePattern = Regex("

See [a-z0-9_\\-]+\\.

", - RegexOption.IGNORE_CASE) - -val svgAttributeSectionsPattern = Regex( - "(.*)Value type\\s*:(.*)\\s*Default value(?:)?\\s*:(.*)\\s+(?:)?Animatable\\s*:\\s*(.*)", - RegexOption.DOT_MATCHES_ALL) - -val bcd: Bcd = readBcd(BROWSER_COMPAT_DATA_PATH) - -val jsWebApiNameFilter: (String) -> Boolean = { name -> - !name.contains('-') - && (!name.contains("_") || name.endsWith("_static")) - && name != "index" -} - -val bcdIdDescriptions = mutableMapOf() - -/** - * Run the tests to generate documentation. Prepare MDN documentation repositories with `prepare-mdn.sh`. - * Afterwards run MdnDocUpdateTestSuite to update any failing tests due to doc content changes. - * - * It's so much easier to run a test, than to setup the whole IJ environment. - * - */ -class GenerateMdnDocumentation : BasePlatformTestCase() { - - /* Run these tests to generate documentation. Prepare MDN documentation repositories with `prepare-mdn.sh` */ - fun testGenHtml() { - val attributes = - extractInformationSimple("html.global_attributes", "html/reference/global_attributes", listOf('_', '-'), - this::extractAttributeDocumentation) - outputJson(MdnApiNamespace.Html.name, MdnHtmlDocumentation( - LICENSE, AUTHOR, BUILT_LANG, - attributes, - extractInformationSimple("html.elements", "html/reference/elements", listOf('_', '-'), - allowList = htmlSpecialMappings.keys) { dir, bcdPath, bcdInfo -> - this.extractElementDocumentation(dir, "html/reference/attributes", "html/reference/global_attributes", - bcdPath, bcdInfo, attributes) - }, - reversedAliasesMap(htmlSpecialMappings) - )) - } - - fun testGenMathML() { - val attributes = - extractInformationSimple("mathml.global_attributes", "mathml/reference/global_attributes", emptyList(), - this::extractAttributeDocumentation) - outputJson(MdnApiNamespace.MathML.name, MdnHtmlDocumentation( - LICENSE, AUTHOR, BUILT_LANG, - attributes, - extractInformationSimple("mathml.elements", "mathml/reference/element", emptyList()) { dir, bcdPath, bcdInfo -> - this.extractElementDocumentation(dir, "mathml/reference/attribute", "mathml/reference/global_attributes", - bcdPath, bcdInfo, attributes) - } - )) - } - - fun testGenSvg() { - val attributes = extractInformationSimple("svg.global_attributes", "svg/reference/attribute", listOf('_')) { dir, bcdPath, bcd -> - extractAttributeDocumentation(dir, bcdPath, bcd) - } - val tags = extractInformationSimple("svg.elements", "svg/reference/element", listOf('_')) { dir, bcdPath, bcdInfo -> - this.extractElementDocumentation(dir, "svg/reference/attribute", null, bcdPath, bcdInfo, attributes) - } - - val knownAttributes = mutableSetOf() - val neededGlobalAttributes = mutableSetOf("requiredfeatures") - val tag = tags["svg"] - for (attrName in Html5TagAndAttributeNamesProvider.getTagAttributes(Html5TagAndAttributeNamesProvider.Namespace.HTML, "svg", false)!!) { - knownAttributes.add(attrName.toString().lowercase()) - if (tag?.attrs?.keys?.find { it.equals(attrName.toString(), true) } == null) { - neededGlobalAttributes.add(attrName.toString()) - } - } - for (tagName in Html5TagAndAttributeNamesProvider.getTags(Html5TagAndAttributeNamesProvider.Namespace.SVG, false)) { - val tag = tags[tagName.toString().lowercase()] - for (attrName in Html5TagAndAttributeNamesProvider.getTagAttributes(Html5TagAndAttributeNamesProvider.Namespace.SVG, tagName, false)!!) { - knownAttributes.add(attrName.toString().lowercase()) - if (tag?.attrs?.keys?.find { it.equals(attrName.toString(), true) } == null) { - neededGlobalAttributes.add(attrName.toString()) - } - } - } - - outputJson(MdnApiNamespace.Svg.name, MdnHtmlDocumentation( - LICENSE, AUTHOR, BUILT_LANG, attributes.filter { it.key in neededGlobalAttributes || it.key !in knownAttributes }, tags - )) - } - - fun testGenJsWebApi() { - val symbols = extractInformation( - "api", bcd.resolve("api"), jsWebApiNameFilter - ) { dir, _, bcdInfo -> - extractJavascriptDocumentation(dir, bcdInfo, "") - } - .filter { !it.key.startsWith("window.window.") } - .resolveReferences() - val fragments = webApiFragmentStarts.associateWithTo(TreeMap()) { sortedMapOf() } - symbols.forEach { (name, doc) -> - (fragments.floorEntry(name[0]) ?: throw IllegalStateException("Null entry for $name")).value[name] = doc - } - fragments.forEach { (prefix, symbols) -> - outputJson("${MdnApiNamespace.WebApi.name}-$prefix", MdnJsDocumentation( - LICENSE, AUTHOR, BUILT_LANG, symbols - )) - } - - val index = createDtsMdnIndex(symbols) - FileUtil.writeToFile(Path.of(PathManager.getCommunityHomePath(), OUTPUT_DIR, "${MdnApiNamespace.WebApi.name}-index.json").toFile(), - GsonBuilder().setPrettyPrinting().disableHtmlEscaping().create() - .toJson(index)) - } - - fun testGenJsGlobalObjects() { - outputJson(MdnApiNamespace.GlobalObjects.name, MdnJsDocumentation( - LICENSE, AUTHOR, BUILT_LANG, - extractInformation("javascript/reference/global_objects", bcd.resolve("javascript.builtins"), - listOf('-', '_')) { it, _, bcdInfo -> - extractJavascriptDocumentation(it, bcdInfo, "") - }.resolveReferences() - )) - } - - fun testGenCss() { - outputJson(MdnApiNamespace.Css.name, buildCssDocs()) - } - - fun testGenDomEvents() { - outputJson(MdnApiNamespace.DomEvents.name, MdnDomEventsDocumentation( - LICENSE, AUTHOR, BUILT_LANG, extractDomEvents(), - )) - } - - override fun setUp() { - super.setUp() - val manager = CodeStyleSettingsManager.getInstance(project) - @Suppress("DEPRECATION") val currSettings = manager.currentSettings - val clone = CodeStyle.createTestSettings(currSettings) - manager.setTemporarySettings(clone) - val htmlSettings = clone.getCustomSettings(HtmlCodeStyleSettings::class.java) - htmlSettings.HTML_ATTRIBUTE_WRAP = CommonCodeStyleSettings.DO_NOT_WRAP - htmlSettings.HTML_TEXT_WRAP = CommonCodeStyleSettings.DO_NOT_WRAP - clone.getCommonSettings(HTMLLanguage.INSTANCE).softMargins.clear() - } - - override fun tearDown() { - try { - CodeStyleSettingsManager.getInstance(project).dropTemporarySettings() - } - catch (e: Throwable) { - addSuppressedException(e) - } - finally { - super.tearDown() - } - } - - private fun outputJson(outputFile: String, data: MdnDocumentation) { - val targetFile = Path.of(PathManager.getCommunityHomePath(), OUTPUT_DIR, "$outputFile.json").toFile() - if (data is MdnHtmlDocumentation || data is MdnCssDocumentation || data is MdnDomEventsDocumentation) { - val targetObsoleteFile = Path.of(PathManager.getCommunityHomePath(), OUTPUT_DIR, "$outputFile-obsolete.json").toFile() - - val obsoleteData = jacksonObjectMapper().readValue(targetObsoleteFile, data::class.java) - val currentData = jacksonObjectMapper().readValue(targetFile, data::class.java) - - when (data) { - is MdnDomEventsDocumentation -> { - currentData as MdnDomEventsDocumentation - obsoleteData as MdnDomEventsDocumentation - - makeMissingSymbolsObsolete(data, currentData, obsoleteData, MdnDomEventsDocumentation::events) { - it.copy(status = setOf(MdnApiStatus.Obsolete)) - } - } - is MdnHtmlDocumentation -> { - currentData as MdnHtmlDocumentation - obsoleteData as MdnHtmlDocumentation - - makeMissingSymbolsObsolete( - data, currentData, obsoleteData, MdnHtmlDocumentation::tags, - { it.copy(status = setOf(MdnApiStatus.Obsolete)) }, - MdnHtmlElementDocumentation::attrs, - { MdnHtmlElementDocumentation(null, null, null, null, "", null, mutableMapOf()) }, - { it.copy(status = setOf(MdnApiStatus.Obsolete)) }, - ) - makeMissingSymbolsObsolete(data, currentData, obsoleteData, MdnHtmlDocumentation::attrs) { - it.copy(status = setOf(MdnApiStatus.Obsolete)) - } - } - is MdnCssDocumentation -> { - currentData as MdnCssDocumentation - obsoleteData as MdnCssDocumentation - - makeMissingSymbolsObsolete( - data, currentData, obsoleteData, MdnCssDocumentation::atRules, - { it.copy(status = setOf(MdnApiStatus.Obsolete)) }, - MdnCssAtRuleSymbolDocumentation::properties, - { MdnCssAtRuleSymbolDocumentation(null, null, null, null, "", mutableMapOf(), null) }, - { it.copy(status = setOf(MdnApiStatus.Obsolete)) } - ) - makeMissingSymbolsObsolete(data, currentData, obsoleteData, MdnCssDocumentation::properties) { - it.copy(status = setOf(MdnApiStatus.Obsolete)) - } - makeMissingSymbolsObsolete(data, currentData, obsoleteData, MdnCssDocumentation::pseudoClasses) { - it.copy(status = setOf(MdnApiStatus.Obsolete)) - } - makeMissingSymbolsObsolete(data, currentData, obsoleteData, MdnCssDocumentation::pseudoElements) { - it.copy(status = setOf(MdnApiStatus.Obsolete)) - } - makeMissingSymbolsObsolete(data, currentData, obsoleteData, MdnCssDocumentation::functions) { - it.copy(status = setOf(MdnApiStatus.Obsolete)) - } - makeMissingSymbolsObsolete(data, currentData, obsoleteData, MdnCssDocumentation::dataTypes) { - it.copy(status = setOf(MdnApiStatus.Obsolete)) - } - } - else -> throw RuntimeException("Unsupported documentation type: ${data::class.java.name}") - } - FileUtil.writeToFile(targetObsoleteFile, GsonBuilder().setPrettyPrinting().disableHtmlEscaping() - .registerTypeAdapter(Map::class.java, CompatibilityMapSerializer(true)) - .create().toJson(obsoleteData)) - } - FileUtil.writeToFile(targetFile, GsonBuilder().setPrettyPrinting().disableHtmlEscaping() - .registerTypeAdapter(Map::class.java, CompatibilityMapSerializer(false)) - .create().toJson(data)) - updateBcdDescriptions() - } - - private fun extractInformationSimple( - bcdPath: String, mdnPath: String, - disallowedChars: List, - extractor: (File, String?, Identifier?) -> T?, - ): Map = - extractInformationSimple(bcdPath, mdnPath, disallowedChars, emptySet()) { file, innerBcdPath, id -> - extractor(file, innerBcdPath, id) - } - - private fun extractInformationSimple( - bcdPath: String, mdnPath: String, disallowedChars: List, - allowList: Set, extractor: (File, String?, Identifier?) -> T?, - ): Map = - extractInformation(mdnPath, bcd.resolve(bcdPath), disallowedChars, bcdPath, allowList) { docDir, innerBcdPath, id -> - try { - extractor(docDir, innerBcdPath, id)?.let { listOf(Pair(docDir.name, it)) } ?: emptyList() - } - catch (e: Exception) { - System.err.println("Error for $docDir: ${e.message}") - throw e - } - } - - private fun getMdnDir(mdnPath: String): File = - Path.of(YARI_BUILD_PATH, BUILT_LANG, WEB_DOCS, mdnPath - .replace("*", "_star_") - .replace("::", "_doublecolon_") - .replace(":", "_colon_") - ).toFile() - - private fun extractInformation( - mdnPath: String, - bcd: Identifier?, - disallowedChars: List, - bcdPath: String? = null, - allowList: Set = emptySet(), - blockList: Set = emptySet(), - mdnUrlBuilder: ((String, Identifier) -> String?)? = null, - extractor: (File, String?, Identifier?) -> List>, - ): Map = - extractInformation(mdnPath, bcd, - { (disallowedChars.none { ch -> it.contains(ch) } || allowList.contains(it)) && !blockList.contains(it) }, - bcdPath, mdnUrlBuilder, extractor) - - private fun extractInformation( - mdnPath: String, - bcd: Identifier?, - nameFilter: (String) -> Boolean, - bcdPath: String? = null, - mdnUrlBuilder: ((String, Identifier) -> String?)? = null, - extractor: (File, String?, Identifier?) -> List>, - ): Map { - val namesWithBcd = mutableSetOf() - val resultWithBcd = (bcd?.additionalProperties?.asSequence() ?: emptySequence()) - .flatMap { (name, bcd) -> - if (bcd.compat == null) { - bcd.additionalProperties.entries.map { Pair(name + "/" + it.key, it.value) } - } - else listOf(Pair(name, bcd)) - } - .flatMap { (name, bcdInfo) -> - if (!nameFilter(name)) return@flatMap emptyList() - try { - val mdnUrl = bcdInfo.compat?.mdnUrl?.lowercase(Locale.US)?.removePrefix("https://developer.mozilla.org/docs/web/") - ?: mdnUrlBuilder?.invoke(name, bcdInfo) - ?: "$mdnPath/$name" - val dir = getMdnDir(mdnUrl).let { - if (it.name.endsWith("()") && !it.exists()) { - val suffixed = File(it.parentFile, it.name.removeSuffix("()") + "_function") - if (suffixed.exists()) return@let suffixed - } - it - } - if (!dir.exists()) { - System.err.println("Dir not found: $dir") - emptyList() - } - else { - namesWithBcd.add(dir.name.takeLastWhile { it != '/' }.lowercase(Locale.US)) - extractor(dir, bcdPath?.let { "$bcdPath.${name.replace('/', '.')}" }, bcdInfo) - } - } - catch (e: Exception) { - throw RuntimeException("Failed to process $mdnPath/$name: ${e.message}", e) - } - } - .toMap(TreeMap()) - - val resultWithoutBcd = (getMdnDir(mdnPath).listFiles()?.asSequence() ?: emptySequence()) - .filter { file -> - file.isDirectory - && file.name.lowercase(Locale.US).let { nameFilter(it) && !namesWithBcd.contains(it) } - && File(file, "index.json").exists() - } - .flatMap { - try { - extractor(it, null, null) - } - catch (e: Exception) { - throw RuntimeException("Failed to process $it: ${e.message}", e) - } - } - .distinct() - .sortedBy { it.first } - .toMap() - return TreeMap(resultWithoutBcd + resultWithBcd) - } - - private fun extractElementDocumentation( - dir: File, - attributesMdnPath: String, - globalAttributesMdnPath: String?, - bcdPath: String?, - compatData: Identifier?, - commonAttributes: Map, - ): MdnHtmlElementDocumentation { - val contents = DocContents(dir, compatData) - - val elementDoc = contents.prose.first().getProseContent().appendOtherSections(contents.prose) - - val attributesDoc = contents.prose.filterProseById( - "attributes", - "individual_attributes", - "attributes_for_form_submission", - "deprecated_attributes", - "obsolete_attributes", - "non-standard_attributes", - ) - .joinToString("\n") { it.getProseContent().content } - .let { RawProse(it) } - - val status = extractStatus(contents) - val compatibility = extractCompatibilityInfo(contents) - val doc = processElementDocumentation(elementDoc, contents.prose.getProseContentById("summary")) - - val documentation = doc.first - val properties = doc.second.takeIf { it.isNotEmpty() } - ?: contents.prose.filterProseById("properties", "technical_summary") - .firstOrNull() - ?.getProseContent() - ?.let { processElementDocumentation(it, null) } - ?.second - ?.takeIf { it.isNotEmpty() } - - return MdnHtmlElementDocumentation(getMdnDocsUrl(dir), status, compatibility, contents.baseline, documentation, properties, - buildAttributes(dir, getMdnDir(attributesMdnPath), globalAttributesMdnPath?.let { getMdnDir(it) }, - attributesDoc, bcdPath, compatData, commonAttributes)) - } - - private fun extractAttributeDocumentation(dir: File, bcdPath: String?, compatData: Identifier?): MdnHtmlAttributeDocumentation { - val contents = DocContents(dir, compatData, bcdPath) - return MdnHtmlAttributeDocumentation(getMdnDocsUrl(dir), extractStatus(contents), - extractCompatibilityInfo(contents), - contents.baseline, - extractDescription(contents.prose, true)) - } - - private fun extractDomEvents(): Map { - val prefix = "/$BUILT_LANG/$WEB_DOCS/events/" - return redirects.asSequence() - .filter { (from, to) -> - from.startsWith(prefix) - && !from.contains("_") - && !to.contains("#") - && !to.endsWith("/window") - } - .mapNotNull { - Pair(it.key.substring(prefix.length), - extractDomEventDocumentation(Path.of(YARI_BUILD_PATH, it.value).toFile()) ?: return@mapNotNull null) - } - .toMap() - } - - private fun extractDomEventDocumentation(dir: File): MdnDomEventDocumentation? { - val contents = DocContents(dir, null) - return MdnDomEventDocumentation(getMdnDocsUrl(dir), extractStatus(contents), - extractCompatibilityInfo(contents), - contents.baseline, - extractEventDescription(contents.prose) ?: return null) - } - - private fun extractJavascriptDocumentation( - dir: File, - compatData: Identifier?, - namePrefix: String, - ): List> { - try { - val contents = DocContents(dir, compatData) - val thisNamePrefix = "$namePrefix${dir.name.lowercase(Locale.US)}".removeSuffix("_static") - return extractInformation(dir.toMdnUrl(), compatData, jsWebApiNameFilter) { subDir, _, subBcdInfo -> - extractJavascriptDocumentation( - subDir, subBcdInfo, "$thisNamePrefix.") - }.toList() + - Pair(thisNamePrefix, - MdnJsSymbolDocumentation(getMdnDocsUrl(dir), compatData?.let { extractStatus(contents) }, - compatData?.let { extractCompatibilityInfo(contents) }, - contents.baseline, - extractDescription(contents.prose), - extractParameters(contents.prose), - extractReturns(contents.prose)?.patch(), - extractThrows(contents.prose))) - - } - catch (e: Exception) { - System.err.println("Error for $dir: ${e.message}") - throw e - } - } - - private fun buildCssDocs(): MdnCssDocumentation { - val result = TreeMap>() - extractInformation( - "css", - bcd.resolve("css"), - { - (it.contains("_colon_") || it.contains("_doublecolon_") || it.endsWith("_function") || !it.contains('_')) - }, - ) { docDir, _, bcdInfo -> - try { - if (!docDir.isDirectory) return@extractInformation emptyList() - val info = CssElementInfo(docDir) - if (info.hasDataType) { - extractInformation(docDir.toMdnUrl(), bcdInfo, { true }) { innerDocDir, _, innerBcdInfo -> - try { - listOf(Pair(CssElementInfo(innerDocDir).name, - extractCssElementDocumentation(innerDocDir, innerBcdInfo))) - } - catch (e: Exception) { - System.err.println("Error for $innerDocDir: ${e.message}") - throw e - } - }.toList() - } - else { - emptyList() - } + Pair(info.name, extractCssElementDocumentation(docDir, bcdInfo)) - } - catch (e: Exception) { - System.err.println("Error for $docDir: ${e.message}") - throw e - } - } - .forEach { (name, doc) -> - when { - name.startsWith("_colon_") -> Pair("pseudoClasses", name.substring("_colon_".length)) - name.startsWith("_doublecolon_") -> Pair("pseudoElements", name.substring("_doublecolon_".length)) - name.startsWith("@") -> Pair("atRules", name.substring(1)) - name.startsWith("<") -> Pair("dataTypes", name.substring(1, name.length - 1)) - name.endsWith("()") -> Pair("functions", name.substring(0, name.length - 2)) - else -> Pair("properties", name) - }.let { (kind, simpleName) -> - result.getOrPut(kind, ::TreeMap)[simpleName] = doc - } - } - postProcessProperties(result["properties"] as MutableMap) - return MdnCssDocumentation( - LICENSE, AUTHOR, BUILT_LANG, - result["atRules"]!!.mapValues { it.value as MdnCssAtRuleSymbolDocumentation }, - result["dataTypes"]!!.mapValues { it.value as MdnCssPropertySymbolDocumentation }, - result["functions"]!!.mapValues { it.value as MdnCssPropertySymbolDocumentation }, - result["properties"]!!.mapValues { it.value as MdnCssPropertySymbolDocumentation }, - result["pseudoClasses"]!!.mapValues { it.value.asMdnCssBasicSymbolDocumentation() }, - result["pseudoElements"]!!.mapValues { it.value.asMdnCssBasicSymbolDocumentation() }, - ) - } - - private fun MdnRawSymbolDocumentation.asMdnCssBasicSymbolDocumentation() = - this as? MdnCssBasicSymbolDocumentation - ?: MdnCssBasicSymbolDocumentation(url, status, compatibility, baseline, doc, (this as? MdnCssPropertySymbolDocumentation)?.formalSyntax) - - private fun extractCssElementDocumentation(dir: File, compatData: Identifier?): MdnRawSymbolDocumentation { - val contents = DocContents(dir, compatData) - val url = getMdnDocsUrl(dir) - val status = extractStatus(contents) - val compatibility = extractCompatibilityInfo(contents) - val description = extractDescription(contents.prose) - val dirName = dir.name - return when { - dirName.startsWith('_') || dirName.endsWith("()") -> - MdnCssBasicSymbolDocumentation(url, status, compatibility, contents.baseline, description, extractFormalSyntax(contents.prose)) - dirName.startsWith('@') -> - MdnCssAtRuleSymbolDocumentation( - url, status, compatibility, contents.baseline, description, - extractInformation(dir.toMdnUrl(), compatData, { !it.contains('_') }) { docDir, _, innerBcdInfo -> - try { - if (!docDir.isDirectory) { - emptyList() - } - else { - listOf(Pair(docDir.name, - extractCssElementDocumentation(docDir, innerBcdInfo) as MdnCssPropertySymbolDocumentation)) - } - } - catch (e: Exception) { - System.err.println("Error for $docDir: ${e.message}") - throw e - } - }.takeIf { it.isNotEmpty() }, extractFormalSyntax(contents.prose) - ) - else -> - MdnCssPropertySymbolDocumentation( - url, status, compatibility, contents.baseline, description, extractFormalSyntax(contents.prose), extractPropertyValues(contents.prose)) - } - } - - private fun postProcessProperties(properties: MutableMap) { - properties.computeIfPresent("place-items", BiFunction { _, doc -> - val alignItems = properties["align-items"]!! as MdnCssPropertySymbolDocumentation - val justifyItems = properties["justify-items"]!! as MdnCssPropertySymbolDocumentation - (doc as MdnCssPropertySymbolDocumentation).copy( - values = alignItems.values!! + justifyItems.values!! - ) - }) - } - - private fun extractDescription(indexDataProseValues: List, appendOtherSections: Boolean = false): String = - indexDataProseValues.firstOrNull()?.getProseContent()?.applyIf(appendOtherSections) { appendOtherSections(indexDataProseValues) } - ?.let { createHtmlFile(it).patchedText() } - ?: "" - - private fun extractFormalSyntax(indexDataProseValues: List): String? = - indexDataProseValues.getProseContentById("formal_syntax") - ?.let { createHtmlFile(it) } - ?.let { PsiTreeUtil.findChildOfType(it, XmlTag::class.java) } - ?.let { extractPreText(it) } - ?.patchProse() - ?.replace(" ", " ") - ?.replace(Regex("\n +"), "\n") - ?.let { formatFormalCssSyntax(it) } - - private fun formatFormalCssSyntax(str: String): String { - if (str.startsWith("\n```css")) { - return str.removePrefix("\n```css\n").removeSuffix("\n```\n") - .replace(Regex(" +"), " ") - } - val result = StringBuilder() - val firstEquals = str.indexOf('=') - val firstLine = str.indexOf('\n') - val start = if (firstEquals < 0 || firstLine in 0 until firstEquals) 0 else firstEquals + 1 - var i = start - var indentation = 1 - while (i < str.length) { - val seq = CharSequenceSubSequence(str, i, str.length) - val prevContents = CharSequenceSubSequence(str, start, i) - if (prevContents.endsWith("\n\n")) { - if (seq.startsWith("where ")) { - if (indentation == 2) break - i += "where ".length - result.append("\n") - repeat(++indentation) { result.append("  ") } - continue - } - else if (seq.startsWith("<")) { - result.append("\n") - repeat(indentation) { result.append("  ") } - result.append("<") - i += "<".length - continue - } - result.append(str[i++]) - } - else { - val prevChar = if (i <= 0) ' ' else str[i - 1] - when (val ch = str[i++]) { - ' ' -> - if (prevChar != ' ') - result.append(" ") - '\n' -> - when (prevChar) { - '(' -> result.append('\n') - '|' -> result.append(" ") - } - else -> result.append(ch) - } - } - } - return result.toString() - .replace(Regex("[ \n]+\n"), "\n") - .trim() - } - - private fun extractEventDescription(indexDataProseValues: List): String? = - indexDataProseValues.first().getProseContent() - .let { createHtmlFile(it) } - .children[0].children.filter { it is XmlTag && it.name == "p" } - .takeIf { it.isNotEmpty() } - ?.joinToString("\n") { it.patchedText() } - - private fun reversedAliasesMap(specialMappings: Map>): Map = - specialMappings.entries.asSequence().flatMap { mapping -> mapping.value.asSequence().map { Pair(it, mapping.key) } }.toMap() - - private fun getMdnDocsUrl(dir: File): String = - MDN_DOCS_URL_PREFIX + dir.path.replace('\\', '/').let { it.substring(it.indexOf("/docs/") + 5) } - - - private fun parseIndexJson(dir: File): JsonObject = - JsonParser.parseReader(JsonReader(FileReader(File(dir, "index.json"))).also { it.isLenient = true }) - .asJsonObject - - - private fun buildAttributes( - tagDir: File, - attributesDir: File, - globalAttributesDir: File?, - attributesDoc: RawProse?, - bcdPath: String?, - elementCompatData: Identifier?, - commonAttributes: Map, - ): Map? { - assert(attributesDir.exists()) { "Attributes dir does not exist - $attributesDir" } - assert(globalAttributesDir == null || globalAttributesDir.exists()) { "Global attributes dir does not exist - $globalAttributesDir" } - val docAttrs = processDataList(attributesDoc).flatMap { (name, doc) -> - if (name.contains(',')) - name.splitToSequence(',').map { Pair(it.trim(), doc) } - else - sequenceOf(Pair(name, doc)) - }.toMap() - val compatAttrs = elementCompatData?.additionalProperties?.entries?.asSequence() - ?.filter { data -> !data.key.any { it == '_' || it == '-' } } - ?.map { - val contents = DocContents(null, it.value, "$bcdPath.${it.key}") - Pair(it.key.lowercase(Locale.US), Triple( - extractStatus(contents), - extractCompatibilityInfo(contents), - contents.baseline - )) - } - ?.toMap() ?: emptyMap() - - val tagName = tagDir.name - val missing = ((compatAttrs.keys - docAttrs.keys)) - commonAttributes.keys - - val fromLocal = docAttrs.keys.asSequence() - .plus(compatAttrs.keys).distinct() - .associateWith { id -> - val dir = File(attributesDir, id).takeIf { it.isDirectory } - val bcd = elementCompatData?.additionalProperties?.entries?.find { it.key.equals(id, true) }?.value - if (dir?.isDirectory == true) { - extractAttributeDocumentation(dir, bcdPath?.let { "$it.$id" }, bcd) - } - else null - } - - val fromGlobal = if (globalAttributesDir != null) - missing.mapNotNull { id -> - val dir = File(globalAttributesDir, id).takeIf { it.isDirectory } - val bcd = elementCompatData?.additionalProperties?.entries?.find { it.key.equals(id, true) }?.value - if (dir?.isDirectory == true) { - Pair(id, extractAttributeDocumentation(dir, bcdPath?.let { "$it.$id" }, bcd)) - } - else null - } - else - emptyList() - - val reallyMissing = missing.minus(fromGlobal.map { it.first }.toSet()) - if (reallyMissing.isNotEmpty()) { - System.err.println("$tagName - missing attrs present in BCD: ${reallyMissing}") - } - - val urlPrefix = getMdnDocsUrl(tagDir) + "#" - return docAttrs.keys.asSequence() - .plus(compatAttrs.keys).distinct() - .map { StringUtil.toLowerCase(it) } - .map { - val local = fromLocal[it] - val (doc, sections) = docAttrs[it].extractSvgAttributesSections() - Pair(it, MdnHtmlAttributeDocumentation( - urlPrefix + it, compatAttrs[it]?.first, compatAttrs[it]?.second, compatAttrs[it]?.third, - doc ?: local?.doc, sections ?: local?.sections?.takeIf { it.isNotEmpty() })) - } - .plus(fromGlobal) - .sortedBy { it.first } - .toMap() - .takeIf { it.isNotEmpty() } - } - - private fun processElementDocumentation(elementDoc: RawProse, summaryDoc: RawProse?): Pair> { - val sections = mutableMapOf() - - fun processPropertiesTable(table: XmlTag) { - table.acceptChildren(object : XmlRecursiveElementVisitor() { - override fun visitXmlTag(tag: XmlTag) { - if (tag.name == "tr") { - var title = "" - var content = "" - tag.subTags.forEach { - when (it.name) { - "th" -> title += it.innerHtml() - "td" -> content += it.innerHtml() + "\n" - } - } - sections[title.patchProse()] = content.patchProse() - } - else super.visitXmlTag(tag) - } - }) - } - - val htmlFile = createHtmlFile(elementDoc) - htmlFile.acceptChildren(object : XmlRecursiveElementVisitor() { - override fun visitXmlTag(tag: XmlTag) { - if (tag.name == "table" && tag.getAttributeValue("class") == "properties") { - processPropertiesTable(tag) - tag.delete() - } - else super.visitXmlTag(tag) - } - }) - if (summaryDoc != null && htmlFile.firstChild.children.none { (it as? XmlTag)?.name == "p" }) { - return Pair(fixSpaces(htmlFile.patchedText() + createHtmlFile(summaryDoc).patchedText()), sections) - } - return Pair(fixSpaces(htmlFile.patchedText()), sections) - } - - private val BRUSH_REGEX = Regex("brush: ?(js|html|css|xml|http)[a-z0-9-;\\[\\] ]*") - - private fun createHtmlFile(contents: RawProse): HtmlFileImpl { - val htmlFile = PsiFileFactory.getInstance(project) - .createFileFromText("dummy.html", HTMLLanguage.INSTANCE, contents.content, false, true) - val toRemove = mutableSetOf() - val codeBlocks = mutableSetOf() - htmlFile.acceptChildren(object : XmlRecursiveElementVisitor() { - - override fun visitXmlComment(comment: XmlComment) { - toRemove.add(comment) - } - - override fun visitXmlTag(tag: XmlTag) { - if (tag.name == "pre" - && tag.getAttributeValue("class")?.matches(BRUSH_REGEX) == true) { - tag.findSubTag("code")?.let { codeBlocks.add(tag) } - } - else if (tag.name == "span" - && tag.getAttributeValue("class")?.trim() == "language-name") { - tag.children.filterTo(toRemove) { it is XmlText } - super.visitXmlTag(tag) - } - else if ((tag.getAttributeValue("class")?.contains("hidden", true) == true) - || tag.getAttributeValue("id") - .let { it == "topExample" || it == "Exeemple" || it == "Example" || it == "Exemple" || it == "LiveSample" } - || (tag.name == "span" && tag.getAttributeValue("class") == "notecard inline warning") - || (tag.name == "p" && tag.innerHtml().trim().startsWith("The source for this interact")) - || tag.name == "iframe" - || tag.name == "img") { - toRemove.add(tag) - } - else if (tag.name == "svg") { - val cls = tag.getAttributeValue("class") - if (cls != null) { - when { - cls.contains("obsolete") -> "🗑" - cls.contains("deprecated") -> "👎" - cls.contains("non-standard") || cls.contains("icon-nonstandard") -> "⚠️" - cls.contains("experimental") -> "🧪" - else -> { - throw Exception("Unknown SVG class: $cls") - } - }.let { - tag.parentTag!!.addBefore(XmlElementFactory.getInstance(project).createDisplayText(it), tag) - } - } - else if ( - // An SVG diagram - !tag.text.contains("height=\"25\" fill=\"#F4F7F8\" stroke=\"#D4DDE4\" stroke-width=\"2px\">" - )) { - throw Exception("SVG with no class: " + tag.text) - } - toRemove.add(tag) - } - else super.visitXmlTag(tag) - } - - override fun visitXmlAttribute(attribute: XmlAttribute) { - if (attribute.name.let { it == "data-flaw-src" || it == "title" || it == "alt" }) { - toRemove.add(attribute) - } - else if (attribute.value?.let { it.contains(""") || it.contains("'") } == true) { - if (attribute.name.let { it == "id" || it == "style" }) { - toRemove.add(attribute) - } - else { - throw Exception("Entities: " + attribute.text) - } - } - } - }) - toRemove.forEach { it.delete() } - removeEmptyTags(htmlFile) - codeBlocks.forEach(::processCodeBlock) - val text = fixSpaces(htmlFile.text) - if (text.contains("The source for this interact")) - throw Exception("Unhidden stuff!") - if (text.contains("class=\"token punctuation\"")) - throw Exception("Code fragment") - return PsiFileFactory.getInstance(project) - .createFileFromText("dummy.html", HtmlFileType.INSTANCE, text, System.currentTimeMillis(), false, true) - as HtmlFileImpl - } - - private fun removeEmptyTags(htmlFile: PsiFile) { - val toRemove = mutableSetOf() - htmlFile.acceptChildren(object : XmlRecursiveElementVisitor() { - override fun visitXmlTag(tag: XmlTag) { - if (isEmptyTag(tag)) { - toRemove.add(tag) - } - else { - super.visitXmlTag(tag) - } - } - }) - toRemove.forEach { it.delete() } - } - - private fun processCodeBlock(tag: XmlTag) { - val language = BRUSH_REGEX - .matchEntire(tag.getAttributeValue("class")!!)!! - .groupValues[1] - val code = tag.findSubTag("code") - ?.let { extractText(it) } - ?.let { StringUtil.unescapeXmlEntities(it) } - val toReplace = if (tag.parent.let { it is XmlTag && it.getAttributeValue("class") == "code-example" }) - tag.parent - else - tag - val parent = toReplace.parent - parent.addBefore(XmlElementFactory.getInstance(tag.project).createTagFromText( - "
\n```$language\n$code\n```\n
", HTMLLanguage.INSTANCE), toReplace) - toReplace.delete() - } - - private fun extractText(tag: XmlTag): String { - val result = StringBuilder() - tag.acceptChildren(object : XmlRecursiveElementVisitor() { - override fun visitXmlText(text: XmlText) { - result.append(text.text.replace(' ', ' ')) - } - }) - return result.toString() - } - - private fun extractPreText(tag: XmlTag): String { - val result = StringBuilder() - tag.acceptChildren(object : XmlRecursiveElementVisitor() { - override fun visitXmlText(text: XmlText) { - result.append(text.text.replace(' ', ' ')) - } - - override fun visitXmlTag(tag: XmlTag) { - if (tag.name == "br") - result.append("\n") - super.visitXmlTag(tag) - } - }) - return result.toString() - } - - private fun isEmptyTag(tag: XmlTag): Boolean = - tag.name.let { it != "br" && it != "hr" } - && !tag.children.map { - (it is XmlAttribute && it.name != "class") - || (it is XmlText && it.text.isNotBlank()) - || (it is XmlTag && !isEmptyTag(it)) - }.any { it } - - private fun extractParameters(sections: List): Map? = - extractFromDataList(sections, "parameters", "syntax") - - private fun extractReturns(sections: List): RawProse? = - sections.filterProseById("return_value").firstOrNull() - ?.getProseContent() - - private fun extractThrows(sections: List): Map? = - extractFromDataList(sections, "exceptions") - - private fun extractPropertyValues(sections: List): Map? = - extractFromDataList(sections, "values") - - - private fun extractFromDataList(sections: List, vararg ids: String): Map? = - ids.asSequence() - .map { processDataList(sections.getProseContentById(it)) } - .filter { it.isNotEmpty() } - .firstOrNull() - ?.mapValues { (_, doc) -> - doc.replace(Regex("\n{2,}"), "
") - .removeSuffix("
") - .patchProse() - } - - private fun processDataList(doc: RawProse?): Map { - val result = mutableMapOf() - if (doc != null && doc.content.isNotBlank()) { - seePattern.matchEntire(doc.content)?.let { - return mapOf(SEE_REFERENCE to it.groupValues[1].lowercase(Locale.US)) - } - var lastTitle = "" - createHtmlFile(doc) - .document?.children?.asSequence() - ?.filterIsInstance() - ?.flatMap { if (it.name == "figure") it.subTags.asSequence() else sequenceOf(it) } - ?.filter { it.name == "dl" || it.name == "table" } - ?.flatMap { it.subTags.asSequence() } - ?.flatMap { if (it.name == "tbody") it.subTags.asSequence() else sequenceOf(it) } - ?.forEach { data -> - when (data.name) { - "dt" -> lastTitle = extractIdentifier(data) - "dd" -> if (lastTitle.isNotBlank()) result[lastTitle] = result.getOrDefault(lastTitle, "") + data.innerHtml() - "tr" -> { - val cells = data.findSubTags("td").filter { - val subTags = it.subTags - subTags.size != 1 || subTags[0].name != "img" - } - if (cells.size == 2) { - val title = extractIdentifier(cells[0]) - if (title.isNotBlank()) result[title] = result.getOrDefault(title, "") + cells[1].innerHtml() - } - } - } - } - } - return result.asSequence().map { Pair(it.key.patchProse(), it.value.patchProse()) }.toMap() - } - - @Suppress("RegExpDuplicateAlternationBranch") - private fun extractIdentifier(data: XmlTag): String { - val result = StringBuilder() - var ok = true - var stop = false - data.acceptChildren(object : XmlRecursiveElementVisitor() { - override fun visitXmlTag(tag: XmlTag) { - val tagName = tag.name - if (tagName == "br") { - result.append("{{br}}") - } - else if (tagName == "table") { - ok = false - } - else if (tagName != "span" || tag.getAttributeValue("class") - ?.let { cls -> - cls.contains("badge") - || cls.contains("inlineIndicator") - || cls.contains("notecard") - } != true) { - super.visitXmlTag(tag) - } - else { - stop = true - } - } - - override fun visitXmlText(text: XmlText) { - if (!stop) { - val infoIndex = text.text.indexOfAny(listOf("🗑", "👎", "⚠️", "🧪")) - if (infoIndex >= 0) { - stop = true - result.append(text.text.substring(0, infoIndex)) - } - else { - result.append(text.text) - } - } - } - }) - if (result.contains(">")) - throw Exception("Something went wrong!") - return if (ok) - result.toString().replace("{{br}}", "
").trim() - .let { - if (!it.contains("(") && it.length > 20) - it.replace(Regex("[,.]\\s+"), "
\n") - else - it - } - else "" - } - - private fun extractStatus(contents: DocContents): Set? = - contents.getBcdMap() - .mapNotNull { it.value.compat?.status } - .takeIf { it.isNotEmpty() } - ?.let { statuses -> - setOfNotNull( - MdnApiStatus.Experimental.takeIf { statuses.all { it.experimental } }, - MdnApiStatus.StandardTrack.takeIf { statuses.any { it.standardTrack } }, - MdnApiStatus.Deprecated.takeIf { statuses.all { it.deprecated } }, - ) - } - ?.takeIf { it.isNotEmpty() } - - private fun extractCompatibilityInfo(contents: DocContents): CompatibilityMap? = - contents.getBcdMap() - .mapNotNull { (id, data) -> - data.compat - ?.support - ?.additionalProperties - ?.asSequence() - ?.mapNotNull { entry -> - jsRuntimesMap[entry.key]?.let { runtime -> - Pair(runtime, entry.value?.let { extractBrowserVersion(runtime, it) }) - } - } - ?.toMap() - ?.takeIf { map -> map.values.any { it == null || it.isNotEmpty() } } - ?.filterValues { it != null } - ?.let { - @Suppress("UNCHECKED_CAST") - val sortedMap = it.toMap(TreeMap()) as MutableMap - val bcdId = if (id != defaultBcdContext) getBcdId(id) else id - if (bcdId != defaultBcdContext) { - val description = data.compat.description - if (description != null) { - bcdIdDescriptions.putIfAbsent(bcdId, description) - } - } - else { - contents.baselineBrowsers?.let { baselineBrowsers -> sortedMap.putAll(baselineBrowsers) } - } - - Pair(bcdId, sortedMap) - } - } - .toMap(TreeMap()) - .takeIf { it.isNotEmpty() } - ?.let { compatMap -> - if (compatMap.size > 1) { - val firstValue = compatMap.values.first() - if (compatMap.values.all { it == firstValue }) - mapOf(defaultBcdContext to firstValue) - else compatMap - } - else compatMap - } - - private fun getBcdId(id: String): String = - id.takeLastWhile { it != '.' }.let { - if (it.endsWith("_context")) - it - else - "support_of_$it" - } - - private fun extractBrowserVersion(runtime: MdnJavaScriptRuntime, versionInfo: SupportStatement): String? { - fun extractVersion(version: Any?): String? = - when (version) { - is Boolean -> { - if (version) "" else null - } - is String -> { - when { - version.isEmpty() -> null - version == runtime.firstVersion -> "" - else -> version.removePrefix("≤") - } - } - else -> null - } - - - @Suppress("UNCHECKED_CAST") - val versions = when (val value = versionInfo.value) { - is SimpleSupportStatement -> listOf(value) - is List<*> -> value as List - is String -> listOf(SimpleSupportStatement().also { it.versionAdded = VersionAdded().also { v -> v.value = value } }) - else -> emptyList() - } - .asSequence() - .filter { it.prefix.isNullOrEmpty() && it.flags.isEmpty() && it.alternativeName.isNullOrEmpty() && it.partialImplementation == null } - .map { - Triple(extractVersion(it.versionAdded?.value), extractVersion(it.versionRemoved?.value), !it.notes.isNullOrEmpty()) - } - .filter { it.first != null && it.second == null } - .sortedBy { it.first!! } - .toList() - if (versions.size > 1) { - if (versions.all { it.third }) { - return versions.joinToString(",") { it.first!! + "*" } - } - val withoutNotes = versions.filter { !it.third } - if (withoutNotes.size == 1) { - return withoutNotes[0].first!! - } - throw IllegalStateException(versionInfo.toString()) - } - else if (versions.size == 1) { - return versions[0].first - } - return null - } - - private fun createDtsMdnIndex(symbols: Map): Map { - val context = JSCorePredefinedLibrariesProvider.getAllJSPredefinedLibraryFiles() - .find { it.name == "lib.dom.d.ts" } - ?.let { PsiManager.getInstance(project).findFile(it) } - - val realNameMap = StubIndex.getInstance().getAllKeys(JSIndexKeys.JS_SYMBOL_INDEX_2_KEY, project) - .associateBy { it.lowercase(Locale.US) } - - return symbols.keys.asSequence() - .filter { it.contains('.') } - .mapNotNull { symbolName -> - val namespace = symbolName.takeWhile { it != '.' } - val member = symbolName.takeLastWhile { it != '.' } - val actualNamespace = realNameMap[namespace] - ?: return@mapNotNull null - (JSNamedTypeFactory.createType(actualNamespace, - JSTypeSourceFactory.createTypeSource(context, false), JSTypeContext.INSTANCE) - .asRecordType() - .properties - .find { it.memberName.equals(member, true) }) - ?.memberSource - ?.singleElement - ?.asSafely() - ?.qualifiedName - ?.takeIf { !it.equals(symbolName, true) } - ?.lowercase(Locale.US) - ?.let { Pair(it, symbolName) } - } - .toMap(TreeMap()) - .ifEmpty { throw IllegalStateException("Uninitialized JS indexes.") } - } - - private val redirects = FileUtil.loadFile(Path.of(MDN_CONTENT_ROOT, BUILT_LANG, "_redirects.txt").toFile()) - .splitToSequence('\n') - .mapNotNull { line -> - line.splitToSequence('\t') - .map { StringUtil.toLowerCase(it.trim()) } - .toList() - .takeIf { it.size == 2 && !it[0].startsWith("#") } - ?.let { Pair(it[0], it[1]) } - } - .toMap() - - private fun File.toMdnUrl(): String = - toString().removePrefix(getMdnDir("").toString()) - - private fun updateBcdDescriptions() { - val bundleFile = Path.of(PathManager.getCommunityHomePath(), BUNDLE_OUTPUT_DIR, "MdnBundle.properties").toFile() - val contents = FileUtil.loadLines(bundleFile) - - val existingProperties = contents.asSequence() - .filter { it.startsWith("mdn.documentation.section.compat.") } - .map { it.substring("mdn.documentation.section.compat.".length).substringBefore("=") } - .toSet() - - bcdIdDescriptions - .filter { it.key !in existingProperties } - .ifEmpty { return } - .forEach { (id, description) -> - contents.add("mdn.documentation.section.compat.$id=$description") - } - - FileUtil.writeToFile(bundleFile, contents.joinToString("\n")); - } - - private inner class CssElementInfo(docDir: File) { - - val name: String - - val hasDataType: Boolean get() = name.startsWith("<") - - init { - val dirName = docDir.name - if (dirName.startsWith("_colon_") - || dirName.startsWith("_doublecolon_") - || dirName.startsWith("@") - || dirName.endsWith("()") - || dirName.endsWith("_function") - ) { - name = if (dirName.endsWith("_function")) { - dirName.removeSuffix("_function") + "()" - } - else dirName - } - else { - val doc = parseIndexJson(docDir).getAsJsonObject("doc") - val title = doc.getAsJsonPrimitive("title").asString - val possiblyType = doc.getAsJsonArray("browserCompat")?.any { it.asString.startsWith("css.types.") } == true - if (title.endsWith("()") || (title.startsWith("<") && title.endsWith(">"))) { - name = title.lowercase(Locale.US) - } - else if (possiblyType) { - name = "<$dirName>" - } - else { - name = dirName - } - } - } - } - - private inner class DocContents(dir: File?, val compatData: Identifier?, bcdPath: String? = null) { - - val prose: List - val browserCompatData: List - val baseline: BaselineData? - val baselineBrowsers: Map? - - fun getBcdMap(): Map = - browserCompatData - .mapNotNull { id -> bcd.tryResolve(id)?.let { Pair(id, it) } } - .let { data -> - if (data.size == 1) { - val entry = data[0].second - val contexts = entry.additionalProperties.entries - .filter { it.key.endsWith("_context") } - if (contexts.isNotEmpty()) { - contexts.map { Pair(it.key, it.value) } - } - else { - listOf(defaultBcdContext to entry) - } - } - else data - } - .ifEmpty { compatData?.let { listOf(Pair(defaultBcdContext, it)) } ?: emptyList() } - .toMap() - - init { - var baselineJson: JsonObject? = null - if (dir != null) { - val doc = parseIndexJson(dir) - .getAsJsonObject("doc") - prose = doc - .getAsJsonArray("body")!! - .map { it.asJsonObject } - .filter { it.getAsJsonPrimitive("type").asString == "prose" } - .map { it.getAsJsonObject("value") } - .toList() - browserCompatData = doc.getAsJsonArray("browserCompat") - ?.map { it.asString } ?: emptyList() - if (doc.has("baseline")) - baselineJson = doc.getAsJsonObject("baseline") - } - else { - prose = emptyList() - browserCompatData = emptyList() - } - if (bcdPath != null) { - baselineJson = BaseLineService.computeBaseline(bcdPath) - } - baseline = if (baselineJson != null) { - BaselineData( - baselineJson.getAsJsonPrimitive("baseline").let { - when { - it.isBoolean -> BaselineLevel.NONE - it.asString == "low" -> BaselineLevel.LOW - it.asString == "high" -> BaselineLevel.HIGH - else -> throw IllegalStateException(it.toString()) - } - }, - lowDate = baselineJson.getAsJsonPrimitive("baseline_low_date")?.asString, - highDate = baselineJson.getAsJsonPrimitive("baseline_high_date")?.asString, - ) - } - else null - - baselineBrowsers = baselineJson?.getAsJsonObject("support")?.entrySet() - ?.mapNotNull { entry -> - jsRuntimesMap[entry.key]?.let { runtime -> - Pair(runtime, entry.value.asString.removePrefix("≤")) - } - } - ?.toMap() - } - - } -} - -private fun makeMissingSymbolsObsolete( - newData: T, - currentData: T, - obsoleteData: T, - mapGetter: (T) -> Map, - copyWithObsoleteStatus: (K) -> K, -) { - makeMissingSymbolsObsolete(newData, currentData, obsoleteData, mapGetter, copyWithObsoleteStatus, null, null, null) -} - -private fun makeMissingSymbolsObsolete( - newData: T, - currentData: T, - obsoleteData: T, - mapGetter: (T) -> Map, - copyWithObsoleteStatus: (K) -> K, - subMapGetter: ((K) -> Map?)?, - symbolCreator: ((String) -> K)?, - subCopyWithObsoleteStatus: ((L) -> L)?, -) { - - val newMap = mapGetter(newData) - val currentMap = mapGetter(currentData) - val obsoleteMap = mapGetter(obsoleteData) as MutableMap - - currentMap.entries.forEach { (key, value) -> - if (!newMap.contains(key)) { - obsoleteMap.put(key, copyWithObsoleteStatus(value)) - } - else if (subMapGetter != null) { - val newSubMap = subMapGetter(newMap[key]!!) - val currentSubMap = subMapGetter(value) - val obsoleteSubMap by lazy { - subMapGetter(obsoleteMap.computeIfAbsent(key, symbolCreator!!)) as MutableMap - } - - currentSubMap?.entries?.forEach { - if (newSubMap == null || !newSubMap.contains(it.key)) { - obsoleteSubMap.put(it.key, subCopyWithObsoleteStatus!!(it.value)) - } - } - } - } - obsoleteMap.entries.removeIf { newMap.containsKey(it.key) && it.value.doc != "" } - if (subMapGetter != null) { - obsoleteMap.entries.forEach { entry -> - val newSubMap = subMapGetter(newMap[entry.key] ?: return@forEach) ?: return@forEach - (subMapGetter(entry.value) as? MutableMap)?.entries?.removeIf { newSubMap.contains(it.key) } - } - } -} - -private fun String?.extractSvgAttributesSections(): Pair?> { - if (this == null) return Pair(null, null) - val match = svgAttributeSectionsPattern.matchEntire(this) - ?: return Pair(this, null) - return Pair( - match.groupValues[1].trim().removeSuffix("
").removeSuffix("

").trim(), - mapOf( - "Value type" to match.groupValues[2].trim().removeSuffix(".").removeSuffix(";").trim(), - "Default" to match.groupValues[3].trim().removeSuffix(".").removeSuffix(";").trim(), - "Animatable" to match.groupValues[4].trim().removeSuffix(".").removeSuffix(";").trim(), - ) - ) -} - -private fun Map.resolveReferences(): Map = - mapValues { (_, value) -> - value.resolveReferences(this) - } - -private fun MdnJsSymbolDocumentation.resolveReferences(symbols: Map): MdnJsSymbolDocumentation { - val newParameters = parameters?.get(SEE_REFERENCE)?.let { ref -> symbols[ref.takeLastWhile { it != '/' }] }?.parameters - val newThrows = throws?.get(SEE_REFERENCE)?.let { ref -> symbols[ref.takeLastWhile { it != '/' }] }?.throws - return if (newParameters != null || newThrows != null) - copy(parameters = newParameters ?: parameters, throws = newThrows ?: throws) - else - this -} - -private fun XmlTag.innerHtml(): String = this.children.asSequence() - .filter { it is XmlTag || it is XmlText }.map { it.text }.joinToString("\n").let { fixSpaces(it) } - -private fun XmlElement.findSubTag(name: String): XmlTag? = this.children.find { (it as? XmlTag)?.name == name } as? XmlTag - -private fun fixSpaces(doc: String): String = doc.replace(Regex("[ \t]*\n[ \t\n]*"), "\n").trim() - -private fun String.toPascalCase(): String = getWords().map { it.lowercase(Locale.US) }.joinToString(separator = "", - transform = StringUtil::capitalize) - -private fun String.getWords() = NameUtilCore.nameToWords(this).filter { it.isNotEmpty() && Character.isLetterOrDigit(it[0]) } - -private data class RawProse(val content: String) { - fun patch(): String = content.patchProse() -} - -private fun PsiElement.patchedText() = - text.patchProse() - -private fun JsonObject.getProseContent(): RawProse = - this.getAsJsonPrimitive("content").asString - .let { RawProse(it) } - -private fun RawProse.appendOtherSections(indexDataProseValues: List): RawProse { - val try_it_section = indexDataProseValues.getProseContentById("try_it")?.content - val description_section = indexDataProseValues.getProseContentById("description")?.content - if (try_it_section == null && description_section == null) return this - return RawProse( - listOf( - content, - if (try_it_section != null) { - val iframeEnd = try_it_section.indexOf("") - .takeIf { it > 0 }?.let { it + "".length } - ?: try_it_section.indexOf("") - .takeIf { it > 0 } - ?.let { try_it_section.lastIndexOf("") + "".length } - ?.takeIf { it > 0 } - if (iframeEnd == null) throw RuntimeException("Cannot find iframe or interactive-example end - $try_it_section") - try_it_section.substring(iframeEnd).trim() - } - else "", - description_section?.trim() ?: "" - ) - .filter { it.isNotEmpty() } - .joinToString("\n") - ) -} - -private fun List.filterProseById(vararg ids: String): Sequence = - asSequence().filter { value -> - value.get("id") - .takeIf { it is JsonPrimitive } - ?.asString?.lowercase(Locale.US)?.let { id -> - ids.any { id == it } - } == true - } - -private fun List.getProseContentById(id: String) = - filterProseById(id).firstOrNull()?.getProseContent() - -private fun String.patchProse(): String = - replace("/en-US/docs", MDN_DOCS_URL_PREFIX, true) - .replace("'", "'") - .replace(""", "\"") - .replace(" ", " ") - .replace("&ldquo", "“") - .replace("&rdquo", "”") - .replace("&hellip", "…") - .replace(Regex("

\\s+"), "

") - .replace(Regex("(^

\\s*)|(\\s*

)|(\\s*]*>)|(\\s*\\s*\\s*)"), "") - .also { fixedProse -> - Regex("&(?!lt|gt|amp|shy)[a-z]*;").find(fixedProse)?.let { - throw Exception("Unknown entity found in prose: ${it.value}") - } - } - -private class CompatibilityMapSerializer(private val sortEntries: Boolean) : JsonSerializer> { - override fun serialize(src: Map<*, *>, typeOfSrc: Type, context: JsonSerializationContext): JsonElement = - if (src.size == 1 && src.containsKey(defaultBcdContext)) { - context.serialize(src[defaultBcdContext]) - } - else if (src.size == 1 && src.containsKey("default_context")) { - context.serialize(src["default_context"]) - } - else { - val result = JsonObject() - src.entries - .let { set -> - if (sortEntries && set.firstOrNull()?.value !is String) - set.sortedBy { it.key.toString() } - else - set - } - .forEach { (key, value) -> - result.add(key.toString(), context.serialize(value)) - } - result - } - -} \ No newline at end of file diff --git a/xml/xml-psi-impl/mdn-doc-gen/src/MdnDocUpdateTestSuite.kt b/xml/xml-psi-impl/mdn-doc-gen/src/MdnDocUpdateTestSuite.kt deleted file mode 100644 index 200d07c72e9c..000000000000 --- a/xml/xml-psi-impl/mdn-doc-gen/src/MdnDocUpdateTestSuite.kt +++ /dev/null @@ -1,44 +0,0 @@ -import com.intellij.codeInsight.XmlDocumentationTest -import com.intellij.html.HtmlDocumentationTest -import com.intellij.htmltools.codeInsight.daemon.HtmlHighlightingTest -import com.intellij.lang.javascript.JSDocumentationTest -import com.intellij.lang.javascript.typescript.TypeScriptDocumentationTest -import com.intellij.lang.javascript.typescript.service.TypeScriptServiceDocumentationTest -import com.intellij.polySymbols.js.css.PolySymbolsCssCodeCompletionTest -import com.intellij.polySymbols.js.html.PolySymbolsHtmlDocumentationTest -import com.intellij.polySymbols.js.html.PolySymbolsHtmlLookupDocumentationTest -import com.intellij.react.ReactDocumentationTest -import com.intellij.react.tsc.ReactDocumentationWithServiceTest -import css.CssDocumentationTest -import org.angular2.codeInsight.Angular2DocumentationTest -import org.angular2.codeInsight.deprecated.Angular2AttributesTest -import org.angular2.resharper.Angular2HtmlCodeCompletionTest -import org.jetbrains.astro.codeInsight.AstroDocumentationTest -import org.jetbrains.vuejs.lang.VueCompletionTest -import org.jetbrains.vuejs.lang.VueDocumentationTest -import org.junit.runner.RunWith -import org.junit.runners.Suite - -@RunWith(Suite::class) -@Suite.SuiteClasses( - HtmlDocumentationTest::class, - XmlDocumentationTest::class, - HtmlHighlightingTest::class, - PolySymbolsHtmlDocumentationTest::class, - PolySymbolsHtmlLookupDocumentationTest::class, - PolySymbolsCssCodeCompletionTest::class, - CssDocumentationTest::class, - JSDocumentationTest::class, - TypeScriptDocumentationTest::class, - TypeScriptServiceDocumentationTest::class, - ReactDocumentationTest::class, - ReactDocumentationWithServiceTest::class, - Angular2DocumentationTest::class, - Angular2AttributesTest::class, - Angular2HtmlCodeCompletionTest::class, - VueDocumentationTest::class, - VueCompletionTest::class, - AstroDocumentationTest::class, - /* Additionally, run `Compile Rider Backend` and the `BlazorDocumentationTest` */ -) -class MdnDocUpdateTestSuite \ No newline at end of file diff --git a/xml/xml-psi-impl/mdn-doc-gen/src/prepare-mdn.sh b/xml/xml-psi-impl/mdn-doc-gen/src/prepare-mdn.sh deleted file mode 100755 index 1af59937dde5..000000000000 --- a/xml/xml-psi-impl/mdn-doc-gen/src/prepare-mdn.sh +++ /dev/null @@ -1,39 +0,0 @@ -#!/bin/bash -set -e - -DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"; - -cd "$DIR/../baseline-server" -npm install - -mkdir -p "$DIR/../work" - -cd "$DIR/../work" - -rm -f browser-compat-data.json -wget "https://unpkg.com/@mdn/browser-compat-data/data.json" -O browser-compat-data.json - -if [ ! -d "mdn-content" ]; then - git clone https://github.com/mdn/content.git mdn-content -fi - -cd "mdn-content" -git pull -yarn install -cd .. - -if [ ! -d "yari" ]; then - git clone https://github.com/mdn/yari.git yari -fi - -cd "yari" -git reset --hard -git pull -rm -Rf cloud-function -yarn install - -export CONTENT_ROOT="$DIR/../work/mdn-content/files" -yarn build:prepare -yarn build - -echo "Done!" \ No newline at end of file