diff --git a/.project b/.project new file mode 100644 index 0000000..d41e75b --- /dev/null +++ b/.project @@ -0,0 +1,17 @@ + + + xtext-docs-gen + + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + + diff --git a/README.md b/README.md index b86798f..16f5a5f 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ To get the gist of it, have a look at the example below, illustrating the docume To check a more comprehensive example, see the [documentation](docs/ExampleDomainmodelDocs.md) generated for the [Domainmodel example grammar](examples/org.example.domainmodel/src/org/example/domainmodel/Domainmodel.xtext), using [this workflow file](examples/org.example.domainmodel/src/org/example/domainmodel/GenerateDomainmodel.mwe2). ### Usage -1. Add `com.github.darvasd.xtextdocs.xtext` as depencency to the `MANIFEST.MF` of your plug-in project containing the Xtext grammar. +1. Add `com.epistimis.xtextdocs.xtext` as depencency to the `MANIFEST.MF` of your plug-in project containing the Xtext grammar. * You can use the http://darvasd.github.io/xtext-docs-gen/release/ update site to fetch it. 1. Add the documentation generation to your workflow description (`.mwe2` file next to your grammar), as a fragment for your language configuration (`XtextGeneratorLanguage` instance). For example: ``` @@ -30,8 +30,8 @@ To check a more comprehensive example, see the [documentation](docs/ExampleDomai You will need some imports: ``` - import com.github.darvasd.xtextdocs.xtext.fragment.DocsGeneratorFragment - import com.github.darvasd.xtextdocs.xtext.formatter.MarkdownDocsFormatter + import com.epistimis.xtextdocs.xtext.fragment.DocsGeneratorFragment + import com.epistimis.xtextdocs.xtext.formatter.MarkdownDocsFormatter ``` 1. If you execute your workflow, the grammar documentation should be generated. You can see it in the log as well: ``` @@ -50,7 +50,7 @@ To get the gist of it, have a look at the example below, illustrating the docume To check a more comprehensive example, see the [documentation](docs/ExampleXcoreDocs.md) generated for the [Library example metamodel](examples/org.example.xcore/model/Library.xcore), using [this workflow file](examples/org.example.xcore/src/org/example/xcore/library/GenerateXcoreDocs.mwe2). ### Usage -1. Add `com.github.darvasd.xtextdocs.xcore` as depencency to the `MANIFEST.MF` of your plug-in project containing the Xcore metamodel(s). +1. Add `com.epistimis.xtextdocs.xcore` as depencency to the `MANIFEST.MF` of your plug-in project containing the Xcore metamodel(s). * You can use the http://darvasd.github.io/xtext-docs-gen/release/ update site to fetch it. 1. You may need in addition the following dependencies (you can make them optional if they are only required for the documentation generation): `org.eclipse.core.runtime`, `org.eclipse.emf.ecore`, `org.eclipse.emf.ecore.xcore.lib`, `org.eclipse.emf.mwe2.launch`, `org.eclipse.emf.mwe2.lib`, `org.eclipse.emf.ecore.xcore`, `org.eclipse.emf.codegen.ecore`, `org.apache.commons.logging`. 1. Create an MWE2 workflow description (`.mwe2` file) that will generate the Xcore documentation. Take [this](https://github.com/darvasd/xtext-docs-gen/tree/master/examples/org.example.xcore/src/org/example/xcore/library/GenerateXcoreDocs.mwe2) as an example for the Xcore metamodel loading. For the documentation generation configuration, here is an example: @@ -74,8 +74,8 @@ To check a more comprehensive example, see the [documentation](docs/ExampleXcore You will need some imports: ``` - import com.github.darvasd.xtextdocs.xcore.fragment.DocsGeneratorFragment - import com.github.darvasd.xtextdocs.xcore.formatter.MarkdownXcoreDocsFormatter + import com.epistimis.xtextdocs.xcore.fragment.DocsGeneratorFragment + import com.epistimis.xtextdocs.xcore.formatter.MarkdownXcoreDocsFormatter ``` 1. If you execute your workflow, the grammar documentation should be generated. You can see it in the log as well: ``` @@ -92,9 +92,10 @@ Use `https://darvasd.github.io/xtext-docs-gen/release/` as update site and insta ## License Copyright (c) 2018, 2019 Daniel Darvas +Copyright (c) 2024 Epistimis LLC This program and the accompanying materials are made available under the terms of the **Eclipse Public License 2.0** which is available at https://www.eclipse.org/legal/epl-2.0/ . The Domainmodel grammar is a commented version of the one available in the Xtext documentation, located at https://www.eclipse.org/Xtext/documentation/102_domainmodelwalkthrough.html. See its [GitHub page](https://github.com/eclipse/xtext/edit/website-published/xtext-website/documentation/102_domainmodelwalkthrough.md) for the list of contributors. Used for demonstration purposes only. -The Library metamodel is an extended version of the one available in the Xcore documentation, located at https://wiki.eclipse.org/Xcore. See [this page](https://wiki.eclipse.org/index.php?title=Xcore&action=credits) for the list of contributors. Used for demonstration purposes only. \ No newline at end of file +The Library metamodel is an extended version of the one available in the Xcore documentation, located at https://wiki.eclipse.org/Xcore. See [this page](https://wiki.eclipse.org/index.php?title=Xcore&action=credits) for the list of contributors. Used for demonstration purposes only. diff --git a/com.epistimis.xtextdocs.common.test/.classpath b/com.epistimis.xtextdocs.common.test/.classpath new file mode 100644 index 0000000..ea0dca2 --- /dev/null +++ b/com.epistimis.xtextdocs.common.test/.classpath @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + diff --git a/com.github.darvasd.xtextdocs.common/.project b/com.epistimis.xtextdocs.common.test/.project similarity index 94% rename from com.github.darvasd.xtextdocs.common/.project rename to com.epistimis.xtextdocs.common.test/.project index 4a2a42f..3c4c3a2 100644 --- a/com.github.darvasd.xtextdocs.common/.project +++ b/com.epistimis.xtextdocs.common.test/.project @@ -1,6 +1,6 @@ - com.github.darvasd.xtextdocs.common + com.epistimis.xtextdocs.common.test diff --git a/com.epistimis.xtextdocs.common.test/META-INF/MANIFEST.MF b/com.epistimis.xtextdocs.common.test/META-INF/MANIFEST.MF new file mode 100644 index 0000000..22f800e --- /dev/null +++ b/com.epistimis.xtextdocs.common.test/META-INF/MANIFEST.MF @@ -0,0 +1,10 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Automatic-Module-Name: com.epistimis.xtextdocs.common.test +Bundle-Name: Test +Bundle-SymbolicName: com.epistimis.xtextdocs.common.test +Bundle-Version: 1.1.0.qualifier +Bundle-Vendor: Daniel Darvas +Fragment-Host: com.epistimis.xtextdocs.common +Bundle-RequiredExecutionEnvironment: JavaSE-17 +Import-Package: org.junit;version="4.12.0" diff --git a/com.github.darvasd.xtextdocs.common.test/build.properties b/com.epistimis.xtextdocs.common.test/build.properties similarity index 100% rename from com.github.darvasd.xtextdocs.common.test/build.properties rename to com.epistimis.xtextdocs.common.test/build.properties diff --git a/com.github.darvasd.xtextdocs.xtext.test/pom.xml b/com.epistimis.xtextdocs.common.test/pom.xml similarity index 80% rename from com.github.darvasd.xtextdocs.xtext.test/pom.xml rename to com.epistimis.xtextdocs.common.test/pom.xml index 5231f3b..f5503d4 100644 --- a/com.github.darvasd.xtextdocs.xtext.test/pom.xml +++ b/com.epistimis.xtextdocs.common.test/pom.xml @@ -2,11 +2,11 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - com.github.darvasd.xtextdocs - com.github.darvasd.xtextdocs.parent + com.epistimis.xtextdocs + com.epistimis.xtextdocs.parent 1.1.0-SNAPSHOT - com.github.darvasd.xtextdocs.xtext.test + com.epistimis.xtextdocs.common.test eclipse-test-plugin diff --git a/com.github.darvasd.xtextdocs.common.test/src/com/github/darvasd/xtextdocs/common/formatter/DocCommentTextUtilTest.xtend b/com.epistimis.xtextdocs.common.test/src/com/epistimis/xtextdocs/common/formatter/DocCommentTextUtilTest.xtend similarity index 92% rename from com.github.darvasd.xtextdocs.common.test/src/com/github/darvasd/xtextdocs/common/formatter/DocCommentTextUtilTest.xtend rename to com.epistimis.xtextdocs.common.test/src/com/epistimis/xtextdocs/common/formatter/DocCommentTextUtilTest.xtend index 31d846a..811fdb9 100644 --- a/com.github.darvasd.xtextdocs.common.test/src/com/github/darvasd/xtextdocs/common/formatter/DocCommentTextUtilTest.xtend +++ b/com.epistimis.xtextdocs.common.test/src/com/epistimis/xtextdocs/common/formatter/DocCommentTextUtilTest.xtend @@ -1,5 +1,6 @@ /********************************************************************* * Copyright (c) 2018 Daniel Darvas + * Copyright (c) 2024 Epistimis LLC * * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 @@ -8,11 +9,11 @@ * SPDX-License-Identifier: EPL-2.0 **********************************************************************/ -package com.github.darvasd.xtextdocs.common.formatter +package com.epistimis.xtextdocs.common.formatter import org.junit.Test import org.junit.Assert -import com.github.darvasd.xtextdocs.common.formatter.MarkdownTextFormatter +import com.epistimis.xtextdocs.common.formatter.MarkdownTextFormatter class DocCommentTextUtilTest { @Test diff --git a/com.github.darvasd.xtextdocs.common.test/src/com/github/darvasd/xtextdocs/common/formatter/MarkdownTextFormatterTest.xtend b/com.epistimis.xtextdocs.common.test/src/com/epistimis/xtextdocs/common/formatter/MarkdownTextFormatterTest.xtend similarity index 91% rename from com.github.darvasd.xtextdocs.common.test/src/com/github/darvasd/xtextdocs/common/formatter/MarkdownTextFormatterTest.xtend rename to com.epistimis.xtextdocs.common.test/src/com/epistimis/xtextdocs/common/formatter/MarkdownTextFormatterTest.xtend index c0cbc93..0a277d4 100644 --- a/com.github.darvasd.xtextdocs.common.test/src/com/github/darvasd/xtextdocs/common/formatter/MarkdownTextFormatterTest.xtend +++ b/com.epistimis.xtextdocs.common.test/src/com/epistimis/xtextdocs/common/formatter/MarkdownTextFormatterTest.xtend @@ -1,5 +1,6 @@ /********************************************************************* * Copyright (c) 2018 Daniel Darvas + * Copyright (c) 2024 Epistimis LLC * * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 @@ -8,11 +9,11 @@ * SPDX-License-Identifier: EPL-2.0 **********************************************************************/ -package com.github.darvasd.xtextdocs.common.formatter +package com.epistimis.xtextdocs.common.formatter import org.junit.Assert import org.junit.Test -import com.github.darvasd.xtextdocs.common.formatter.MarkdownTextFormatter +import com.epistimis.xtextdocs.common.formatter.MarkdownTextFormatter class MarkdownTextFormatterTest { @Test diff --git a/com.github.darvasd.xtextdocs.common.test/.classpath b/com.epistimis.xtextdocs.common/.classpath similarity index 95% rename from com.github.darvasd.xtextdocs.common.test/.classpath rename to com.epistimis.xtextdocs.common/.classpath index 428337e..bde7c66 100644 --- a/com.github.darvasd.xtextdocs.common.test/.classpath +++ b/com.epistimis.xtextdocs.common/.classpath @@ -1,8 +1,8 @@ - + diff --git a/com.github.darvasd.xtextdocs.xtext/.project b/com.epistimis.xtextdocs.common/.project similarity index 94% rename from com.github.darvasd.xtextdocs.xtext/.project rename to com.epistimis.xtextdocs.common/.project index 95417f8..b165b42 100644 --- a/com.github.darvasd.xtextdocs.xtext/.project +++ b/com.epistimis.xtextdocs.common/.project @@ -1,6 +1,6 @@ - com.github.darvasd.xtextdocs.xtext + com.epistimis.xtextdocs.common diff --git a/com.github.darvasd.xtextdocs.common/META-INF/MANIFEST.MF b/com.epistimis.xtextdocs.common/META-INF/MANIFEST.MF similarity index 54% rename from com.github.darvasd.xtextdocs.common/META-INF/MANIFEST.MF rename to com.epistimis.xtextdocs.common/META-INF/MANIFEST.MF index d1d733c..1a2ecc8 100644 --- a/com.github.darvasd.xtextdocs.common/META-INF/MANIFEST.MF +++ b/com.epistimis.xtextdocs.common/META-INF/MANIFEST.MF @@ -1,15 +1,16 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 +Automatic-Module-Name: com.epistimis.xtextdocs.common Bundle-Name: Commons for documentation generation -Bundle-SymbolicName: com.github.darvasd.xtextdocs.common +Bundle-SymbolicName: com.epistimis.xtextdocs.common Bundle-Version: 1.1.0.qualifier Bundle-Vendor: Daniel Darvas -Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Bundle-RequiredExecutionEnvironment: JavaSE-17 Require-Bundle: com.google.guava, org.eclipse.xtext.xbase.lib, org.eclipse.xtend.lib, org.eclipse.xtend.lib.macro, org.eclipse.xtext -Export-Package: com.github.darvasd.xtextdocs.common.formatter, - com.github.darvasd.xtextdocs.common.xtext +Export-Package: com.epistimis.xtextdocs.common.formatter, + com.epistimis.xtextdocs.common.xtext diff --git a/com.github.darvasd.xtextdocs.common/build.properties b/com.epistimis.xtextdocs.common/build.properties similarity index 100% rename from com.github.darvasd.xtextdocs.common/build.properties rename to com.epistimis.xtextdocs.common/build.properties diff --git a/com.github.darvasd.xtextdocs.xcore/pom.xml b/com.epistimis.xtextdocs.common/pom.xml similarity index 74% rename from com.github.darvasd.xtextdocs.xcore/pom.xml rename to com.epistimis.xtextdocs.common/pom.xml index 1bc4467..172b01e 100644 --- a/com.github.darvasd.xtextdocs.xcore/pom.xml +++ b/com.epistimis.xtextdocs.common/pom.xml @@ -2,11 +2,11 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - com.github.darvasd.xtextdocs - com.github.darvasd.xtextdocs.parent + com.epistimis.xtextdocs + com.epistimis.xtextdocs.parent 1.1.0-SNAPSHOT - com.github.darvasd.xtextdocs.xcore + com.epistimis.xtextdocs.common eclipse-plugin diff --git a/com.github.darvasd.xtextdocs.common/src/com/github/darvasd/xtextdocs/common/formatter/DocCommentTextUtil.java b/com.epistimis.xtextdocs.common/src/com/epistimis/xtextdocs/common/formatter/DocCommentTextUtil.java similarity index 95% rename from com.github.darvasd.xtextdocs.common/src/com/github/darvasd/xtextdocs/common/formatter/DocCommentTextUtil.java rename to com.epistimis.xtextdocs.common/src/com/epistimis/xtextdocs/common/formatter/DocCommentTextUtil.java index 431d0e9..3e86bae 100644 --- a/com.github.darvasd.xtextdocs.common/src/com/github/darvasd/xtextdocs/common/formatter/DocCommentTextUtil.java +++ b/com.epistimis.xtextdocs.common/src/com/epistimis/xtextdocs/common/formatter/DocCommentTextUtil.java @@ -1,6 +1,7 @@ /********************************************************************* * Copyright (c) 2018 Daniel Darvas -* +* Copyright (c) 2024 Epistimis LLC +* * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ @@ -8,7 +9,7 @@ * SPDX-License-Identifier: EPL-2.0 **********************************************************************/ -package com.github.darvasd.xtextdocs.common.formatter; +package com.epistimis.xtextdocs.common.formatter; import java.util.List; import java.util.function.Function; diff --git a/com.epistimis.xtextdocs.common/src/com/epistimis/xtextdocs/common/formatter/HTMLTextFormatter.xtend b/com.epistimis.xtextdocs.common/src/com/epistimis/xtextdocs/common/formatter/HTMLTextFormatter.xtend new file mode 100644 index 0000000..50e77b9 --- /dev/null +++ b/com.epistimis.xtextdocs.common/src/com/epistimis/xtextdocs/common/formatter/HTMLTextFormatter.xtend @@ -0,0 +1,72 @@ +package com.epistimis.xtextdocs.common.formatter + +import java.util.List + +class HTMLTextFormatter implements ITextFormatter { + public static final HTMLTextFormatter INSTANCE = new HTMLTextFormatter(); + + private new() { + } + + override escape(String original) { + // FIXME do not escape inside "`" + var ret = original; + if (!original.contains("@code") && !original.contains("`")) { // quickfix + ret = "
"+ original + "
"; + } + return ret; + } + + override bold(String original) { + if (original.isNullOrEmpty) { + return ""; + } + + // The '**' does not support multiline! + return '''«original»'''; + } + + override codeBlock(String original) { + return ''' +

+		«original»
+		
'''; + } + + override inlineCode(String original) { + if (original.isNullOrEmpty) { + return ""; + } + + return '''
«original»
'''; + } + + override italic(String original) { + if (original.isNullOrEmpty) { + return ""; + } + + // The '_' does not support multiline! + return '''«original»'''; + } + + override newLine() { + return ''' + + '''; + } + + override String link(String linkText, String target) { + return '''«linkText»'''; + } + + override unorderedList(List originals) { + return ''' +
    + «FOR line : originals» +
  • «line»
  • + «ENDFOR» +
