diff --git a/.licenserc.yaml b/.licenserc.yaml index 3614fb22..b848bcc0 100755 --- a/.licenserc.yaml +++ b/.licenserc.yaml @@ -1,16 +1,21 @@ header: license: spdx-id: EPL-2.0 - copyright-owner: Data In Motion Consulting GmbH + copyright-owner: Data In Motion content: | - This program and the accompanying materials are made available under the terms of the - Eclipse Public License v2.0 which accompanies this distribution, and is available at - http://www.eclipse.org/legal/epl-v20.html - + Copyright (c) 2012 - 2022 Data In Motion and others. + All rights reserved. + + 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 + + Contributors: pattern: | - This program and the accompanying materials are made available under the terms of the - Eclipse Public License v2.0 which accompanies this distribution, and is available at - http://www.eclipse.org/legal/epl-v20.html + 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/ paths-ignore: - 'dist' @@ -54,5 +59,6 @@ header: - 'gradlew' - 'gradlew.bat' - 'settings.gradle' + - '**/*Test.java' comment: always diff --git a/build.gradle b/build.gradle index 77b4358f..d06ae0e8 100644 --- a/build.gradle +++ b/build.gradle @@ -7,6 +7,7 @@ plugins { sonarqube { properties { + property "sonar.ce.javaOpts", "-Xmx2G" property "sonar.projectName", "Gecko EMF Utilities" property "sonar.projectKey", "geckoprojects-org_org.gecko.emf.utils" property "sonar.organization", "geckoprojects-org" diff --git a/cnf/build.bnd b/cnf/build.bnd index e3941155..40ceb982 100644 --- a/cnf/build.bnd +++ b/cnf/build.bnd @@ -25,7 +25,7 @@ base-version: 1.0.0.SNAPSHOT javac.source: 11 javac.target: 11 --require-bnd "(version>=6.2.0)" +-require-bnd "(version>=6.3.1)" -plugin.Central: \ aQute.bnd.repository.maven.provider.MavenBndRepository; \ diff --git a/cnf/central.mvn b/cnf/central.mvn index 82756dc8..6a0d51e3 100644 --- a/cnf/central.mvn +++ b/cnf/central.mvn @@ -130,9 +130,9 @@ org.osgi:osgi.core:8.0.0 org.slf4j:slf4j-api:1.7.30 org.slf4j:slf4j-simple:1.7.30 -org.eclipse.emf:org.eclipse.emf.common:2.23.0 -org.eclipse.emf:org.eclipse.emf.ecore:2.25.0 -org.eclipse.emf:org.eclipse.emf.ecore.xmi:2.16.0 +#org.eclipse.emf:org.eclipse.emf.common:2.23.0 +#org.eclipse.emf:org.eclipse.emf.ecore:2.25.0 +#org.eclipse.emf:org.eclipse.emf.ecore.xmi:2.16.0 org.eclipse.emf:org.eclipse.emf.codegen.ecore:2.28.0 org.eclipse.emf:org.eclipse.emf.codegen:2.22.0 org.eclipse.emf:org.eclipse.emf.ecore.xcore.lib:1.6.0 @@ -157,14 +157,23 @@ org.geckoprojects.bnd:org.gecko.bnd.jacoco.library:1.1.1 #org.geckoprojects.emf:org.gecko.emf.osgi.api:4.1.1.202202162308 org.geckoprojects.emf:org.gecko.emf.osgi.bnd.library.workspace:4.1.1-SNAPSHOT -org.geckoprojects.emf:org.gecko.emf.osgi.example.model.basic:4.1.1-SNAPSHOT com.fasterxml.jackson.core:jackson-core:2.13.2 com.fasterxml.jackson.core:jackson-databind:2.13.2 com.fasterxml.jackson.core:jackson-annotations:2.13.2 com.fasterxml.jackson.dataformat:jackson-dataformat-properties:2.13.2 com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.13.2 -org.eclipse.emfcloud:emfjson-jackson:2.1.0-SNAPSHOT +org.eclipse.emfcloud:emfjson-jackson:2.1.0 de.undercouch:bson4jackson:2.13.1 org.yaml:snakeyaml:1.30 #org.emfjson:emfjson-jackson:1.3.0 +org.geckoprojects.emf:org.gecko.emf.osgi.example.model.basic:4.1.1-SNAPSHOT + + +#xtext +org.eclipse.xtext:org.eclipse.xtext.xbase.lib:2.29.0.M1 +org.eclipse.xtext:org.eclipse.xtext.builder:2.10.0 +com.google.guava:guava:30.1-jre +com.google.guava:failureaccess:1.0.1 + +org.gecko.runtime:org.gecko.templates:1.0.31 diff --git a/gradle.properties b/gradle.properties index a9503cfa..37a305d1 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,2 +1,3 @@ -bnd_version=6.3.0-RC1 +bnd_version=6.3.1 bnd_snapshots=https://bndtools.jfrog.io/ui/native/libs-release/ +org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m diff --git a/org.gecko.emf.bson.tests/test.bndrun b/org.gecko.emf.bson.tests/test.bndrun index 089d2688..66623e8a 100644 --- a/org.gecko.emf.bson.tests/test.bndrun +++ b/org.gecko.emf.bson.tests/test.bndrun @@ -7,9 +7,7 @@ org.apache.felix.configadmin;version='[1.9.22,1.9.23)',\ org.eclipse.emf.ecore.xmi;version='[2.16.0,2.16.1)',\ org.opentest4j;version='[1.2.0,1.2.1)',\ - org.osgi.service.component;version='[1.4.0,1.4.1)',\ org.osgi.util.function;version='[1.1.0,1.1.1)',\ - org.osgi.util.promise;version='[1.1.1,1.1.2)',\ com.fasterxml.jackson.core.jackson-annotations;version='[2.13.2,2.13.3)',\ com.fasterxml.jackson.core.jackson-core;version='[2.13.2,2.13.3)',\ com.fasterxml.jackson.core.jackson-databind;version='[2.13.2,2.13.3)',\ @@ -23,7 +21,6 @@ org.gecko.emf.osgi.example.model.basic;version='[4.1.1,4.1.2)',\ com.fasterxml.jackson.dataformat.jackson-dataformat-properties;version='[2.13.2,2.13.3)',\ com.fasterxml.jackson.dataformat.jackson-dataformat-yaml;version='[2.13.2,2.13.3)',\ - emfjson-jackson;version='[2.1.0,2.1.1)',\ org.gecko.emf.bson;version=snapshot,\ org.gecko.emf.json;version=snapshot,\ org.yaml.snakeyaml;version='[1.30.0,1.30.1)',\ @@ -31,4 +28,8 @@ junit-jupiter-api;version='[5.8.2,5.8.3)',\ junit-jupiter-params;version='[5.8.2,5.8.3)',\ org.osgi.test.common;version='[1.1.0,1.1.1)',\ - org.osgi.test.junit5;version='[1.1.0,1.1.1)' \ No newline at end of file + org.osgi.test.junit5;version='[1.1.0,1.1.1)',\ + org.apache.felix.converter;version='[1.0.18,1.0.19)',\ + org.eclipse.emfcloud.emfjson-jackson;version='[2.1.0,2.1.1)',\ + org.osgi.service.cm;version='[1.6.0,1.6.1)',\ + org.osgi.util.promise;version='[1.2.0,1.2.1)' \ No newline at end of file diff --git a/org.gecko.emf.bson/src/org/gecko/emf/bson/EMFBsonResourceFactoryConfigurator.java b/org.gecko.emf.bson/src/org/gecko/emf/bson/EMFBsonResourceFactoryConfigurator.java index 70de3b8e..9695e875 100644 --- a/org.gecko.emf.bson/src/org/gecko/emf/bson/EMFBsonResourceFactoryConfigurator.java +++ b/org.gecko.emf.bson/src/org/gecko/emf/bson/EMFBsonResourceFactoryConfigurator.java @@ -2,9 +2,11 @@ * Copyright (c) 2012 - 2022 Data In Motion and others. * All rights reserved. * - * This program and the accompanying materials are made available under the terms of the - * Eclipse Public License v2.0 which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v20.html + * 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 * * Contributors: * Data In Motion - initial API and implementation diff --git a/org.gecko.emf.bson/src/org/gecko/emf/bson/annotation/RequireEMFBson.java b/org.gecko.emf.bson/src/org/gecko/emf/bson/annotation/RequireEMFBson.java index 0e140751..2fc36191 100644 --- a/org.gecko.emf.bson/src/org/gecko/emf/bson/annotation/RequireEMFBson.java +++ b/org.gecko.emf.bson/src/org/gecko/emf/bson/annotation/RequireEMFBson.java @@ -2,9 +2,11 @@ * Copyright (c) 2012 - 2022 Data In Motion and others. * All rights reserved. * - * This program and the accompanying materials are made available under the terms of the - * Eclipse Public License v2.0 which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v20.html + * 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 * * Contributors: * Data In Motion - initial API and implementation diff --git a/org.gecko.emf.bson/src/org/gecko/emf/bson/handler/BsonDateProblemHandler.java b/org.gecko.emf.bson/src/org/gecko/emf/bson/handler/BsonDateProblemHandler.java index cacb9bbc..7b5ba44c 100644 --- a/org.gecko.emf.bson/src/org/gecko/emf/bson/handler/BsonDateProblemHandler.java +++ b/org.gecko.emf.bson/src/org/gecko/emf/bson/handler/BsonDateProblemHandler.java @@ -2,9 +2,11 @@ * Copyright (c) 2012 - 2022 Data In Motion and others. * All rights reserved. * - * This program and the accompanying materials are made available under the terms of the - * Eclipse Public License v2.0 which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v20.html + * 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 * * Contributors: * Data In Motion - initial API and implementation diff --git a/org.gecko.emf.json.tests/bnd.bnd b/org.gecko.emf.json.tests/bnd.bnd index 7a9faf5d..9b5ff3ed 100644 --- a/org.gecko.emf.json.tests/bnd.bnd +++ b/org.gecko.emf.json.tests/bnd.bnd @@ -6,4 +6,8 @@ javac.target: 11 Bundle-Version: 1.0.1.SNAPSHOT -buildpath: \ - org.eclipse.emfcloud.emfjson-jackson;version=latest \ No newline at end of file + org.eclipse.emfcloud.emfjson-jackson;version=latest,\ + org.gecko.emf.osgi.component,\ + org.eclipse.emf.ecore.xmi,\ + org.eclipse.emf.ecore,\ + org.gecko.emf.osgi.example.model.basic \ No newline at end of file diff --git a/org.gecko.emf.json.tests/src/org/gecko/emf/json/tests/RootElementTest.java b/org.gecko.emf.json.tests/src/org/gecko/emf/json/tests/RootElementTest.java new file mode 100644 index 00000000..026ec926 --- /dev/null +++ b/org.gecko.emf.json.tests/src/org/gecko/emf/json/tests/RootElementTest.java @@ -0,0 +1,147 @@ +/** + * Copyright (c) 2012 - 2022 Data In Motion and others. + * All rights reserved. + * + * This program and the accompanying materials are made available under the terms of the + * Eclipse Public License v2.0 which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v20.html + * + * Contributors: + * Data In Motion - initial API and implementation + */ +package org.gecko.emf.json.tests; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; + +import org.eclipse.emf.common.util.URI; +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.emf.ecore.resource.ResourceSet; +import org.gecko.emf.json.configuration.ConfigurableJsonResource; +import org.gecko.emf.json.constants.EMFJs; +import org.gecko.emf.osgi.example.model.basic.BasicFactory; +import org.gecko.emf.osgi.example.model.basic.BasicPackage; +import org.gecko.emf.osgi.example.model.basic.Person; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.osgi.test.common.annotation.InjectService; +import org.osgi.test.common.service.ServiceAware; +import org.osgi.test.junit5.context.BundleContextExtension; +import org.osgi.test.junit5.service.ServiceExtension; + +/** + * + * @author mark + * @since 15.07.2022 + */ +@ExtendWith(BundleContextExtension.class) +@ExtendWith(ServiceExtension.class) +public class RootElementTest { + + @Test + public void testSaveJson(@InjectService(timeout = 2000) ServiceAware rsAware, + @InjectService(timeout = 2000) ServiceAware bfAware) { + + assertNotNull(rsAware); + assertThat(rsAware.getServices()).hasSize(1); + ResourceSet resourceSet = rsAware.getService(); + assertNotNull(resourceSet); + + assertNotNull(bfAware); + assertThat(bfAware.getServices()).hasSize(1); + BasicFactory factoryImpl = bfAware.getService(); + assertNotNull(factoryImpl); + + Resource resource = resourceSet.createResource(URI.createURI("test.json")); + assertNotNull(resource); + assertTrue(resource instanceof ConfigurableJsonResource); + + Person p = factoryImpl.createPerson(); + p.setFirstName("Emil"); + p.setLastName("Tester"); + resource.getContents().add(p); + + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + try { + resource.save(baos, null); + } catch (IOException e) { + fail("Error saving Person"); + } + String result = new String(baos.toByteArray()); + System.out.println(result); + } + + + + @Test + public void testLoadJsonError(@InjectService(timeout = 2000) ServiceAware rsAware) { + + assertNotNull(rsAware); + assertThat(rsAware.getServices()).hasSize(1); + ResourceSet resourceSet = rsAware.getService(); + assertNotNull(resourceSet); + + String json = "{\n" + + " \"firstName\" : \"Emil\",\n" + + " \"lastName\" : \"Tester\"\n" + + "}"; + Resource loadResource = resourceSet.createResource(URI.createURI("test-load-error.json")); + assertNotNull(loadResource); + assertTrue(loadResource instanceof ConfigurableJsonResource); + + ByteArrayInputStream bais = new ByteArrayInputStream(json.getBytes()); + try { + loadResource.load(bais, null); + assertEquals(0, loadResource.getContents().size()); + } catch (IOException e) { + fail("Error loading Person"); + } + } + + + @Test + public void testLoadJson(@InjectService(timeout = 2000) ServiceAware rsAware, + @InjectService(timeout = 2000) ServiceAware basicPackageAware) { + + assertNotNull(rsAware); + assertThat(rsAware.getServices()).hasSize(1); + ResourceSet resourceSet = rsAware.getService(); + assertNotNull(resourceSet); + + assertNotNull(basicPackageAware); + assertThat(basicPackageAware.getServices()).hasSize(1); + BasicPackage packageImpl = basicPackageAware.getService(); + assertNotNull(packageImpl); + + String json = "{\n" + + " \"firstName\" : \"Emil\",\n" + + " \"lastName\" : \"Tester\"\n" + + "}"; + Resource loadResource = resourceSet.createResource(URI.createURI("test-load.json")); + assertNotNull(loadResource); + assertTrue(loadResource instanceof ConfigurableJsonResource); + + ByteArrayInputStream bais = new ByteArrayInputStream(json.getBytes()); + try { + Map loadOptions = new HashMap(); + loadOptions.put(EMFJs.OPTION_ROOT_ELEMENT, packageImpl.getPerson()); + loadResource.load(bais, loadOptions); + assertEquals(1, loadResource.getContents().size()); + Person p = (Person) loadResource.getContents().get(0); + assertEquals("Emil", p.getFirstName()); + assertEquals("Tester", p.getLastName()); + } catch (IOException e) { + fail("Error loading Person"); + } + } + +} diff --git a/org.gecko.emf.json.tests/test.bndrun b/org.gecko.emf.json.tests/test.bndrun index 774cb76c..7273e5e1 100644 --- a/org.gecko.emf.json.tests/test.bndrun +++ b/org.gecko.emf.json.tests/test.bndrun @@ -12,7 +12,6 @@ com.fasterxml.jackson.dataformat.jackson-dataformat-properties;version='[2.13.2,2.13.3)',\ com.fasterxml.jackson.dataformat.jackson-dataformat-yaml;version='[2.13.2,2.13.3)',\ de.undercouch.bson4jackson;version='[2.13.1,2.13.2)',\ - emfjson-jackson;version='[2.1.0,2.1.1)',\ junit-jupiter-api;version='[5.8.2,5.8.3)',\ junit-platform-commons;version='[1.8.2,1.8.3)',\ net.bytebuddy.byte-buddy;version='[1.12.8,1.12.9)',\ @@ -30,11 +29,19 @@ org.mockito.mockito-core;version='[4.4.0,4.4.1)',\ org.objenesis;version='[3.2.0,3.2.1)',\ org.opentest4j;version='[1.2.0,1.2.1)',\ - org.osgi.service.component;version='[1.4.0,1.4.1)',\ org.osgi.util.function;version='[1.1.0,1.1.1)',\ - org.osgi.util.promise;version='[1.1.1,1.1.2)',\ org.osgi.util.pushstream;version='[1.0.1,1.0.2)',\ - org.yaml.snakeyaml;version='[1.30.0,1.30.1)' + org.yaml.snakeyaml;version='[1.30.0,1.30.1)',\ + org.apache.felix.converter;version='[1.0.18,1.0.19)',\ + org.eclipse.emfcloud.emfjson-jackson;version='[2.1.0,2.1.1)',\ + org.osgi.util.promise;version='[1.2.0,1.2.1)',\ + org.gecko.emf.bson;version=snapshot,\ + org.gecko.emf.util.model;version=snapshot,\ + org.osgi.service.cm;version='[1.6.0,1.6.1)',\ + assertj-core;version='[3.22.0,3.22.1)',\ + junit-jupiter-params;version='[5.8.2,5.8.3)',\ + org.osgi.test.common;version='[1.1.0,1.1.1)',\ + org.osgi.test.junit5;version='[1.1.0,1.1.1)' diff --git a/org.gecko.emf.json/src/org/gecko/emf/json/EMFJSONResourceFactoryConfigurator.java b/org.gecko.emf.json/src/org/gecko/emf/json/EMFJSONResourceFactoryConfigurator.java index 8f22f536..0d6eff29 100644 --- a/org.gecko.emf.json/src/org/gecko/emf/json/EMFJSONResourceFactoryConfigurator.java +++ b/org.gecko.emf.json/src/org/gecko/emf/json/EMFJSONResourceFactoryConfigurator.java @@ -2,9 +2,11 @@ * Copyright (c) 2012 - 2022 Data In Motion and others. * All rights reserved. * - * This program and the accompanying materials are made available under the terms of the - * Eclipse Public License v2.0 which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v20.html + * 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 * * Contributors: * Data In Motion - initial API and implementation diff --git a/org.gecko.emf.json/src/org/gecko/emf/json/annotation/RequireEMFJson.java b/org.gecko.emf.json/src/org/gecko/emf/json/annotation/RequireEMFJson.java index ff5161bd..ba80d026 100644 --- a/org.gecko.emf.json/src/org/gecko/emf/json/annotation/RequireEMFJson.java +++ b/org.gecko.emf.json/src/org/gecko/emf/json/annotation/RequireEMFJson.java @@ -2,9 +2,11 @@ * Copyright (c) 2012 - 2022 Data In Motion and others. * All rights reserved. * - * This program and the accompanying materials are made available under the terms of the - * Eclipse Public License v2.0 which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v20.html + * 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 * * Contributors: * Data In Motion - initial API and implementation diff --git a/org.gecko.emf.json/src/org/gecko/emf/json/configuration/ConfigurableJsonResource.java b/org.gecko.emf.json/src/org/gecko/emf/json/configuration/ConfigurableJsonResource.java index 800020c4..39bab10f 100644 --- a/org.gecko.emf.json/src/org/gecko/emf/json/configuration/ConfigurableJsonResource.java +++ b/org.gecko.emf.json/src/org/gecko/emf/json/configuration/ConfigurableJsonResource.java @@ -2,15 +2,18 @@ * Copyright (c) 2012 - 2022 Data In Motion and others. * All rights reserved. * - * This program and the accompanying materials are made available under the terms of the - * Eclipse Public License v2.0 which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v20.html + * 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 * * Contributors: * Data In Motion - initial API and implementation */ package org.gecko.emf.json.configuration; +import static org.eclipse.emfcloud.jackson.databind.EMFContext.Attributes.ROOT_ELEMENT; import static org.eclipse.emfcloud.jackson.databind.EMFContext.Attributes.RESOURCE; import static org.eclipse.emfcloud.jackson.databind.EMFContext.Attributes.RESOURCE_SET; @@ -107,11 +110,6 @@ public ObjectMapper configureMapper(Map options) { private EMFModule createInitModule(Map options, boolean isNew) { EMFModule module = new EMFModule(); - Boolean serContainment = getOrDefault(options, EMFJs.OPTION_SERIALIZE_CONTAINMENT_AS_HREF, - isNew ? false : null); - if (serContainment != null) { - module.configure(Feature.OPTION_SERIALIZE_CONTAINMENT_AS_HREF, serContainment); - } Boolean serDefaults = getOrDefault(options, EMFJs.OPTION_SERIALIZE_DEFAULT_VALUE, isNew ? false : null); if (serDefaults != null) { module.configure(Feature.OPTION_SERIALIZE_DEFAULT_VALUE, serDefaults); @@ -216,6 +214,10 @@ protected void doLoad(InputStream inputStream, Map options) throws IOExcep ContextAttributes attributes = EMFContext.from(options).withPerCallAttribute(RESOURCE_SET, getResourceSet()) .withPerCallAttribute(RESOURCE, this); + EClass eclass = getOrDefault(options, EMFJs.OPTION_ROOT_ELEMENT, null); + if (eclass != null) { + attributes = attributes.withPerCallAttribute(ROOT_ELEMENT, eclass); + } configureMapper(options).reader().with(attributes).forType(Resource.class).withValueToUpdate(this) .readValue(inputStream); diff --git a/org.gecko.emf.json/src/org/gecko/emf/json/configuration/ConfigurableJsonResourceFactory.java b/org.gecko.emf.json/src/org/gecko/emf/json/configuration/ConfigurableJsonResourceFactory.java index 2d1f0afe..17457379 100644 --- a/org.gecko.emf.json/src/org/gecko/emf/json/configuration/ConfigurableJsonResourceFactory.java +++ b/org.gecko.emf.json/src/org/gecko/emf/json/configuration/ConfigurableJsonResourceFactory.java @@ -2,9 +2,11 @@ * Copyright (c) 2012 - 2022 Data In Motion and others. * All rights reserved. * - * This program and the accompanying materials are made available under the terms of the - * Eclipse Public License v2.0 which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v20.html + * 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 * * Contributors: * Data In Motion - initial API and implementation diff --git a/org.gecko.emf.json/src/org/gecko/emf/json/configuration/XMLResourceUriHandlerWrapper.java b/org.gecko.emf.json/src/org/gecko/emf/json/configuration/XMLResourceUriHandlerWrapper.java index 898477cf..20b293f6 100644 --- a/org.gecko.emf.json/src/org/gecko/emf/json/configuration/XMLResourceUriHandlerWrapper.java +++ b/org.gecko.emf.json/src/org/gecko/emf/json/configuration/XMLResourceUriHandlerWrapper.java @@ -2,9 +2,11 @@ * Copyright (c) 2012 - 2022 Data In Motion and others. * All rights reserved. * - * This program and the accompanying materials are made available under the terms of the - * Eclipse Public License v2.0 which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v20.html + * 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 * * Contributors: * Data In Motion - initial API and implementation diff --git a/org.gecko.emf.json/src/org/gecko/emf/json/constants/EMFJs.java b/org.gecko.emf.json/src/org/gecko/emf/json/constants/EMFJs.java index 1e1d832f..d1f13b09 100644 --- a/org.gecko.emf.json/src/org/gecko/emf/json/constants/EMFJs.java +++ b/org.gecko.emf.json/src/org/gecko/emf/json/constants/EMFJs.java @@ -2,9 +2,11 @@ * Copyright (c) 2012 - 2022 Data In Motion and others. * All rights reserved. * - * This program and the accompanying materials are made available under the terms of the - * Eclipse Public License v2.0 which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v20.html + * 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 * * Contributors: * Data In Motion - initial API and implementation @@ -51,10 +53,6 @@ public final class EMFJs { */ public static final String OPTION_INDENT_OUTPUT = "OPTION_INDENT_OUTPUT"; - /** - * Option used to indicate the module to serialize containments as references. - */ - public static final String OPTION_SERIALIZE_CONTAINMENT_AS_HREF = "OPTION_SERIALIZE_CONTAINMENT_AS_HREF"; /** * When value is true, the writer will include an _id key to each json objects * and sets as value the fragment identifier. diff --git a/org.gecko.emf.rest/src/org/gecko/emf/jaxrs/AbstractEMFMessageBodyReaderWriter.java b/org.gecko.emf.rest/src/org/gecko/emf/jaxrs/AbstractEMFMessageBodyReaderWriter.java index 3eb8de58..ec08d3cb 100644 --- a/org.gecko.emf.rest/src/org/gecko/emf/jaxrs/AbstractEMFMessageBodyReaderWriter.java +++ b/org.gecko.emf.rest/src/org/gecko/emf/jaxrs/AbstractEMFMessageBodyReaderWriter.java @@ -2,9 +2,11 @@ * Copyright (c) 2012 - 2022 Data In Motion and others. * All rights reserved. * - * This program and the accompanying materials are made available under the terms of the - * Eclipse Public License v2.0 which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v20.html + * 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 * * Contributors: * Data In Motion - initial API and implementation diff --git a/org.gecko.emf.rest/src/org/gecko/emf/jaxrs/EMFJsonAnnotationConverter.java b/org.gecko.emf.rest/src/org/gecko/emf/jaxrs/EMFJsonAnnotationConverter.java index 6b7e9455..e33b29ea 100644 --- a/org.gecko.emf.rest/src/org/gecko/emf/jaxrs/EMFJsonAnnotationConverter.java +++ b/org.gecko.emf.rest/src/org/gecko/emf/jaxrs/EMFJsonAnnotationConverter.java @@ -2,9 +2,11 @@ * Copyright (c) 2012 - 2022 Data In Motion and others. * All rights reserved. * - * This program and the accompanying materials are made available under the terms of the - * Eclipse Public License v2.0 which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v20.html + * 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 * * Contributors: * Data In Motion - initial API and implementation @@ -70,7 +72,6 @@ public void convertAnnotation(Annotation annotation, boolean serialize, Map + + + + + + + + + + + + + + + diff --git a/org.gecko.emf.util.documentation.generators.apis/.gitignore b/org.gecko.emf.util.documentation.generators.apis/.gitignore new file mode 100644 index 00000000..7fdbdef7 --- /dev/null +++ b/org.gecko.emf.util.documentation.generators.apis/.gitignore @@ -0,0 +1,2 @@ +/bin/ +/bin_test/ diff --git a/org.gecko.emf.util.documentation.generators.apis/.project b/org.gecko.emf.util.documentation.generators.apis/.project new file mode 100644 index 00000000..2e8e4134 --- /dev/null +++ b/org.gecko.emf.util.documentation.generators.apis/.project @@ -0,0 +1,23 @@ + + + org.gecko.emf.util.documentation.generators.apis + + + + + + org.eclipse.jdt.core.javabuilder + + + + + bndtools.core.bndbuilder + + + + + + org.eclipse.jdt.core.javanature + bndtools.core.bndnature + + diff --git a/org.gecko.emf.util.documentation.generators.apis/.settings/org.eclipse.core.resources.prefs b/org.gecko.emf.util.documentation.generators.apis/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 00000000..416633d8 --- /dev/null +++ b/org.gecko.emf.util.documentation.generators.apis/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,10 @@ +eclipse.preferences.version=1 +encoding//.settings/org.eclipse.core.resources.prefs=UTF-8 +encoding//.settings/org.eclipse.jdt.core.prefs=UTF-8 +encoding//.settings/org.eclipse.jdt.ui.prefs=UTF-8 +encoding//src/org/gecko/emf/util/documentation/generators/apis/EcoreToDocumentationService.java=UTF-8 +encoding//src/org/gecko/emf/util/documentation/generators/apis/package-info.java=UTF-8 +encoding//src/test/component/Example.java=UTF-8 +encoding//test/test/component/ExampleTest.java=UTF-8 +encoding/bnd.bnd=UTF-8 +encoding/launch.bndrun=UTF-8 diff --git a/org.gecko.emf.util.documentation.generators.apis/.settings/org.eclipse.jdt.core.prefs b/org.gecko.emf.util.documentation.generators.apis/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 00000000..049e42fd --- /dev/null +++ b/org.gecko.emf.util.documentation.generators.apis/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,11 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=11 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=11 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=11 diff --git a/org.gecko.emf.util.documentation.generators.apis/.settings/org.eclipse.jdt.ui.prefs b/org.gecko.emf.util.documentation.generators.apis/.settings/org.eclipse.jdt.ui.prefs new file mode 100644 index 00000000..25b8c0de --- /dev/null +++ b/org.gecko.emf.util.documentation.generators.apis/.settings/org.eclipse.jdt.ui.prefs @@ -0,0 +1,10 @@ +content_assist_proposals_background=255,255,255 +content_assist_proposals_foreground=0,0,0 +eclipse.preferences.version=1 +org.eclipse.jdt.ui.formatterprofiles.version=13 +org.eclipse.jdt.ui.javadoc=true +org.eclipse.jdt.ui.text.code_templates_migrated=true +org.eclipse.jdt.ui.text.custom_code_templates= +spelling_locale_initialized=true +useAnnotationsPrefPage=true +useQuickDiffPrefPage=true diff --git a/org.gecko.emf.util.documentation.generators.apis/bnd.bnd b/org.gecko.emf.util.documentation.generators.apis/bnd.bnd new file mode 100644 index 00000000..612b3c3a --- /dev/null +++ b/org.gecko.emf.util.documentation.generators.apis/bnd.bnd @@ -0,0 +1,7 @@ +javac.source: 11 +javac.target: 11 + +-library: enable-emf + +Bundle-Version: 1.0.0.SNAPSHOT +Export-Package: org.gecko.emf.util.documentation.generators.apis diff --git a/org.gecko.emf.util.documentation.generators.apis/src/org/gecko/emf/util/documentation/generators/apis/EcoreToClassDiagramCodeGenerator.java b/org.gecko.emf.util.documentation.generators.apis/src/org/gecko/emf/util/documentation/generators/apis/EcoreToClassDiagramCodeGenerator.java new file mode 100644 index 00000000..de7112aa --- /dev/null +++ b/org.gecko.emf.util.documentation.generators.apis/src/org/gecko/emf/util/documentation/generators/apis/EcoreToClassDiagramCodeGenerator.java @@ -0,0 +1,41 @@ +/** + * Copyright (c) 2012 - 2022 Data In Motion and others. + * All rights reserved. + * + * 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 + * + * Contributors: + * Data In Motion - initial API and implementation + */ +package org.gecko.emf.util.documentation.generators.apis; + +import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.EClassifier; +import org.eclipse.emf.ecore.EPackage; + +/** + * + * @author ilenia + * @since Oct 18, 2022 + */ +public interface EcoreToClassDiagramCodeGenerator { + + CharSequence generateClassDiagram(EPackage ePackage); + + + /** + * + * @param eClass + * @return + * @deprecated use {@link generateClassDiagram(EClassifier eClassifier)} instead + */ + @Deprecated() + CharSequence generateClassDiagram(EClass eClass); + + CharSequence generateClassDiagram(EClassifier eClassifier); + +} diff --git a/org.gecko.emf.util.documentation.generators.apis/src/org/gecko/emf/util/documentation/generators/apis/EcoreToDocumentationCodeGenerator.java b/org.gecko.emf.util.documentation.generators.apis/src/org/gecko/emf/util/documentation/generators/apis/EcoreToDocumentationCodeGenerator.java new file mode 100644 index 00000000..58c34eb0 --- /dev/null +++ b/org.gecko.emf.util.documentation.generators.apis/src/org/gecko/emf/util/documentation/generators/apis/EcoreToDocumentationCodeGenerator.java @@ -0,0 +1,40 @@ +/** + * Copyright (c) 2012 - 2022 Data In Motion and others. + * All rights reserved. + * + * 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 + * + * Contributors: + * Data In Motion - initial API and implementation + */ +package org.gecko.emf.util.documentation.generators.apis; + +import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.EClassifier; +import org.eclipse.emf.ecore.EPackage; + +/** + * + * @author ilenia + * @since Oct 19, 2022 + */ +public interface EcoreToDocumentationCodeGenerator { + + CharSequence generateDocumentation(EPackage ePackage, EcoreToDocumentationOptions docGenOption); + + /** + * @param eClass + * @param docGenOption + * @return + * @deprecated use {@link generateDocumentation(EClassifier eClassifier, EcoreToDocumentationOptions docGenOption)} instead + */ + @Deprecated + CharSequence generateDocumentation(EClass eClass, EcoreToDocumentationOptions docGenOption); + + CharSequence generateDocumentation(EClassifier eClassifier, EcoreToDocumentationOptions docGenOption); + +} diff --git a/org.gecko.emf.util.documentation.generators.apis/src/org/gecko/emf/util/documentation/generators/apis/EcoreToDocumentationOptions.java b/org.gecko.emf.util.documentation.generators.apis/src/org/gecko/emf/util/documentation/generators/apis/EcoreToDocumentationOptions.java new file mode 100644 index 00000000..467f2c9b --- /dev/null +++ b/org.gecko.emf.util.documentation.generators.apis/src/org/gecko/emf/util/documentation/generators/apis/EcoreToDocumentationOptions.java @@ -0,0 +1,30 @@ +/** + * Copyright (c) 2012 - 2022 Data In Motion and others. + * All rights reserved. + * + * 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 + * + * Contributors: + * Data In Motion - initial API and implementation + */ +package org.gecko.emf.util.documentation.generators.apis; + +/** + * + * @author ilenia + * @since Oct 18, 2022 + */ +public enum EcoreToDocumentationOptions { + + MARKDOWN_WITH_MERMAID_CLASS_DIAGRAM, + MARKDOWN_WITH_PLANTUML_CLASS_DIAGRAM, + HTML_WITH_MERMAID_CLASS_DIAGRAM, + HTML_WITH_PLANTUML_CLASS_DIAGRAM, + ONLY_MARKDOWN_CLASS_OVERVIEW, + ONLY_HTML_CLASS_OVERVIEW; + +} diff --git a/org.gecko.emf.util.documentation.generators.apis/src/org/gecko/emf/util/documentation/generators/apis/EcoreToDocumentationService.java b/org.gecko.emf.util.documentation.generators.apis/src/org/gecko/emf/util/documentation/generators/apis/EcoreToDocumentationService.java new file mode 100644 index 00000000..7e80e372 --- /dev/null +++ b/org.gecko.emf.util.documentation.generators.apis/src/org/gecko/emf/util/documentation/generators/apis/EcoreToDocumentationService.java @@ -0,0 +1,87 @@ +/** + * Copyright (c) 2012 - 2022 Data In Motion and others. + * All rights reserved. + * + * 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 + * + * Contributors: + * Data In Motion - initial API and implementation + */ +package org.gecko.emf.util.documentation.generators.apis; + +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.io.OutputStream; +import java.io.PrintWriter; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; + +import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.EClassifier; +import org.eclipse.emf.ecore.EPackage; +import org.osgi.annotation.versioning.ProviderType; + +@ProviderType +public interface EcoreToDocumentationService{ + + boolean canHandleMediaType(String mediaType); + String getOutputFileExtension(); + String getOutputFolder(EcoreToDocumentationOptions mode); + OutputStream doGenerateDocumentation(EPackage ePackage, EcoreToDocumentationOptions mode, String outputFolderRoot) throws IOException; + + /** + * @param eClass + * @param mode + * @param outputFolderRoot + * @return + * @throws IOException + * @deprecated use {@link doGenerateDocumentation(EClassifier eClassifier, EcoreToDocumentationOptions mode, String outputFolderRoot)} instead + */ + @Deprecated + OutputStream doGenerateDocumentation(EClass eClass, EcoreToDocumentationOptions mode, String outputFolderRoot) throws IOException; + + OutputStream doGenerateDocumentation(EClassifier eClassifier, EcoreToDocumentationOptions mode, String outputFolderRoot) throws IOException; + + default File generateOutputFile(EPackage ePackage, CharSequence generatedDoc, EcoreToDocumentationOptions mode, String outputFolderRoot) throws IOException { + String outputFileName = ePackage.getName().concat(getOutputFileExtension()); + return doCreateOutputFile(outputFileName, generatedDoc, mode, outputFolderRoot); + } + + /** + * @param eClass + * @param generatedDoc + * @param mode + * @param outputFolderRoot + * @return + * @throws IOException + * @deprecated use {@link generateOutputFile(EClassifier eClassifier, CharSequence generatedDoc, EcoreToDocumentationOptions mode, String outputFolderRoot) } instead + */ + @Deprecated + default File generateOutputFile(EClass eClass, CharSequence generatedDoc, EcoreToDocumentationOptions mode, String outputFolderRoot) throws IOException { + String outputFileName = eClass.getEPackage().getName().concat("_").concat(eClass.getName()).concat(getOutputFileExtension()); + return doCreateOutputFile(outputFileName, generatedDoc, mode, outputFolderRoot); + } + + default File generateOutputFile(EClassifier eClassifier, CharSequence generatedDoc, EcoreToDocumentationOptions mode, String outputFolderRoot) throws IOException { + String outputFileName = eClassifier.getEPackage().getName().concat("_").concat(eClassifier.getName()).concat(getOutputFileExtension()); + return doCreateOutputFile(outputFileName, generatedDoc, mode, outputFolderRoot); + } + + default File doCreateOutputFile(String outputFileName, CharSequence generatedDoc, EcoreToDocumentationOptions mode, String outputFolderRoot) throws IOException { + Path outputPath = Paths.get(outputFolderRoot, getOutputFolder(mode), outputFileName); + Files.deleteIfExists(outputPath); + Files.createDirectories(outputPath.getParent()); + File outputFile = Files.createFile(outputPath).toFile(); + try(PrintWriter pw = new PrintWriter(new FileWriter(outputFile))) { + pw.write(generatedDoc.toString()); + } + return outputFile; + } + +} diff --git a/org.gecko.emf.util.documentation.generators.apis/src/org/gecko/emf/util/documentation/generators/apis/package-info.java b/org.gecko.emf.util.documentation.generators.apis/src/org/gecko/emf/util/documentation/generators/apis/package-info.java new file mode 100644 index 00000000..85c57a69 --- /dev/null +++ b/org.gecko.emf.util.documentation.generators.apis/src/org/gecko/emf/util/documentation/generators/apis/package-info.java @@ -0,0 +1,3 @@ +@org.osgi.annotation.versioning.Version("1.0.0") +@org.osgi.annotation.bundle.Export +package org.gecko.emf.util.documentation.generators.apis; diff --git a/org.gecko.emf.util.documentation.generators.apis/test/.keep b/org.gecko.emf.util.documentation.generators.apis/test/.keep new file mode 100644 index 00000000..e69de29b diff --git a/org.gecko.emf.util.documentation.generators.html.component/.classpath b/org.gecko.emf.util.documentation.generators.html.component/.classpath new file mode 100644 index 00000000..1e6e6a74 --- /dev/null +++ b/org.gecko.emf.util.documentation.generators.html.component/.classpath @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + diff --git a/org.gecko.emf.util.documentation.generators.html.component/.gitignore b/org.gecko.emf.util.documentation.generators.html.component/.gitignore new file mode 100644 index 00000000..7fdbdef7 --- /dev/null +++ b/org.gecko.emf.util.documentation.generators.html.component/.gitignore @@ -0,0 +1,2 @@ +/bin/ +/bin_test/ diff --git a/org.gecko.emf.util.documentation.generators.html.component/.project b/org.gecko.emf.util.documentation.generators.html.component/.project new file mode 100644 index 00000000..067e37c1 --- /dev/null +++ b/org.gecko.emf.util.documentation.generators.html.component/.project @@ -0,0 +1,23 @@ + + + org.gecko.emf.util.documentation.generators.html.component + + + + + + org.eclipse.jdt.core.javabuilder + + + + + bndtools.core.bndbuilder + + + + + + org.eclipse.jdt.core.javanature + bndtools.core.bndnature + + diff --git a/org.gecko.emf.util.documentation.generators.html.component/.settings/org.eclipse.core.resources.prefs b/org.gecko.emf.util.documentation.generators.html.component/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 00000000..03f9b4a8 --- /dev/null +++ b/org.gecko.emf.util.documentation.generators.html.component/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,8 @@ +eclipse.preferences.version=1 +encoding//.settings/org.eclipse.core.resources.prefs=UTF-8 +encoding//.settings/org.eclipse.jdt.core.prefs=UTF-8 +encoding//.settings/org.eclipse.jdt.ui.prefs=UTF-8 +encoding//src/org/gecko/emf/util/documentation/generators/html/component/EcoreToHtmlComponent.java=UTF-8 +encoding//src/test/component/Example.java=UTF-8 +encoding//test/test/component/ExampleTest.java=UTF-8 +encoding/bnd.bnd=UTF-8 diff --git a/org.gecko.emf.util.documentation.generators.html.component/.settings/org.eclipse.jdt.core.prefs b/org.gecko.emf.util.documentation.generators.html.component/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 00000000..049e42fd --- /dev/null +++ b/org.gecko.emf.util.documentation.generators.html.component/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,11 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=11 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=11 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=11 diff --git a/org.gecko.emf.util.documentation.generators.html.component/.settings/org.eclipse.jdt.ui.prefs b/org.gecko.emf.util.documentation.generators.html.component/.settings/org.eclipse.jdt.ui.prefs new file mode 100644 index 00000000..25b8c0de --- /dev/null +++ b/org.gecko.emf.util.documentation.generators.html.component/.settings/org.eclipse.jdt.ui.prefs @@ -0,0 +1,10 @@ +content_assist_proposals_background=255,255,255 +content_assist_proposals_foreground=0,0,0 +eclipse.preferences.version=1 +org.eclipse.jdt.ui.formatterprofiles.version=13 +org.eclipse.jdt.ui.javadoc=true +org.eclipse.jdt.ui.text.code_templates_migrated=true +org.eclipse.jdt.ui.text.custom_code_templates= +spelling_locale_initialized=true +useAnnotationsPrefPage=true +useQuickDiffPrefPage=true diff --git a/org.gecko.emf.util.documentation.generators.html.component/bnd.bnd b/org.gecko.emf.util.documentation.generators.html.component/bnd.bnd new file mode 100644 index 00000000..8ad584dc --- /dev/null +++ b/org.gecko.emf.util.documentation.generators.html.component/bnd.bnd @@ -0,0 +1,12 @@ +javac.source: 11 +javac.target: 11 + +-library: enable-emf + +Bundle-Version: 1.0.0.SNAPSHOT + +-buildpath: \ + org.gecko.emf.util.documentation.generators.apis;version=latest,\ + org.gecko.emf.util.documentation.generators.html;version=latest + +Private-Package: org.gecko.emf.util.documentation.generators.html.component diff --git a/org.gecko.emf.util.documentation.generators.html.component/src/org/gecko/emf/util/documentation/generators/html/component/EcoreToHtmlComponent.java b/org.gecko.emf.util.documentation.generators.html.component/src/org/gecko/emf/util/documentation/generators/html/component/EcoreToHtmlComponent.java new file mode 100644 index 00000000..9195980b --- /dev/null +++ b/org.gecko.emf.util.documentation.generators.html.component/src/org/gecko/emf/util/documentation/generators/html/component/EcoreToHtmlComponent.java @@ -0,0 +1,119 @@ +/** + * Copyright (c) 2012 - 2022 Data In Motion and others. + * All rights reserved. + * + * 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 + * + * Contributors: + * Data In Motion - initial API and implementation + */ +package org.gecko.emf.util.documentation.generators.html.component; + +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; + +import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.EClassifier; +import org.eclipse.emf.ecore.EPackage; +import org.gecko.emf.util.documentation.generators.apis.EcoreToDocumentationCodeGenerator; +import org.gecko.emf.util.documentation.generators.apis.EcoreToDocumentationOptions; +import org.gecko.emf.util.documentation.generators.apis.EcoreToDocumentationService; +import org.gecko.emf.util.documentation.generators.html.HtmlCodeGen; +import org.osgi.service.component.annotations.Component; + +@Component(name="EcoreToHtmlComponent", service=EcoreToDocumentationService.class) +public class EcoreToHtmlComponent implements EcoreToDocumentationService { + + private static final String HTML_FILE_EXTENSION = ".html"; + private static final String HTML_OUTPUT_FOLDER = "html"; + private static final String HTML_WITH_MERMAID_OUTPUT_FOLDER = "html_mermaid"; + private static final String HTML_MEDIA_TYPE = "text/html"; + + /* + * (non-Javadoc) + * @see org.gecko.emf.util.documentation.generators.apis.EcoreToDocumentationService#canHandleMediaType(java.lang.String) + */ + @Override + public boolean canHandleMediaType(String mediaType) { + return HTML_MEDIA_TYPE.equals(mediaType); + } + + /* + * (non-Javadoc) + * @see org.gecko.emf.util.documentation.generators.apis.EcoreToDocumentationService#getOutputFileExtension() + */ + @Override + public String getOutputFileExtension() { + return HTML_FILE_EXTENSION; + } + + /* + * (non-Javadoc) + * @see org.gecko.emf.util.documentation.generators.apis.EcoreToDocumentationService#getOutputFolder(org.gecko.emf.util.documentation.generators.apis.EcoreToDocumentationOptions) + */ + @Override + public String getOutputFolder(EcoreToDocumentationOptions mode) { + switch(mode) { + case HTML_WITH_MERMAID_CLASS_DIAGRAM: + return HTML_WITH_MERMAID_OUTPUT_FOLDER; + case ONLY_HTML_CLASS_OVERVIEW: default: + return HTML_OUTPUT_FOLDER; + } + } + + /* + * (non-Javadoc) + * @see org.gecko.emf.util.documentation.generators.apis.EcoreToDocumentationService#doGenerateDocumentation(org.eclipse.emf.ecore.EPackage, org.gecko.emf.util.documentation.generators.apis.EcoreToDocumentationOptions, java.lang.String) + */ + @Override + public OutputStream doGenerateDocumentation(EPackage ePackage, EcoreToDocumentationOptions mode, String outputFolderRoot) throws IOException { + EcoreToDocumentationCodeGenerator mdCodeGenerator = new HtmlCodeGen(); + CharSequence cs = mdCodeGenerator.generateDocumentation(ePackage, mode); + File outputFile = generateOutputFile(ePackage, cs, mode, outputFolderRoot); + try(InputStream is = new FileInputStream(outputFile); OutputStream os = new ByteArrayOutputStream();) { + os.write(is.readAllBytes()); + return os; + } + } + + /* + * (non-Javadoc) + * @see org.gecko.emf.util.documentation.generators.apis.EcoreToDocumentationService#doGenerateDocumentation(org.eclipse.emf.ecore.EClass, org.gecko.emf.util.documentation.generators.apis.EcoreToDocumentationOptions, java.lang.String) + */ + @Override + public OutputStream doGenerateDocumentation(EClass eClass, EcoreToDocumentationOptions mode, String outputFolderRoot) throws IOException { + EcoreToDocumentationCodeGenerator mdCodeGenerator = new HtmlCodeGen(); + CharSequence cs = mdCodeGenerator.generateDocumentation(eClass, mode); + File outputFile = generateOutputFile(eClass, cs, mode, outputFolderRoot); + try(InputStream is = new FileInputStream(outputFile); OutputStream os = new ByteArrayOutputStream();) { + os.write(is.readAllBytes()); + return os; + } + } + + /* + * (non-Javadoc) + * @see org.gecko.emf.util.documentation.generators.apis.EcoreToDocumentationService#doGenerateDocumentation(org.eclipse.emf.ecore.EClassifier, org.gecko.emf.util.documentation.generators.apis.EcoreToDocumentationOptions, java.lang.String) + */ + @Override + public OutputStream doGenerateDocumentation(EClassifier eClassifier, EcoreToDocumentationOptions mode, + String outputFolderRoot) throws IOException { + EcoreToDocumentationCodeGenerator mdCodeGenerator = new HtmlCodeGen(); + CharSequence cs = mdCodeGenerator.generateDocumentation(eClassifier, mode); + File outputFile = generateOutputFile(eClassifier, cs, mode, outputFolderRoot); + try(InputStream is = new FileInputStream(outputFile); OutputStream os = new ByteArrayOutputStream();) { + os.write(is.readAllBytes()); + return os; + } + } + + +} diff --git a/org.gecko.emf.util.documentation.generators.html.component/test/.keep b/org.gecko.emf.util.documentation.generators.html.component/test/.keep new file mode 100644 index 00000000..e69de29b diff --git a/org.gecko.emf.util.documentation.generators.html/.classpath b/org.gecko.emf.util.documentation.generators.html/.classpath new file mode 100644 index 00000000..e37cc369 --- /dev/null +++ b/org.gecko.emf.util.documentation.generators.html/.classpath @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/org.gecko.emf.util.documentation.generators.html/.gitignore b/org.gecko.emf.util.documentation.generators.html/.gitignore new file mode 100644 index 00000000..1a9ea807 --- /dev/null +++ b/org.gecko.emf.util.documentation.generators.html/.gitignore @@ -0,0 +1,2 @@ +/bin/ +/xtend-gen/* \ No newline at end of file diff --git a/org.gecko.emf.util.documentation.generators.html/.project b/org.gecko.emf.util.documentation.generators.html/.project new file mode 100644 index 00000000..1be1216b --- /dev/null +++ b/org.gecko.emf.util.documentation.generators.html/.project @@ -0,0 +1,29 @@ + + + org.gecko.emf.util.documentation.generators.html + + + + + + org.eclipse.xtext.ui.shared.xtextBuilder + + + + + org.eclipse.jdt.core.javabuilder + + + + + bndtools.core.bndbuilder + + + + + + org.eclipse.jdt.core.javanature + bndtools.core.bndnature + org.eclipse.xtext.ui.shared.xtextNature + + diff --git a/org.gecko.emf.util.documentation.generators.html/.settings/org.eclipse.jdt.core.prefs b/org.gecko.emf.util.documentation.generators.html/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 00000000..f2525a8b --- /dev/null +++ b/org.gecko.emf.util.documentation.generators.html/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,14 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=11 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=11 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning +org.eclipse.jdt.core.compiler.release=enabled +org.eclipse.jdt.core.compiler.source=11 diff --git a/org.gecko.emf.util.documentation.generators.html/bnd.bnd b/org.gecko.emf.util.documentation.generators.html/bnd.bnd new file mode 100644 index 00000000..d953a2ad --- /dev/null +++ b/org.gecko.emf.util.documentation.generators.html/bnd.bnd @@ -0,0 +1,16 @@ +Bundle-Name: Xtend Generator for Html +Bundle-Description: Xtend Generator for Html +Bundle-Version: 1.0.0-SNAPSHOT + +src.xtend-gen=xtend-gen + +-buildpath: \ + org.eclipse.xtext.xbase.lib,\ + org.gecko.emf.util.documentation.generators.mermaid;version=latest,\ + org.gecko.emf.util.documentation.generators.plantuml;version=latest,\ + org.gecko.emf.util.documentation.generators.apis;version=latest + +-library: \ + enable-emf + +Export-Package: org.gecko.emf.util.documentation.generators.html \ No newline at end of file diff --git a/org.gecko.emf.util.documentation.generators.html/src/org/gecko/emf/util/documentation/generators/html/HtmlCodeGen.xtend b/org.gecko.emf.util.documentation.generators.html/src/org/gecko/emf/util/documentation/generators/html/HtmlCodeGen.xtend new file mode 100644 index 00000000..935fd237 --- /dev/null +++ b/org.gecko.emf.util.documentation.generators.html/src/org/gecko/emf/util/documentation/generators/html/HtmlCodeGen.xtend @@ -0,0 +1,233 @@ +/** + * Copyright (c) 2012 - 2022 Data In Motion and others. + * All rights reserved. + * + * 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 + * + * Contributors: + * Data In Motion - initial API and implementation + */ +package org.gecko.emf.util.documentation.generators.html; + +import java.util.List +import org.eclipse.emf.common.util.EList +import org.eclipse.emf.common.util.EMap +import org.eclipse.emf.ecore.EAnnotation +import org.eclipse.emf.ecore.EClass +import org.eclipse.emf.ecore.EClassifier +import org.eclipse.emf.ecore.EEnum +import org.eclipse.emf.ecore.EEnumLiteral +import org.eclipse.emf.ecore.EModelElement +import org.eclipse.emf.ecore.EPackage +import org.eclipse.emf.ecore.EStructuralFeature +import org.gecko.emf.util.documentation.generators.apis.EcoreToClassDiagramCodeGenerator +import org.gecko.emf.util.documentation.generators.mermaid.MermaidClassDiagramCodeGen +import org.gecko.emf.util.documentation.generators.apis.EcoreToDocumentationOptions +import org.gecko.emf.util.documentation.generators.apis.EcoreToDocumentationCodeGenerator + +class HtmlCodeGen implements EcoreToDocumentationCodeGenerator { + + EcoreToClassDiagramCodeGenerator classDiagramCodeGen; + String docStart = "\n"+ + "\t\n"+ + "\t\t\n" + + "\t\t\n" + + "\t\n" + + "\t"; + String docEnd = "\t\n"; + String diagramStartSyntax = ""; + String diagramEndSyntax = ""; + String mdBlockStart = "\t\t"; + String mdBlockEnd = "\t\t"; + + def generateHtmlDoc(EPackage epackage, EcoreToDocumentationOptions mode) { + if(EcoreToDocumentationOptions.HTML_WITH_MERMAID_CLASS_DIAGRAM.equals(mode)) { + classDiagramCodeGen = new MermaidClassDiagramCodeGen(); + diagramStartSyntax = "\t\t\t
"; + diagramEndSyntax = "\t\t\t
"; + } + ''' +«docStart» +«mdBlockStart» +# Package: «epackage.name» +«"\n"» +«mdBlockEnd» +«IF classDiagramCodeGen !== null» +«mdBlockStart» +## Class Diagram +«"\n"» +«mdBlockEnd» +«diagramStartSyntax» +«classDiagramCodeGen.generateClassDiagram(epackage).toString().replace("<","<").replace(">", ">")» +«diagramEndSyntax» +«"\n"» +«ENDIF» +«toEClassifierOverview(epackage.EClassifiers)» +«docEnd» + ''' + } + + + def toEClassifierOverview(EList eclassifiers) { +var List classes = eclassifiers.filter[ec | ec instanceof EClass].map[ec | ec as EClass].toList; +var List enums = eclassifiers.filter[ec | ec instanceof EEnum].map[ec | ec as EEnum].toList; +''' +«IF !classes.isEmpty» +«mdBlockStart» +## Classes Overview +«"\n"» +«mdBlockEnd» +«FOR eclass: classes» +«toClassOverview(eclass)» +«"\n"» +«"\n"» +«ENDFOR» +«"\n"» +«ENDIF» +«mdBlockStart» +## Enumerators Overview +«"\n"» +«mdBlockEnd» +«IF enums.empty» +«mdBlockStart» +None. +«"\n"» +«mdBlockEnd» +«ELSE» +«FOR enumerator: enums» +«toEnumOverview(enumerator)» +«"\n"» +«"\n"» +«ENDFOR» +«ENDIF» +''' +} + + + def toEnumOverview(EEnum enumerator) + ''' +«mdBlockStart» +### Enumerator: «enumerator.name» +«"\n"» +#### Description +«"\n"» +«toModelElementDescription(enumerator)» +«"\n"» +#### Literals +«"\n"» +«toLiteralOverview(enumerator.ELiterals)» +«mdBlockEnd» + ''' + + def toLiteralOverview(EList literals) + ''' +«IF literals.empty» +None. +«ELSE» +| Literal| Description| +| -----| -----------| +«FOR literal: literals» +|«literal.name»|«toModelElementDescription(literal)»| +«ENDFOR» +«ENDIF» + ''' + + def toClassOverview(EClass eclass) + ''' +«mdBlockStart» +### Class: «eclass.name» +«"\n"» +#### Description +«"\n"» +«toModelElementDescription(eclass)» +«"\n"» +«mdBlockEnd» +«IF classDiagramCodeGen !== null» +«mdBlockStart» +#### Class Diagram +«"\n"» +«mdBlockEnd» +«diagramStartSyntax» +«classDiagramCodeGen.generateClassDiagram(eclass).toString().replace("<","<").replace(">", ">")» +«diagramEndSyntax» +«"\n"» +«ENDIF» +«mdBlockStart» +#### Fields +«"\n"» +«toClassStructuralFeaturesDescription(eclass.EAttributes)» +«"\n"» +#### References +«"\n"» +«toClassStructuralFeaturesDescription(eclass.EReferences)» +«"\n"» +«mdBlockEnd» + ''' + + + def toClassStructuralFeaturesDescription(EList features) { + ''' +«IF features.empty» +None. +«ELSE» +| Name| Type| Bounds| Description| +| -----| ----| ------| -----------| +«FOR feature: features» +|«feature.name»|«feature.EType.name»|«feature.lowerBound»..«feature.upperBound»|«toModelElementDescription(feature)»| +«ENDFOR» +«ENDIF» + ''' + } + + + def String toModelElementDescription(EModelElement element) { + for(EAnnotation annotation : element.EAnnotations) { + var EMap details = annotation.details; + if(details.containsKey("documentation")) { + return details.get("documentation").trim; + } + + } + return "None." + } + + override generateDocumentation(EPackage ePackage, EcoreToDocumentationOptions docGenOption) { + generateHtmlDoc(ePackage, docGenOption); + } + + override generateDocumentation(EClass eClass, EcoreToDocumentationOptions docGenOption) { + if(EcoreToDocumentationOptions.HTML_WITH_MERMAID_CLASS_DIAGRAM.equals(docGenOption)) { + classDiagramCodeGen = new MermaidClassDiagramCodeGen(); + diagramStartSyntax = "
"; + diagramEndSyntax = "
"; + } + ''' +«docStart» +«toClassOverview(eClass)» +«docEnd» + ''' + + } + + override generateDocumentation(EClassifier eClassifier, EcoreToDocumentationOptions docGenOption) { + if(EcoreToDocumentationOptions.HTML_WITH_MERMAID_CLASS_DIAGRAM.equals(docGenOption)) { + classDiagramCodeGen = new MermaidClassDiagramCodeGen(); + diagramStartSyntax = "
"; + diagramEndSyntax = "
"; + } + ''' +«docStart» +«IF eClassifier instanceof EClass» +«toClassOverview(eClassifier as EClass)» +«ELSEIF eClassifier instanceof EEnum» +«toEnumOverview(eClassifier as EEnum)» +«ENDIF» +«docEnd» + ''' + } + +} \ No newline at end of file diff --git a/org.gecko.emf.util.documentation.generators.html/xtend-gen/org/gecko/emf/util/documentation/generators/html/.HtmlCodeGen.xtendbin b/org.gecko.emf.util.documentation.generators.html/xtend-gen/org/gecko/emf/util/documentation/generators/html/.HtmlCodeGen.xtendbin new file mode 100644 index 00000000..0d4b0671 Binary files /dev/null and b/org.gecko.emf.util.documentation.generators.html/xtend-gen/org/gecko/emf/util/documentation/generators/html/.HtmlCodeGen.xtendbin differ diff --git a/org.gecko.emf.util.documentation.generators.html/xtend-gen/org/gecko/emf/util/documentation/generators/html/.gitignore b/org.gecko.emf.util.documentation.generators.html/xtend-gen/org/gecko/emf/util/documentation/generators/html/.gitignore new file mode 100644 index 00000000..ad117701 --- /dev/null +++ b/org.gecko.emf.util.documentation.generators.html/xtend-gen/org/gecko/emf/util/documentation/generators/html/.gitignore @@ -0,0 +1,3 @@ +/.HtmlCodeGen.java._trace +/.HtmlCodeGen.xtendbin +/HtmlCodeGen.java diff --git a/org.gecko.emf.util.documentation.generators.html/xtend-gen/org/gecko/emf/util/documentation/generators/html/HtmlCodeGen.java b/org.gecko.emf.util.documentation.generators.html/xtend-gen/org/gecko/emf/util/documentation/generators/html/HtmlCodeGen.java new file mode 100644 index 00000000..76d09395 --- /dev/null +++ b/org.gecko.emf.util.documentation.generators.html/xtend-gen/org/gecko/emf/util/documentation/generators/html/HtmlCodeGen.java @@ -0,0 +1,436 @@ +/** + * Copyright (c) 2012 - 2022 Data In Motion and others. + * All rights reserved. + * + * 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 + * + * Contributors: + * Data In Motion - initial API and implementation + */ +package org.gecko.emf.util.documentation.generators.html; + +import java.util.List; +import org.eclipse.emf.common.util.EList; +import org.eclipse.emf.common.util.EMap; +import org.eclipse.emf.ecore.EAnnotation; +import org.eclipse.emf.ecore.EAttribute; +import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.EClassifier; +import org.eclipse.emf.ecore.EEnum; +import org.eclipse.emf.ecore.EEnumLiteral; +import org.eclipse.emf.ecore.EModelElement; +import org.eclipse.emf.ecore.EPackage; +import org.eclipse.emf.ecore.EReference; +import org.eclipse.emf.ecore.EStructuralFeature; +import org.eclipse.xtend2.lib.StringConcatenation; +import org.eclipse.xtext.xbase.lib.Functions.Function1; +import org.eclipse.xtext.xbase.lib.IterableExtensions; +import org.gecko.emf.util.documentation.generators.apis.EcoreToClassDiagramCodeGenerator; +import org.gecko.emf.util.documentation.generators.apis.EcoreToDocumentationCodeGenerator; +import org.gecko.emf.util.documentation.generators.apis.EcoreToDocumentationOptions; +import org.gecko.emf.util.documentation.generators.mermaid.MermaidClassDiagramCodeGen; + +@SuppressWarnings("all") +public class HtmlCodeGen implements EcoreToDocumentationCodeGenerator { + private EcoreToClassDiagramCodeGenerator classDiagramCodeGen; + + private String docStart = ((((("\n" + + "\t\n") + + "\t\t\n") + + "\t\t\n") + + "\t\n") + + "\t"); + + private String docEnd = "\t\n"; + + private String diagramStartSyntax = ""; + + private String diagramEndSyntax = ""; + + private String mdBlockStart = "\t\t"; + + private String mdBlockEnd = "\t\t"; + + public CharSequence generateHtmlDoc(final EPackage epackage, final EcoreToDocumentationOptions mode) { + CharSequence _xblockexpression = null; + { + boolean _equals = EcoreToDocumentationOptions.HTML_WITH_MERMAID_CLASS_DIAGRAM.equals(mode); + if (_equals) { + MermaidClassDiagramCodeGen _mermaidClassDiagramCodeGen = new MermaidClassDiagramCodeGen(); + this.classDiagramCodeGen = _mermaidClassDiagramCodeGen; + this.diagramStartSyntax = "\t\t\t
"; + this.diagramEndSyntax = "\t\t\t
"; + } + StringConcatenation _builder = new StringConcatenation(); + _builder.append(this.docStart); + _builder.newLineIfNotEmpty(); + _builder.append(this.mdBlockStart); + _builder.newLineIfNotEmpty(); + _builder.append("# Package: "); + String _name = epackage.getName(); + _builder.append(_name); + _builder.newLineIfNotEmpty(); + _builder.append("\n"); + _builder.newLineIfNotEmpty(); + _builder.append(this.mdBlockEnd); + _builder.newLineIfNotEmpty(); + { + if ((this.classDiagramCodeGen != null)) { + _builder.append(this.mdBlockStart); + _builder.newLineIfNotEmpty(); + _builder.append("## Class Diagram"); + _builder.newLine(); + _builder.append("\n"); + _builder.newLineIfNotEmpty(); + _builder.append(this.mdBlockEnd); + _builder.newLineIfNotEmpty(); + _builder.append(this.diagramStartSyntax); + _builder.newLineIfNotEmpty(); + String _replace = this.classDiagramCodeGen.generateClassDiagram(epackage).toString().replace("<", "<").replace(">", ">"); + _builder.append(_replace); + _builder.newLineIfNotEmpty(); + _builder.append(this.diagramEndSyntax); + _builder.newLineIfNotEmpty(); + _builder.append("\n"); + _builder.newLineIfNotEmpty(); + } + } + CharSequence _eClassifierOverview = this.toEClassifierOverview(epackage.getEClassifiers()); + _builder.append(_eClassifierOverview); + _builder.newLineIfNotEmpty(); + _builder.append(this.docEnd); + _builder.newLineIfNotEmpty(); + _xblockexpression = _builder; + } + return _xblockexpression; + } + + public CharSequence toEClassifierOverview(final EList eclassifiers) { + CharSequence _xblockexpression = null; + { + final Function1 _function = (EClassifier ec) -> { + return Boolean.valueOf((ec instanceof EClass)); + }; + final Function1 _function_1 = (EClassifier ec) -> { + return ((EClass) ec); + }; + List classes = IterableExtensions.toList(IterableExtensions.map(IterableExtensions.filter(eclassifiers, _function), _function_1)); + final Function1 _function_2 = (EClassifier ec) -> { + return Boolean.valueOf((ec instanceof EEnum)); + }; + final Function1 _function_3 = (EClassifier ec) -> { + return ((EEnum) ec); + }; + List enums = IterableExtensions.toList(IterableExtensions.map(IterableExtensions.filter(eclassifiers, _function_2), _function_3)); + StringConcatenation _builder = new StringConcatenation(); + { + boolean _isEmpty = classes.isEmpty(); + boolean _not = (!_isEmpty); + if (_not) { + _builder.append(this.mdBlockStart); + _builder.newLineIfNotEmpty(); + _builder.append("## Classes Overview"); + _builder.newLine(); + _builder.append("\n"); + _builder.newLineIfNotEmpty(); + _builder.append(this.mdBlockEnd); + _builder.newLineIfNotEmpty(); + { + for(final EClass eclass : classes) { + CharSequence _classOverview = this.toClassOverview(eclass); + _builder.append(_classOverview); + _builder.newLineIfNotEmpty(); + _builder.append("\n"); + _builder.newLineIfNotEmpty(); + _builder.append("\n"); + _builder.newLineIfNotEmpty(); + } + } + _builder.append("\n"); + _builder.newLineIfNotEmpty(); + } + } + _builder.append(this.mdBlockStart); + _builder.newLineIfNotEmpty(); + _builder.append("## Enumerators Overview"); + _builder.newLine(); + _builder.append("\n"); + _builder.newLineIfNotEmpty(); + _builder.append(this.mdBlockEnd); + _builder.newLineIfNotEmpty(); + { + boolean _isEmpty_1 = enums.isEmpty(); + if (_isEmpty_1) { + _builder.append(this.mdBlockStart); + _builder.newLineIfNotEmpty(); + _builder.append("None."); + _builder.newLine(); + _builder.append("\n"); + _builder.newLineIfNotEmpty(); + _builder.append(this.mdBlockEnd); + _builder.newLineIfNotEmpty(); + } else { + { + for(final EEnum enumerator : enums) { + CharSequence _enumOverview = this.toEnumOverview(enumerator); + _builder.append(_enumOverview); + _builder.newLineIfNotEmpty(); + _builder.append("\n"); + _builder.newLineIfNotEmpty(); + _builder.append("\n"); + _builder.newLineIfNotEmpty(); + } + } + } + } + _xblockexpression = _builder; + } + return _xblockexpression; + } + + public CharSequence toEnumOverview(final EEnum enumerator) { + StringConcatenation _builder = new StringConcatenation(); + _builder.append(this.mdBlockStart); + _builder.newLineIfNotEmpty(); + _builder.append("### Enumerator: "); + String _name = enumerator.getName(); + _builder.append(_name); + _builder.newLineIfNotEmpty(); + _builder.append("\n"); + _builder.newLineIfNotEmpty(); + _builder.append("#### Description"); + _builder.newLine(); + _builder.append("\n"); + _builder.newLineIfNotEmpty(); + String _modelElementDescription = this.toModelElementDescription(enumerator); + _builder.append(_modelElementDescription); + _builder.newLineIfNotEmpty(); + _builder.append("\n"); + _builder.newLineIfNotEmpty(); + _builder.append("#### Literals"); + _builder.newLine(); + _builder.append("\n"); + _builder.newLineIfNotEmpty(); + CharSequence _literalOverview = this.toLiteralOverview(enumerator.getELiterals()); + _builder.append(_literalOverview); + _builder.newLineIfNotEmpty(); + _builder.append(this.mdBlockEnd); + _builder.newLineIfNotEmpty(); + return _builder; + } + + public CharSequence toLiteralOverview(final EList literals) { + StringConcatenation _builder = new StringConcatenation(); + { + boolean _isEmpty = literals.isEmpty(); + if (_isEmpty) { + _builder.append("None."); + _builder.newLine(); + } else { + _builder.append("| Literal| Description|"); + _builder.newLine(); + _builder.append("| -----| -----------|"); + _builder.newLine(); + { + for(final EEnumLiteral literal : literals) { + _builder.append("|"); + String _name = literal.getName(); + _builder.append(_name); + _builder.append("|"); + String _modelElementDescription = this.toModelElementDescription(literal); + _builder.append(_modelElementDescription); + _builder.append("|"); + _builder.newLineIfNotEmpty(); + } + } + } + } + return _builder; + } + + public CharSequence toClassOverview(final EClass eclass) { + StringConcatenation _builder = new StringConcatenation(); + _builder.append(this.mdBlockStart); + _builder.newLineIfNotEmpty(); + _builder.append("### Class: "); + String _name = eclass.getName(); + _builder.append(_name); + _builder.newLineIfNotEmpty(); + _builder.append("\n"); + _builder.newLineIfNotEmpty(); + _builder.append("#### Description"); + _builder.newLine(); + _builder.append("\n"); + _builder.newLineIfNotEmpty(); + String _modelElementDescription = this.toModelElementDescription(eclass); + _builder.append(_modelElementDescription); + _builder.newLineIfNotEmpty(); + _builder.append("\n"); + _builder.newLineIfNotEmpty(); + _builder.append(this.mdBlockEnd); + _builder.newLineIfNotEmpty(); + { + if ((this.classDiagramCodeGen != null)) { + _builder.append(this.mdBlockStart); + _builder.newLineIfNotEmpty(); + _builder.append("#### Class Diagram"); + _builder.newLine(); + _builder.append("\n"); + _builder.newLineIfNotEmpty(); + _builder.append(this.mdBlockEnd); + _builder.newLineIfNotEmpty(); + _builder.append(this.diagramStartSyntax); + _builder.newLineIfNotEmpty(); + String _replace = this.classDiagramCodeGen.generateClassDiagram(eclass).toString().replace("<", "<").replace(">", ">"); + _builder.append(_replace); + _builder.newLineIfNotEmpty(); + _builder.append(this.diagramEndSyntax); + _builder.newLineIfNotEmpty(); + _builder.append("\n"); + _builder.newLineIfNotEmpty(); + } + } + _builder.append(this.mdBlockStart); + _builder.newLineIfNotEmpty(); + _builder.append("#### Fields"); + _builder.newLine(); + _builder.append("\n"); + _builder.newLineIfNotEmpty(); + CharSequence _classStructuralFeaturesDescription = this.toClassStructuralFeaturesDescription(eclass.getEAttributes()); + _builder.append(_classStructuralFeaturesDescription); + _builder.newLineIfNotEmpty(); + _builder.append("\n"); + _builder.newLineIfNotEmpty(); + _builder.append("#### References"); + _builder.newLine(); + _builder.append("\n"); + _builder.newLineIfNotEmpty(); + CharSequence _classStructuralFeaturesDescription_1 = this.toClassStructuralFeaturesDescription(eclass.getEReferences()); + _builder.append(_classStructuralFeaturesDescription_1); + _builder.newLineIfNotEmpty(); + _builder.append("\n"); + _builder.newLineIfNotEmpty(); + _builder.append(this.mdBlockEnd); + _builder.newLineIfNotEmpty(); + return _builder; + } + + public CharSequence toClassStructuralFeaturesDescription(final EList features) { + StringConcatenation _builder = new StringConcatenation(); + { + boolean _isEmpty = features.isEmpty(); + if (_isEmpty) { + _builder.append("None."); + _builder.newLine(); + } else { + _builder.append("| Name| Type| Bounds| Description|"); + _builder.newLine(); + _builder.append("| -----| ----| ------| -----------|"); + _builder.newLine(); + { + for(final T feature : features) { + _builder.append("|"); + String _name = feature.getName(); + _builder.append(_name); + _builder.append("|"); + String _name_1 = feature.getEType().getName(); + _builder.append(_name_1); + _builder.append("|"); + int _lowerBound = feature.getLowerBound(); + _builder.append(_lowerBound); + _builder.append(".."); + int _upperBound = feature.getUpperBound(); + _builder.append(_upperBound); + _builder.append("|"); + String _modelElementDescription = this.toModelElementDescription(feature); + _builder.append(_modelElementDescription); + _builder.append("|"); + _builder.newLineIfNotEmpty(); + } + } + } + } + return _builder; + } + + public String toModelElementDescription(final EModelElement element) { + EList _eAnnotations = element.getEAnnotations(); + for (final EAnnotation annotation : _eAnnotations) { + { + EMap details = annotation.getDetails(); + boolean _containsKey = details.containsKey("documentation"); + if (_containsKey) { + return details.get("documentation").trim(); + } + } + } + return "None."; + } + + @Override + public CharSequence generateDocumentation(final EPackage ePackage, final EcoreToDocumentationOptions docGenOption) { + return this.generateHtmlDoc(ePackage, docGenOption); + } + + @Override + public CharSequence generateDocumentation(final EClass eClass, final EcoreToDocumentationOptions docGenOption) { + CharSequence _xblockexpression = null; + { + boolean _equals = EcoreToDocumentationOptions.HTML_WITH_MERMAID_CLASS_DIAGRAM.equals(docGenOption); + if (_equals) { + MermaidClassDiagramCodeGen _mermaidClassDiagramCodeGen = new MermaidClassDiagramCodeGen(); + this.classDiagramCodeGen = _mermaidClassDiagramCodeGen; + this.diagramStartSyntax = "
"; + this.diagramEndSyntax = "
"; + } + StringConcatenation _builder = new StringConcatenation(); + _builder.append(this.docStart); + _builder.newLineIfNotEmpty(); + CharSequence _classOverview = this.toClassOverview(eClass); + _builder.append(_classOverview); + _builder.newLineIfNotEmpty(); + _builder.append(this.docEnd); + _builder.newLineIfNotEmpty(); + _xblockexpression = _builder; + } + return _xblockexpression; + } + + @Override + public CharSequence generateDocumentation(final EClassifier eClassifier, final EcoreToDocumentationOptions docGenOption) { + CharSequence _xblockexpression = null; + { + boolean _equals = EcoreToDocumentationOptions.HTML_WITH_MERMAID_CLASS_DIAGRAM.equals(docGenOption); + if (_equals) { + MermaidClassDiagramCodeGen _mermaidClassDiagramCodeGen = new MermaidClassDiagramCodeGen(); + this.classDiagramCodeGen = _mermaidClassDiagramCodeGen; + this.diagramStartSyntax = "
"; + this.diagramEndSyntax = "
"; + } + StringConcatenation _builder = new StringConcatenation(); + _builder.append(this.docStart); + _builder.newLineIfNotEmpty(); + { + if ((eClassifier instanceof EClass)) { + CharSequence _classOverview = this.toClassOverview(((EClass) eClassifier)); + _builder.append(_classOverview); + _builder.newLineIfNotEmpty(); + } else { + if ((eClassifier instanceof EEnum)) { + CharSequence _enumOverview = this.toEnumOverview(((EEnum) eClassifier)); + _builder.append(_enumOverview); + _builder.newLineIfNotEmpty(); + } + } + } + _builder.append(this.docEnd); + _builder.newLineIfNotEmpty(); + _xblockexpression = _builder; + } + return _xblockexpression; + } +} diff --git a/org.gecko.emf.util.documentation.generators.markdown.component/.classpath b/org.gecko.emf.util.documentation.generators.markdown.component/.classpath new file mode 100644 index 00000000..1e6e6a74 --- /dev/null +++ b/org.gecko.emf.util.documentation.generators.markdown.component/.classpath @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + diff --git a/org.gecko.emf.util.documentation.generators.markdown.component/.gitignore b/org.gecko.emf.util.documentation.generators.markdown.component/.gitignore new file mode 100644 index 00000000..7fdbdef7 --- /dev/null +++ b/org.gecko.emf.util.documentation.generators.markdown.component/.gitignore @@ -0,0 +1,2 @@ +/bin/ +/bin_test/ diff --git a/org.gecko.emf.util.documentation.generators.markdown.component/.project b/org.gecko.emf.util.documentation.generators.markdown.component/.project new file mode 100644 index 00000000..ce09e1ea --- /dev/null +++ b/org.gecko.emf.util.documentation.generators.markdown.component/.project @@ -0,0 +1,23 @@ + + + org.gecko.emf.util.documentation.generators.markdown.component + + + + + + org.eclipse.jdt.core.javabuilder + + + + + bndtools.core.bndbuilder + + + + + + org.eclipse.jdt.core.javanature + bndtools.core.bndnature + + diff --git a/org.gecko.emf.util.documentation.generators.markdown.component/.settings/org.eclipse.core.resources.prefs b/org.gecko.emf.util.documentation.generators.markdown.component/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 00000000..74deb3b7 --- /dev/null +++ b/org.gecko.emf.util.documentation.generators.markdown.component/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,7 @@ +eclipse.preferences.version=1 +encoding//.settings/org.eclipse.core.resources.prefs=UTF-8 +encoding//.settings/org.eclipse.jdt.core.prefs=UTF-8 +encoding//.settings/org.eclipse.jdt.ui.prefs=UTF-8 +encoding//src/test/component/Example.java=UTF-8 +encoding//test/test/component/ExampleTest.java=UTF-8 +encoding/bnd.bnd=UTF-8 diff --git a/org.gecko.emf.util.documentation.generators.markdown.component/.settings/org.eclipse.jdt.core.prefs b/org.gecko.emf.util.documentation.generators.markdown.component/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 00000000..049e42fd --- /dev/null +++ b/org.gecko.emf.util.documentation.generators.markdown.component/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,11 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=11 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=11 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=11 diff --git a/org.gecko.emf.util.documentation.generators.markdown.component/.settings/org.eclipse.jdt.ui.prefs b/org.gecko.emf.util.documentation.generators.markdown.component/.settings/org.eclipse.jdt.ui.prefs new file mode 100644 index 00000000..25b8c0de --- /dev/null +++ b/org.gecko.emf.util.documentation.generators.markdown.component/.settings/org.eclipse.jdt.ui.prefs @@ -0,0 +1,10 @@ +content_assist_proposals_background=255,255,255 +content_assist_proposals_foreground=0,0,0 +eclipse.preferences.version=1 +org.eclipse.jdt.ui.formatterprofiles.version=13 +org.eclipse.jdt.ui.javadoc=true +org.eclipse.jdt.ui.text.code_templates_migrated=true +org.eclipse.jdt.ui.text.custom_code_templates= +spelling_locale_initialized=true +useAnnotationsPrefPage=true +useQuickDiffPrefPage=true diff --git a/org.gecko.emf.util.documentation.generators.markdown.component/bnd.bnd b/org.gecko.emf.util.documentation.generators.markdown.component/bnd.bnd new file mode 100644 index 00000000..cafca32b --- /dev/null +++ b/org.gecko.emf.util.documentation.generators.markdown.component/bnd.bnd @@ -0,0 +1,12 @@ +javac.source: 11 +javac.target: 11 + +-library: enable-emf + +Bundle-Version: 1.0.0.SNAPSHOT + +-buildpath: \ + org.gecko.emf.util.documentation.generators.apis;version=latest,\ + org.gecko.emf.util.documentation.generators.markdown;version=latest + +Private-Package: org.gecko.emf.util.documentation.generators.markdown.component \ No newline at end of file diff --git a/org.gecko.emf.util.documentation.generators.markdown.component/src/org/gecko/emf/util/documentation/generators/markdown/component/EcoreToMarkdownComponent.java b/org.gecko.emf.util.documentation.generators.markdown.component/src/org/gecko/emf/util/documentation/generators/markdown/component/EcoreToMarkdownComponent.java new file mode 100644 index 00000000..bad22f81 --- /dev/null +++ b/org.gecko.emf.util.documentation.generators.markdown.component/src/org/gecko/emf/util/documentation/generators/markdown/component/EcoreToMarkdownComponent.java @@ -0,0 +1,128 @@ +/** + * Copyright (c) 2012 - 2022 Data In Motion and others. + * All rights reserved. + * + * 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 + * + * Contributors: + * Data In Motion - initial API and implementation + */ +package org.gecko.emf.util.documentation.generators.markdown.component; + +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; + +import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.EClassifier; +import org.eclipse.emf.ecore.EPackage; +import org.gecko.emf.util.documentation.generators.apis.EcoreToDocumentationCodeGenerator; +import org.gecko.emf.util.documentation.generators.apis.EcoreToDocumentationOptions; +import org.gecko.emf.util.documentation.generators.apis.EcoreToDocumentationService; +import org.gecko.emf.util.documentation.generators.markdown.MarkdownCodeGen; +import org.osgi.service.component.annotations.Component; + +/** + * + * @author ilenia + * @since Oct 19, 2022 + */ +@Component(name="EcoreToMarkdownComponent", service=EcoreToDocumentationService.class) +public class EcoreToMarkdownComponent implements EcoreToDocumentationService { + + private static final String MD_FILE_EXTENSION = ".md"; + private static final String MD_OUTPUT_FOLDER = "md"; + private static final String MD_WITH_MERMAID_OUTPUT_FOLDER = "md_mermaid"; + private static final String MD_WITH_PLANTUML_OUTPUT_FOLDER = "md_plantuml"; + private static final String MD_MEDIA_TYPE = "text/markdown"; + + + /* + * (non-Javadoc) + * @see org.gecko.emf.util.documentation.generators.apis.EcoreToDocumentationService#getOutputFileExtension() + */ + @Override + public String getOutputFileExtension() { + return MD_FILE_EXTENSION; + } + + /* + * (non-Javadoc) + * @see org.gecko.emf.util.documentation.generators.apis.EcoreToDocumentationService#getOutputFolder(org.gecko.emf.util.documentation.generators.apis.EcoreToDocumentationOptions) + */ + @Override + public String getOutputFolder(EcoreToDocumentationOptions mode) { + switch(mode) { + case MARKDOWN_WITH_MERMAID_CLASS_DIAGRAM: + return MD_WITH_MERMAID_OUTPUT_FOLDER; + case MARKDOWN_WITH_PLANTUML_CLASS_DIAGRAM: + return MD_WITH_PLANTUML_OUTPUT_FOLDER; + case ONLY_MARKDOWN_CLASS_OVERVIEW: default: + return MD_OUTPUT_FOLDER; + } + } + + /* + * (non-Javadoc) + * @see org.gecko.emf.util.documentation.generators.apis.EcoreToDocumentationService#doGenerateDocumentation(org.eclipse.emf.ecore.EPackage, org.gecko.emf.util.documentation.generators.apis.EcoreToDocumentationOptions, java.lang.String) + */ + @Override + public OutputStream doGenerateDocumentation(EPackage ePackage, EcoreToDocumentationOptions mode, String outputFolderRoot) throws IOException { + EcoreToDocumentationCodeGenerator mdCodeGenerator = new MarkdownCodeGen(); + CharSequence cs = mdCodeGenerator.generateDocumentation(ePackage, mode); + File outputFile = generateOutputFile(ePackage, cs, mode, outputFolderRoot); + try(InputStream is = new FileInputStream(outputFile); OutputStream os = new ByteArrayOutputStream();) { + os.write(is.readAllBytes()); + return os; + } + } + + /* + * (non-Javadoc) + * @see org.gecko.emf.util.documentation.generators.apis.EcoreToDocumentationService#doGenerateDocumentation(org.eclipse.emf.ecore.EClass, org.gecko.emf.util.documentation.generators.apis.EcoreToDocumentationOptions, java.lang.String) + */ + @Override + public OutputStream doGenerateDocumentation(EClass eClass, EcoreToDocumentationOptions mode, String outputFolderRoot) throws IOException{ + EcoreToDocumentationCodeGenerator mdCodeGenerator = new MarkdownCodeGen(); + CharSequence cs = mdCodeGenerator.generateDocumentation(eClass, mode); + File outputFile = generateOutputFile(eClass, cs, mode, outputFolderRoot); + try(InputStream is = new FileInputStream(outputFile); OutputStream os = new ByteArrayOutputStream();) { + os.write(is.readAllBytes()); + return os; + } + } + + + /* + * (non-Javadoc) + * @see org.gecko.emf.util.documentation.generators.apis.EcoreToDocumentationService#canHandleMediaType(java.lang.String) + */ + @Override + public boolean canHandleMediaType(String mediaType) { + return MD_MEDIA_TYPE.equals(mediaType); + } + + /* + * (non-Javadoc) + * @see org.gecko.emf.util.documentation.generators.apis.EcoreToDocumentationService#doGenerateDocumentation(org.eclipse.emf.ecore.EClassifier, org.gecko.emf.util.documentation.generators.apis.EcoreToDocumentationOptions, java.lang.String) + */ + @Override + public OutputStream doGenerateDocumentation(EClassifier eClassifier, EcoreToDocumentationOptions mode, + String outputFolderRoot) throws IOException { + EcoreToDocumentationCodeGenerator mdCodeGenerator = new MarkdownCodeGen(); + CharSequence cs = mdCodeGenerator.generateDocumentation(eClassifier, mode); + File outputFile = generateOutputFile(eClassifier, cs, mode, outputFolderRoot); + try(InputStream is = new FileInputStream(outputFile); OutputStream os = new ByteArrayOutputStream();) { + os.write(is.readAllBytes()); + return os; + } + } + +} diff --git a/org.gecko.emf.util.documentation.generators.markdown.component/test/.keep b/org.gecko.emf.util.documentation.generators.markdown.component/test/.keep new file mode 100644 index 00000000..e69de29b diff --git a/org.gecko.emf.util.documentation.generators.markdown/.classpath b/org.gecko.emf.util.documentation.generators.markdown/.classpath new file mode 100644 index 00000000..e37cc369 --- /dev/null +++ b/org.gecko.emf.util.documentation.generators.markdown/.classpath @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/org.gecko.emf.util.documentation.generators.markdown/.gitignore b/org.gecko.emf.util.documentation.generators.markdown/.gitignore new file mode 100644 index 00000000..1a9ea807 --- /dev/null +++ b/org.gecko.emf.util.documentation.generators.markdown/.gitignore @@ -0,0 +1,2 @@ +/bin/ +/xtend-gen/* \ No newline at end of file diff --git a/org.gecko.emf.util.documentation.generators.markdown/.project b/org.gecko.emf.util.documentation.generators.markdown/.project new file mode 100644 index 00000000..b3e04704 --- /dev/null +++ b/org.gecko.emf.util.documentation.generators.markdown/.project @@ -0,0 +1,29 @@ + + + org.gecko.emf.util.documentation.generators.markdown + + + + + + org.eclipse.xtext.ui.shared.xtextBuilder + + + + + org.eclipse.jdt.core.javabuilder + + + + + bndtools.core.bndbuilder + + + + + + org.eclipse.jdt.core.javanature + org.eclipse.xtext.ui.shared.xtextNature + bndtools.core.bndnature + + diff --git a/org.gecko.emf.util.documentation.generators.markdown/.settings/org.eclipse.jdt.core.prefs b/org.gecko.emf.util.documentation.generators.markdown/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 00000000..f2525a8b --- /dev/null +++ b/org.gecko.emf.util.documentation.generators.markdown/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,14 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=11 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=11 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning +org.eclipse.jdt.core.compiler.release=enabled +org.eclipse.jdt.core.compiler.source=11 diff --git a/org.gecko.emf.util.documentation.generators.markdown/bnd.bnd b/org.gecko.emf.util.documentation.generators.markdown/bnd.bnd new file mode 100644 index 00000000..1a6b2386 --- /dev/null +++ b/org.gecko.emf.util.documentation.generators.markdown/bnd.bnd @@ -0,0 +1,16 @@ +Bundle-Name: Xtend Generator for Markdown +Bundle-Description: Xtend Generator for Markdown +Bundle-Version: 1.0.0-SNAPSHOT + +src.xtend-gen=xtend-gen + +-buildpath: \ + org.eclipse.xtext.xbase.lib,\ + org.gecko.emf.util.documentation.generators.mermaid;version=latest,\ + org.gecko.emf.util.documentation.generators.plantuml;version=latest,\ + org.gecko.emf.util.documentation.generators.apis;version=latest + +-library: \ + enable-emf + +Export-Package: org.gecko.emf.util.documentation.generators.markdown \ No newline at end of file diff --git a/org.gecko.emf.util.documentation.generators.markdown/src/org/gecko/emf/util/documentation/generators/markdown/MarkdownCodeGen.xtend b/org.gecko.emf.util.documentation.generators.markdown/src/org/gecko/emf/util/documentation/generators/markdown/MarkdownCodeGen.xtend new file mode 100644 index 00000000..5fbece1a --- /dev/null +++ b/org.gecko.emf.util.documentation.generators.markdown/src/org/gecko/emf/util/documentation/generators/markdown/MarkdownCodeGen.xtend @@ -0,0 +1,204 @@ +/** + * Copyright (c) 2012 - 2022 Data In Motion and others. + * All rights reserved. + * + * 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 + * + * Contributors: + * Data In Motion - initial API and implementation + */ +package org.gecko.emf.util.documentation.generators.markdown; + +import java.util.List +import org.eclipse.emf.common.util.EList +import org.eclipse.emf.common.util.EMap +import org.eclipse.emf.ecore.EAnnotation +import org.eclipse.emf.ecore.EClass +import org.eclipse.emf.ecore.EClassifier +import org.eclipse.emf.ecore.EEnum +import org.eclipse.emf.ecore.EEnumLiteral +import org.eclipse.emf.ecore.EModelElement +import org.eclipse.emf.ecore.EPackage +import org.eclipse.emf.ecore.EStructuralFeature +import org.gecko.emf.util.documentation.generators.apis.EcoreToClassDiagramCodeGenerator +import org.gecko.emf.util.documentation.generators.mermaid.MermaidClassDiagramCodeGen +import org.gecko.emf.util.documentation.generators.plantuml.PlantumlClassDiagramCodeGen +import org.gecko.emf.util.documentation.generators.apis.EcoreToDocumentationOptions +import org.gecko.emf.util.documentation.generators.apis.EcoreToDocumentationCodeGenerator + +class MarkdownCodeGen implements EcoreToDocumentationCodeGenerator{ + + EcoreToClassDiagramCodeGenerator classDiagramCodeGen; + String diagramStartSyntax; + String diagramEndSyntax = "```"; + + def generateMarkdownDoc(EPackage epackage, EcoreToDocumentationOptions mode) { + if(EcoreToDocumentationOptions.MARKDOWN_WITH_MERMAID_CLASS_DIAGRAM.equals(mode)) { + classDiagramCodeGen = new MermaidClassDiagramCodeGen(); + diagramStartSyntax = "```mermaid"; + } + else if(EcoreToDocumentationOptions.MARKDOWN_WITH_PLANTUML_CLASS_DIAGRAM.equals(mode)) { + classDiagramCodeGen = new PlantumlClassDiagramCodeGen(); + diagramStartSyntax = "```plantuml"; + } + ''' +# Package: «epackage.name» +«"\n"» +«IF classDiagramCodeGen !== null» +## Class Diagram +«"\n"» +«diagramStartSyntax» +«classDiagramCodeGen.generateClassDiagram(epackage)» +«diagramEndSyntax» +«"\n"» +«ENDIF» +«toEClassifierOverview(epackage.EClassifiers)» + ''' + } + + + def toEClassifierOverview(EList eclassifiers) { +var List classes = eclassifiers.filter[ec | ec instanceof EClass].map[ec | ec as EClass].toList; +var List enums = eclassifiers.filter[ec | ec instanceof EEnum].map[ec | ec as EEnum].toList; +''' +## Classes Overview +«"\n"» +«FOR eclass: classes» +«toClassOverview(eclass)» +«"\n"» +«"\n"» +«ENDFOR» +«"\n"» +## Enumerators Overview +«"\n"» +«IF enums.empty» +None. +«ELSE» +«FOR enumerator: enums» +«toEnumOverview(enumerator)» +«"\n"» +«"\n"» +«ENDFOR» +«ENDIF» +''' +} + + + def toEnumOverview(EEnum enumerator) + ''' +### Enumerator: «enumerator.name» +«"\n"» +#### Description +«"\n"» +«toModelElementDescription(enumerator)» +«"\n"» +#### Literals +«"\n"» +«toLiteralOverview(enumerator.ELiterals)» + ''' + + def toLiteralOverview(EList literals) + ''' +«IF literals.empty» +None. +«ELSE» +| Literal| Description| +| -----| -----------| +«FOR literal: literals» +|«literal.name»|«toModelElementDescription(literal)»| +«ENDFOR» +«ENDIF» + ''' + + def toClassOverview(EClass eclass) + ''' +### Class: «eclass.name» +«"\n"» +#### Description +«"\n"» +«toModelElementDescription(eclass)» +«"\n"» +«IF classDiagramCodeGen !== null» +#### Class Diagram +«"\n"» +«diagramStartSyntax» +«classDiagramCodeGen.generateClassDiagram(eclass)» +«diagramEndSyntax» +«"\n"» +«ENDIF» +#### Fields +«"\n"» +«toClassStructuralFeaturesDescription(eclass.EAttributes)» +«"\n"» +#### References +«"\n"» +«toClassStructuralFeaturesDescription(eclass.EReferences)» +«"\n"» + ''' + + + def toClassStructuralFeaturesDescription(EList features) { + ''' +«IF features.empty» +None. +«ELSE» +| Name| Type| Bounds| Description| +| -----| ----| ------| -----------| +«FOR feature: features» +|«feature.name»|«feature.EType.name»|«feature.lowerBound»..«feature.upperBound»|«toModelElementDescription(feature)»| +«ENDFOR» +«ENDIF» + ''' + } + + + def String toModelElementDescription(EModelElement element) { + for(EAnnotation annotation : element.EAnnotations) { + var EMap details = annotation.details; + if(details.containsKey("documentation")) { + return details.get("documentation").trim; + } + + } + return "None." + } + + override generateDocumentation(EPackage ePackage, EcoreToDocumentationOptions docGenOption) { + generateMarkdownDoc(ePackage, docGenOption); + } + + override generateDocumentation(EClass eClass, EcoreToDocumentationOptions docGenOption) { + if(EcoreToDocumentationOptions.MARKDOWN_WITH_MERMAID_CLASS_DIAGRAM.equals(docGenOption)) { + classDiagramCodeGen = new MermaidClassDiagramCodeGen(); + diagramStartSyntax = "```mermaid"; + } + else if(EcoreToDocumentationOptions.MARKDOWN_WITH_PLANTUML_CLASS_DIAGRAM.equals(docGenOption)) { + classDiagramCodeGen = new PlantumlClassDiagramCodeGen(); + diagramStartSyntax = "```plantuml"; + } + toClassOverview(eClass); + } + + override generateDocumentation(EClassifier eClassifier, EcoreToDocumentationOptions docGenOption) { + if(EcoreToDocumentationOptions.MARKDOWN_WITH_MERMAID_CLASS_DIAGRAM.equals(docGenOption)) { + classDiagramCodeGen = new MermaidClassDiagramCodeGen(); + diagramStartSyntax = "```mermaid"; + } + else if(EcoreToDocumentationOptions.MARKDOWN_WITH_PLANTUML_CLASS_DIAGRAM.equals(docGenOption)) { + classDiagramCodeGen = new PlantumlClassDiagramCodeGen(); + diagramStartSyntax = "```plantuml"; + } + ''' +«IF eClassifier instanceof EClass» +«toClassOverview(eClassifier as EClass)» +«ELSEIF eClassifier instanceof EEnum» +«toEnumOverview(eClassifier as EEnum)» +«ENDIF» + ''' + } + +} \ No newline at end of file diff --git a/org.gecko.emf.util.documentation.generators.markdown/xtend-gen/org/gecko/emf/util/documentation/generators/markdown/.MarkdownCodeGen.xtendbin b/org.gecko.emf.util.documentation.generators.markdown/xtend-gen/org/gecko/emf/util/documentation/generators/markdown/.MarkdownCodeGen.xtendbin new file mode 100644 index 00000000..91c65c69 Binary files /dev/null and b/org.gecko.emf.util.documentation.generators.markdown/xtend-gen/org/gecko/emf/util/documentation/generators/markdown/.MarkdownCodeGen.xtendbin differ diff --git a/org.gecko.emf.util.documentation.generators.markdown/xtend-gen/org/gecko/emf/util/documentation/generators/markdown/.gitignore b/org.gecko.emf.util.documentation.generators.markdown/xtend-gen/org/gecko/emf/util/documentation/generators/markdown/.gitignore new file mode 100644 index 00000000..4c18a9b1 --- /dev/null +++ b/org.gecko.emf.util.documentation.generators.markdown/xtend-gen/org/gecko/emf/util/documentation/generators/markdown/.gitignore @@ -0,0 +1,3 @@ +/.MarkdownCodeGen.java._trace +/.MarkdownCodeGen.xtendbin +/MarkdownCodeGen.java diff --git a/org.gecko.emf.util.documentation.generators.markdown/xtend-gen/org/gecko/emf/util/documentation/generators/markdown/MarkdownCodeGen.java b/org.gecko.emf.util.documentation.generators.markdown/xtend-gen/org/gecko/emf/util/documentation/generators/markdown/MarkdownCodeGen.java new file mode 100644 index 00000000..a85f8612 --- /dev/null +++ b/org.gecko.emf.util.documentation.generators.markdown/xtend-gen/org/gecko/emf/util/documentation/generators/markdown/MarkdownCodeGen.java @@ -0,0 +1,382 @@ +/** + * Copyright (c) 2012 - 2022 Data In Motion and others. + * All rights reserved. + * + * 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 + * + * Contributors: + * Data In Motion - initial API and implementation + */ +package org.gecko.emf.util.documentation.generators.markdown; + +import java.util.List; +import org.eclipse.emf.common.util.EList; +import org.eclipse.emf.common.util.EMap; +import org.eclipse.emf.ecore.EAnnotation; +import org.eclipse.emf.ecore.EAttribute; +import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.EClassifier; +import org.eclipse.emf.ecore.EEnum; +import org.eclipse.emf.ecore.EEnumLiteral; +import org.eclipse.emf.ecore.EModelElement; +import org.eclipse.emf.ecore.EPackage; +import org.eclipse.emf.ecore.EReference; +import org.eclipse.emf.ecore.EStructuralFeature; +import org.eclipse.xtend2.lib.StringConcatenation; +import org.eclipse.xtext.xbase.lib.Functions.Function1; +import org.eclipse.xtext.xbase.lib.IterableExtensions; +import org.gecko.emf.util.documentation.generators.apis.EcoreToClassDiagramCodeGenerator; +import org.gecko.emf.util.documentation.generators.apis.EcoreToDocumentationCodeGenerator; +import org.gecko.emf.util.documentation.generators.apis.EcoreToDocumentationOptions; +import org.gecko.emf.util.documentation.generators.mermaid.MermaidClassDiagramCodeGen; +import org.gecko.emf.util.documentation.generators.plantuml.PlantumlClassDiagramCodeGen; + +@SuppressWarnings("all") +public class MarkdownCodeGen implements EcoreToDocumentationCodeGenerator { + private EcoreToClassDiagramCodeGenerator classDiagramCodeGen; + + private String diagramStartSyntax; + + private String diagramEndSyntax = "```"; + + public CharSequence generateMarkdownDoc(final EPackage epackage, final EcoreToDocumentationOptions mode) { + CharSequence _xblockexpression = null; + { + boolean _equals = EcoreToDocumentationOptions.MARKDOWN_WITH_MERMAID_CLASS_DIAGRAM.equals(mode); + if (_equals) { + MermaidClassDiagramCodeGen _mermaidClassDiagramCodeGen = new MermaidClassDiagramCodeGen(); + this.classDiagramCodeGen = _mermaidClassDiagramCodeGen; + this.diagramStartSyntax = "```mermaid"; + } else { + boolean _equals_1 = EcoreToDocumentationOptions.MARKDOWN_WITH_PLANTUML_CLASS_DIAGRAM.equals(mode); + if (_equals_1) { + PlantumlClassDiagramCodeGen _plantumlClassDiagramCodeGen = new PlantumlClassDiagramCodeGen(); + this.classDiagramCodeGen = _plantumlClassDiagramCodeGen; + this.diagramStartSyntax = "```plantuml"; + } + } + StringConcatenation _builder = new StringConcatenation(); + _builder.append("# Package: "); + String _name = epackage.getName(); + _builder.append(_name); + _builder.newLineIfNotEmpty(); + _builder.append("\n"); + _builder.newLineIfNotEmpty(); + { + if ((this.classDiagramCodeGen != null)) { + _builder.append("## Class Diagram"); + _builder.newLine(); + _builder.append("\n"); + _builder.newLineIfNotEmpty(); + _builder.append(this.diagramStartSyntax); + _builder.newLineIfNotEmpty(); + CharSequence _generateClassDiagram = this.classDiagramCodeGen.generateClassDiagram(epackage); + _builder.append(_generateClassDiagram); + _builder.newLineIfNotEmpty(); + _builder.append(this.diagramEndSyntax); + _builder.newLineIfNotEmpty(); + _builder.append("\n"); + _builder.newLineIfNotEmpty(); + } + } + CharSequence _eClassifierOverview = this.toEClassifierOverview(epackage.getEClassifiers()); + _builder.append(_eClassifierOverview); + _builder.newLineIfNotEmpty(); + _xblockexpression = _builder; + } + return _xblockexpression; + } + + public CharSequence toEClassifierOverview(final EList eclassifiers) { + CharSequence _xblockexpression = null; + { + final Function1 _function = (EClassifier ec) -> { + return Boolean.valueOf((ec instanceof EClass)); + }; + final Function1 _function_1 = (EClassifier ec) -> { + return ((EClass) ec); + }; + List classes = IterableExtensions.toList(IterableExtensions.map(IterableExtensions.filter(eclassifiers, _function), _function_1)); + final Function1 _function_2 = (EClassifier ec) -> { + return Boolean.valueOf((ec instanceof EEnum)); + }; + final Function1 _function_3 = (EClassifier ec) -> { + return ((EEnum) ec); + }; + List enums = IterableExtensions.toList(IterableExtensions.map(IterableExtensions.filter(eclassifiers, _function_2), _function_3)); + StringConcatenation _builder = new StringConcatenation(); + _builder.append("## Classes Overview"); + _builder.newLine(); + _builder.append("\n"); + _builder.newLineIfNotEmpty(); + { + for(final EClass eclass : classes) { + CharSequence _classOverview = this.toClassOverview(eclass); + _builder.append(_classOverview); + _builder.newLineIfNotEmpty(); + _builder.append("\n"); + _builder.newLineIfNotEmpty(); + _builder.append("\n"); + _builder.newLineIfNotEmpty(); + } + } + _builder.append("\n"); + _builder.newLineIfNotEmpty(); + _builder.append("## Enumerators Overview"); + _builder.newLine(); + _builder.append("\n"); + _builder.newLineIfNotEmpty(); + { + boolean _isEmpty = enums.isEmpty(); + if (_isEmpty) { + _builder.append("None."); + _builder.newLine(); + } else { + { + for(final EEnum enumerator : enums) { + CharSequence _enumOverview = this.toEnumOverview(enumerator); + _builder.append(_enumOverview); + _builder.newLineIfNotEmpty(); + _builder.append("\n"); + _builder.newLineIfNotEmpty(); + _builder.append("\n"); + _builder.newLineIfNotEmpty(); + } + } + } + } + _xblockexpression = _builder; + } + return _xblockexpression; + } + + public CharSequence toEnumOverview(final EEnum enumerator) { + StringConcatenation _builder = new StringConcatenation(); + _builder.append("### Enumerator: "); + String _name = enumerator.getName(); + _builder.append(_name); + _builder.newLineIfNotEmpty(); + _builder.append("\n"); + _builder.newLineIfNotEmpty(); + _builder.append("#### Description"); + _builder.newLine(); + _builder.append("\n"); + _builder.newLineIfNotEmpty(); + String _modelElementDescription = this.toModelElementDescription(enumerator); + _builder.append(_modelElementDescription); + _builder.newLineIfNotEmpty(); + _builder.append("\n"); + _builder.newLineIfNotEmpty(); + _builder.append("#### Literals"); + _builder.newLine(); + _builder.append("\n"); + _builder.newLineIfNotEmpty(); + CharSequence _literalOverview = this.toLiteralOverview(enumerator.getELiterals()); + _builder.append(_literalOverview); + _builder.newLineIfNotEmpty(); + return _builder; + } + + public CharSequence toLiteralOverview(final EList literals) { + StringConcatenation _builder = new StringConcatenation(); + { + boolean _isEmpty = literals.isEmpty(); + if (_isEmpty) { + _builder.append("None."); + _builder.newLine(); + } else { + _builder.append("| Literal| Description|"); + _builder.newLine(); + _builder.append("| -----| -----------|"); + _builder.newLine(); + { + for(final EEnumLiteral literal : literals) { + _builder.append("|"); + String _name = literal.getName(); + _builder.append(_name); + _builder.append("|"); + String _modelElementDescription = this.toModelElementDescription(literal); + _builder.append(_modelElementDescription); + _builder.append("|"); + _builder.newLineIfNotEmpty(); + } + } + } + } + return _builder; + } + + public CharSequence toClassOverview(final EClass eclass) { + StringConcatenation _builder = new StringConcatenation(); + _builder.append("### Class: "); + String _name = eclass.getName(); + _builder.append(_name); + _builder.newLineIfNotEmpty(); + _builder.append("\n"); + _builder.newLineIfNotEmpty(); + _builder.append("#### Description"); + _builder.newLine(); + _builder.append("\n"); + _builder.newLineIfNotEmpty(); + String _modelElementDescription = this.toModelElementDescription(eclass); + _builder.append(_modelElementDescription); + _builder.newLineIfNotEmpty(); + _builder.append("\n"); + _builder.newLineIfNotEmpty(); + { + if ((this.classDiagramCodeGen != null)) { + _builder.append("#### Class Diagram"); + _builder.newLine(); + _builder.append("\n"); + _builder.newLineIfNotEmpty(); + _builder.append(this.diagramStartSyntax); + _builder.newLineIfNotEmpty(); + CharSequence _generateClassDiagram = this.classDiagramCodeGen.generateClassDiagram(eclass); + _builder.append(_generateClassDiagram); + _builder.newLineIfNotEmpty(); + _builder.append(this.diagramEndSyntax); + _builder.newLineIfNotEmpty(); + _builder.append("\n"); + _builder.newLineIfNotEmpty(); + } + } + _builder.append("#### Fields"); + _builder.newLine(); + _builder.append("\n"); + _builder.newLineIfNotEmpty(); + CharSequence _classStructuralFeaturesDescription = this.toClassStructuralFeaturesDescription(eclass.getEAttributes()); + _builder.append(_classStructuralFeaturesDescription); + _builder.newLineIfNotEmpty(); + _builder.append("\n"); + _builder.newLineIfNotEmpty(); + _builder.append("#### References"); + _builder.newLine(); + _builder.append("\n"); + _builder.newLineIfNotEmpty(); + CharSequence _classStructuralFeaturesDescription_1 = this.toClassStructuralFeaturesDescription(eclass.getEReferences()); + _builder.append(_classStructuralFeaturesDescription_1); + _builder.newLineIfNotEmpty(); + _builder.append("\n"); + _builder.newLineIfNotEmpty(); + return _builder; + } + + public CharSequence toClassStructuralFeaturesDescription(final EList features) { + StringConcatenation _builder = new StringConcatenation(); + { + boolean _isEmpty = features.isEmpty(); + if (_isEmpty) { + _builder.append("None."); + _builder.newLine(); + } else { + _builder.append("| Name| Type| Bounds| Description|"); + _builder.newLine(); + _builder.append("| -----| ----| ------| -----------|"); + _builder.newLine(); + { + for(final T feature : features) { + _builder.append("|"); + String _name = feature.getName(); + _builder.append(_name); + _builder.append("|"); + String _name_1 = feature.getEType().getName(); + _builder.append(_name_1); + _builder.append("|"); + int _lowerBound = feature.getLowerBound(); + _builder.append(_lowerBound); + _builder.append(".."); + int _upperBound = feature.getUpperBound(); + _builder.append(_upperBound); + _builder.append("|"); + String _modelElementDescription = this.toModelElementDescription(feature); + _builder.append(_modelElementDescription); + _builder.append("|"); + _builder.newLineIfNotEmpty(); + } + } + } + } + return _builder; + } + + public String toModelElementDescription(final EModelElement element) { + EList _eAnnotations = element.getEAnnotations(); + for (final EAnnotation annotation : _eAnnotations) { + { + EMap details = annotation.getDetails(); + boolean _containsKey = details.containsKey("documentation"); + if (_containsKey) { + return details.get("documentation").trim(); + } + } + } + return "None."; + } + + @Override + public CharSequence generateDocumentation(final EPackage ePackage, final EcoreToDocumentationOptions docGenOption) { + return this.generateMarkdownDoc(ePackage, docGenOption); + } + + @Override + public CharSequence generateDocumentation(final EClass eClass, final EcoreToDocumentationOptions docGenOption) { + CharSequence _xblockexpression = null; + { + boolean _equals = EcoreToDocumentationOptions.MARKDOWN_WITH_MERMAID_CLASS_DIAGRAM.equals(docGenOption); + if (_equals) { + MermaidClassDiagramCodeGen _mermaidClassDiagramCodeGen = new MermaidClassDiagramCodeGen(); + this.classDiagramCodeGen = _mermaidClassDiagramCodeGen; + this.diagramStartSyntax = "```mermaid"; + } else { + boolean _equals_1 = EcoreToDocumentationOptions.MARKDOWN_WITH_PLANTUML_CLASS_DIAGRAM.equals(docGenOption); + if (_equals_1) { + PlantumlClassDiagramCodeGen _plantumlClassDiagramCodeGen = new PlantumlClassDiagramCodeGen(); + this.classDiagramCodeGen = _plantumlClassDiagramCodeGen; + this.diagramStartSyntax = "```plantuml"; + } + } + _xblockexpression = this.toClassOverview(eClass); + } + return _xblockexpression; + } + + @Override + public CharSequence generateDocumentation(final EClassifier eClassifier, final EcoreToDocumentationOptions docGenOption) { + CharSequence _xblockexpression = null; + { + boolean _equals = EcoreToDocumentationOptions.MARKDOWN_WITH_MERMAID_CLASS_DIAGRAM.equals(docGenOption); + if (_equals) { + MermaidClassDiagramCodeGen _mermaidClassDiagramCodeGen = new MermaidClassDiagramCodeGen(); + this.classDiagramCodeGen = _mermaidClassDiagramCodeGen; + this.diagramStartSyntax = "```mermaid"; + } else { + boolean _equals_1 = EcoreToDocumentationOptions.MARKDOWN_WITH_PLANTUML_CLASS_DIAGRAM.equals(docGenOption); + if (_equals_1) { + PlantumlClassDiagramCodeGen _plantumlClassDiagramCodeGen = new PlantumlClassDiagramCodeGen(); + this.classDiagramCodeGen = _plantumlClassDiagramCodeGen; + this.diagramStartSyntax = "```plantuml"; + } + } + StringConcatenation _builder = new StringConcatenation(); + { + if ((eClassifier instanceof EClass)) { + CharSequence _classOverview = this.toClassOverview(((EClass) eClassifier)); + _builder.append(_classOverview); + _builder.newLineIfNotEmpty(); + } else { + if ((eClassifier instanceof EEnum)) { + CharSequence _enumOverview = this.toEnumOverview(((EEnum) eClassifier)); + _builder.append(_enumOverview); + _builder.newLineIfNotEmpty(); + } + } + } + _xblockexpression = _builder; + } + return _xblockexpression; + } +} diff --git a/org.gecko.emf.util.documentation.generators.mermaid/.classpath b/org.gecko.emf.util.documentation.generators.mermaid/.classpath new file mode 100644 index 00000000..504cdaa3 --- /dev/null +++ b/org.gecko.emf.util.documentation.generators.mermaid/.classpath @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/org.gecko.emf.util.documentation.generators.mermaid/.gitignore b/org.gecko.emf.util.documentation.generators.mermaid/.gitignore new file mode 100644 index 00000000..1a9ea807 --- /dev/null +++ b/org.gecko.emf.util.documentation.generators.mermaid/.gitignore @@ -0,0 +1,2 @@ +/bin/ +/xtend-gen/* \ No newline at end of file diff --git a/org.gecko.emf.util.documentation.generators.mermaid/.project b/org.gecko.emf.util.documentation.generators.mermaid/.project new file mode 100644 index 00000000..43aa3897 --- /dev/null +++ b/org.gecko.emf.util.documentation.generators.mermaid/.project @@ -0,0 +1,29 @@ + + + org.gecko.emf.util.documentation.generators.mermaid + + + + + + org.eclipse.xtext.ui.shared.xtextBuilder + + + + + org.eclipse.jdt.core.javabuilder + + + + + bndtools.core.bndbuilder + + + + + + org.eclipse.jdt.core.javanature + org.eclipse.xtext.ui.shared.xtextNature + bndtools.core.bndnature + + diff --git a/org.gecko.emf.util.documentation.generators.mermaid/bnd.bnd b/org.gecko.emf.util.documentation.generators.mermaid/bnd.bnd new file mode 100644 index 00000000..1aa7917b --- /dev/null +++ b/org.gecko.emf.util.documentation.generators.mermaid/bnd.bnd @@ -0,0 +1,13 @@ +Bundle-Name: Xtend Generator for Mermaid +Bundle-Description: Xtend Generator for Mermaid +Bundle-Version: 1.0.0-SNAPSHOT + +src.xtend-gen=xtend-gen + +-buildpath: \ + org.eclipse.xtext.xbase.lib,\ + org.gecko.emf.util.documentation.generators.apis;version=latest + +-library: \ + enable-emf +Export-Package: org.gecko.emf.util.documentation.generators.mermaid \ No newline at end of file diff --git a/org.gecko.emf.util.documentation.generators.mermaid/src/org/gecko/emf/util/documentation/generators/mermaid/MermaidClassDiagramCodeGen.xtend b/org.gecko.emf.util.documentation.generators.mermaid/src/org/gecko/emf/util/documentation/generators/mermaid/MermaidClassDiagramCodeGen.xtend new file mode 100644 index 00000000..2d2119dd --- /dev/null +++ b/org.gecko.emf.util.documentation.generators.mermaid/src/org/gecko/emf/util/documentation/generators/mermaid/MermaidClassDiagramCodeGen.xtend @@ -0,0 +1,179 @@ +/** + * Copyright (c) 2012 - 2022 Data In Motion and others. + * All rights reserved. + * + * 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 + * + * Contributors: + * Data In Motion - initial API and implementation + */ +package org.gecko.emf.util.documentation.generators.mermaid; + +import java.util.List +import org.eclipse.emf.common.util.EList +import org.eclipse.emf.ecore.EClass +import org.eclipse.emf.ecore.EClassifier +import org.eclipse.emf.ecore.EEnum +import org.eclipse.emf.ecore.EPackage +import org.eclipse.emf.ecore.EReference +import org.gecko.emf.util.documentation.generators.apis.EcoreToClassDiagramCodeGenerator + +class MermaidClassDiagramCodeGen implements EcoreToClassDiagramCodeGenerator{ + + def toMermaidClassDiagram(EPackage epackage) + ''' +«startMermaidClassDiagram()» +«toEClassifierDiagram(epackage.EClassifiers)» + ''' + + def startMermaidClassDiagram() + ''' +classDiagram + ''' + + def toEClassifierDiagram(EList eclassifiers) { +var List classes = eclassifiers.filter[ec | ec instanceof EClass].map[ec | ec as EClass].toList; +var List enums = eclassifiers.filter[ec | ec instanceof EEnum].map[ec | ec as EEnum].toList; +''' +«FOR eclass: classes» +«toClassDiagram(eclass)» +«"\n"» +«"\n"» +«ENDFOR» +«FOR enumerator: enums» +«toEnumerator(enumerator)» +«"\n"» +«"\n"» +«ENDFOR» +''' +} + + + def toClassDiagram(EClass eclass) + ''' +«" "»class «eclass.name» { +«IF eclass.isInterface» +«" <>"» +«ELSEIF eclass.isAbstract» +«" <>"» +«ENDIF» +«toClassMembers(eclass)» +} +«"\n"» +«toClassReferences(eclass)» +«"\n"» +«IF !eclass.ESuperTypes.isEmpty» +«toSuperTypes(eclass)» +«"\n"» +«ENDIF» + ''' + + def toClassDiagram(EClassifier eclassifier) + ''' +«IF eclassifier instanceof EClass» +«toClassDiagram(eclassifier as EClass)» +«ELSEIF eclassifier instanceof EEnum» +«toEnumerator(eclassifier as EEnum)» +«ENDIF» + ''' + + def toClassMembers(EClass eclass) + ''' +«IF eclass.EAttributes.isEmpty» +«" \n"» +«ENDIF» +«FOR attribute: eclass.EAttributes» +«" "»«attribute.EType.name» «attribute.name» +«ENDFOR» + ''' + + def toClassReferences(EClass eclass) + ''' +«FOR ref: eclass.EReferences» +«toClassRef(eclass, ref)» +«ENDFOR» + ''' + + def toClassRef(EClass eclass, EReference ref) { + var multiplicity = extractMultiplicity(ref.lowerBound, ref.upperBound) + var refType = extractRefType(ref, eclass) + var isInRefModel = isInRefModel(ref, eclass) + ''' +«IF isInRefModel» +«" "»«eclass.name» «' ..> '» «'\"'»«multiplicity»«'\"'» «refType»«' : '»«ref.name» +«ELSE» +«" "»«eclass.name» «' --> '» «'\"'»«multiplicity»«'\"'» «refType»«' : '»«ref.name» +«ENDIF» + ''' + } + + def String extractRefType(EReference ref, EClass containerClass) { + if(ref.EType.EPackage.name === containerClass.EPackage.name) { + return ref.EType.name + } else { +// TODO this should be the correct form when linking to a reference model (https://github.com/mermaid-js/mermaid/issues/1052) +// return ref.EType.EPackage.nsURI + "#//" + ref.EType.name; + return ref.EType.name + } + } + + def boolean isInRefModel(EReference ref, EClass containerClass) { + if(ref.EType.EPackage.name === containerClass.EPackage.name) { + return false + } else { + return true + } + } + + def String extractMultiplicity(int lowerBound, int upperBound) { + if(lowerBound == 0 && upperBound == -1) { + return "*" + } + else if(lowerBound == 1 && upperBound == -1) { + return "1..*" + } + return ((String.valueOf(lowerBound) + ".." + (String.valueOf(upperBound)))) + } + + + + def toSuperTypes(EClass eclass) + ''' +«FOR parent: eclass.ESuperTypes» +«" "»«eclass.name» ..> «parent.name» +«ENDFOR» + ''' + + def toEnumerator(EEnum enumerator) + ''' +«" "»class «enumerator.name» { +«" <>"» +«FOR value: enumerator.ELiterals» +«" "»«value.name» +«ENDFOR» +} + ''' + + override generateClassDiagram(EPackage ePackage) { + toMermaidClassDiagram(ePackage); + } + + override generateClassDiagram(EClass eClass) { + ''' +«startMermaidClassDiagram()» +«toClassDiagram(eClass)» + ''' + } + + override generateClassDiagram(EClassifier eClassifier) { + ''' +«startMermaidClassDiagram()» +«toClassDiagram(eClassifier)» + ''' + } + +} \ No newline at end of file diff --git a/org.gecko.emf.util.documentation.generators.mermaid/src/org/gecko/emf/util/documentation/generators/mermaid/packageinfo b/org.gecko.emf.util.documentation.generators.mermaid/src/org/gecko/emf/util/documentation/generators/mermaid/packageinfo new file mode 100644 index 00000000..9ad81f6f --- /dev/null +++ b/org.gecko.emf.util.documentation.generators.mermaid/src/org/gecko/emf/util/documentation/generators/mermaid/packageinfo @@ -0,0 +1 @@ +version 1.0.0 diff --git a/org.gecko.emf.util.documentation.generators.mermaid/xtend-gen/org/gecko/emf/util/documentation/generators/mermaid/.MermaidClassDiagramCodeGen.xtendbin b/org.gecko.emf.util.documentation.generators.mermaid/xtend-gen/org/gecko/emf/util/documentation/generators/mermaid/.MermaidClassDiagramCodeGen.xtendbin new file mode 100644 index 00000000..ea8f94dd Binary files /dev/null and b/org.gecko.emf.util.documentation.generators.mermaid/xtend-gen/org/gecko/emf/util/documentation/generators/mermaid/.MermaidClassDiagramCodeGen.xtendbin differ diff --git a/org.gecko.emf.util.documentation.generators.mermaid/xtend-gen/org/gecko/emf/util/documentation/generators/mermaid/.gitignore b/org.gecko.emf.util.documentation.generators.mermaid/xtend-gen/org/gecko/emf/util/documentation/generators/mermaid/.gitignore new file mode 100644 index 00000000..6c879e53 --- /dev/null +++ b/org.gecko.emf.util.documentation.generators.mermaid/xtend-gen/org/gecko/emf/util/documentation/generators/mermaid/.gitignore @@ -0,0 +1,9 @@ +/.MarkdownCodeGen.java._trace +/.MermaidCodeGen.java._trace +/.MarkdownCodeGen.xtendbin +/.MermaidCodeGen.xtendbin +/MarkdownCodeGen.java +/MermaidCodeGen.java +/.MermaidClassDiagramCodeGen.java._trace +/.MermaidClassDiagramCodeGen.xtendbin +/MermaidClassDiagramCodeGen.java diff --git a/org.gecko.emf.util.documentation.generators.mermaid/xtend-gen/org/gecko/emf/util/documentation/generators/mermaid/MermaidClassDiagramCodeGen.java b/org.gecko.emf.util.documentation.generators.mermaid/xtend-gen/org/gecko/emf/util/documentation/generators/mermaid/MermaidClassDiagramCodeGen.java new file mode 100644 index 00000000..55714eec --- /dev/null +++ b/org.gecko.emf.util.documentation.generators.mermaid/xtend-gen/org/gecko/emf/util/documentation/generators/mermaid/MermaidClassDiagramCodeGen.java @@ -0,0 +1,349 @@ +/** + * Copyright (c) 2012 - 2022 Data In Motion and others. + * All rights reserved. + * + * 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 + * + * Contributors: + * Data In Motion - initial API and implementation + */ +package org.gecko.emf.util.documentation.generators.mermaid; + +import java.util.List; +import org.eclipse.emf.common.util.EList; +import org.eclipse.emf.ecore.EAttribute; +import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.EClassifier; +import org.eclipse.emf.ecore.EEnum; +import org.eclipse.emf.ecore.EEnumLiteral; +import org.eclipse.emf.ecore.EPackage; +import org.eclipse.emf.ecore.EReference; +import org.eclipse.xtend2.lib.StringConcatenation; +import org.eclipse.xtext.xbase.lib.Functions.Function1; +import org.eclipse.xtext.xbase.lib.IterableExtensions; +import org.gecko.emf.util.documentation.generators.apis.EcoreToClassDiagramCodeGenerator; + +@SuppressWarnings("all") +public class MermaidClassDiagramCodeGen implements EcoreToClassDiagramCodeGenerator { + public CharSequence toMermaidClassDiagram(final EPackage epackage) { + StringConcatenation _builder = new StringConcatenation(); + CharSequence _startMermaidClassDiagram = this.startMermaidClassDiagram(); + _builder.append(_startMermaidClassDiagram); + _builder.newLineIfNotEmpty(); + CharSequence _eClassifierDiagram = this.toEClassifierDiagram(epackage.getEClassifiers()); + _builder.append(_eClassifierDiagram); + _builder.newLineIfNotEmpty(); + return _builder; + } + + public CharSequence startMermaidClassDiagram() { + StringConcatenation _builder = new StringConcatenation(); + _builder.append("classDiagram"); + _builder.newLine(); + return _builder; + } + + public CharSequence toEClassifierDiagram(final EList eclassifiers) { + CharSequence _xblockexpression = null; + { + final Function1 _function = (EClassifier ec) -> { + return Boolean.valueOf((ec instanceof EClass)); + }; + final Function1 _function_1 = (EClassifier ec) -> { + return ((EClass) ec); + }; + List classes = IterableExtensions.toList(IterableExtensions.map(IterableExtensions.filter(eclassifiers, _function), _function_1)); + final Function1 _function_2 = (EClassifier ec) -> { + return Boolean.valueOf((ec instanceof EEnum)); + }; + final Function1 _function_3 = (EClassifier ec) -> { + return ((EEnum) ec); + }; + List enums = IterableExtensions.toList(IterableExtensions.map(IterableExtensions.filter(eclassifiers, _function_2), _function_3)); + StringConcatenation _builder = new StringConcatenation(); + { + for(final EClass eclass : classes) { + CharSequence _classDiagram = this.toClassDiagram(eclass); + _builder.append(_classDiagram); + _builder.newLineIfNotEmpty(); + _builder.append("\n"); + _builder.newLineIfNotEmpty(); + _builder.append("\n"); + _builder.newLineIfNotEmpty(); + } + } + { + for(final EEnum enumerator : enums) { + CharSequence _enumerator = this.toEnumerator(enumerator); + _builder.append(_enumerator); + _builder.newLineIfNotEmpty(); + _builder.append("\n"); + _builder.newLineIfNotEmpty(); + _builder.append("\n"); + _builder.newLineIfNotEmpty(); + } + } + _xblockexpression = _builder; + } + return _xblockexpression; + } + + public CharSequence toClassDiagram(final EClass eclass) { + StringConcatenation _builder = new StringConcatenation(); + _builder.append(" "); + _builder.append("class "); + String _name = eclass.getName(); + _builder.append(_name); + _builder.append(" {"); + _builder.newLineIfNotEmpty(); + { + boolean _isInterface = eclass.isInterface(); + if (_isInterface) { + _builder.append(" <>"); + _builder.newLineIfNotEmpty(); + } else { + boolean _isAbstract = eclass.isAbstract(); + if (_isAbstract) { + _builder.append(" <>"); + _builder.newLineIfNotEmpty(); + } + } + } + CharSequence _classMembers = this.toClassMembers(eclass); + _builder.append(_classMembers); + _builder.newLineIfNotEmpty(); + _builder.append("}"); + _builder.newLine(); + _builder.append("\n"); + _builder.newLineIfNotEmpty(); + CharSequence _classReferences = this.toClassReferences(eclass); + _builder.append(_classReferences); + _builder.newLineIfNotEmpty(); + _builder.append("\n"); + _builder.newLineIfNotEmpty(); + { + boolean _isEmpty = eclass.getESuperTypes().isEmpty(); + boolean _not = (!_isEmpty); + if (_not) { + CharSequence _superTypes = this.toSuperTypes(eclass); + _builder.append(_superTypes); + _builder.newLineIfNotEmpty(); + _builder.append("\n"); + _builder.newLineIfNotEmpty(); + } + } + return _builder; + } + + public CharSequence toClassDiagram(final EClassifier eclassifier) { + StringConcatenation _builder = new StringConcatenation(); + { + if ((eclassifier instanceof EClass)) { + CharSequence _classDiagram = this.toClassDiagram(((EClass) eclassifier)); + _builder.append(_classDiagram); + _builder.newLineIfNotEmpty(); + } else { + if ((eclassifier instanceof EEnum)) { + CharSequence _enumerator = this.toEnumerator(((EEnum) eclassifier)); + _builder.append(_enumerator); + _builder.newLineIfNotEmpty(); + } + } + } + return _builder; + } + + public CharSequence toClassMembers(final EClass eclass) { + StringConcatenation _builder = new StringConcatenation(); + { + boolean _isEmpty = eclass.getEAttributes().isEmpty(); + if (_isEmpty) { + _builder.append(" \n"); + _builder.newLineIfNotEmpty(); + } + } + { + EList _eAttributes = eclass.getEAttributes(); + for(final EAttribute attribute : _eAttributes) { + _builder.append(" "); + String _name = attribute.getEType().getName(); + _builder.append(_name); + _builder.append(" "); + String _name_1 = attribute.getName(); + _builder.append(_name_1); + _builder.newLineIfNotEmpty(); + } + } + return _builder; + } + + public CharSequence toClassReferences(final EClass eclass) { + StringConcatenation _builder = new StringConcatenation(); + { + EList _eReferences = eclass.getEReferences(); + for(final EReference ref : _eReferences) { + CharSequence _classRef = this.toClassRef(eclass, ref); + _builder.append(_classRef); + _builder.newLineIfNotEmpty(); + } + } + return _builder; + } + + public CharSequence toClassRef(final EClass eclass, final EReference ref) { + CharSequence _xblockexpression = null; + { + String multiplicity = this.extractMultiplicity(ref.getLowerBound(), ref.getUpperBound()); + String refType = this.extractRefType(ref, eclass); + boolean isInRefModel = this.isInRefModel(ref, eclass); + StringConcatenation _builder = new StringConcatenation(); + { + if (isInRefModel) { + _builder.append(" "); + String _name = eclass.getName(); + _builder.append(_name); + _builder.append(" "); + _builder.append(" ..> "); + _builder.append(" "); + _builder.append("\""); + _builder.append(multiplicity); + _builder.append("\""); + _builder.append(" "); + _builder.append(refType); + _builder.append(" : "); + String _name_1 = ref.getName(); + _builder.append(_name_1); + _builder.newLineIfNotEmpty(); + } else { + _builder.append(" "); + String _name_2 = eclass.getName(); + _builder.append(_name_2); + _builder.append(" "); + _builder.append(" --> "); + _builder.append(" "); + _builder.append("\""); + _builder.append(multiplicity); + _builder.append("\""); + _builder.append(" "); + _builder.append(refType); + _builder.append(" : "); + String _name_3 = ref.getName(); + _builder.append(_name_3); + _builder.newLineIfNotEmpty(); + } + } + _xblockexpression = _builder; + } + return _xblockexpression; + } + + public String extractRefType(final EReference ref, final EClass containerClass) { + String _name = ref.getEType().getEPackage().getName(); + String _name_1 = containerClass.getEPackage().getName(); + boolean _tripleEquals = (_name == _name_1); + if (_tripleEquals) { + return ref.getEType().getName(); + } else { + return ref.getEType().getName(); + } + } + + public boolean isInRefModel(final EReference ref, final EClass containerClass) { + String _name = ref.getEType().getEPackage().getName(); + String _name_1 = containerClass.getEPackage().getName(); + boolean _tripleEquals = (_name == _name_1); + if (_tripleEquals) { + return false; + } else { + return true; + } + } + + public String extractMultiplicity(final int lowerBound, final int upperBound) { + if (((lowerBound == 0) && (upperBound == (-1)))) { + return "*"; + } else { + if (((lowerBound == 1) && (upperBound == (-1)))) { + return "1..*"; + } + } + String _valueOf = String.valueOf(lowerBound); + String _plus = (_valueOf + ".."); + String _valueOf_1 = String.valueOf(upperBound); + return (_plus + _valueOf_1); + } + + public CharSequence toSuperTypes(final EClass eclass) { + StringConcatenation _builder = new StringConcatenation(); + { + EList _eSuperTypes = eclass.getESuperTypes(); + for(final EClass parent : _eSuperTypes) { + _builder.append(" "); + String _name = eclass.getName(); + _builder.append(_name); + _builder.append(" ..> "); + String _name_1 = parent.getName(); + _builder.append(_name_1); + _builder.newLineIfNotEmpty(); + } + } + return _builder; + } + + public CharSequence toEnumerator(final EEnum enumerator) { + StringConcatenation _builder = new StringConcatenation(); + _builder.append(" "); + _builder.append("class "); + String _name = enumerator.getName(); + _builder.append(_name); + _builder.append(" {"); + _builder.newLineIfNotEmpty(); + _builder.append(" <>"); + _builder.newLineIfNotEmpty(); + { + EList _eLiterals = enumerator.getELiterals(); + for(final EEnumLiteral value : _eLiterals) { + _builder.append(" "); + String _name_1 = value.getName(); + _builder.append(_name_1); + _builder.newLineIfNotEmpty(); + } + } + _builder.append("}"); + _builder.newLine(); + return _builder; + } + + @Override + public CharSequence generateClassDiagram(final EPackage ePackage) { + return this.toMermaidClassDiagram(ePackage); + } + + @Override + public CharSequence generateClassDiagram(final EClass eClass) { + StringConcatenation _builder = new StringConcatenation(); + CharSequence _startMermaidClassDiagram = this.startMermaidClassDiagram(); + _builder.append(_startMermaidClassDiagram); + _builder.newLineIfNotEmpty(); + CharSequence _classDiagram = this.toClassDiagram(eClass); + _builder.append(_classDiagram); + _builder.newLineIfNotEmpty(); + return _builder; + } + + @Override + public CharSequence generateClassDiagram(final EClassifier eClassifier) { + StringConcatenation _builder = new StringConcatenation(); + CharSequence _startMermaidClassDiagram = this.startMermaidClassDiagram(); + _builder.append(_startMermaidClassDiagram); + _builder.newLineIfNotEmpty(); + CharSequence _classDiagram = this.toClassDiagram(eClassifier); + _builder.append(_classDiagram); + _builder.newLineIfNotEmpty(); + return _builder; + } +} diff --git a/org.gecko.emf.util.documentation.generators.plantuml/.classpath b/org.gecko.emf.util.documentation.generators.plantuml/.classpath new file mode 100644 index 00000000..e37cc369 --- /dev/null +++ b/org.gecko.emf.util.documentation.generators.plantuml/.classpath @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/org.gecko.emf.util.documentation.generators.plantuml/.gitignore b/org.gecko.emf.util.documentation.generators.plantuml/.gitignore new file mode 100644 index 00000000..1a9ea807 --- /dev/null +++ b/org.gecko.emf.util.documentation.generators.plantuml/.gitignore @@ -0,0 +1,2 @@ +/bin/ +/xtend-gen/* \ No newline at end of file diff --git a/org.gecko.emf.util.documentation.generators.plantuml/.project b/org.gecko.emf.util.documentation.generators.plantuml/.project new file mode 100644 index 00000000..1cff4b35 --- /dev/null +++ b/org.gecko.emf.util.documentation.generators.plantuml/.project @@ -0,0 +1,29 @@ + + + org.gecko.emf.util.documentation.generators.plantuml + + + + + + org.eclipse.xtext.ui.shared.xtextBuilder + + + + + org.eclipse.jdt.core.javabuilder + + + + + bndtools.core.bndbuilder + + + + + + org.eclipse.jdt.core.javanature + bndtools.core.bndnature + org.eclipse.xtext.ui.shared.xtextNature + + diff --git a/org.gecko.emf.util.documentation.generators.plantuml/.settings/org.eclipse.jdt.core.prefs b/org.gecko.emf.util.documentation.generators.plantuml/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 00000000..f2525a8b --- /dev/null +++ b/org.gecko.emf.util.documentation.generators.plantuml/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,14 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=11 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=11 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning +org.eclipse.jdt.core.compiler.release=enabled +org.eclipse.jdt.core.compiler.source=11 diff --git a/org.gecko.emf.util.documentation.generators.plantuml/bnd.bnd b/org.gecko.emf.util.documentation.generators.plantuml/bnd.bnd new file mode 100644 index 00000000..1121c1fb --- /dev/null +++ b/org.gecko.emf.util.documentation.generators.plantuml/bnd.bnd @@ -0,0 +1,14 @@ +Bundle-Name: Xtend Generator for Plantuml +Bundle-Description: Xtend Generator for Plantuml +Bundle-Version: 1.0.0-SNAPSHOT + +src.xtend-gen=xtend-gen + +-buildpath: \ + org.eclipse.xtext.xbase.lib,\ + org.gecko.emf.util.documentation.generators.apis;version=latest + +-library: \ + enable-emf + +Export-Package: org.gecko.emf.util.documentation.generators.plantuml diff --git a/org.gecko.emf.util.documentation.generators.plantuml/src/org/gecko/emf/util/documentation/generators/plantuml/PlantumlClassDiagramCodeGen.xtend b/org.gecko.emf.util.documentation.generators.plantuml/src/org/gecko/emf/util/documentation/generators/plantuml/PlantumlClassDiagramCodeGen.xtend new file mode 100644 index 00000000..f12bc46d --- /dev/null +++ b/org.gecko.emf.util.documentation.generators.plantuml/src/org/gecko/emf/util/documentation/generators/plantuml/PlantumlClassDiagramCodeGen.xtend @@ -0,0 +1,222 @@ +/** + * Copyright (c) 2012 - 2022 Data In Motion and others. + * All rights reserved. + * + * 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 + * + * Contributors: + * Data In Motion - initial API and implementation + */ +package org.gecko.emf.util.documentation.generators.plantuml; + +import java.util.List +import org.eclipse.emf.common.util.EList +import org.eclipse.emf.common.util.EMap +import org.eclipse.emf.ecore.EAnnotation +import org.eclipse.emf.ecore.EClass +import org.eclipse.emf.ecore.EClassifier +import org.eclipse.emf.ecore.EEnum +import org.eclipse.emf.ecore.EModelElement +import org.eclipse.emf.ecore.EPackage +import org.eclipse.emf.ecore.EReference +import org.gecko.emf.util.documentation.generators.apis.EcoreToClassDiagramCodeGenerator + +class PlantumlClassDiagramCodeGen implements EcoreToClassDiagramCodeGenerator{ + def toPlantumlClassDiagram(EPackage epackage) + ''' +«startPlantumlClassDiagram()» +«toEClassifierDiagram(epackage.EClassifiers)» +«endPlantumlClassDiagram()» + ''' + + def startPlantumlClassDiagram() + ''' +@startuml + ''' + + def endPlantumlClassDiagram() + ''' +@enduml + ''' + + + def toEClassifierDiagram(EList eclassifiers) { +var List classes = eclassifiers.filter[ec | ec instanceof EClass].map[ec | ec as EClass].toList; +var List enums = eclassifiers.filter[ec | ec instanceof EEnum].map[ec | ec as EEnum].toList; +''' +«FOR eclass: classes» +«toClassDiagram(eclass)» +«ENDFOR» +«FOR enumerator: enums» +«toEnumerator(enumerator)» +«ENDFOR» +''' +} + + def toClassDiagram(EClass eclass) + ''' +«IF eclass.isInterface» +«" "»interface «eclass.name» { +«ELSEIF eclass.isAbstract» +«" "»abstract class «eclass.name» { +«ELSE» +«" "»class «eclass.name» { +«ENDIF» +«toClassMembers(eclass)» +} +«"\n"» +«toOnTopDescription(eclass)» +«"\n"» +«toClassReferences(eclass)» +«"\n"» +«IF !eclass.ESuperTypes.isEmpty» +«toSuperTypes(eclass)» +«"\n"» +«ENDIF» + ''' + + def toClassDiagram(EClassifier eclassifier) + ''' +«IF eclassifier instanceof EClass» +«toClassDiagram(eclassifier as EClass)» +«ELSEIF eclassifier instanceof EEnum» +«toEnumerator(eclassifier as EEnum)» +«ENDIF» + ''' + + def toClassMembers(EClass eclass) + ''' +«FOR attribute: eclass.EAttributes» +«" "»«attribute.name» : «attribute.EType.name» +«ENDFOR» + ''' + + def toClassReferences(EClass eclass) + ''' +«FOR ref: eclass.EReferences» +«toClassRef(eclass, ref)» +«ENDFOR» + ''' + + def toClassRef(EClass eclass, EReference ref) { + var multiplicity = extractMultiplicity(ref.lowerBound, ref.upperBound) + var isInRefModel = isInRefModel(ref, eclass) + ''' +«IF isInRefModel» +«createRefPackage(ref)» +«"\n"» +«" "»«eclass.name» «' ..> '» «'\"'»«multiplicity»«'\"'» «ref.EType.name»«' : '»«ref.name» +«ELSE» +«" "»«eclass.name» «' --> '» «'\"'»«multiplicity»«'\"'» «ref.EType.name»«' : '»«ref.name» +«ENDIF» +«"\n"» + ''' + } + + def createRefPackage(EReference ref) + ''' +«" "»package "«ref.EType.EPackage.nsURI»" #DDDDDD { +«" "»«ref.EType.name» : «ref.name» +} + ''' + + def boolean isInRefModel(EReference ref, EClass containerClass) { + if(ref.EType.EPackage.name === containerClass.EPackage.name) { + return false + } else { + return true + } + } + + def String extractMultiplicity(int lowerBound, int upperBound) { + if(lowerBound == 0 && upperBound == -1) { + return "*" + } + else if(lowerBound == 1 && upperBound == -1) { + return "1..*" + } + return ((String.valueOf(lowerBound) + ".." + (String.valueOf(upperBound)))) + } + + + + def toSuperTypes(EClass eclass) + ''' +«FOR parent: eclass.ESuperTypes» +«" "»«eclass.name» ..> «parent.name» +«ENDFOR» + ''' + + def toEnumerator(EEnum enumerator) + ''' +«" "»enum «enumerator.name» { +«FOR value: enumerator.ELiterals» +«" "»«value.name» +«ENDFOR» +} +«"\n"» +«toOnTopDescription(enumerator)» +«"\n"» + ''' + + def toOnTopDescription(EClassifier eclassifier) { + var description = toModelElementDescription(eclassifier) + if(description !== "None.") { + ''' +note top of «eclassifier.name» +«" "»«description» +end note + ''' + } + } + + def String toModelElementDescription(EModelElement element) { + for(EAnnotation annotation : element.EAnnotations) { + var EMap details = annotation.details; + if(details.containsKey("documentation")) { + var descr = details.get("documentation").replace("\n", "").trim; + if(descr.length > 30) { + var splitStr = descr.split(" "); + var counter = 0; + descr = ""; + for(sp : splitStr) { + counter += sp.length; + descr += " " + sp; + if(counter > 30) { + descr += " \n"; + counter = 0; + } + } + } + return descr.trim; + } + + } + return "None." + } + + override generateClassDiagram(EPackage ePackage) { + toPlantumlClassDiagram(ePackage) + } + + override generateClassDiagram(EClass eClass) { + ''' +«startPlantumlClassDiagram()» +«toClassDiagram(eClass)» +«endPlantumlClassDiagram()» + ''' + } + + override generateClassDiagram(EClassifier eClassifier) { + ''' +«startPlantumlClassDiagram()» +«toClassDiagram(eClassifier)» +«endPlantumlClassDiagram()» + ''' + } + +} \ No newline at end of file diff --git a/org.gecko.emf.util.documentation.generators.plantuml/src/org/gecko/emf/util/documentation/generators/plantuml/packageinfo b/org.gecko.emf.util.documentation.generators.plantuml/src/org/gecko/emf/util/documentation/generators/plantuml/packageinfo new file mode 100644 index 00000000..9ad81f6f --- /dev/null +++ b/org.gecko.emf.util.documentation.generators.plantuml/src/org/gecko/emf/util/documentation/generators/plantuml/packageinfo @@ -0,0 +1 @@ +version 1.0.0 diff --git a/org.gecko.emf.util.documentation.generators.plantuml/xtend-gen/org/gecko/emf/util/documentation/generators/plantuml/.PlantumlClassDiagramCodeGen.xtendbin b/org.gecko.emf.util.documentation.generators.plantuml/xtend-gen/org/gecko/emf/util/documentation/generators/plantuml/.PlantumlClassDiagramCodeGen.xtendbin new file mode 100644 index 00000000..e3e0ae46 Binary files /dev/null and b/org.gecko.emf.util.documentation.generators.plantuml/xtend-gen/org/gecko/emf/util/documentation/generators/plantuml/.PlantumlClassDiagramCodeGen.xtendbin differ diff --git a/org.gecko.emf.util.documentation.generators.plantuml/xtend-gen/org/gecko/emf/util/documentation/generators/plantuml/.gitignore b/org.gecko.emf.util.documentation.generators.plantuml/xtend-gen/org/gecko/emf/util/documentation/generators/plantuml/.gitignore new file mode 100644 index 00000000..71a65ddc --- /dev/null +++ b/org.gecko.emf.util.documentation.generators.plantuml/xtend-gen/org/gecko/emf/util/documentation/generators/plantuml/.gitignore @@ -0,0 +1,6 @@ +/.PlantumlCodeGen.java._trace +/.PlantumlCodeGen.xtendbin +/PlantumlCodeGen.java +/.PlantumlClassDiagramCodeGen.java._trace +/.PlantumlClassDiagramCodeGen.xtendbin +/PlantumlClassDiagramCodeGen.java diff --git a/org.gecko.emf.util.documentation.generators.plantuml/xtend-gen/org/gecko/emf/util/documentation/generators/plantuml/PlantumlClassDiagramCodeGen.java b/org.gecko.emf.util.documentation.generators.plantuml/xtend-gen/org/gecko/emf/util/documentation/generators/plantuml/PlantumlClassDiagramCodeGen.java new file mode 100644 index 00000000..c27ef1b9 --- /dev/null +++ b/org.gecko.emf.util.documentation.generators.plantuml/xtend-gen/org/gecko/emf/util/documentation/generators/plantuml/PlantumlClassDiagramCodeGen.java @@ -0,0 +1,449 @@ +/** + * Copyright (c) 2012 - 2022 Data In Motion and others. + * All rights reserved. + * + * 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 + * + * Contributors: + * Data In Motion - initial API and implementation + */ +package org.gecko.emf.util.documentation.generators.plantuml; + +import java.util.List; +import org.eclipse.emf.common.util.EList; +import org.eclipse.emf.common.util.EMap; +import org.eclipse.emf.ecore.EAnnotation; +import org.eclipse.emf.ecore.EAttribute; +import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.EClassifier; +import org.eclipse.emf.ecore.EEnum; +import org.eclipse.emf.ecore.EEnumLiteral; +import org.eclipse.emf.ecore.EModelElement; +import org.eclipse.emf.ecore.EPackage; +import org.eclipse.emf.ecore.EReference; +import org.eclipse.xtend2.lib.StringConcatenation; +import org.eclipse.xtext.xbase.lib.Functions.Function1; +import org.eclipse.xtext.xbase.lib.IterableExtensions; +import org.gecko.emf.util.documentation.generators.apis.EcoreToClassDiagramCodeGenerator; + +@SuppressWarnings("all") +public class PlantumlClassDiagramCodeGen implements EcoreToClassDiagramCodeGenerator { + public CharSequence toPlantumlClassDiagram(final EPackage epackage) { + StringConcatenation _builder = new StringConcatenation(); + CharSequence _startPlantumlClassDiagram = this.startPlantumlClassDiagram(); + _builder.append(_startPlantumlClassDiagram); + _builder.newLineIfNotEmpty(); + CharSequence _eClassifierDiagram = this.toEClassifierDiagram(epackage.getEClassifiers()); + _builder.append(_eClassifierDiagram); + _builder.newLineIfNotEmpty(); + CharSequence _endPlantumlClassDiagram = this.endPlantumlClassDiagram(); + _builder.append(_endPlantumlClassDiagram); + _builder.newLineIfNotEmpty(); + return _builder; + } + + public CharSequence startPlantumlClassDiagram() { + StringConcatenation _builder = new StringConcatenation(); + _builder.append("@startuml"); + _builder.newLine(); + return _builder; + } + + public CharSequence endPlantumlClassDiagram() { + StringConcatenation _builder = new StringConcatenation(); + _builder.append("@enduml"); + _builder.newLine(); + return _builder; + } + + public CharSequence toEClassifierDiagram(final EList eclassifiers) { + CharSequence _xblockexpression = null; + { + final Function1 _function = (EClassifier ec) -> { + return Boolean.valueOf((ec instanceof EClass)); + }; + final Function1 _function_1 = (EClassifier ec) -> { + return ((EClass) ec); + }; + List classes = IterableExtensions.toList(IterableExtensions.map(IterableExtensions.filter(eclassifiers, _function), _function_1)); + final Function1 _function_2 = (EClassifier ec) -> { + return Boolean.valueOf((ec instanceof EEnum)); + }; + final Function1 _function_3 = (EClassifier ec) -> { + return ((EEnum) ec); + }; + List enums = IterableExtensions.toList(IterableExtensions.map(IterableExtensions.filter(eclassifiers, _function_2), _function_3)); + StringConcatenation _builder = new StringConcatenation(); + { + for(final EClass eclass : classes) { + CharSequence _classDiagram = this.toClassDiagram(eclass); + _builder.append(_classDiagram); + _builder.newLineIfNotEmpty(); + } + } + { + for(final EEnum enumerator : enums) { + CharSequence _enumerator = this.toEnumerator(enumerator); + _builder.append(_enumerator); + _builder.newLineIfNotEmpty(); + } + } + _xblockexpression = _builder; + } + return _xblockexpression; + } + + public CharSequence toClassDiagram(final EClass eclass) { + StringConcatenation _builder = new StringConcatenation(); + { + boolean _isInterface = eclass.isInterface(); + if (_isInterface) { + _builder.append(" "); + _builder.append("interface "); + String _name = eclass.getName(); + _builder.append(_name); + _builder.append(" {"); + _builder.newLineIfNotEmpty(); + } else { + boolean _isAbstract = eclass.isAbstract(); + if (_isAbstract) { + _builder.append(" "); + _builder.append("abstract class "); + String _name_1 = eclass.getName(); + _builder.append(_name_1); + _builder.append(" {"); + _builder.newLineIfNotEmpty(); + } else { + _builder.append(" "); + _builder.append("class "); + String _name_2 = eclass.getName(); + _builder.append(_name_2); + _builder.append(" {"); + _builder.newLineIfNotEmpty(); + } + } + } + CharSequence _classMembers = this.toClassMembers(eclass); + _builder.append(_classMembers); + _builder.newLineIfNotEmpty(); + _builder.append("}"); + _builder.newLine(); + _builder.append("\n"); + _builder.newLineIfNotEmpty(); + CharSequence _onTopDescription = this.toOnTopDescription(eclass); + _builder.append(_onTopDescription); + _builder.newLineIfNotEmpty(); + _builder.append("\n"); + _builder.newLineIfNotEmpty(); + CharSequence _classReferences = this.toClassReferences(eclass); + _builder.append(_classReferences); + _builder.newLineIfNotEmpty(); + _builder.append("\n"); + _builder.newLineIfNotEmpty(); + { + boolean _isEmpty = eclass.getESuperTypes().isEmpty(); + boolean _not = (!_isEmpty); + if (_not) { + CharSequence _superTypes = this.toSuperTypes(eclass); + _builder.append(_superTypes); + _builder.newLineIfNotEmpty(); + _builder.append("\n"); + _builder.newLineIfNotEmpty(); + } + } + return _builder; + } + + public CharSequence toClassDiagram(final EClassifier eclassifier) { + StringConcatenation _builder = new StringConcatenation(); + { + if ((eclassifier instanceof EClass)) { + CharSequence _classDiagram = this.toClassDiagram(((EClass) eclassifier)); + _builder.append(_classDiagram); + _builder.newLineIfNotEmpty(); + } else { + if ((eclassifier instanceof EEnum)) { + CharSequence _enumerator = this.toEnumerator(((EEnum) eclassifier)); + _builder.append(_enumerator); + _builder.newLineIfNotEmpty(); + } + } + } + return _builder; + } + + public CharSequence toClassMembers(final EClass eclass) { + StringConcatenation _builder = new StringConcatenation(); + { + EList _eAttributes = eclass.getEAttributes(); + for(final EAttribute attribute : _eAttributes) { + _builder.append(" "); + String _name = attribute.getName(); + _builder.append(_name); + _builder.append(" : "); + String _name_1 = attribute.getEType().getName(); + _builder.append(_name_1); + _builder.append(" "); + _builder.newLineIfNotEmpty(); + } + } + return _builder; + } + + public CharSequence toClassReferences(final EClass eclass) { + StringConcatenation _builder = new StringConcatenation(); + { + EList _eReferences = eclass.getEReferences(); + for(final EReference ref : _eReferences) { + CharSequence _classRef = this.toClassRef(eclass, ref); + _builder.append(_classRef); + _builder.newLineIfNotEmpty(); + } + } + return _builder; + } + + public CharSequence toClassRef(final EClass eclass, final EReference ref) { + CharSequence _xblockexpression = null; + { + String multiplicity = this.extractMultiplicity(ref.getLowerBound(), ref.getUpperBound()); + boolean isInRefModel = this.isInRefModel(ref, eclass); + StringConcatenation _builder = new StringConcatenation(); + { + if (isInRefModel) { + CharSequence _createRefPackage = this.createRefPackage(ref); + _builder.append(_createRefPackage); + _builder.newLineIfNotEmpty(); + _builder.append("\n"); + _builder.newLineIfNotEmpty(); + _builder.append(" "); + String _name = eclass.getName(); + _builder.append(_name); + _builder.append(" "); + _builder.append(" ..> "); + _builder.append(" "); + _builder.append("\""); + _builder.append(multiplicity); + _builder.append("\""); + _builder.append(" "); + String _name_1 = ref.getEType().getName(); + _builder.append(_name_1); + _builder.append(" : "); + String _name_2 = ref.getName(); + _builder.append(_name_2); + _builder.newLineIfNotEmpty(); + } else { + _builder.append(" "); + String _name_3 = eclass.getName(); + _builder.append(_name_3); + _builder.append(" "); + _builder.append(" --> "); + _builder.append(" "); + _builder.append("\""); + _builder.append(multiplicity); + _builder.append("\""); + _builder.append(" "); + String _name_4 = ref.getEType().getName(); + _builder.append(_name_4); + _builder.append(" : "); + String _name_5 = ref.getName(); + _builder.append(_name_5); + _builder.newLineIfNotEmpty(); + } + } + _builder.append("\n"); + _builder.newLineIfNotEmpty(); + _xblockexpression = _builder; + } + return _xblockexpression; + } + + public CharSequence createRefPackage(final EReference ref) { + StringConcatenation _builder = new StringConcatenation(); + _builder.append(" "); + _builder.append("package \""); + String _nsURI = ref.getEType().getEPackage().getNsURI(); + _builder.append(_nsURI); + _builder.append("\" #DDDDDD {"); + _builder.newLineIfNotEmpty(); + _builder.append(" "); + String _name = ref.getEType().getName(); + _builder.append(_name); + _builder.append(" : "); + String _name_1 = ref.getName(); + _builder.append(_name_1); + _builder.newLineIfNotEmpty(); + _builder.append("}"); + _builder.newLine(); + return _builder; + } + + public boolean isInRefModel(final EReference ref, final EClass containerClass) { + String _name = ref.getEType().getEPackage().getName(); + String _name_1 = containerClass.getEPackage().getName(); + boolean _tripleEquals = (_name == _name_1); + if (_tripleEquals) { + return false; + } else { + return true; + } + } + + public String extractMultiplicity(final int lowerBound, final int upperBound) { + if (((lowerBound == 0) && (upperBound == (-1)))) { + return "*"; + } else { + if (((lowerBound == 1) && (upperBound == (-1)))) { + return "1..*"; + } + } + String _valueOf = String.valueOf(lowerBound); + String _plus = (_valueOf + ".."); + String _valueOf_1 = String.valueOf(upperBound); + return (_plus + _valueOf_1); + } + + public CharSequence toSuperTypes(final EClass eclass) { + StringConcatenation _builder = new StringConcatenation(); + { + EList _eSuperTypes = eclass.getESuperTypes(); + for(final EClass parent : _eSuperTypes) { + _builder.append(" "); + String _name = eclass.getName(); + _builder.append(_name); + _builder.append(" ..> "); + String _name_1 = parent.getName(); + _builder.append(_name_1); + _builder.newLineIfNotEmpty(); + } + } + return _builder; + } + + public CharSequence toEnumerator(final EEnum enumerator) { + StringConcatenation _builder = new StringConcatenation(); + _builder.append(" "); + _builder.append("enum "); + String _name = enumerator.getName(); + _builder.append(_name); + _builder.append(" {"); + _builder.newLineIfNotEmpty(); + { + EList _eLiterals = enumerator.getELiterals(); + for(final EEnumLiteral value : _eLiterals) { + _builder.append(" "); + String _name_1 = value.getName(); + _builder.append(_name_1); + _builder.newLineIfNotEmpty(); + } + } + _builder.append("}"); + _builder.newLine(); + _builder.append("\n"); + _builder.newLineIfNotEmpty(); + CharSequence _onTopDescription = this.toOnTopDescription(enumerator); + _builder.append(_onTopDescription); + _builder.newLineIfNotEmpty(); + _builder.append("\n"); + _builder.newLineIfNotEmpty(); + return _builder; + } + + public CharSequence toOnTopDescription(final EClassifier eclassifier) { + CharSequence _xblockexpression = null; + { + String description = this.toModelElementDescription(eclassifier); + CharSequence _xifexpression = null; + if ((description != "None.")) { + StringConcatenation _builder = new StringConcatenation(); + _builder.append("note top of "); + String _name = eclassifier.getName(); + _builder.append(_name); + _builder.newLineIfNotEmpty(); + _builder.append(" "); + _builder.append(description); + _builder.newLineIfNotEmpty(); + _builder.append("end note"); + _builder.newLine(); + _xifexpression = _builder; + } + _xblockexpression = _xifexpression; + } + return _xblockexpression; + } + + public String toModelElementDescription(final EModelElement element) { + EList _eAnnotations = element.getEAnnotations(); + for (final EAnnotation annotation : _eAnnotations) { + { + EMap details = annotation.getDetails(); + boolean _containsKey = details.containsKey("documentation"); + if (_containsKey) { + String descr = details.get("documentation").replace("\n", "").trim(); + int _length = descr.length(); + boolean _greaterThan = (_length > 30); + if (_greaterThan) { + String[] splitStr = descr.split(" "); + int counter = 0; + descr = ""; + for (final String sp : splitStr) { + { + int _counter = counter; + int _length_1 = sp.length(); + counter = (_counter + _length_1); + String _descr = descr; + descr = (_descr + (" " + sp)); + if ((counter > 30)) { + String _descr_1 = descr; + descr = (_descr_1 + " \n"); + counter = 0; + } + } + } + } + return descr.trim(); + } + } + } + return "None."; + } + + @Override + public CharSequence generateClassDiagram(final EPackage ePackage) { + return this.toPlantumlClassDiagram(ePackage); + } + + @Override + public CharSequence generateClassDiagram(final EClass eClass) { + StringConcatenation _builder = new StringConcatenation(); + CharSequence _startPlantumlClassDiagram = this.startPlantumlClassDiagram(); + _builder.append(_startPlantumlClassDiagram); + _builder.newLineIfNotEmpty(); + CharSequence _classDiagram = this.toClassDiagram(eClass); + _builder.append(_classDiagram); + _builder.newLineIfNotEmpty(); + CharSequence _endPlantumlClassDiagram = this.endPlantumlClassDiagram(); + _builder.append(_endPlantumlClassDiagram); + _builder.newLineIfNotEmpty(); + return _builder; + } + + @Override + public CharSequence generateClassDiagram(final EClassifier eClassifier) { + StringConcatenation _builder = new StringConcatenation(); + CharSequence _startPlantumlClassDiagram = this.startPlantumlClassDiagram(); + _builder.append(_startPlantumlClassDiagram); + _builder.newLineIfNotEmpty(); + CharSequence _classDiagram = this.toClassDiagram(eClassifier); + _builder.append(_classDiagram); + _builder.newLineIfNotEmpty(); + CharSequence _endPlantumlClassDiagram = this.endPlantumlClassDiagram(); + _builder.append(_endPlantumlClassDiagram); + _builder.newLineIfNotEmpty(); + return _builder; + } +} diff --git a/org.gecko.emf.util.model/src/org/gecko/emf/util/helper/UtilModelHelper.java b/org.gecko.emf.util.model/src/org/gecko/emf/util/helper/UtilModelHelper.java index 8bdd3a02..05dc83e0 100644 --- a/org.gecko.emf.util.model/src/org/gecko/emf/util/helper/UtilModelHelper.java +++ b/org.gecko.emf.util.model/src/org/gecko/emf/util/helper/UtilModelHelper.java @@ -2,9 +2,11 @@ * Copyright (c) 2012 - 2022 Data In Motion and others. * All rights reserved. * - * This program and the accompanying materials are made available under the terms of the - * Eclipse Public License v2.0 which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v20.html + * 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 * * Contributors: * Data In Motion - initial API and implementation