+ ''' + } +} diff --git a/com.github.darvasd.xtextdocs.common/src/com/github/darvasd/xtextdocs/common/formatter/ITextFormatter.java b/com.epistimis.xtextdocs.common/src/com/epistimis/xtextdocs/common/formatter/ITextFormatter.java similarity index 93% rename from com.github.darvasd.xtextdocs.common/src/com/github/darvasd/xtextdocs/common/formatter/ITextFormatter.java rename to com.epistimis.xtextdocs.common/src/com/epistimis/xtextdocs/common/formatter/ITextFormatter.java index 1c59962..10cd931 100644 --- a/com.github.darvasd.xtextdocs.common/src/com/github/darvasd/xtextdocs/common/formatter/ITextFormatter.java +++ b/com.epistimis.xtextdocs.common/src/com/epistimis/xtextdocs/common/formatter/ITextFormatter.java @@ -1,6 +1,7 @@ /********************************************************************* * Copyright (c) 2018 Daniel Darvas -* +* Copyright (c) 2024 Epistimis LLC +* * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ @@ -8,7 +9,7 @@ * SPDX-License-Identifier: EPL-2.0 **********************************************************************/ -package com.github.darvasd.xtextdocs.common.formatter; +package com.epistimis.xtextdocs.common.formatter; import java.util.List; diff --git a/com.github.darvasd.xtextdocs.common/src/com/github/darvasd/xtextdocs/common/formatter/MarkdownTextFormatter.xtend b/com.epistimis.xtextdocs.common/src/com/epistimis/xtextdocs/common/formatter/MarkdownTextFormatter.xtend similarity index 91% rename from com.github.darvasd.xtextdocs.common/src/com/github/darvasd/xtextdocs/common/formatter/MarkdownTextFormatter.xtend rename to com.epistimis.xtextdocs.common/src/com/epistimis/xtextdocs/common/formatter/MarkdownTextFormatter.xtend index fe1d75a..3179f91 100644 --- a/com.github.darvasd.xtextdocs.common/src/com/github/darvasd/xtextdocs/common/formatter/MarkdownTextFormatter.xtend +++ b/com.epistimis.xtextdocs.common/src/com/epistimis/xtextdocs/common/formatter/MarkdownTextFormatter.xtend @@ -1,4 +1,4 @@ -package com.github.darvasd.xtextdocs.common.formatter +package com.epistimis.xtextdocs.common.formatter import java.util.List diff --git a/com.github.darvasd.xtextdocs.common/src/com/github/darvasd/xtextdocs/common/xtext/XtextTokenUtil.xtend b/com.epistimis.xtextdocs.common/src/com/epistimis/xtextdocs/common/xtext/XtextTokenUtil.xtend similarity index 96% rename from com.github.darvasd.xtextdocs.common/src/com/github/darvasd/xtextdocs/common/xtext/XtextTokenUtil.xtend rename to com.epistimis.xtextdocs.common/src/com/epistimis/xtextdocs/common/xtext/XtextTokenUtil.xtend index 0e0e820..ec1c14c 100644 --- a/com.github.darvasd.xtextdocs.common/src/com/github/darvasd/xtextdocs/common/xtext/XtextTokenUtil.xtend +++ b/com.epistimis.xtextdocs.common/src/com/epistimis/xtextdocs/common/xtext/XtextTokenUtil.xtend @@ -1,4 +1,4 @@ -package com.github.darvasd.xtextdocs.common.xtext +package com.epistimis.xtextdocs.common.xtext import org.eclipse.emf.ecore.EObject import org.eclipse.xtext.TerminalRule diff --git a/com.github.darvasd.xtextdocs.p2/.project b/com.epistimis.xtextdocs.p2/.project similarity index 79% rename from com.github.darvasd.xtextdocs.p2/.project rename to com.epistimis.xtextdocs.p2/.project index 40ad38a..461c206 100644 --- a/com.github.darvasd.xtextdocs.p2/.project +++ b/com.epistimis.xtextdocs.p2/.project @@ -1,6 +1,6 @@ - com.github.darvasd.xtextdocs.p2 + com.epistimis.xtextdocs.p2 diff --git a/com.epistimis.xtextdocs.p2/category.xml b/com.epistimis.xtextdocs.p2/category.xml new file mode 100644 index 0000000..39f1ae5 --- /dev/null +++ b/com.epistimis.xtextdocs.p2/category.xml @@ -0,0 +1,21 @@ + + + + + + + + + + + + Visit http://github.com/darvasd/xtext-docs-gen for more details. + + + + + Visit http://github.com/darvasd/xtext-docs-gen for more details. + + + + diff --git a/com.github.darvasd.xtextdocs.p2/pom.xml b/com.epistimis.xtextdocs.p2/pom.xml similarity index 52% rename from com.github.darvasd.xtextdocs.p2/pom.xml rename to com.epistimis.xtextdocs.p2/pom.xml index 9bc2116..11a83f8 100644 --- a/com.github.darvasd.xtextdocs.p2/pom.xml +++ b/com.epistimis.xtextdocs.p2/pom.xml @@ -1,11 +1,11 @@ 4.0.0 - com.github.darvasd.xtextdocs - com.github.darvasd.xtextdocs.parent + com.epistimis.xtextdocs + com.epistimis.xtextdocs.parent 1.1.0-SNAPSHOT - com.github.darvasd.xtextdocs.p2 + com.epistimis.xtextdocs.p2 1.1.0-SNAPSHOT eclipse-repository \ No newline at end of file diff --git a/com.github.darvasd.xtextdocs.target/.project b/com.epistimis.xtextdocs.target/.project similarity index 100% rename from com.github.darvasd.xtextdocs.target/.project rename to com.epistimis.xtextdocs.target/.project diff --git a/com.github.darvasd.xtextdocs.target/com.github.darvasd.xtextdocs.target.target b/com.epistimis.xtextdocs.target/com.github.darvasd.xtextdocs.target.target similarity index 100% rename from com.github.darvasd.xtextdocs.target/com.github.darvasd.xtextdocs.target.target rename to com.epistimis.xtextdocs.target/com.github.darvasd.xtextdocs.target.target diff --git a/com.github.darvasd.xtextdocs.target/pom.xml b/com.epistimis.xtextdocs.target/pom.xml similarity index 69% rename from com.github.darvasd.xtextdocs.target/pom.xml rename to com.epistimis.xtextdocs.target/pom.xml index 2d8d7bf..d7689f8 100644 --- a/com.github.darvasd.xtextdocs.target/pom.xml +++ b/com.epistimis.xtextdocs.target/pom.xml @@ -2,11 +2,11 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - com.github.darvasd.xtextdocs - com.github.darvasd.xtextdocs.parent + com.epistimis.xtextdocs + com.epistimis.xtextdocs.parent 1.1.0-SNAPSHOT - com.github.darvasd.xtextdocs.target + com.epistimis.xtextdocs.target eclipse-target-definition diff --git a/com.github.darvasd.xtextdocs.common/.classpath b/com.epistimis.xtextdocs.xcore/.classpath similarity index 95% rename from com.github.darvasd.xtextdocs.common/.classpath rename to com.epistimis.xtextdocs.xcore/.classpath index 428337e..4301eb3 100644 --- a/com.github.darvasd.xtextdocs.common/.classpath +++ b/com.epistimis.xtextdocs.xcore/.classpath @@ -1,8 +1,8 @@ - - + + diff --git a/com.epistimis.xtextdocs.xcore/.project b/com.epistimis.xtextdocs.xcore/.project new file mode 100644 index 0000000..f1d624e --- /dev/null +++ b/com.epistimis.xtextdocs.xcore/.project @@ -0,0 +1,34 @@ + + + com.epistimis.xtextdocs.xcore + + + + + + org.eclipse.xtext.ui.shared.xtextBuilder + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + org.eclipse.xtext.ui.shared.xtextNature + + diff --git a/com.github.darvasd.xtextdocs.xcore/META-INF/MANIFEST.MF b/com.epistimis.xtextdocs.xcore/META-INF/MANIFEST.MF similarity index 62% rename from com.github.darvasd.xtextdocs.xcore/META-INF/MANIFEST.MF rename to com.epistimis.xtextdocs.xcore/META-INF/MANIFEST.MF index c126aa3..ffc054e 100644 --- a/com.github.darvasd.xtextdocs.xcore/META-INF/MANIFEST.MF +++ b/com.epistimis.xtextdocs.xcore/META-INF/MANIFEST.MF @@ -1,10 +1,12 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 +Automatic-Module-Name: com.epistimis.xtextdocs.xcore Bundle-Name: Xcore metamodel documentation generator -Bundle-SymbolicName: com.github.darvasd.xtextdocs.xcore +Bundle-SymbolicName: com.epistimis.xtextdocs.xcore Bundle-Version: 1.1.0.qualifier +Import-Package: org.apache.log4j;version="1.2.24" Bundle-Vendor: Daniel Darvas -Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Bundle-RequiredExecutionEnvironment: JavaSE-17 Require-Bundle: com.google.guava, org.eclipse.xtext.xbase.lib, org.eclipse.xtend.lib, @@ -15,5 +17,5 @@ Require-Bundle: com.google.guava, org.eclipse.emf.ecore.xcore.lib, org.eclipse.emf.ecore.xcore, org.eclipse.emf.codegen.ecore, - com.github.darvasd.xtextdocs.common;bundle-version="1.1.0";visibility:=reexport + com.epistimis.xtextdocs.common;bundle-version="1.1.0";visibility:=reexport diff --git a/com.github.darvasd.xtextdocs.xcore/build.properties b/com.epistimis.xtextdocs.xcore/build.properties similarity index 100% rename from com.github.darvasd.xtextdocs.xcore/build.properties rename to com.epistimis.xtextdocs.xcore/build.properties diff --git a/com.github.darvasd.xtextdocs.xtext/pom.xml b/com.epistimis.xtextdocs.xcore/pom.xml similarity index 74% rename from com.github.darvasd.xtextdocs.xtext/pom.xml rename to com.epistimis.xtextdocs.xcore/pom.xml index 98f37f1..bb7996f 100644 --- a/com.github.darvasd.xtextdocs.xtext/pom.xml +++ b/com.epistimis.xtextdocs.xcore/pom.xml @@ -2,11 +2,11 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - com.github.darvasd.xtextdocs - com.github.darvasd.xtextdocs.parent + com.epistimis.xtextdocs + com.epistimis.xtextdocs.parent 1.1.0-SNAPSHOT - com.github.darvasd.xtextdocs.xtext + com.epistimis.xtextdocs.xcore eclipse-plugin diff --git a/com.github.darvasd.xtextdocs.xcore/src/com/github/darvasd/xtextdocs/xcore/formatter/IXcoreDocsFormatter.java b/com.epistimis.xtextdocs.xcore/src/com/epistimis/xtextdocs/xcore/formatter/IXcoreDocsFormatter.java similarity index 86% rename from com.github.darvasd.xtextdocs.xcore/src/com/github/darvasd/xtextdocs/xcore/formatter/IXcoreDocsFormatter.java rename to com.epistimis.xtextdocs.xcore/src/com/epistimis/xtextdocs/xcore/formatter/IXcoreDocsFormatter.java index 14f5995..c178f7f 100644 --- a/com.github.darvasd.xtextdocs.xcore/src/com/github/darvasd/xtextdocs/xcore/formatter/IXcoreDocsFormatter.java +++ b/com.epistimis.xtextdocs.xcore/src/com/epistimis/xtextdocs/xcore/formatter/IXcoreDocsFormatter.java @@ -1,4 +1,4 @@ -package com.github.darvasd.xtextdocs.xcore.formatter; +package com.epistimis.xtextdocs.xcore.formatter; import org.eclipse.emf.ecore.xcore.resource.XcoreResource; diff --git a/com.github.darvasd.xtextdocs.xcore/src/com/github/darvasd/xtextdocs/xcore/formatter/MarkdownXcoreDocsFormatter.xtend b/com.epistimis.xtextdocs.xcore/src/com/epistimis/xtextdocs/xcore/formatter/MarkdownXcoreDocsFormatter.xtend similarity index 92% rename from com.github.darvasd.xtextdocs.xcore/src/com/github/darvasd/xtextdocs/xcore/formatter/MarkdownXcoreDocsFormatter.xtend rename to com.epistimis.xtextdocs.xcore/src/com/epistimis/xtextdocs/xcore/formatter/MarkdownXcoreDocsFormatter.xtend index cce1033..9198a62 100644 --- a/com.github.darvasd.xtextdocs.xcore/src/com/github/darvasd/xtextdocs/xcore/formatter/MarkdownXcoreDocsFormatter.xtend +++ b/com.epistimis.xtextdocs.xcore/src/com/epistimis/xtextdocs/xcore/formatter/MarkdownXcoreDocsFormatter.xtend @@ -1,4 +1,4 @@ -package com.github.darvasd.xtextdocs.xcore.formatter +package com.epistimis.xtextdocs.xcore.formatter import org.eclipse.emf.codegen.ecore.genmodel.GenBase import org.eclipse.emf.codegen.ecore.genmodel.GenClass @@ -25,24 +25,24 @@ import org.eclipse.xtext.nodemodel.util.NodeModelUtils import com.google.common.base.Strings import java.util.TreeMap import java.util.SortedMap -import com.github.darvasd.xtextdocs.common.xtext.XtextTokenUtil -import com.github.darvasd.xtextdocs.common.formatter.MarkdownTextFormatter -import com.github.darvasd.xtextdocs.common.formatter.DocCommentTextUtil +import com.epistimis.xtextdocs.common.xtext.XtextTokenUtil +import com.epistimis.xtextdocs.common.formatter.MarkdownTextFormatter +import com.epistimis.xtextdocs.common.formatter.DocCommentTextUtil /** * Class to be used for generating a Markdown documentation for an Xcore metamodel description. */ class MarkdownXcoreDocsFormatter implements IXcoreDocsFormatter { - private static val DOCUMENTATION_ANNOTATION_KEY = "documentation"; + static val DOCUMENTATION_ANNOTATION_KEY = "documentation"; - private static val extension MarkdownTextFormatter mdFormatter = MarkdownTextFormatter.INSTANCE; + static val extension MarkdownTextFormatter mdFormatter = MarkdownTextFormatter.INSTANCE; /** * The main title text of the documentation to be generated. * If not set ({@code null}), the title will be the URI of the metamodel. */ - @Accessors private String mainTitle = null; + @Accessors String mainTitle = null; @Accessors boolean gitbookLinkStyle = true; @@ -56,7 +56,7 @@ class MarkdownXcoreDocsFormatter implements IXcoreDocsFormatter { * If it is greater than zero, the number of {@code #} characters will be increased * with this number at each title. */ - private int titleLevelOffset = 0; + int titleLevelOffset = 0; /** * Sets the title depth offset. If set to 0, the main title will be prefixed with {@code #}, @@ -68,15 +68,15 @@ class MarkdownXcoreDocsFormatter implements IXcoreDocsFormatter { * as MWE2 does not support integer properties. * See https://bugs.eclipse.org/bugs/show_bug.cgi?id=377068 . */ - public def void setTitleLevelOffset(String value) { + def void setTitleLevelOffset(String value) { this.titleLevelOffset = Integer.parseInt(value); } /** * Map that stores (name, id) pairs. The stored 'id' is the anchor that is used for the definition of the class 'name'. */ - private SortedMap anchors = new TreeMap(); - private int anchorCounter = 1; + SortedMap anchors = new TreeMap(); + int anchorCounter = 1; override generateDocs(XcoreResource resource) { fillAnchors(resource); diff --git a/com.github.darvasd.xtextdocs.xcore/src/com/github/darvasd/xtextdocs/xcore/fragment/DocsGeneratorFragment.xtend b/com.epistimis.xtextdocs.xcore/src/com/epistimis/xtextdocs/xcore/fragment/DocsGeneratorFragment.xtend similarity index 87% rename from com.github.darvasd.xtextdocs.xcore/src/com/github/darvasd/xtextdocs/xcore/fragment/DocsGeneratorFragment.xtend rename to com.epistimis.xtextdocs.xcore/src/com/epistimis/xtextdocs/xcore/fragment/DocsGeneratorFragment.xtend index 0fa9adb..30d069e 100644 --- a/com.github.darvasd.xtextdocs.xcore/src/com/github/darvasd/xtextdocs/xcore/fragment/DocsGeneratorFragment.xtend +++ b/com.epistimis.xtextdocs.xcore/src/com/epistimis/xtextdocs/xcore/fragment/DocsGeneratorFragment.xtend @@ -1,4 +1,4 @@ -package com.github.darvasd.xtextdocs.xcore.fragment +package com.epistimis.xtextdocs.xcore.fragment import org.eclipse.emf.common.util.URI import org.eclipse.emf.ecore.resource.ResourceSet @@ -9,14 +9,14 @@ import org.eclipse.emf.mwe2.runtime.workflow.IWorkflowContext import org.eclipse.xtend.lib.annotations.Accessors import java.nio.file.Paths import java.io.FileWriter -import com.github.darvasd.xtextdocs.xcore.formatter.IXcoreDocsFormatter +import com.epistimis.xtextdocs.xcore.formatter.IXcoreDocsFormatter import org.apache.log4j.Logger /** * Xcore documentation generation fragment to be used in MWE2 workflows. */ class DocsGeneratorFragment implements IWorkflowComponent { - private final static Logger LOG = Logger.getLogger(DocsGeneratorFragment); + final static Logger LOG = Logger.getLogger(DocsGeneratorFragment); /** * The URI of the Xcore metamodel to be documented. diff --git a/com.github.darvasd.xtextdocs.xtext.test/.classpath b/com.epistimis.xtextdocs.xtext.test/.classpath similarity index 96% rename from com.github.darvasd.xtextdocs.xtext.test/.classpath rename to com.epistimis.xtextdocs.xtext.test/.classpath index 3fe0962..51bc151 100644 --- a/com.github.darvasd.xtextdocs.xtext.test/.classpath +++ b/com.epistimis.xtextdocs.xtext.test/.classpath @@ -1,9 +1,9 @@ - - + + diff --git a/com.github.darvasd.xtextdocs.xtext.test/.project b/com.epistimis.xtextdocs.xtext.test/.project similarity index 93% rename from com.github.darvasd.xtextdocs.xtext.test/.project rename to com.epistimis.xtextdocs.xtext.test/.project index 332f1d4..a81a8a4 100644 --- a/com.github.darvasd.xtextdocs.xtext.test/.project +++ b/com.epistimis.xtextdocs.xtext.test/.project @@ -1,6 +1,6 @@ - com.github.darvasd.xtextdocs.xtext.test + com.epistimis.xtextdocs.xtext.test diff --git a/com.epistimis.xtextdocs.xtext.test/META-INF/MANIFEST.MF b/com.epistimis.xtextdocs.xtext.test/META-INF/MANIFEST.MF new file mode 100644 index 0000000..011307d --- /dev/null +++ b/com.epistimis.xtextdocs.xtext.test/META-INF/MANIFEST.MF @@ -0,0 +1,8 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Automatic-Module-Name: com.epistimis.xtextdocs.xtext.test +Bundle-Name: com.epistimis.xtextdocs.xtext.test +Bundle-SymbolicName: com.epistimis.xtextdocs.xtext.test +Bundle-Version: 1.1.0.qualifier +Fragment-Host: com.epistimis.xtextdocs.xtext;bundle-version="1.1.0" +Bundle-RequiredExecutionEnvironment: JavaSE-17 diff --git a/com.github.darvasd.xtextdocs.xtext.test/build.properties b/com.epistimis.xtextdocs.xtext.test/build.properties similarity index 100% rename from com.github.darvasd.xtextdocs.xtext.test/build.properties rename to com.epistimis.xtextdocs.xtext.test/build.properties diff --git a/com.github.darvasd.xtextdocs.common.test/pom.xml b/com.epistimis.xtextdocs.xtext.test/pom.xml similarity index 80% rename from com.github.darvasd.xtextdocs.common.test/pom.xml rename to com.epistimis.xtextdocs.xtext.test/pom.xml index 63a0646..6b3bd61 100644 --- a/com.github.darvasd.xtextdocs.common.test/pom.xml +++ b/com.epistimis.xtextdocs.xtext.test/pom.xml @@ -2,11 +2,11 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - com.github.darvasd.xtextdocs - com.github.darvasd.xtextdocs.parent + com.epistimis.xtextdocs + com.epistimis.xtextdocs.parent 1.1.0-SNAPSHOT - com.github.darvasd.xtextdocs.common.test + com.epistimis.xtextdocs.xtext.test eclipse-test-plugin diff --git a/com.github.darvasd.xtextdocs.xtext.test/resources/DomainmodelGrammar.xmi b/com.epistimis.xtextdocs.xtext.test/resources/DomainmodelGrammar.xmi similarity index 100% rename from com.github.darvasd.xtextdocs.xtext.test/resources/DomainmodelGrammar.xmi rename to com.epistimis.xtextdocs.xtext.test/resources/DomainmodelGrammar.xmi diff --git a/com.github.darvasd.xtextdocs.xtext.test/src/com/github/darvasd/xtextdocs/xtext/doccomment/DocCommentTest.xtend b/com.epistimis.xtextdocs.xtext.test/src/com/epistimis/xtextdocs/xtext/doccomment/DocCommentTest.xtend similarity index 95% rename from com.github.darvasd.xtextdocs.xtext.test/src/com/github/darvasd/xtextdocs/xtext/doccomment/DocCommentTest.xtend rename to com.epistimis.xtextdocs.xtext.test/src/com/epistimis/xtextdocs/xtext/doccomment/DocCommentTest.xtend index 1a50960..3a607cc 100644 --- a/com.github.darvasd.xtextdocs.xtext.test/src/com/github/darvasd/xtextdocs/xtext/doccomment/DocCommentTest.xtend +++ b/com.epistimis.xtextdocs.xtext.test/src/com/epistimis/xtextdocs/xtext/doccomment/DocCommentTest.xtend @@ -1,5 +1,6 @@ /********************************************************************* * Copyright (c) 2018 Daniel Darvas + * Copyright (c) 2024 Epistimis LLC * * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 @@ -8,7 +9,7 @@ * SPDX-License-Identifier: EPL-2.0 **********************************************************************/ -package com.github.darvasd.xtextdocs.xtext.doccomment +package com.epistimis.xtextdocs.xtext.doccomment import org.junit.Test import org.junit.Assert diff --git a/com.github.darvasd.xtextdocs.xtext.test/src/com/github/darvasd/xtextdocs/xtext/integrationtest/IntegrationTest.xtend b/com.epistimis.xtextdocs.xtext.test/src/com/epistimis/xtextdocs/xtext/integrationtest/IntegrationTest.xtend similarity index 90% rename from com.github.darvasd.xtextdocs.xtext.test/src/com/github/darvasd/xtextdocs/xtext/integrationtest/IntegrationTest.xtend rename to com.epistimis.xtextdocs.xtext.test/src/com/epistimis/xtextdocs/xtext/integrationtest/IntegrationTest.xtend index 7e4a89c..6d02bc3 100644 --- a/com.github.darvasd.xtextdocs.xtext.test/src/com/github/darvasd/xtextdocs/xtext/integrationtest/IntegrationTest.xtend +++ b/com.epistimis.xtextdocs.xtext.test/src/com/epistimis/xtextdocs/xtext/integrationtest/IntegrationTest.xtend @@ -1,5 +1,6 @@ /********************************************************************* * Copyright (c) 2018 Daniel Darvas + * Copyright (c) 2024 Epistimis LLC * * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 @@ -8,9 +9,9 @@ * SPDX-License-Identifier: EPL-2.0 **********************************************************************/ -package com.github.darvasd.xtextdocs.xtext.integrationtest +package com.epistimis.xtextdocs.xtext.integrationtest -import com.github.darvasd.xtextdocs.xtext.DocsGenerator +import com.epistimis.xtextdocs.xtext.DocsGenerator import com.google.common.base.Preconditions import org.eclipse.emf.common.util.URI import org.eclipse.emf.ecore.util.EcoreUtil @@ -20,10 +21,10 @@ import org.eclipse.xtext.Grammar import org.junit.Assert import org.junit.Before import org.junit.Test -import com.github.darvasd.xtextdocs.xtext.formatter.MarkdownDocsFormatter +import com.epistimis.xtextdocs.xtext.formatter.MarkdownDocsFormatter class IntegrationTest { - private Grammar grammar; + Grammar grammar; /** * Loads the grammar metamodel for the integration tests. diff --git a/com.github.darvasd.xtextdocs.xcore/.classpath b/com.epistimis.xtextdocs.xtext/.classpath similarity index 78% rename from com.github.darvasd.xtextdocs.xcore/.classpath rename to com.epistimis.xtextdocs.xtext/.classpath index 1c96fe2..28adbe3 100644 --- a/com.github.darvasd.xtextdocs.xcore/.classpath +++ b/com.epistimis.xtextdocs.xtext/.classpath @@ -1,8 +1,12 @@ - - - - - - - - + + + + + + + + + + + + diff --git a/com.github.darvasd.xtextdocs.common.test/.project b/com.epistimis.xtextdocs.xtext/.project similarity index 93% rename from com.github.darvasd.xtextdocs.common.test/.project rename to com.epistimis.xtextdocs.xtext/.project index 6be8eaa..1a6b0ac 100644 --- a/com.github.darvasd.xtextdocs.common.test/.project +++ b/com.epistimis.xtextdocs.xtext/.project @@ -1,6 +1,6 @@ - com.github.darvasd.xtextdocs.common.test + com.epistimis.xtextdocs.xtext diff --git a/com.github.darvasd.xtextdocs.xtext/META-INF/MANIFEST.MF b/com.epistimis.xtextdocs.xtext/META-INF/MANIFEST.MF similarity index 54% rename from com.github.darvasd.xtextdocs.xtext/META-INF/MANIFEST.MF rename to com.epistimis.xtextdocs.xtext/META-INF/MANIFEST.MF index 44b9359..547915e 100644 --- a/com.github.darvasd.xtextdocs.xtext/META-INF/MANIFEST.MF +++ b/com.epistimis.xtextdocs.xtext/META-INF/MANIFEST.MF @@ -1,19 +1,20 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 +Automatic-Module-Name: com.epistimis.xtextdocs.xtext Bundle-Name: Xtext grammar documentation generator -Bundle-SymbolicName: com.github.darvasd.xtextdocs.xtext +Bundle-SymbolicName: com.epistimis.xtextdocs.xtext Bundle-Version: 1.1.0.qualifier -Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Bundle-RequiredExecutionEnvironment: JavaSE-17 Require-Bundle: org.eclipse.xtext;bundle-version="2.10.0", com.google.guava;bundle-version="15.0.0", org.junit;bundle-version="4.12.0", org.eclipse.xtext.xbase.lib, org.eclipse.xtend.lib, org.eclipse.xtend.lib.macro, - org.eclipse.xtext.generator;bundle-version="2.12.0", - com.github.darvasd.xtextdocs.common;visibility:=reexport -Export-Package: com.github.darvasd.xtextdocs.xtext.fragment, - com.github.darvasd.xtextdocs.xtext + com.epistimis.xtextdocs.common;visibility:=reexport, + org.eclipse.xtext.xtext.generator;bundle-version="2.33.0" +Export-Package: com.epistimis.xtextdocs.xtext.fragment, + com.epistimis.xtextdocs.xtext Import-Package: org.apache.log4j Bundle-Vendor: Daniel Darvas diff --git a/com.github.darvasd.xtextdocs.xtext/build.properties b/com.epistimis.xtextdocs.xtext/build.properties similarity index 100% rename from com.github.darvasd.xtextdocs.xtext/build.properties rename to com.epistimis.xtextdocs.xtext/build.properties diff --git a/com.github.darvasd.xtextdocs.common/pom.xml b/com.epistimis.xtextdocs.xtext/pom.xml similarity index 74% rename from com.github.darvasd.xtextdocs.common/pom.xml rename to com.epistimis.xtextdocs.xtext/pom.xml index d2c2534..6452c2e 100644 --- a/com.github.darvasd.xtextdocs.common/pom.xml +++ b/com.epistimis.xtextdocs.xtext/pom.xml @@ -2,11 +2,11 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - com.github.darvasd.xtextdocs - com.github.darvasd.xtextdocs.parent + com.epistimis.xtextdocs + com.epistimis.xtextdocs.parent 1.1.0-SNAPSHOT - com.github.darvasd.xtextdocs.common + com.epistimis.xtextdocs.xtext eclipse-plugin diff --git a/com.github.darvasd.xtextdocs.xtext/src/com/github/darvasd/xtextdocs/xtext/DocsGenerator.java b/com.epistimis.xtextdocs.xtext/src/com/epistimis/xtextdocs/xtext/DocsGenerator.java similarity index 85% rename from com.github.darvasd.xtextdocs.xtext/src/com/github/darvasd/xtextdocs/xtext/DocsGenerator.java rename to com.epistimis.xtextdocs.xtext/src/com/epistimis/xtextdocs/xtext/DocsGenerator.java index 5e9999b..b59f145 100644 --- a/com.github.darvasd.xtextdocs.xtext/src/com/github/darvasd/xtextdocs/xtext/DocsGenerator.java +++ b/com.epistimis.xtextdocs.xtext/src/com/epistimis/xtextdocs/xtext/DocsGenerator.java @@ -1,6 +1,7 @@ /********************************************************************* * Copyright (c) 2018 Daniel Darvas -* +* Copyright (c) 2024 Epistimis LLC +* * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ @@ -8,7 +9,7 @@ * SPDX-License-Identifier: EPL-2.0 **********************************************************************/ -package com.github.darvasd.xtextdocs.xtext; +package com.epistimis.xtextdocs.xtext; import java.util.ArrayList; import java.util.List; @@ -21,10 +22,10 @@ import org.eclipse.xtext.nodemodel.INode; import org.eclipse.xtext.nodemodel.util.NodeModelUtils; -import com.github.darvasd.xtextdocs.xtext.ruledoc.RuleDoc; -import com.github.darvasd.xtextdocs.xtext.doccomment.DocComment; -import com.github.darvasd.xtextdocs.xtext.formatter.IGrammarDocsFormatter; -import com.github.darvasd.xtextdocs.xtext.ruledoc.GrammarDoc; +import com.epistimis.xtextdocs.xtext.ruledoc.RuleDoc; +import com.epistimis.xtextdocs.xtext.doccomment.DocComment; +import com.epistimis.xtextdocs.xtext.formatter.IGrammarDocsFormatter; +import com.epistimis.xtextdocs.xtext.ruledoc.GrammarDoc; /** * Utility class containing the entry points for the documentation generation @@ -50,6 +51,20 @@ public static CharSequence generateFormattedDoc(Grammar grammar, IGrammarDocsFor return formatter.formatGrammar(grammarDoc); } + /** + * Generates a DOT graph textual documentation for the given grammar, using the + * given formatter. + * + * @param grammar + * The grammar to be represented. + * @param formatter + * The formatter to be used. + * @return DOT graph textual documentation. + */ + public static CharSequence generateDOTGraph(Grammar grammar, IGrammarDocsFormatter formatter) { + GrammarDoc grammarDoc = createGrammarDocumentation(grammar); + return formatter.formatGraph(grammarDoc); + } /** * Creates and returns a documentation object for the grammar, including its * rules. diff --git a/com.github.darvasd.xtextdocs.xtext/src/com/github/darvasd/xtextdocs/xtext/doccomment/DocComment.java b/com.epistimis.xtextdocs.xtext/src/com/epistimis/xtextdocs/xtext/doccomment/DocComment.java similarity index 98% rename from com.github.darvasd.xtextdocs.xtext/src/com/github/darvasd/xtextdocs/xtext/doccomment/DocComment.java rename to com.epistimis.xtextdocs.xtext/src/com/epistimis/xtextdocs/xtext/doccomment/DocComment.java index ab9af4e..f134651 100644 --- a/com.github.darvasd.xtextdocs.xtext/src/com/github/darvasd/xtextdocs/xtext/doccomment/DocComment.java +++ b/com.epistimis.xtextdocs.xtext/src/com/epistimis/xtextdocs/xtext/doccomment/DocComment.java @@ -1,6 +1,7 @@ /********************************************************************* * Copyright (c) 2018 Daniel Darvas -* +* Copyright (c) 2024 Epistimis LLC +* * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ @@ -8,7 +9,7 @@ * SPDX-License-Identifier: EPL-2.0 **********************************************************************/ -package com.github.darvasd.xtextdocs.xtext.doccomment; +package com.epistimis.xtextdocs.xtext.doccomment; import java.util.ArrayList; import java.util.Arrays; diff --git a/com.github.darvasd.xtextdocs.xtext/src/com/github/darvasd/xtextdocs/xtext/doccomment/DocCommentBlockTag.java b/com.epistimis.xtextdocs.xtext/src/com/epistimis/xtextdocs/xtext/doccomment/DocCommentBlockTag.java similarity index 94% rename from com.github.darvasd.xtextdocs.xtext/src/com/github/darvasd/xtextdocs/xtext/doccomment/DocCommentBlockTag.java rename to com.epistimis.xtextdocs.xtext/src/com/epistimis/xtextdocs/xtext/doccomment/DocCommentBlockTag.java index 9230342..6aa28a2 100644 --- a/com.github.darvasd.xtextdocs.xtext/src/com/github/darvasd/xtextdocs/xtext/doccomment/DocCommentBlockTag.java +++ b/com.epistimis.xtextdocs.xtext/src/com/epistimis/xtextdocs/xtext/doccomment/DocCommentBlockTag.java @@ -1,6 +1,7 @@ /********************************************************************* * Copyright (c) 2018 Daniel Darvas -* +* Copyright (c) 2024 Epistimis LLC +* * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ @@ -8,7 +9,7 @@ * SPDX-License-Identifier: EPL-2.0 **********************************************************************/ -package com.github.darvasd.xtextdocs.xtext.doccomment; +package com.epistimis.xtextdocs.xtext.doccomment; import com.google.common.base.Preconditions; diff --git a/com.epistimis.xtextdocs.xtext/src/com/epistimis/xtextdocs/xtext/formatter/DotGraphBaseFormatter.xtend b/com.epistimis.xtextdocs.xtext/src/com/epistimis/xtextdocs/xtext/formatter/DotGraphBaseFormatter.xtend new file mode 100644 index 0000000..393f060 --- /dev/null +++ b/com.epistimis.xtextdocs.xtext/src/com/epistimis/xtextdocs/xtext/formatter/DotGraphBaseFormatter.xtend @@ -0,0 +1,418 @@ +/********************************************************************* +* Copyright (c) 2018 Daniel Darvas +* Copyright (c) 2024 Epistimis LLC +* +* This program and the accompanying materials are made +* available under the terms of the Eclipse Public License 2.0 +* which is available at https://www.eclipse.org/legal/epl-2.0/ +* +* SPDX-License-Identifier: EPL-2.0 +**********************************************************************/ + +package com.epistimis.xtextdocs.xtext.formatter + +import com.epistimis.xtextdocs.xtext.ruledoc.EnumRuleDoc +import com.epistimis.xtextdocs.xtext.ruledoc.GrammarDoc +import com.epistimis.xtextdocs.xtext.ruledoc.ParserRuleDoc +import com.epistimis.xtextdocs.xtext.ruledoc.ReferenceRuleDoc +import com.epistimis.xtextdocs.xtext.ruledoc.RuleDoc +import com.epistimis.xtextdocs.xtext.ruledoc.TerminalRuleDoc +import com.google.common.base.Preconditions +import java.util.LinkedList +import java.util.List +import java.util.Map +import java.util.Queue +import org.eclipse.xtend.lib.annotations.Accessors +import org.eclipse.xtext.AbstractElement +import org.eclipse.xtext.AbstractRule +import org.eclipse.xtext.Action +import org.eclipse.xtext.Alternatives +import org.eclipse.xtext.Assignment +import org.eclipse.xtext.CharacterRange +import org.eclipse.xtext.CrossReference +import org.eclipse.xtext.EnumLiteralDeclaration +import org.eclipse.xtext.Group +import org.eclipse.xtext.Keyword +import org.eclipse.xtext.NegatedToken +import org.eclipse.xtext.RuleCall +import org.eclipse.xtext.UnorderedGroup +import org.eclipse.xtext.UntilToken +import org.eclipse.xtext.Wildcard + +abstract class DotGraphBaseFormatter implements IGrammarDocsFormatter { + protected static final String EXAMPLE_TAG = "@example" + protected static final String VALIDATION_TAG = "@validation" + + @Accessors boolean includeSimplifiedGrammar = true; + @Accessors boolean includeDotReferenceGraph = false; + @Accessors boolean includeToc = false; + @Accessors boolean gitbookLinkStyle = false; + + /** + * The main title text of the documentation to be generated. + * If not set ({@code null}), the title will be the full name of the grammar. + */ + @Accessors String mainTitle = null; + + /** + * Title depth offset. If set to 0, the main title will be prefixed with {@code #}, + * the second level titles with {@code ##}, etc. + * If it is greater than zero, the number of {@code #} characters will be increased + * with this number at each title. + */ + protected int titleLevelOffset = 0; + + /** + * Sets the title depth offset. If set to 0, the main title will be prefixed with {@code #}, + * the second level titles with {@code ##}, etc. + * If it is greater than zero, the number of {@code #} characters will be increased + * with this number at each title. + *

+ * It is an ugly workaround to take a string as argument, but this is necessary + * as MWE2 does not support integer properties. + * See https://bugs.eclipse.org/bugs/show_bug.cgi?id=377068 . + */ + def void setTitleLevelOffset(String value) { + this.titleLevelOffset = Integer.parseInt(value); + } + + /** + * Returns a Markdown-formatted document describing the given grammar, + * including all its rules. + *

+ * If the value of {@code includeSimplifiedGrammar} is true, the document + * will contain a simplified BNF description of the grammar. + * If the value of {@code includeDotReferenceGraph} is true, a + * GraphViz-style representation of the dependency between the grammar + * rules will also be included. + * If the value of {@code gitbookLinkStyle} is true, the document will + * use gitbook-style links and link anchors. + */ + override CharSequence formatGraph(GrammarDoc grammarDoc) { + Preconditions.checkNotNull(grammarDoc, "grammarDoc"); + + val Map mapping = grammarDoc.rules.toMap([it|it.rule], [it|it]); + + ''' + «IF includeDotReferenceGraph» + «dotRefGraph(grammarDoc.rules, grammarDoc.rules.get(0), mapping)» + «ENDIF» + ''' + } + +// /** +// * Returns a Markdown-formatted document describing the given grammar rule. +// *

+// * If the value of {@code gitbookLinkStyle} is true, the document will +// * use gitbook-style links and link anchors. +// */ +// dispatch def CharSequence formatRule(RuleDoc ruleDoc, Map mapping) { +// } +// +// dispatch def CharSequence formatRule(ParserRuleDoc ruleDoc, Map mapping) ''' +// «ruleDocHeader(ruleDoc.ruleName, "")» +// «ruleDoc.headComment.getMainDescription.docCommentFormattingToMd» +// +// «validationPartIfExists(ruleDoc.headComment)» +// «examplePartIfExists(ruleDoc.headComment)» +// +// «ruleReferences(ruleDoc, mapping)» +// +// «returns(ruleDoc.rule)» +// +// «ruleToCodeSnippet(ruleDoc.rule)» +// ''' +// +// +// dispatch def CharSequence formatRule(EnumRuleDoc ruleDoc, Map mapping) ''' +// «ruleDocHeader(ruleDoc.ruleName, "enum")» +// «ruleDoc.headComment.getMainDescription.docCommentFormattingToMd» +// +// «validationPartIfExists(ruleDoc.headComment)» +// «examplePartIfExists(ruleDoc.headComment)» +// +// Literals: +// «FOR entry : getPerEnumLiteral(ruleDoc).entrySet.sortBy[it.key.name]» +// - «entry.key.name» («FOR textLit : entry.value.map[it | it.literalText] SEPARATOR ', '»`«textLit»`«ENDFOR») +// «val firstCommentedLiteral = entry.value.findFirst[it | it.comment.isPresent && !it.comment.get.mainDescription.isNullOrEmpty]»«IF firstCommentedLiteral !== null» : «MarkdownTextFormatter.INSTANCE.italic(firstCommentedLiteral.comment.get.getMainDescription.docCommentFormattingToMd)»«ENDIF» +// «ENDFOR» +// +// «ruleToCodeSnippet(ruleDoc.rule)» +// ''' +// +// +// private def getPerEnumLiteral(EnumRuleDoc ruleDoc) { +// val Map> ret = newHashMap(); +// for (enumLiteral : ruleDoc.literals.map[it | it.literalEnum].toSet) { +// ret.put(enumLiteral, ruleDoc.literals.filter[it.literalEnum == enumLiteral].toList); +// } +// return ret; +// } +// +// dispatch def CharSequence formatRule(TerminalRuleDoc ruleDoc, Map mapping) ''' +// «ruleDocHeader(ruleDoc.ruleName, '''terminal«IF ruleDoc.isTerminalFragment» fragment«ENDIF»''')» +// «ruleDoc.headComment.getMainDescription.docCommentFormattingToMd» +// +// «validationPartIfExists(ruleDoc.headComment)» +// «examplePartIfExists(ruleDoc.headComment)» +// +// «ruleReferences(ruleDoc, mapping)» +// +// «ruleToCodeSnippet(ruleDoc.rule)» +// ''' + + // Private helpers + + /** + * Returns all rules which are used from the given root rule (transitively), + * even if they are not in the current grammar. + */ + protected def List allUsedRules(AbstractRule rootRule) { + val List ret = newArrayList(); + val Queue toBeChecked = new LinkedList(); + toBeChecked.add(rootRule); + + while (!toBeChecked.isEmpty()) { + val current = toBeChecked.remove(); + if (!ret.contains(current)) { + ret.add(current); + current.eAllContents.toIterable.filter(RuleCall).map[it | it.rule].forEach[it | toBeChecked.add(it)]; + } + } + + return ret; + } + +// private def ruleDocHeader(String ruleName, String ruleType) { +// return '''«headerPrefix(3)» «ruleName» «IF !ruleType.nullOrEmpty»(«ruleType»)«ENDIF» «IF gitbookLinkStyle»{«toLink(ruleName)»}«ENDIF»''' +// } +// +// +// private def ruleToCodeSnippet(AbstractRule rule) ''' +// ``` +// «XtextTokenUtil.tokenTextOrUnknown(rule)» +// ``` +// ''' +// +// private def validationPartIfExists(DocComment headComment) ''' +// «IF headComment.getPartsWithTag(VALIDATION_TAG).isEmpty == false» +// - **Validation:** +// «FOR validationPart : headComment.getPartsWithTag(VALIDATION_TAG)» +// * «validationPart.getArgument.docCommentFormattingToMd» +// «ENDFOR» +// «ENDIF» +// ''' +// +// private def examplePartIfExists(DocComment headComment) ''' +// «IF headComment.getPartsWithTag(EXAMPLE_TAG).isEmpty == false» +// - **Examples:** +// «FOR validationPart : headComment.getPartsWithTag(EXAMPLE_TAG)» +// * «IF DocCommentTextUtil.containsCode(validationPart.getArgument)»«validationPart.getArgument.docCommentFormattingToMd»«ELSE»«'''`«validationPart.getArgument»`'''.toString.docCommentFormattingToMd»«ENDIF» +// «ENDFOR» +// «ENDIF» +// ''' +// +// private def ruleReferences(ReferenceRuleDoc ruleDoc, Map mapping) ''' +// «val refersTo = ruleDoc.refersTo.sortBy[it | it.name ?: ""]» +// «IF ruleDoc.refersTo.empty == false» +// **Refers to:** +// «FOR ref : refersTo» +// «IF mapping.containsKey(ref)» +// - «mapping.get(ref).ruleName.ruleNameAsLink» +// «ELSE» +// - «ref.name» +// «ENDIF» +// «ENDFOR» +// +// «ENDIF» +// «val referredBy = mapping.values.filter(ParserRuleDoc).filter[it | it.getRefersTo().contains(ruleDoc.rule)].toSet.sortBy[it.ruleName]» +// «IF referredBy.empty == false» +// **Referenced by:** +// «FOR ref : referredBy» +// - «ref.ruleName.ruleNameAsLink» +// «ENDFOR» +// «ENDIF» +// ''' +// +// private def returns(ParserRule rule) { +// if (rule.type.metamodel.alias.nullOrEmpty) { +// // it is in the generated metamodel, not so interesting +// return ""; +// } else { +// return '''**Returns:** `«rule.type.metamodel.alias»::«rule.type.classifier.name»`''' +// } +// } +// +// private def ruleNameAsLink(String ruleName) { +// return MarkdownTextFormatter.INSTANCE.link(ruleName, toLink(ruleName)); +// } + + /** + * The original code for generating the diagraph was Markdown specific in that it used [fenced code blocks](https://www.markdownguide.org/extended-syntax/#syntax-highlighting) - an approach similar to + * [this](https://oko.io/howto/graphviz-in-markdown/) to dynamically generate the graph in the page. This makes + * some assumptions about the browser being used to render the content. + * The more general approach is to simply create a .dot file and then use graphviz to generate a static file (possibly an image map) that is then + * referenced in the final page. + * + * So here we just generate the raw .dot file content without the fencing + */ + protected def dotRefGraph(List rules, RuleDoc rootRule, Map mapping) ''' + + + digraph G { + node[ shape="rectangle", style="filled" ]; + + // Highlight root rule + «rootRule.ruleName» [ color="red" ]; + + «FOR rule : rules» + «rule.ruleName» [ color="«ruleDotNodeColor(rule, rootRule)»", fillcolor="«ruleDotNodeFillColor(rule)»" ]; + «IF rule instanceof ReferenceRuleDoc» + «FOR ref : rule.refersTo» +««« external dependencies are skipped (e.g. ID) + «IF mapping.containsKey(ref)» +««« internal dependendy + «rule.ruleName» -> «mapping.get(ref).ruleName»; + «ELSE» +««« external dependency + «ref.name» [ color="«ruleDotNodeColor(rule, rootRule)»", fillcolor="«ruleDotNodeFillColor(rule)»", style="dashed" ]; + «rule.ruleName» -> «ref.name» [ style="dashed" ]; + «ENDIF» + «ENDFOR» + «ENDIF» + «ENDFOR» + } + + ''' + + protected def ruleDotNodeColor(RuleDoc ruleDoc, RuleDoc rootRule) { + if (ruleDoc == rootRule) { + return "red"; + } else { + return "black"; + } + } + + protected def ruleDotNodeFillColor(RuleDoc ruleDoc) { + switch (ruleDoc) { + EnumRuleDoc: return "#ffffcc" + ParserRuleDoc: return "#e6e6ff" + TerminalRuleDoc: return if (ruleDoc.isTerminalFragment) "#e6ffe6" else "#ccffcc" + default: return "white" + } + } + + /** + * Returns a BNF-like simplified representation of the given rule + * definition, with Markdown formatting. + */ + protected def CharSequence formattedRuleDef(AbstractElement element) { + return formattedRuleDef(element, false); + } + + /** + * Returns a BNF-like simplified representation of the given rule + * definition, with Markdown formatting. + * @param element Element to be represented. + * @param parenNeeded If true and the represented element is not atomic, + * it will be surrounded with parentheses. + * @return Simplified textual representation of the given rule definition. + */ + private def dispatch CharSequence formattedRuleDef(AbstractElement element, boolean parenNeeded) { + return '''??«element.class.simpleName»??''' + } + + private def dispatch CharSequence formattedRuleDef(Void element, boolean parenNeeded) { + return '''(null)''' + } + + private def dispatch CharSequence formattedRuleDef(Alternatives element, boolean parenNeeded) { + return '''«IF parenNeeded && element.elements.size > 1»(«ENDIF»«FOR it : element.elements SEPARATOR ' | '»«formattedRuleDef(it, element.elements.size > 1)»«ENDFOR»«IF parenNeeded && element.elements.size > 1»)«ENDIF»«element.cardinality»''' + } + + private def dispatch CharSequence formattedRuleDef(UnorderedGroup element, boolean parenNeeded) { + return '''«IF parenNeeded && element.elements.size > 1»(«ENDIF»«FOR it : element.elements SEPARATOR ' & '»«formattedRuleDef(it, element.elements.size > 1)»«ENDFOR»«IF parenNeeded && element.elements.size > 1»)«ENDIF»«element.cardinality»''' + } + + private def dispatch CharSequence formattedRuleDef(Group element, boolean parenNeeded) { + return '''«IF parenNeeded && element.elements.size > 1»(«ENDIF»«IF element.guardCondition !== null»<...>«ENDIF»«FOR it : element.elements SEPARATOR ' '»«formattedRuleDef(it, element.elements.size > 1)»«ENDFOR»«IF parenNeeded && element.elements.size > 1»)«ENDIF»«element.cardinality»''' + } + + private def dispatch CharSequence formattedRuleDef(Assignment element, boolean parenNeeded) { + return '''«formattedRuleDef(element.terminal, true)»«element.cardinality»''' + } + + private def dispatch CharSequence formattedRuleDef(CrossReference element, boolean parenNeeded) { + return '''«formattedRuleDef(element.terminal)»«element.cardinality»'''; + } + + private def dispatch CharSequence formattedRuleDef(Action element, boolean parenNeeded) { + return '' + } + + private def dispatch CharSequence formattedRuleDef(NegatedToken element, boolean parenNeeded) { + return '''!(«formattedRuleDef(element.terminal)»)«element.cardinality»''' + } + + private def dispatch CharSequence formattedRuleDef(Wildcard element, boolean parenNeeded) { + return '''_._«element.cardinality»''' + } + + private def dispatch CharSequence formattedRuleDef(UntilToken element, boolean parenNeeded) { + return ''' --> «formattedRuleDef(element.terminal)» «element.cardinality»''' + } + + private def dispatch CharSequence formattedRuleDef(Keyword element, boolean parenNeeded) { + return '''`«keywordText(element.value)»`«element.cardinality»''' + } + + private def dispatch CharSequence formattedRuleDef(RuleCall element, boolean parenNeeded) { + return '''_«element.rule.name»_«element.cardinality»''' + } + + private def dispatch CharSequence formattedRuleDef(EnumLiteralDeclaration element, boolean parenNeeded) { + return formattedRuleDef(element.literal); + } + + private def dispatch CharSequence formattedRuleDef(CharacterRange element, boolean parenNeeded) { + return '''[«formattedRuleDef(element.left)»..«formattedRuleDef(element.right)»]«element.cardinality»'''; + } + + private def String keywordText(String keywordValue) { + return keywordValue.replace("\t", "\\t").replace("\r", "\\r").replace("\n", "\\n"); + } + + /** + * Create a valid anchor string from the given text. This ensures + */ + protected def String toAnchor(String text) { + // First, remove all non word text - in our case, we only need to check for parens + // And, compress all multiple spaces to singles + // Then replace spaces with dash + // This anchor style should work for both HTML and MD - and allows for mixed case which Gitbook MD uses + return text.replaceAll("\\(","").replaceAll("\\)","").replaceAll(" "," ").replaceAll("\\s", "-") //.toLowerCase; + + } + +// private def String docCommentFormattingToMd(String text) { +// val escaped = MarkdownTextFormatter.INSTANCE.escape(text); +// val String resolved = DocCommentTextUtil.resolveLinks(escaped, MarkdownTextFormatter.INSTANCE, [it | toLink(it)]); +// return DocCommentTextUtil.format(resolved, MarkdownTextFormatter.INSTANCE); +// } + +// private def String toLink(String text) { +// if (text.trim().matches("^https?://.*")) { +// return text; +// } else { +// if (gitbookLinkStyle) { +// return '''#«text.replaceAll("\\s", "-")»'''; +// } else { +// return '''#«text.replaceAll("\\s", "-").toLowerCase»'''; +// } +// } +// } +// +// private def String headerPrefix(int level) { +// return '''«Strings.repeat("#", level + titleLevelOffset)» '''; +// } +} diff --git a/com.epistimis.xtextdocs.xtext/src/com/epistimis/xtextdocs/xtext/formatter/HTMLDocsFormatter.xtend b/com.epistimis.xtextdocs.xtext/src/com/epistimis/xtextdocs/xtext/formatter/HTMLDocsFormatter.xtend new file mode 100644 index 0000000..5bef11e --- /dev/null +++ b/com.epistimis.xtextdocs.xtext/src/com/epistimis/xtextdocs/xtext/formatter/HTMLDocsFormatter.xtend @@ -0,0 +1,422 @@ +/********************************************************************* +* Copyright (c) 2018 Daniel Darvas +* Copyright (c) 2024 Epistimis LLC +* +* This program and the accompanying materials are made +* available under the terms of the Eclipse Public License 2.0 +* which is available at https://www.eclipse.org/legal/epl-2.0/ +* +* SPDX-License-Identifier: EPL-2.0 +**********************************************************************/ + +package com.epistimis.xtextdocs.xtext.formatter + +import com.epistimis.xtextdocs.common.formatter.DocCommentTextUtil +import com.epistimis.xtextdocs.common.formatter.MarkdownTextFormatter +import com.epistimis.xtextdocs.common.xtext.XtextTokenUtil +import com.epistimis.xtextdocs.xtext.doccomment.DocComment +import com.epistimis.xtextdocs.xtext.ruledoc.EnumRuleDoc +import com.epistimis.xtextdocs.xtext.ruledoc.EnumRuleDoc.EnumLiteralDoc +import com.epistimis.xtextdocs.xtext.ruledoc.GrammarDoc +import com.epistimis.xtextdocs.xtext.ruledoc.ParserRuleDoc +import com.epistimis.xtextdocs.xtext.ruledoc.ReferenceRuleDoc +import com.epistimis.xtextdocs.xtext.ruledoc.RuleDoc +import com.epistimis.xtextdocs.xtext.ruledoc.TerminalRuleDoc +import com.google.common.base.Preconditions +import com.google.common.base.Strings +import java.util.List +import java.util.Map +import org.eclipse.emf.ecore.EEnumLiteral +import org.eclipse.xtext.AbstractElement +import org.eclipse.xtext.AbstractRule +import org.eclipse.xtext.Action +import org.eclipse.xtext.Alternatives +import org.eclipse.xtext.Assignment +import org.eclipse.xtext.CharacterRange +import org.eclipse.xtext.CrossReference +import org.eclipse.xtext.EnumLiteralDeclaration +import org.eclipse.xtext.Group +import org.eclipse.xtext.Keyword +import org.eclipse.xtext.NegatedToken +import org.eclipse.xtext.ParserRule +import org.eclipse.xtext.RuleCall +import org.eclipse.xtext.UnorderedGroup +import org.eclipse.xtext.UntilToken +import org.eclipse.xtext.Wildcard +import com.epistimis.xtextdocs.common.formatter.HTMLTextFormatter + +class HTMLDocsFormatter extends DotGraphBaseFormatter { + + static val extension HTMLTextFormatter textFormatter = HTMLTextFormatter.INSTANCE; + + override outputFileExtension() { + return ".html"; + } + + /** + * Generates a table of contents representation based on the stored anchors. + * For now, we only create a ToC of the Parser Rules - they are the key ones. + */ + private def toc(GrammarDoc grammarDoc) { + return ''' +

+

Table of contents

+ «val tocContents = grammarDoc.rules.filter(ParserRuleDoc).toSet.sortBy[it.ruleName]» +
    + «FOR ruleDoc : tocContents» +
  • «link(ruleDoc.getRuleName(), toAnchor(ruleDoc.getRuleName()).toLowerCase())»
  • + «ENDFOR» +
+
+ '''; + } + + /** + * Returns a Markdown-formatted document describing the given grammar, + * including all its rules. + *

+ * If the value of {@code includeSimplifiedGrammar} is true, the document + * will contain a simplified BNF description of the grammar. + * If the value of {@code includeDotReferenceGraph} is true, a + * GraphViz-style representation of the dependency between the grammar + * rules will also be included. + * If the value of {@code gitbookLinkStyle} is true, the document will + * use gitbook-style links and link anchors. + */ + override CharSequence formatGrammar(GrammarDoc grammarDoc) { + Preconditions.checkNotNull(grammarDoc, "grammarDoc"); + + val Map mapping = grammarDoc.rules.toMap([it|it.rule], [it|it]); + + ''' + + + + + + Table of Contents + + + + +

«mainTitle ?: grammarDoc.grammarName»

+ + «IF !grammarDoc.headComment.getMainDescription.nullOrEmpty»«grammarDoc.headComment.getMainDescription.docCommentFormattingToHtml»«ENDIF» + + «IF includeToc» + «toc(grammarDoc)» + «ENDIF» + + +
+ + «IF !grammarDoc.grammar.usedGrammars.isEmpty» +
+

Included grammars:

+
    + «FOR x : grammarDoc.grammar.usedGrammars» +
  • «x.name»
  • + «ENDFOR» +
+
+ «ENDIF» + + «val metamodels = grammarDoc.grammar.metamodelDeclarations.filter[!alias.nullOrEmpty]» + «IF !metamodels.isEmpty» +
+

Included metamodels:

+
    + «FOR x : metamodels» +
  • «x.alias» («x.EPackage.nsURI»)
  • + «ENDFOR» +
+
+ «ENDIF» + +

Rules

+ «FOR ruleDoc : grammarDoc.rules» + «formatRule(ruleDoc, mapping)» + «ENDFOR» + + «IF includeSimplifiedGrammar» +

Simplified grammar

+ «FOR rule : allUsedRules(grammarDoc.rules.get(0).rule)» + «rule.name» ::= «formattedRuleDef(rule.alternatives)»; + + «ENDFOR» + «ENDIF» + + «IF includeDotReferenceGraph» + «dotGraphRef(grammarDoc.rules, grammarDoc.rules.get(0), mapping)» + «ENDIF» + +
+ + + + ''' + } + + /** + * Returns a Markdown-formatted document describing the given grammar rule. + *

+ * If the value of {@code gitbookLinkStyle} is true, the document will + * use gitbook-style links and link anchors. + */ + dispatch def CharSequence formatRule(RuleDoc ruleDoc, Map mapping) { + } + def dispatch CharSequence genRuleHeader(RuleDoc ruleDoc) { + } + + def dispatch CharSequence genRuleHeader(ParserRuleDoc ruleDoc) { + return ruleDocHeaderText(ruleDoc.ruleName, ""); + } + dispatch def CharSequence formatRule(ParserRuleDoc ruleDoc, Map mapping) ''' + «ruleDocHeader(ruleDoc.ruleName, "")» + «ruleDoc.headComment.getMainDescription.docCommentFormattingToHtml» + + «validationPartIfExists(ruleDoc.headComment)» + «examplePartIfExists(ruleDoc.headComment)» + + «ruleReferences(ruleDoc, mapping)» + + «returns(ruleDoc.rule)» + + «ruleToCodeSnippet(ruleDoc.rule)» + «ruleDocFooter(ruleDoc.ruleName,"")» + + ''' + + + def dispatch CharSequence genRuleHeader(EnumRuleDoc ruleDoc) { + return ruleDocHeaderText(ruleDoc.ruleName, "enum"); + } + dispatch def CharSequence formatRule(EnumRuleDoc ruleDoc, Map mapping) ''' + «ruleDocHeader(ruleDoc.ruleName, "enum")» + «ruleDoc.headComment.getMainDescription.docCommentFormattingToHtml» + + «validationPartIfExists(ruleDoc.headComment)» + «examplePartIfExists(ruleDoc.headComment)» + + Literals: +

    + «FOR entry : getPerEnumLiteral(ruleDoc).entrySet.sortBy[it.key.name]» +
  • «entry.key.name» («FOR textLit : entry.value.map[it | it.literalText] SEPARATOR ', '»`«textLit»`«ENDFOR») + «val firstCommentedLiteral = entry.value.findFirst[it | it.comment.isPresent && !it.comment.get.mainDescription.isNullOrEmpty]»«IF firstCommentedLiteral !== null» : «textFormatter.italic(firstCommentedLiteral.comment.get.getMainDescription.docCommentFormattingToHtml)»«ENDIF» + «ENDFOR» +
+ «ruleToCodeSnippet(ruleDoc.rule)» + ''' + + + private def getPerEnumLiteral(EnumRuleDoc ruleDoc) { + val Map> ret = newHashMap(); + for (enumLiteral : ruleDoc.literals.map[it | it.literalEnum].toSet) { + ret.put(enumLiteral, ruleDoc.literals.filter[it.literalEnum == enumLiteral].toList); + } + return ret; + } + + def dispatch CharSequence genRuleHeader(TerminalRuleDoc ruleDoc) { + return ruleDocHeaderText(ruleDoc.ruleName, '''terminal«IF ruleDoc.isTerminalFragment» fragment«ENDIF»'''); + } + dispatch def CharSequence formatRule(TerminalRuleDoc ruleDoc, Map mapping) ''' + «ruleDocHeader(ruleDoc.ruleName, '''terminal«IF ruleDoc.isTerminalFragment» fragment«ENDIF»''')» + «ruleDoc.headComment.getMainDescription.docCommentFormattingToHtml» + + «validationPartIfExists(ruleDoc.headComment)» + «examplePartIfExists(ruleDoc.headComment)» + + «ruleReferences(ruleDoc, mapping)» + + «ruleToCodeSnippet(ruleDoc.rule)» + ''' + + // Private helpers + + + /** + * To generate links based on the header content, we must know what that text is. + */ + private def ruleDocHeaderText(String ruleName, String ruleType) { + return '''«ruleName»«IF !ruleType.nullOrEmpty» («ruleType»)«ENDIF»''' + } + private def ruleDocHeader(String ruleName, String ruleType) { + return ''' +
+

«ruleDocHeaderText(ruleName,ruleType)» «IF gitbookLinkStyle»{«toLink(ruleName)»}«ENDIF»

+ ''' + } + private def ruleDocFooter(String ruleName, String ruleType) { + return '''
''' + } + + + private def ruleToCodeSnippet(AbstractRule rule) ''' +

+		«XtextTokenUtil.tokenTextOrUnknown(rule)»
+		
+ ''' + + private def validationPartIfExists(DocComment headComment) ''' + «IF headComment.getPartsWithTag(VALIDATION_TAG).isEmpty == false» +
  • Validation: + «FOR validationPart : headComment.getPartsWithTag(VALIDATION_TAG)» + * «validationPart.getArgument.docCommentFormattingToHtml» + «ENDFOR» +
  • + «ENDIF» + ''' + + private def examplePartIfExists(DocComment headComment) ''' + «IF headComment.getPartsWithTag(EXAMPLE_TAG).isEmpty == false» +
      Examples: + «FOR validationPart : headComment.getPartsWithTag(EXAMPLE_TAG)» +
    • «IF DocCommentTextUtil.containsCode(validationPart.getArgument)»«validationPart.getArgument.docCommentFormattingToHtml»«ELSE»«'''`«validationPart.getArgument»`'''.toString.docCommentFormattingToHtml»«ENDIF»
    • + «ENDFOR» +
    + «ENDIF» + ''' + + private def ruleReferences(ReferenceRuleDoc ruleDoc, Map mapping) ''' + «val refersTo = ruleDoc.refersTo.sortBy[it | it.name ?: ""]» + «IF ruleDoc.refersTo.empty == false» + Refers to: +
      + «FOR ref : refersTo» + «IF mapping.containsKey(ref)» +
    • «mapping.get(ref).ruleNameAsLink»
    • + «ELSE» +
    • «ref.name»
    • + «ENDIF» + «ENDFOR» +
    + + «ENDIF» + «val referredBy = mapping.values.filter(ParserRuleDoc).filter[it | it.getRefersTo().contains(ruleDoc.rule)].toSet.sortBy[it.ruleName]» + «IF referredBy.empty == false» + Referenced by: +
      + «FOR ref : referredBy» +
    • «ref.ruleNameAsLink»
    • + «ENDFOR» +
    + «ENDIF» + ''' + + private def returns(ParserRule rule) { + if (rule.type.metamodel.alias.nullOrEmpty) { + // it is in the generated metamodel, not so interesting + return ""; + } else { + return '''Returns: `«rule.type.metamodel.alias»::«rule.type.classifier.name»`''' + } + } + + private def ruleNameAsLink(RuleDoc rule) { + + return textFormatter.link(rule.ruleName, toLink(genRuleHeader(rule).toString.trim)); + } + + private def dotGraphRef(List rules, RuleDoc rootRule, Map mapping) ''' +

    Rule dependencies

    + + ```[graph_ref_goes_here]Graph Reference Goes Here + ``` + ''' + + + /** + * Returns a BNF-like simplified representation of the given rule + * definition, with HTML formatting. + * @param element Element to be represented. + * @param parenNeeded If true and the represented element is not atomic, + * it will be surrounded with parentheses. + * @return Simplified textual representation of the given rule definition. + */ + private def dispatch CharSequence formattedRuleDef(AbstractElement element, boolean parenNeeded) { + return '''??«element.class.simpleName»??''' + } + + private def dispatch CharSequence formattedRuleDef(Void element, boolean parenNeeded) { + return '''(null)''' + } + + private def dispatch CharSequence formattedRuleDef(Alternatives element, boolean parenNeeded) { + return '''«IF parenNeeded && element.elements.size > 1»(«ENDIF»«FOR it : element.elements SEPARATOR ' | '»«formattedRuleDef(it, element.elements.size > 1)»«ENDFOR»«IF parenNeeded && element.elements.size > 1»)«ENDIF»«element.cardinality»''' + } + + private def dispatch CharSequence formattedRuleDef(UnorderedGroup element, boolean parenNeeded) { + return '''«IF parenNeeded && element.elements.size > 1»(«ENDIF»«FOR it : element.elements SEPARATOR ' & '»«formattedRuleDef(it, element.elements.size > 1)»«ENDFOR»«IF parenNeeded && element.elements.size > 1»)«ENDIF»«element.cardinality»''' + } + + private def dispatch CharSequence formattedRuleDef(Group element, boolean parenNeeded) { + return '''«IF parenNeeded && element.elements.size > 1»(«ENDIF»«IF element.guardCondition !== null»<...>«ENDIF»«FOR it : element.elements SEPARATOR ' '»«formattedRuleDef(it, element.elements.size > 1)»«ENDFOR»«IF parenNeeded && element.elements.size > 1»)«ENDIF»«element.cardinality»''' + } + + private def dispatch CharSequence formattedRuleDef(Assignment element, boolean parenNeeded) { + return '''«formattedRuleDef(element.terminal, true)»«element.cardinality»''' + } + + private def dispatch CharSequence formattedRuleDef(CrossReference element, boolean parenNeeded) { + return '''«formattedRuleDef(element.terminal)»«element.cardinality»'''; + } + + private def dispatch CharSequence formattedRuleDef(Action element, boolean parenNeeded) { + return '' + } + + private def dispatch CharSequence formattedRuleDef(NegatedToken element, boolean parenNeeded) { + return '''!(«formattedRuleDef(element.terminal)»)«element.cardinality»''' + } + + private def dispatch CharSequence formattedRuleDef(Wildcard element, boolean parenNeeded) { + return '''_._«element.cardinality»''' + } + + private def dispatch CharSequence formattedRuleDef(UntilToken element, boolean parenNeeded) { + return ''' --> «formattedRuleDef(element.terminal)» «element.cardinality»''' + } + + private def dispatch CharSequence formattedRuleDef(Keyword element, boolean parenNeeded) { + return '''«keywordText(element.value)»«element.cardinality»''' + } + + private def dispatch CharSequence formattedRuleDef(RuleCall element, boolean parenNeeded) { + return '''_«element.rule.name»_«element.cardinality»''' + } + + private def dispatch CharSequence formattedRuleDef(EnumLiteralDeclaration element, boolean parenNeeded) { + return formattedRuleDef(element.literal); + } + + private def dispatch CharSequence formattedRuleDef(CharacterRange element, boolean parenNeeded) { + return '''[«formattedRuleDef(element.left)»..«formattedRuleDef(element.right)»]«element.cardinality»'''; + } + + private def String keywordText(String keywordValue) { + return keywordValue.replace("\t", "\\t").replace("\r", "\\r").replace("\n", "\\n"); + } + + private def String docCommentFormattingToHtml(String text) { + val escaped = textFormatter.escape(text); + val String resolved = DocCommentTextUtil.resolveLinks(escaped, textFormatter, [it | toLink(it)]); + return DocCommentTextUtil.format(resolved, textFormatter); + } + + private def String toLink(String text) { + if (text.trim().matches("^https?://.*")) { + return text; + } else { + // First, remove all non word text - in our case, we only need to check for parens + // And, compress all multiple spaces to singles + var temp = toAnchor(text) + + if (gitbookLinkStyle) { + return temp; + } else { + return temp.toLowerCase; + } + } + } +} diff --git a/com.github.darvasd.xtextdocs.xtext/src/com/github/darvasd/xtextdocs/xtext/formatter/IGrammarDocsFormatter.java b/com.epistimis.xtextdocs.xtext/src/com/epistimis/xtextdocs/xtext/formatter/IGrammarDocsFormatter.java similarity index 69% rename from com.github.darvasd.xtextdocs.xtext/src/com/github/darvasd/xtextdocs/xtext/formatter/IGrammarDocsFormatter.java rename to com.epistimis.xtextdocs.xtext/src/com/epistimis/xtextdocs/xtext/formatter/IGrammarDocsFormatter.java index 98ce810..dc99dc6 100644 --- a/com.github.darvasd.xtextdocs.xtext/src/com/github/darvasd/xtextdocs/xtext/formatter/IGrammarDocsFormatter.java +++ b/com.epistimis.xtextdocs.xtext/src/com/epistimis/xtextdocs/xtext/formatter/IGrammarDocsFormatter.java @@ -1,6 +1,7 @@ /********************************************************************* * Copyright (c) 2018 Daniel Darvas -* +* Copyright (c) 2024 Epistimis LLC +* * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ @@ -8,14 +9,14 @@ * SPDX-License-Identifier: EPL-2.0 **********************************************************************/ -package com.github.darvasd.xtextdocs.xtext.formatter; +package com.epistimis.xtextdocs.xtext.formatter; import java.util.Map; import org.eclipse.xtext.AbstractRule; -import com.github.darvasd.xtextdocs.xtext.ruledoc.RuleDoc; -import com.github.darvasd.xtextdocs.xtext.ruledoc.GrammarDoc; +import com.epistimis.xtextdocs.xtext.ruledoc.RuleDoc; +import com.epistimis.xtextdocs.xtext.ruledoc.GrammarDoc; /** * Interface for grammar documentation generators. A class implementing this @@ -33,6 +34,16 @@ public interface IGrammarDocsFormatter { */ CharSequence formatGrammar(GrammarDoc grammarDoc); + /** + * Returns a DOT graph textual representation of the given grammar + * documentation node, including the rules contained within. + * + * @param grammarDoc + * Grammar documentation. + * @return DOT graph textual representation of the grammar. + */ + CharSequence formatGraph(GrammarDoc grammarDoc); + /** * Returns a formatted, textual representation of the given single rule * documentation node. @@ -46,4 +57,10 @@ public interface IGrammarDocsFormatter { * @return Formatted, textual representation of the rule. */ CharSequence formatRule(RuleDoc ruleDoc, Map mapping); + + /** + * Returns the file extension for the output files created by this formatter. + * @return The file extension + */ + String outputFileExtension(); } diff --git a/com.github.darvasd.xtextdocs.xtext/src/com/github/darvasd/xtextdocs/xtext/formatter/MarkdownDocsFormatter.xtend b/com.epistimis.xtextdocs.xtext/src/com/epistimis/xtextdocs/xtext/formatter/MarkdownDocsFormatter.xtend similarity index 62% rename from com.github.darvasd.xtextdocs.xtext/src/com/github/darvasd/xtextdocs/xtext/formatter/MarkdownDocsFormatter.xtend rename to com.epistimis.xtextdocs.xtext/src/com/epistimis/xtextdocs/xtext/formatter/MarkdownDocsFormatter.xtend index 4a8add9..f131f4c 100644 --- a/com.github.darvasd.xtextdocs.xtext/src/com/github/darvasd/xtextdocs/xtext/formatter/MarkdownDocsFormatter.xtend +++ b/com.epistimis.xtextdocs.xtext/src/com/epistimis/xtextdocs/xtext/formatter/MarkdownDocsFormatter.xtend @@ -1,6 +1,7 @@ /********************************************************************* * Copyright (c) 2018 Daniel Darvas -* +* Copyright (c) 2024 Epistimis LLC +* * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ @@ -8,26 +9,24 @@ * SPDX-License-Identifier: EPL-2.0 **********************************************************************/ -package com.github.darvasd.xtextdocs.xtext.formatter +package com.epistimis.xtextdocs.xtext.formatter -import com.github.darvasd.xtextdocs.common.formatter.MarkdownTextFormatter -import com.github.darvasd.xtextdocs.common.xtext.XtextTokenUtil -import com.github.darvasd.xtextdocs.xtext.doccomment.DocComment -import com.github.darvasd.xtextdocs.xtext.ruledoc.EnumRuleDoc -import com.github.darvasd.xtextdocs.xtext.ruledoc.EnumRuleDoc.EnumLiteralDoc -import com.github.darvasd.xtextdocs.xtext.ruledoc.GrammarDoc -import com.github.darvasd.xtextdocs.xtext.ruledoc.ParserRuleDoc -import com.github.darvasd.xtextdocs.xtext.ruledoc.ReferenceRuleDoc -import com.github.darvasd.xtextdocs.xtext.ruledoc.RuleDoc -import com.github.darvasd.xtextdocs.xtext.ruledoc.TerminalRuleDoc +import com.epistimis.xtextdocs.common.formatter.DocCommentTextUtil +import com.epistimis.xtextdocs.common.formatter.MarkdownTextFormatter +import com.epistimis.xtextdocs.common.xtext.XtextTokenUtil +import com.epistimis.xtextdocs.xtext.doccomment.DocComment +import com.epistimis.xtextdocs.xtext.ruledoc.EnumRuleDoc +import com.epistimis.xtextdocs.xtext.ruledoc.EnumRuleDoc.EnumLiteralDoc +import com.epistimis.xtextdocs.xtext.ruledoc.GrammarDoc +import com.epistimis.xtextdocs.xtext.ruledoc.ParserRuleDoc +import com.epistimis.xtextdocs.xtext.ruledoc.ReferenceRuleDoc +import com.epistimis.xtextdocs.xtext.ruledoc.RuleDoc +import com.epistimis.xtextdocs.xtext.ruledoc.TerminalRuleDoc import com.google.common.base.Preconditions import com.google.common.base.Strings -import java.util.LinkedList import java.util.List import java.util.Map -import java.util.Queue import org.eclipse.emf.ecore.EEnumLiteral -import org.eclipse.xtend.lib.annotations.Accessors import org.eclipse.xtext.AbstractElement import org.eclipse.xtext.AbstractRule import org.eclipse.xtext.Action @@ -44,44 +43,46 @@ import org.eclipse.xtext.RuleCall import org.eclipse.xtext.UnorderedGroup import org.eclipse.xtext.UntilToken import org.eclipse.xtext.Wildcard -import com.github.darvasd.xtextdocs.common.formatter.DocCommentTextUtil -class MarkdownDocsFormatter implements IGrammarDocsFormatter { - private static final String EXAMPLE_TAG = "@example" - private static final String VALIDATION_TAG = "@validation" - - @Accessors private boolean includeSimplifiedGrammar = true; - @Accessors private boolean includeDotReferenceGraph = false; - @Accessors private boolean gitbookLinkStyle = false; - - /** - * The main title text of the documentation to be generated. - * If not set ({@code null}), the title will be the full name of the grammar. - */ - @Accessors private String mainTitle = null; - - /** - * Title depth offset. If set to 0, the main title will be prefixed with {@code #}, - * the second level titles with {@code ##}, etc. - * If it is greater than zero, the number of {@code #} characters will be increased - * with this number at each title. - */ - private int titleLevelOffset = 0; - +class MarkdownDocsFormatter extends DotGraphBaseFormatter { + + static val extension MarkdownTextFormatter textFormatter = MarkdownTextFormatter.INSTANCE; + + override outputFileExtension() { + return ".md"; + } + +// /** +// * Map that stores (name, id) pairs. The stored 'id' is the anchor that is used for the definition of the class 'name'. +// */ +// SortedMap anchors = new TreeMap(); +// int anchorCounter = 1; /** - * Sets the title depth offset. If set to 0, the main title will be prefixed with {@code #}, - * the second level titles with {@code ##}, etc. - * If it is greater than zero, the number of {@code #} characters will be increased - * with this number at each title. - *

    - * It is an ugly workaround to take a string as argument, but this is necessary - * as MWE2 does not support integer properties. - * See https://bugs.eclipse.org/bugs/show_bug.cgi?id=377068 . + * Generates a table of contents representation based on the stored anchors. + * For now, we only create a ToC of the Parser Rules - they are the key ones. */ - public def void setTitleLevelOffset(String value) { - this.titleLevelOffset = Integer.parseInt(value); + private def toc(GrammarDoc grammarDoc) { + return ''' + «headerPrefix(2)» Table of contents + «val tocContents = grammarDoc.rules.filter(ParserRuleDoc).toSet.sortBy[it.ruleName]» + «FOR ruleDoc : tocContents» + - «link(ruleDoc.getRuleName(), "#"+ruleDoc.getRuleName().toLowerCase())» + «ENDFOR» + '''; } +// /** +// * Generates unique anchors for the classifiers in the given resource. +// */ +// private def fillAnchors(XtextResource resource) { +// for (EObject e : resource.allContents.toIterable) { +// if (e instanceof XClassifier) { +// anchors.put(e.name, "#anchor" + anchorCounter); +// anchorCounter++; +// } +// } +// } + /** * Returns a Markdown-formatted document describing the given grammar, * including all its rules. @@ -94,18 +95,30 @@ class MarkdownDocsFormatter implements IGrammarDocsFormatter { * If the value of {@code gitbookLinkStyle} is true, the document will * use gitbook-style links and link anchors. */ - public override CharSequence formatGrammar(GrammarDoc grammarDoc) { + override CharSequence formatGrammar(GrammarDoc grammarDoc) { Preconditions.checkNotNull(grammarDoc, "grammarDoc"); val Map mapping = grammarDoc.rules.toMap([it|it.rule], [it|it]); ''' + + «headerPrefix(1)» «mainTitle ?: grammarDoc.grammarName» «IF !grammarDoc.headComment.getMainDescription.nullOrEmpty»«grammarDoc.headComment.getMainDescription.docCommentFormattingToMd»«ENDIF» + +

    + + «IF includeToc» + «toc(grammarDoc)» + «ENDIF» + +
    + +
    «IF !grammarDoc.grammar.usedGrammars.isEmpty» - Included grammars: + «headerPrefix(2)»Included grammars: «FOR x : grammarDoc.grammar.usedGrammars» - `«x.name»` «ENDFOR» @@ -113,7 +126,7 @@ class MarkdownDocsFormatter implements IGrammarDocsFormatter { «val metamodels = grammarDoc.grammar.metamodelDeclarations.filter[!alias.nullOrEmpty]» «IF !metamodels.isEmpty» - Included metamodels: + «headerPrefix(2)»Included metamodels: «FOR x : metamodels» - «x.alias» (`«x.EPackage.nsURI»`) «ENDFOR» @@ -121,10 +134,7 @@ class MarkdownDocsFormatter implements IGrammarDocsFormatter { «headerPrefix(2)» Rules «FOR ruleDoc : grammarDoc.rules» - «formatRule(ruleDoc, mapping)» - - - + «formatRule(ruleDoc, mapping)» «ENDFOR» «IF includeSimplifiedGrammar» @@ -136,8 +146,10 @@ class MarkdownDocsFormatter implements IGrammarDocsFormatter { «ENDIF» «IF includeDotReferenceGraph» - «dotRefGraph(grammarDoc.rules, grammarDoc.rules.get(0), mapping)» + «dotGraphRef(grammarDoc.rules, grammarDoc.rules.get(0), mapping)» «ENDIF» + +
    ''' } @@ -147,10 +159,15 @@ class MarkdownDocsFormatter implements IGrammarDocsFormatter { * If the value of {@code gitbookLinkStyle} is true, the document will * use gitbook-style links and link anchors. */ - public dispatch def CharSequence formatRule(RuleDoc ruleDoc, Map mapping) { + dispatch def CharSequence formatRule(RuleDoc ruleDoc, Map mapping) { + } + def dispatch CharSequence genRuleHeader(RuleDoc ruleDoc) { } - public dispatch def CharSequence formatRule(ParserRuleDoc ruleDoc, Map mapping) ''' + def dispatch CharSequence genRuleHeader(ParserRuleDoc ruleDoc) { + return ruleDocHeaderText(ruleDoc.ruleName, ""); + } + dispatch def CharSequence formatRule(ParserRuleDoc ruleDoc, Map mapping) ''' «ruleDocHeader(ruleDoc.ruleName, "")» «ruleDoc.headComment.getMainDescription.docCommentFormattingToMd» @@ -165,7 +182,10 @@ class MarkdownDocsFormatter implements IGrammarDocsFormatter { ''' - public dispatch def CharSequence formatRule(EnumRuleDoc ruleDoc, Map mapping) ''' + def dispatch CharSequence genRuleHeader(EnumRuleDoc ruleDoc) { + return ruleDocHeaderText(ruleDoc.ruleName, "enum"); + } + dispatch def CharSequence formatRule(EnumRuleDoc ruleDoc, Map mapping) ''' «ruleDocHeader(ruleDoc.ruleName, "enum")» «ruleDoc.headComment.getMainDescription.docCommentFormattingToMd» @@ -175,7 +195,7 @@ class MarkdownDocsFormatter implements IGrammarDocsFormatter { Literals: «FOR entry : getPerEnumLiteral(ruleDoc).entrySet.sortBy[it.key.name]» - «entry.key.name» («FOR textLit : entry.value.map[it | it.literalText] SEPARATOR ', '»`«textLit»`«ENDFOR») - «val firstCommentedLiteral = entry.value.findFirst[it | it.comment.isPresent && !it.comment.get.mainDescription.isNullOrEmpty]»«IF firstCommentedLiteral !== null» : «MarkdownTextFormatter.INSTANCE.italic(firstCommentedLiteral.comment.get.getMainDescription.docCommentFormattingToMd)»«ENDIF» + «val firstCommentedLiteral = entry.value.findFirst[it | it.comment.isPresent && !it.comment.get.mainDescription.isNullOrEmpty]»«IF firstCommentedLiteral !== null» : «textFormatter.italic(firstCommentedLiteral.comment.get.getMainDescription.docCommentFormattingToMd)»«ENDIF» «ENDFOR» «ruleToCodeSnippet(ruleDoc.rule)» @@ -190,7 +210,10 @@ class MarkdownDocsFormatter implements IGrammarDocsFormatter { return ret; } - public dispatch def CharSequence formatRule(TerminalRuleDoc ruleDoc, Map mapping) ''' + def dispatch CharSequence genRuleHeader(TerminalRuleDoc ruleDoc) { + return ruleDocHeaderText(ruleDoc.ruleName, '''terminal«IF ruleDoc.isTerminalFragment» fragment«ENDIF»'''); + } + dispatch def CharSequence formatRule(TerminalRuleDoc ruleDoc, Map mapping) ''' «ruleDocHeader(ruleDoc.ruleName, '''terminal«IF ruleDoc.isTerminalFragment» fragment«ENDIF»''')» «ruleDoc.headComment.getMainDescription.docCommentFormattingToMd» @@ -203,29 +226,15 @@ class MarkdownDocsFormatter implements IGrammarDocsFormatter { ''' // Private helpers - + /** - * Returns all rules which are used from the given root rule (transitively), - * even if they are not in the current grammar. + * Since Markdown generates links based on the header content, we must know what that text is. */ - private def List allUsedRules(AbstractRule rootRule) { - val List ret = newArrayList(); - val Queue toBeChecked = new LinkedList(); - toBeChecked.add(rootRule); - - while (!toBeChecked.isEmpty()) { - val current = toBeChecked.remove(); - if (!ret.contains(current)) { - ret.add(current); - current.eAllContents.toIterable.filter(RuleCall).map[it | it.rule].forEach[it | toBeChecked.add(it)]; - } - } - - return ret; + private def ruleDocHeaderText(String ruleName, String ruleType) { + return '''«ruleName»«IF !ruleType.nullOrEmpty» («ruleType»)«ENDIF»''' } - private def ruleDocHeader(String ruleName, String ruleType) { - return '''«headerPrefix(3)» «ruleName» «IF !ruleType.nullOrEmpty»(«ruleType»)«ENDIF» «IF gitbookLinkStyle»{«toLink(ruleName)»}«ENDIF»''' + return '''«headerPrefix(3)» «ruleDocHeaderText(ruleName,ruleType)» «IF gitbookLinkStyle»{«toLink(ruleName)»}«ENDIF»''' } @@ -259,7 +268,7 @@ class MarkdownDocsFormatter implements IGrammarDocsFormatter { **Refers to:** «FOR ref : refersTo» «IF mapping.containsKey(ref)» - - «mapping.get(ref).ruleName.ruleNameAsLink» + - «mapping.get(ref).ruleNameAsLink» «ELSE» - «ref.name» «ENDIF» @@ -268,9 +277,9 @@ class MarkdownDocsFormatter implements IGrammarDocsFormatter { «ENDIF» «val referredBy = mapping.values.filter(ParserRuleDoc).filter[it | it.getRefersTo().contains(ruleDoc.rule)].toSet.sortBy[it.ruleName]» «IF referredBy.empty == false» - **Referred by:** + **Referenced by:** «FOR ref : referredBy» - - «ref.ruleName.ruleNameAsLink» + - «ref.ruleNameAsLink» «ENDFOR» «ENDIF» ''' @@ -284,65 +293,18 @@ class MarkdownDocsFormatter implements IGrammarDocsFormatter { } } - private def ruleNameAsLink(String ruleName) { - return MarkdownTextFormatter.INSTANCE.link(ruleName, toLink(ruleName)); + private def ruleNameAsLink(RuleDoc rule) { + + return textFormatter.link(rule.ruleName, toLink(genRuleHeader(rule).toString.trim)); } - private def dotRefGraph(List rules, RuleDoc rootRule, Map mapping) ''' + private def dotGraphRef(List rules, RuleDoc rootRule, Map mapping) ''' «headerPrefix(2)» Rule dependencies - ```dot - digraph G { - node[ shape="rectangle", style="filled" ]; - - // Highlight root rule - «rootRule.ruleName» [ color="red" ]; - - «FOR rule : rules» - «rule.ruleName» [ color="«ruleDotNodeColor(rule, rootRule)»", fillcolor="«ruleDotNodeFillColor(rule)»" ]; - «IF rule instanceof ReferenceRuleDoc» - «FOR ref : rule.refersTo» -««« external dependencies are skipped (e.g. ID) - «IF mapping.containsKey(ref)» -««« internal dependendy - «rule.ruleName» -> «mapping.get(ref).ruleName»; - «ELSE» -««« external dependency - «ref.name» [ color="«ruleDotNodeColor(rule, rootRule)»", fillcolor="«ruleDotNodeFillColor(rule)»", style="dashed" ]; - «rule.ruleName» -> «ref.name» [ style="dashed" ]; - «ENDIF» - «ENDFOR» - «ENDIF» - «ENDFOR» - } + ```[graph_ref_goes_here]Graph Reference Goes Here ``` ''' - private def ruleDotNodeColor(RuleDoc ruleDoc, RuleDoc rootRule) { - if (ruleDoc == rootRule) { - return "red"; - } else { - return "black"; - } - } - - private def ruleDotNodeFillColor(RuleDoc ruleDoc) { - switch (ruleDoc) { - EnumRuleDoc: return "#ffffcc" - ParserRuleDoc: return "#e6e6ff" - TerminalRuleDoc: return if (ruleDoc.isTerminalFragment) "#e6ffe6" else "#ccffcc" - default: return "white" - } - } - - /** - * Returns a BNF-like simplified representation of the given rule - * definition, with Markdown formatting. - */ - private def CharSequence formattedRuleDef(AbstractElement element) { - return formattedRuleDef(element, false); - } - /** * Returns a BNF-like simplified representation of the given rule * definition, with Markdown formatting. @@ -416,19 +378,23 @@ class MarkdownDocsFormatter implements IGrammarDocsFormatter { } private def String docCommentFormattingToMd(String text) { - val escaped = MarkdownTextFormatter.INSTANCE.escape(text); - val String resolved = DocCommentTextUtil.resolveLinks(escaped, MarkdownTextFormatter.INSTANCE, [it | toLink(it)]); - return DocCommentTextUtil.format(resolved, MarkdownTextFormatter.INSTANCE); + val escaped = textFormatter.escape(text); + val String resolved = DocCommentTextUtil.resolveLinks(escaped, textFormatter, [it | toLink(it)]); + return DocCommentTextUtil.format(resolved, textFormatter); } private def String toLink(String text) { if (text.trim().matches("^https?://.*")) { return text; } else { + // First, remove all non word text - in our case, we only need to check for parens + // And, compress all multiple spaces to singles + var temp = toAnchor(text); + if (gitbookLinkStyle) { - return '''#«text.replaceAll("\\s", "-")»'''; + return "#"+temp; } else { - return '''#«text.replaceAll("\\s", "-").toLowerCase»'''; + return "#"+temp.toLowerCase; } } } diff --git a/com.github.darvasd.xtextdocs.xtext/src/com/github/darvasd/xtextdocs/xtext/fragment/DocsGeneratorFragment.xtend b/com.epistimis.xtextdocs.xtext/src/com/epistimis/xtextdocs/xtext/fragment/DocsGeneratorFragment.xtend similarity index 60% rename from com.github.darvasd.xtextdocs.xtext/src/com/github/darvasd/xtextdocs/xtext/fragment/DocsGeneratorFragment.xtend rename to com.epistimis.xtextdocs.xtext/src/com/epistimis/xtextdocs/xtext/fragment/DocsGeneratorFragment.xtend index cf7fd55..ae1d4ae 100644 --- a/com.github.darvasd.xtextdocs.xtext/src/com/github/darvasd/xtextdocs/xtext/fragment/DocsGeneratorFragment.xtend +++ b/com.epistimis.xtextdocs.xtext/src/com/epistimis/xtextdocs/xtext/fragment/DocsGeneratorFragment.xtend @@ -1,5 +1,6 @@ /********************************************************************* * Copyright (c) 2018 Daniel Darvas + * Copyright (c) 2024 Epistimis LLC * * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 @@ -8,16 +9,17 @@ * SPDX-License-Identifier: EPL-2.0 **********************************************************************/ -package com.github.darvasd.xtextdocs.xtext.fragment +package com.epistimis.xtextdocs.xtext.fragment -import com.github.darvasd.xtextdocs.xtext.DocsGenerator -import com.github.darvasd.xtextdocs.xtext.formatter.IGrammarDocsFormatter +import com.epistimis.xtextdocs.xtext.DocsGenerator +import com.epistimis.xtextdocs.xtext.formatter.IGrammarDocsFormatter import com.google.inject.Inject import org.apache.log4j.Logger import org.eclipse.xtend.lib.annotations.Accessors import org.eclipse.xtext.Grammar import org.eclipse.xtext.xtext.generator.AbstractXtextGeneratorFragment import org.eclipse.xtext.xtext.generator.model.FileAccessFactory +import org.eclipse.xtend2.lib.StringConcatenationClient /** * Documentation generation fragment to be used in the Xtext generation workflow. @@ -25,14 +27,15 @@ import org.eclipse.xtext.xtext.generator.model.FileAccessFactory * Contains ideas from https://www.eclipse.org/forums/index.php/t/1067192/ . */ class DocsGeneratorFragment extends AbstractXtextGeneratorFragment { - private final static Logger LOG = Logger.getLogger(DocsGeneratorFragment); + final static Logger LOG = Logger.getLogger(DocsGeneratorFragment); Grammar grammar; @Inject FileAccessFactory fileAccessFactory /** - * The file name of the generated grammar documentation. + * The file name of the generated grammar documentation (with or without the type extension). + * If the file extension is not specified, then the extension defined for the formatter is used.sd *

    * Mandatory. */ @@ -66,12 +69,30 @@ class DocsGeneratorFragment extends AbstractXtextGeneratorFragment { LOG.error("Unknown 'formatter'"); return; } - + /** Add the appropriate extension based on the formatter type */ + if (outputFileName.lastIndexOf('.') == -1) { + outputFileName = outputFileName + formatter.outputFileExtension; + } // Generation of the textual output using the given formatter val textFileAccess = fileAccessFactory.createTextFile( outputFileName, '''«DocsGenerator.generateFormattedDoc(grammar, formatter)»'''); textFileAccess.writeTo(projectConfig.runtime.root) + /** + * All graphviz files are in DOT format, so the extension is fixed. + */ + val graphFileName = outputFileName.substring(0, outputFileName.lastIndexOf('.'))+ ".dot"; + val content = DocsGenerator.generateDOTGraph(grammar, formatter); + if (content.length > 0) { + // Only create the DOT file if there is something to put into it + val graphFileAccess = fileAccessFactory.createTextFile( + graphFileName, '''«content»'''); + graphFileAccess.writeTo(projectConfig.runtime.root) +// val Runtime rt = Runtime.getRuntime(); +// val Process pr = rt.exec("/opt/bin/homebrew/dot "+graphFileName); +// val ret = pr.waitFor(); + } + LOG.info('''Grammar documentation using '«formatter.class.simpleName»' written to '«outputFileName»' '''); } } diff --git a/com.github.darvasd.xtextdocs.xtext/src/com/github/darvasd/xtextdocs/xtext/ruledoc/EnumRuleDoc.java b/com.epistimis.xtextdocs.xtext/src/com/epistimis/xtextdocs/xtext/ruledoc/EnumRuleDoc.java similarity index 94% rename from com.github.darvasd.xtextdocs.xtext/src/com/github/darvasd/xtextdocs/xtext/ruledoc/EnumRuleDoc.java rename to com.epistimis.xtextdocs.xtext/src/com/epistimis/xtextdocs/xtext/ruledoc/EnumRuleDoc.java index f49c498..fc5c626 100644 --- a/com.github.darvasd.xtextdocs.xtext/src/com/github/darvasd/xtextdocs/xtext/ruledoc/EnumRuleDoc.java +++ b/com.epistimis.xtextdocs.xtext/src/com/epistimis/xtextdocs/xtext/ruledoc/EnumRuleDoc.java @@ -1,6 +1,7 @@ /********************************************************************* * Copyright (c) 2018 Daniel Darvas -* +* Copyright (c) 2024 Epistimis LLC +* * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ @@ -8,7 +9,7 @@ * SPDX-License-Identifier: EPL-2.0 **********************************************************************/ -package com.github.darvasd.xtextdocs.xtext.ruledoc; +package com.epistimis.xtextdocs.xtext.ruledoc; import java.util.ArrayList; import java.util.Collections; @@ -22,9 +23,8 @@ import org.eclipse.xtext.EnumRule; import org.eclipse.xtext.nodemodel.util.NodeModelUtils; -import com.github.darvasd.xtextdocs.xtext.ruledoc.RuleDoc; -import com.github.darvasd.xtextdocs.xtext.DocsGenerator; -import com.github.darvasd.xtextdocs.xtext.doccomment.DocComment; +import com.epistimis.xtextdocs.xtext.DocsGenerator; +import com.epistimis.xtextdocs.xtext.doccomment.DocComment; import com.google.common.base.Preconditions; /** diff --git a/com.github.darvasd.xtextdocs.xtext/src/com/github/darvasd/xtextdocs/xtext/ruledoc/GrammarDoc.java b/com.epistimis.xtextdocs.xtext/src/com/epistimis/xtextdocs/xtext/ruledoc/GrammarDoc.java similarity index 92% rename from com.github.darvasd.xtextdocs.xtext/src/com/github/darvasd/xtextdocs/xtext/ruledoc/GrammarDoc.java rename to com.epistimis.xtextdocs.xtext/src/com/epistimis/xtextdocs/xtext/ruledoc/GrammarDoc.java index 04e8915..0a71b68 100644 --- a/com.github.darvasd.xtextdocs.xtext/src/com/github/darvasd/xtextdocs/xtext/ruledoc/GrammarDoc.java +++ b/com.epistimis.xtextdocs.xtext/src/com/epistimis/xtextdocs/xtext/ruledoc/GrammarDoc.java @@ -1,6 +1,7 @@ /********************************************************************* * Copyright (c) 2018 Daniel Darvas -* +* Copyright (c) 2024 Epistimis LLC +* * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ @@ -8,15 +9,14 @@ * SPDX-License-Identifier: EPL-2.0 **********************************************************************/ -package com.github.darvasd.xtextdocs.xtext.ruledoc; +package com.epistimis.xtextdocs.xtext.ruledoc; import java.util.Collections; import java.util.List; import org.eclipse.xtext.Grammar; -import com.github.darvasd.xtextdocs.xtext.ruledoc.RuleDoc; -import com.github.darvasd.xtextdocs.xtext.doccomment.DocComment; +import com.epistimis.xtextdocs.xtext.doccomment.DocComment; import com.google.common.base.Preconditions; /** diff --git a/com.github.darvasd.xtextdocs.xtext/src/com/github/darvasd/xtextdocs/xtext/ruledoc/ParserRuleDoc.java b/com.epistimis.xtextdocs.xtext/src/com/epistimis/xtextdocs/xtext/ruledoc/ParserRuleDoc.java similarity index 90% rename from com.github.darvasd.xtextdocs.xtext/src/com/github/darvasd/xtextdocs/xtext/ruledoc/ParserRuleDoc.java rename to com.epistimis.xtextdocs.xtext/src/com/epistimis/xtextdocs/xtext/ruledoc/ParserRuleDoc.java index b95aa63..f732f55 100644 --- a/com.github.darvasd.xtextdocs.xtext/src/com/github/darvasd/xtextdocs/xtext/ruledoc/ParserRuleDoc.java +++ b/com.epistimis.xtextdocs.xtext/src/com/epistimis/xtextdocs/xtext/ruledoc/ParserRuleDoc.java @@ -1,6 +1,7 @@ /********************************************************************* * Copyright (c) 2018 Daniel Darvas -* +* Copyright (c) 2024 Epistimis LLC +* * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ @@ -8,12 +9,12 @@ * SPDX-License-Identifier: EPL-2.0 **********************************************************************/ -package com.github.darvasd.xtextdocs.xtext.ruledoc; +package com.epistimis.xtextdocs.xtext.ruledoc; import org.eclipse.xtext.AbstractElement; import org.eclipse.xtext.ParserRule; -import com.github.darvasd.xtextdocs.xtext.doccomment.DocComment; +import com.epistimis.xtextdocs.xtext.doccomment.DocComment; import com.google.common.base.Preconditions; /** diff --git a/com.github.darvasd.xtextdocs.xtext/src/com/github/darvasd/xtextdocs/xtext/ruledoc/ReferenceRuleDoc.java b/com.epistimis.xtextdocs.xtext/src/com/epistimis/xtextdocs/xtext/ruledoc/ReferenceRuleDoc.java similarity index 91% rename from com.github.darvasd.xtextdocs.xtext/src/com/github/darvasd/xtextdocs/xtext/ruledoc/ReferenceRuleDoc.java rename to com.epistimis.xtextdocs.xtext/src/com/epistimis/xtextdocs/xtext/ruledoc/ReferenceRuleDoc.java index 650d868..db649aa 100644 --- a/com.github.darvasd.xtextdocs.xtext/src/com/github/darvasd/xtextdocs/xtext/ruledoc/ReferenceRuleDoc.java +++ b/com.epistimis.xtextdocs.xtext/src/com/epistimis/xtextdocs/xtext/ruledoc/ReferenceRuleDoc.java @@ -1,6 +1,7 @@ /********************************************************************* * Copyright (c) 2018 Daniel Darvas -* +* Copyright (c) 2024 Epistimis LLC +* * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ @@ -8,7 +9,7 @@ * SPDX-License-Identifier: EPL-2.0 **********************************************************************/ -package com.github.darvasd.xtextdocs.xtext.ruledoc; +package com.epistimis.xtextdocs.xtext.ruledoc; import java.util.ArrayList; import java.util.Collection; @@ -22,8 +23,7 @@ import org.eclipse.xtext.AbstractRule; import org.eclipse.xtext.RuleCall; -import com.github.darvasd.xtextdocs.xtext.ruledoc.RuleDoc; -import com.github.darvasd.xtextdocs.xtext.doccomment.DocComment; +import com.epistimis.xtextdocs.xtext.doccomment.DocComment; /** * Represents the documentation attached to a Xtext rule which may have diff --git a/com.github.darvasd.xtextdocs.xtext/src/com/github/darvasd/xtextdocs/xtext/ruledoc/RuleDoc.xtend b/com.epistimis.xtextdocs.xtext/src/com/epistimis/xtextdocs/xtext/ruledoc/RuleDoc.xtend similarity index 78% rename from com.github.darvasd.xtextdocs.xtext/src/com/github/darvasd/xtextdocs/xtext/ruledoc/RuleDoc.xtend rename to com.epistimis.xtextdocs.xtext/src/com/epistimis/xtextdocs/xtext/ruledoc/RuleDoc.xtend index 070ba18..ad30477 100644 --- a/com.github.darvasd.xtextdocs.xtext/src/com/github/darvasd/xtextdocs/xtext/ruledoc/RuleDoc.xtend +++ b/com.epistimis.xtextdocs.xtext/src/com/epistimis/xtextdocs/xtext/ruledoc/RuleDoc.xtend @@ -1,5 +1,6 @@ /********************************************************************* * Copyright (c) 2018 Daniel Darvas + * Copyright (c) 2024 Epistimis LLC * * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 @@ -8,39 +9,39 @@ * SPDX-License-Identifier: EPL-2.0 **********************************************************************/ -package com.github.darvasd.xtextdocs.xtext.ruledoc; +package com.epistimis.xtextdocs.xtext.ruledoc; import org.eclipse.xtext.AbstractRule; import org.eclipse.xtext.TerminalRule import com.google.common.base.Preconditions -import com.github.darvasd.xtextdocs.xtext.doccomment.DocComment +import com.epistimis.xtextdocs.xtext.doccomment.DocComment import org.eclipse.xtext.ParserRule import org.eclipse.xtext.EnumRule /** * Generic representation of documentation attached to an {@link AbstractRule} Xtext rule. */ -public abstract class RuleDoc { - private DocComment headComment; +abstract class RuleDoc { + DocComment headComment; /** * Creates a new Xtext rule representation with the given head comment. * @param headComment Parsed head comment. Shall not be {@null}. */ - public new(DocComment headComment) { + new(DocComment headComment) { this.headComment = Preconditions.checkNotNull(headComment); } /** * Returns the Xtext rule that is represented by this. */ - public abstract def AbstractRule getRule(); + abstract def AbstractRule getRule(); /** * Returns the name of the represented grammar rule. */ - public def String getRuleName() { + def String getRuleName() { return getRule().getName(); } @@ -48,7 +49,7 @@ public abstract class RuleDoc { * Returns the head comment attached to the represented grammar rule. * @return Head comment. Never {@code null}. */ - public def DocComment getHeadComment() { + def DocComment getHeadComment() { return headComment; } @@ -56,7 +57,7 @@ public abstract class RuleDoc { * Creates an appropriate {@link RuleDoc} representation for the given * rule, with the given head comment. */ - public def static RuleDoc create(AbstractRule rule, DocComment headComment) { + def static RuleDoc create(AbstractRule rule, DocComment headComment) { switch (rule) { ParserRule: return new ParserRuleDoc(rule, headComment) EnumRule: return new EnumRuleDoc(rule, headComment) diff --git a/com.github.darvasd.xtextdocs.xtext/src/com/github/darvasd/xtextdocs/xtext/ruledoc/TerminalRuleDoc.java b/com.epistimis.xtextdocs.xtext/src/com/epistimis/xtextdocs/xtext/ruledoc/TerminalRuleDoc.java similarity index 90% rename from com.github.darvasd.xtextdocs.xtext/src/com/github/darvasd/xtextdocs/xtext/ruledoc/TerminalRuleDoc.java rename to com.epistimis.xtextdocs.xtext/src/com/epistimis/xtextdocs/xtext/ruledoc/TerminalRuleDoc.java index 556feb8..28f604a 100644 --- a/com.github.darvasd.xtextdocs.xtext/src/com/github/darvasd/xtextdocs/xtext/ruledoc/TerminalRuleDoc.java +++ b/com.epistimis.xtextdocs.xtext/src/com/epistimis/xtextdocs/xtext/ruledoc/TerminalRuleDoc.java @@ -1,6 +1,7 @@ /********************************************************************* * Copyright (c) 2018 Daniel Darvas -* +* Copyright (c) 2024 Epistimis LLC +* * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ @@ -8,11 +9,11 @@ * SPDX-License-Identifier: EPL-2.0 **********************************************************************/ -package com.github.darvasd.xtextdocs.xtext.ruledoc; +package com.epistimis.xtextdocs.xtext.ruledoc; import org.eclipse.xtext.TerminalRule; -import com.github.darvasd.xtextdocs.xtext.doccomment.DocComment; +import com.epistimis.xtextdocs.xtext.doccomment.DocComment; import com.google.common.base.Preconditions; /** diff --git a/com.github.darvasd.xtextdocs.common.test/META-INF/MANIFEST.MF b/com.github.darvasd.xtextdocs.common.test/META-INF/MANIFEST.MF deleted file mode 100644 index 6d2bef0..0000000 --- a/com.github.darvasd.xtextdocs.common.test/META-INF/MANIFEST.MF +++ /dev/null @@ -1,9 +0,0 @@ -Manifest-Version: 1.0 -Bundle-ManifestVersion: 2 -Bundle-Name: Test -Bundle-SymbolicName: com.github.darvasd.xtextdocs.common.test -Bundle-Version: 1.1.0.qualifier -Bundle-Vendor: Daniel Darvas -Fragment-Host: com.github.darvasd.xtextdocs.common -Bundle-RequiredExecutionEnvironment: JavaSE-1.8 -Import-Package: org.junit;version="4.12.0" diff --git a/com.github.darvasd.xtextdocs.p2/category.xml b/com.github.darvasd.xtextdocs.p2/category.xml deleted file mode 100644 index 4129361..0000000 --- a/com.github.darvasd.xtextdocs.p2/category.xml +++ /dev/null @@ -1,21 +0,0 @@ - - - - - - - - - - - - Visit http://github.com/darvasd/xtext-docs-gen for more details. - - - - - Visit http://github.com/darvasd/xtext-docs-gen for more details. - - - - diff --git a/com.github.darvasd.xtextdocs.xcore/.project b/com.github.darvasd.xtextdocs.xcore/.project deleted file mode 100644 index ec2487c..0000000 --- a/com.github.darvasd.xtextdocs.xcore/.project +++ /dev/null @@ -1,34 +0,0 @@ - - - com.github.darvasd.xtextdocs.xcore - - - - - - org.eclipse.xtext.ui.shared.xtextBuilder - - - - - org.eclipse.jdt.core.javabuilder - - - - - org.eclipse.pde.ManifestBuilder - - - - - org.eclipse.pde.SchemaBuilder - - - - - - org.eclipse.pde.PluginNature - org.eclipse.jdt.core.javanature - org.eclipse.xtext.ui.shared.xtextNature - - diff --git a/com.github.darvasd.xtextdocs.xtext.test/META-INF/MANIFEST.MF b/com.github.darvasd.xtextdocs.xtext.test/META-INF/MANIFEST.MF deleted file mode 100644 index ba96296..0000000 --- a/com.github.darvasd.xtextdocs.xtext.test/META-INF/MANIFEST.MF +++ /dev/null @@ -1,7 +0,0 @@ -Manifest-Version: 1.0 -Bundle-ManifestVersion: 2 -Bundle-Name: com.github.darvasd.xtextdocs.xtext.test -Bundle-SymbolicName: com.github.darvasd.xtextdocs.xtext.test -Bundle-Version: 1.1.0.qualifier -Fragment-Host: com.github.darvasd.xtextdocs.xtext;bundle-version="1.1.0" -Bundle-RequiredExecutionEnvironment: JavaSE-1.8 diff --git a/com.github.darvasd.xtextdocs.xtext/.classpath b/com.github.darvasd.xtextdocs.xtext/.classpath deleted file mode 100644 index 428337e..0000000 --- a/com.github.darvasd.xtextdocs.xtext/.classpath +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - diff --git a/docs/xcore_small_example.svg b/docs/xcore_small_example.svg index 4e366a9..64ee004 100644 --- a/docs/xcore_small_example.svg +++ b/docs/xcore_small_example.svg @@ -120,7 +120,7 @@ id="tspan4282" x="246.67984" y="225.7034" - style="font-style:italic;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:15px;font-family:Arial;-inkscape-font-specification:'Arial Italic';fill:#214478;fill-opacity:1">xtext-docs-gen (com.github.darvasd.xtextdocsgen.xcore)xtext-docs-gen (com.epistimis.xtextdocsgen.xcore)xtext-docs-gen (com.github.darvasd.xtextdocsgen.xtext)xtext-docs-gen (com.epistimis.xtextdocsgen.xtext) - + diff --git a/examples/org.example.domainmodel/META-INF/MANIFEST.MF b/examples/org.example.domainmodel/META-INF/MANIFEST.MF index 840b6f8..cffd42a 100644 --- a/examples/org.example.domainmodel/META-INF/MANIFEST.MF +++ b/examples/org.example.domainmodel/META-INF/MANIFEST.MF @@ -1,30 +1,31 @@ -Manifest-Version: 1.0 -Bundle-ManifestVersion: 2 -Bundle-Name: org.example.domainmodel -Bundle-Vendor: My Company -Bundle-Version: 1.1.0.qualifier -Bundle-SymbolicName: org.example.domainmodel; singleton:=true -Bundle-ActivationPolicy: lazy -Require-Bundle: org.eclipse.xtext, - org.eclipse.xtext.xbase, - org.eclipse.equinox.common;bundle-version="3.5.0", - org.eclipse.emf.ecore, - org.eclipse.xtext.xbase.lib, - org.antlr.runtime, - org.eclipse.xtext.util, - org.eclipse.xtend.lib, - org.eclipse.emf.common, - com.github.darvasd.xtextdocs.xtext;bundle-version="1.1.0" -Bundle-RequiredExecutionEnvironment: JavaSE-1.8 -Export-Package: org.example.domainmodel.scoping, - org.example.domainmodel.serializer, - org.example.domainmodel.parser.antlr.internal, - org.example.domainmodel.parser.antlr, - org.example.domainmodel.domainmodel.impl, - org.example.domainmodel.services, - org.example.domainmodel.domainmodel, - org.example.domainmodel.validation, - org.example.domainmodel.generator, - org.example.domainmodel.domainmodel.util, - org.example.domainmodel -Import-Package: org.apache.log4j +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Automatic-Module-Name: org.example.domainmodel +Bundle-Name: org.example.domainmodel +Bundle-Vendor: My Company +Bundle-Version: 1.1.0.qualifier +Bundle-SymbolicName: org.example.domainmodel; singleton:=true +Bundle-ActivationPolicy: lazy +Require-Bundle: org.eclipse.xtext, + org.eclipse.xtext.xbase, + org.eclipse.equinox.common;bundle-version="3.5.0", + org.eclipse.emf.ecore, + org.eclipse.xtext.xbase.lib;bundle-version="2.14.0", + org.antlr.runtime;bundle-version="[3.2.0,3.2.1)", + org.eclipse.xtext.util, + org.eclipse.xtend.lib;bundle-version="2.14.0", + org.eclipse.emf.common, + com.epistimis.xtextdocs.xtext;bundle-version="1.1.0" +Bundle-RequiredExecutionEnvironment: JavaSE-17 +Export-Package: org.example.domainmodel.scoping, + org.example.domainmodel.serializer, + org.example.domainmodel.parser.antlr.internal, + org.example.domainmodel.parser.antlr, + org.example.domainmodel.domainmodel.impl, + org.example.domainmodel.services, + org.example.domainmodel.domainmodel, + org.example.domainmodel.validation, + org.example.domainmodel.generator, + org.example.domainmodel.domainmodel.util, + org.example.domainmodel +Import-Package: org.apache.log4j diff --git a/examples/org.example.domainmodel/docs.md b/examples/org.example.domainmodel/docs.md index 3ee3fe1..ca3287d 100644 --- a/examples/org.example.domainmodel/docs.md +++ b/examples/org.example.domainmodel/docs.md @@ -31,7 +31,7 @@ Domainmodel: #### AbstractElement An **element** is a _package declaration_, -_import_ or _type_. + _import_ or _type_. This is the root element of the grammar. @@ -55,7 +55,7 @@ AbstractElement: #### PackageDeclaration -A **package** has a _qualified name_ and +A **package** has a _qualified name_ and [elements](#abstractelement) inside. - **Validation:** @@ -231,11 +231,11 @@ A dummy enum to demonstrate its documentation. Literals: - One (`ONE`) - : _Representation of **number 1**._ + : _Representation of **number 1**._ - Three (`THREE`) - : _Representation of **number 3**._ + : _Representation of **number 3**._ - Two (`TWO`, `ZWEI`) - : _Representation of **number 2**._ + : _Representation of **number 2**._ ``` enum DummyEnum: @@ -284,12 +284,12 @@ digraph G { Domainmodel [ color="red", fillcolor="#e6e6ff" ]; Domainmodel -> AbstractElement; AbstractElement [ color="black", fillcolor="#e6e6ff" ]; - AbstractElement -> PackageDeclaration; AbstractElement -> Type; + AbstractElement -> PackageDeclaration; AbstractElement -> Import; PackageDeclaration [ color="black", fillcolor="#e6e6ff" ]; - PackageDeclaration -> AbstractElement; PackageDeclaration -> QualifiedName; + PackageDeclaration -> AbstractElement; Import [ color="black", fillcolor="#e6e6ff" ]; Import -> QualifiedNameWithWildcard; QualifiedName [ color="black", fillcolor="#e6e6ff" ]; @@ -306,8 +306,8 @@ digraph G { Entity [ color="black", fillcolor="#e6e6ff" ]; ID [ color="black", fillcolor="#e6e6ff", style="dashed" ]; Entity -> ID [ style="dashed" ]; - Entity -> Feature; Entity -> QualifiedName; + Entity -> Feature; Feature [ color="black", fillcolor="#e6e6ff" ]; ID [ color="black", fillcolor="#e6e6ff", style="dashed" ]; Feature -> ID [ style="dashed" ]; diff --git a/examples/org.example.domainmodel/model/generated/Domainmodel.ecore b/examples/org.example.domainmodel/model/generated/Domainmodel.ecore index c285a3d..772b91a 100644 --- a/examples/org.example.domainmodel/model/generated/Domainmodel.ecore +++ b/examples/org.example.domainmodel/model/generated/Domainmodel.ecore @@ -1,37 +1,37 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/examples/org.example.domainmodel/model/generated/Domainmodel.genmodel b/examples/org.example.domainmodel/model/generated/Domainmodel.genmodel index e227cb2..9625031 100644 --- a/examples/org.example.domainmodel/model/generated/Domainmodel.genmodel +++ b/examples/org.example.domainmodel/model/generated/Domainmodel.genmodel @@ -1,39 +1,39 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/examples/org.example.domainmodel/plugin.xml_gen b/examples/org.example.domainmodel/plugin.xml_gen new file mode 100644 index 0000000..e79509e --- /dev/null +++ b/examples/org.example.domainmodel/plugin.xml_gen @@ -0,0 +1,10 @@ + + + + + + + diff --git a/examples/org.example.domainmodel/pom.xml b/examples/org.example.domainmodel/pom.xml index 0578d2a..80fa631 100644 --- a/examples/org.example.domainmodel/pom.xml +++ b/examples/org.example.domainmodel/pom.xml @@ -2,8 +2,8 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - com.github.darvasd.xtextdocs - com.github.darvasd.xtextdocs.examples + com.epistimis.xtextdocs + com.epistimis.xtextdocs.examples 1.1.0-SNAPSHOT org.example.domainmodel diff --git a/examples/org.example.domainmodel/src/org/example/domainmodel/GenerateDomainmodel.mwe2 b/examples/org.example.domainmodel/src/org/example/domainmodel/GenerateDomainmodel.mwe2 index 765f1df..4af45ef 100644 --- a/examples/org.example.domainmodel/src/org/example/domainmodel/GenerateDomainmodel.mwe2 +++ b/examples/org.example.domainmodel/src/org/example/domainmodel/GenerateDomainmodel.mwe2 @@ -2,8 +2,8 @@ module org.example.domainmodel.GenerateDomainmodel import org.eclipse.xtext.xtext.generator.* import org.eclipse.xtext.xtext.generator.model.project.* -import com.github.darvasd.xtextdocs.xtext.fragment.DocsGeneratorFragment -import com.github.darvasd.xtextdocs.xtext.formatter.MarkdownFormatter +import com.epistimis.xtextdocs.xtext.fragment.DocsGeneratorFragment +import com.epistimis.xtextdocs.xtext.formatter.MarkdownFormatter var rootPath = ".." @@ -36,7 +36,7 @@ Workflow { // xtext-docs-gen fragment = DocsGeneratorFragment auto-inject { outputFileName = "docs.md" - formatter = com.github.darvasd.xtextdocs.xtext.formatter.MarkdownDocsFormatter { + formatter = com.epistimis.xtextdocs.xtext.formatter.MarkdownDocsFormatter { includeDotReferenceGraph = true includeSimplifiedGrammar = true mainTitle = "Domain model grammar documentation" diff --git a/examples/org.example.xcore/.classpath b/examples/org.example.xcore/.classpath index 2534a14..b5e203f 100644 --- a/examples/org.example.xcore/.classpath +++ b/examples/org.example.xcore/.classpath @@ -2,7 +2,7 @@ - + diff --git a/examples/org.example.xcore/META-INF/MANIFEST.MF b/examples/org.example.xcore/META-INF/MANIFEST.MF index 1901eb3..6b07c89 100644 --- a/examples/org.example.xcore/META-INF/MANIFEST.MF +++ b/examples/org.example.xcore/META-INF/MANIFEST.MF @@ -1,12 +1,13 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 -Bundle-Name: Example for Xcore documentation generation +Bundle-Name: %pluginName Bundle-SymbolicName: org.example.xcore;singleton:=true +Automatic-Module-Name: org.example.xcore Bundle-Version: 1.1.0.qualifier Bundle-ClassPath: . Bundle-Vendor: %providerName Bundle-Localization: plugin -Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Bundle-RequiredExecutionEnvironment: JavaSE-17 Export-Package: org.example.xcore.library, org.example.xcore.library.impl, org.example.xcore.library.util @@ -16,7 +17,7 @@ Require-Bundle: org.eclipse.core.runtime, org.eclipse.emf.ecore.xcore.lib;resolution:=optional, org.eclipse.emf.mwe2.lib;bundle-version="2.9.0";resolution:=optional, org.eclipse.emf.ecore.xcore;bundle-version="1.4.0";resolution:=optional, - com.github.darvasd.xtextdocs.xcore;bundle-version="1.1.0", + com.epistimis.xtextdocs.xcore;bundle-version="1.1.0", org.eclipse.emf.mwe2.launch;bundle-version="2.9.0";resolution:=optional Bundle-ActivationPolicy: lazy Import-Package: org.apache.commons.logging;version="1.1.1" diff --git a/examples/org.example.xcore/src/org/example/xcore/library/GenerateXcoreDocs.mwe2 b/examples/org.example.xcore/src/org/example/xcore/library/GenerateXcoreDocs.mwe2 index 4726be1..1351088 100644 --- a/examples/org.example.xcore/src/org/example/xcore/library/GenerateXcoreDocs.mwe2 +++ b/examples/org.example.xcore/src/org/example/xcore/library/GenerateXcoreDocs.mwe2 @@ -1,7 +1,7 @@ module org.examle.xcore.library.GenerateXcoreDocs -import com.github.darvasd.xtextdocs.xcore.fragment.DocsGeneratorFragment -import com.github.darvasd.xtextdocs.xcore.formatter.MarkdownXcoreDocsFormatter +import com.epistimis.xtextdocs.xcore.fragment.DocsGeneratorFragment +import com.epistimis.xtextdocs.xcore.formatter.MarkdownXcoreDocsFormatter var rootPath = ".." @@ -34,5 +34,5 @@ Workflow { } } - // Multiple 'component = com.github.darvasd.xtextdocs.xcore.fragment.DocsGeneratorFragment' can be included here + // Multiple 'component = com.epistimis.xtextdocs.xcore.fragment.DocsGeneratorFragment' can be included here } \ No newline at end of file diff --git a/examples/pom.xml b/examples/pom.xml index 68c8ec3..7944c45 100644 --- a/examples/pom.xml +++ b/examples/pom.xml @@ -1,13 +1,13 @@ 4.0.0 - com.github.darvasd.xtextdocs - com.github.darvasd.xtextdocs.examples + com.epistimis.xtextdocs + com.epistimis.xtextdocs.examples 1.1.0-SNAPSHOT pom - com.github.darvasd.xtextdocs - com.github.darvasd.xtextdocs.parent + com.epistimis.xtextdocs + com.epistimis.xtextdocs.parent 1.1.0-SNAPSHOT diff --git a/pom.xml b/pom.xml index 4992b56..a581b40 100644 --- a/pom.xml +++ b/pom.xml @@ -1,9 +1,9 @@ 4.0.0 - com.github.darvasd.xtextdocs + com.epistimis.xtextdocs 1.1.0-SNAPSHOT - com.github.darvasd.xtextdocs.parent + com.epistimis.xtextdocs.parent pom @@ -15,13 +15,13 @@ - com.github.darvasd.xtextdocs.common - com.github.darvasd.xtextdocs.common.test - com.github.darvasd.xtextdocs.xcore - com.github.darvasd.xtextdocs.xtext - com.github.darvasd.xtextdocs.xtext.test - com.github.darvasd.xtextdocs.target - com.github.darvasd.xtextdocs.p2 + com.epistimis.xtextdocs.common + com.epistimis.xtextdocs.common.test + com.epistimis.xtextdocs.xcore + com.epistimis.xtextdocs.xtext + com.epistimis.xtextdocs.xtext.test + com.epistimis.xtextdocs.target + com.epistimis.xtextdocs.p2 examples @@ -41,8 +41,8 @@ - com.github.darvasd.xtextdocs - com.github.darvasd.xtextdocs.target + com.epistimis.xtextdocs + com.epistimis.xtextdocs.target ${project.version}