Commit 55cc008b authored by Philip Makedonski's avatar Philip Makedonski
Browse files

Merge branch 'yang-import' into dev

# Conflicts:
#	plugins/org.etsi.mts.tdl.openapi.generator.wrapper/README.md
parents 335cd669 1438b723
Loading
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -374,4 +374,11 @@ any resulting litigation.
         version="0.0.0"
         unpack="false"/>

   <plugin
         id="org.etsi.mts.tdl.yang2tdl"
         download-size="0"
         install-size="0"
         version="0.0.0"
         unpack="false"/>

</feature>
+1 −0
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xs
		<module>../plugins/org.etsi.mts.tdl.json2tdl</module>
		<module>../plugins/org.etsi.mts.tdl.to2tdl</module>
		<module>../plugins/org.etsi.mts.tdl.asn2tdl</module>
		<module>../plugins/org.etsi.mts.tdl.yang2tdl</module>
		<module>../plugins/org.etsi.mts.tdl.ttcn3</module>
		<module>../plugins/org.etsi.mts.tdl.ttcn3.ui</module>
		<module>../plugins/org.etsi.mts.tdl.importers.ui</module>
+1 −1
Original line number Diff line number Diff line
@@ -67,7 +67,7 @@
	</location>
	<location includeAllPlatforms="false" includeConfigurePhase="true" includeMode="planner" includeSource="true" type="InstallableUnit">
		<repository location="https://top.etsi.org/top-extras/updatesite/stable"/>
		<unit id="org.etsi.mts.tdl.extras.feature.feature.group" version="1.0.0.202311021145"/>
		<unit id="org.etsi.mts.tdl.extras.feature.feature.group" version="1.0.0.202401102125"/>
	</location>
</locations>
</target>
 No newline at end of file
+48 −6
Original line number Diff line number Diff line
@@ -7,8 +7,11 @@ import java.util.function.Predicate;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.xtext.EcoreUtil2;
import org.etsi.mts.tdl.Annotation;
import org.etsi.mts.tdl.AnnotationType;
import org.etsi.mts.tdl.CollectionDataType;
import org.etsi.mts.tdl.Comment;
import org.etsi.mts.tdl.Constraint;
import org.etsi.mts.tdl.ConstraintType;
import org.etsi.mts.tdl.DataElementMapping;
@@ -22,6 +25,7 @@ import org.etsi.mts.tdl.Package;
import org.etsi.mts.tdl.PackageableElement;
import org.etsi.mts.tdl.Parameter;
import org.etsi.mts.tdl.ParameterMapping;
import org.etsi.mts.tdl.SimpleDataInstance;
import org.etsi.mts.tdl.SimpleDataType;
import org.etsi.mts.tdl.StructuredDataInstance;
import org.etsi.mts.tdl.StructuredDataType;
@@ -74,6 +78,10 @@ public abstract class AbstractTranslator {
		return getTypeFor(getCleanName(name), tdlPackage.Literals.ENUM_DATA_TYPE);
	}

	protected SimpleDataInstance getSimpleDataInstanceFor(String name) {
		return getTypeFor(getCleanName(name), tdlPackage.Literals.SIMPLE_DATA_INSTANCE);
	}
	
	protected StructuredDataType getStructuredDataTypeFor(String name) {
		return getTypeFor(getCleanName(name), tdlPackage.Literals.STRUCTURED_DATA_TYPE);
	}
@@ -82,6 +90,14 @@ public abstract class AbstractTranslator {
		return getTypeFor(getCleanName(name), tdlPackage.Literals.STRUCTURED_DATA_INSTANCE);
	}
	
	protected CollectionDataType getCollectionDataTypeFor(DataType itemType) {
		CollectionDataType collectionType = getTypeFor(itemType.getName() + "_collection",
				tdlPackage.Literals.COLLECTION_DATA_TYPE);
		collectionType.setItemType(itemType);
		return collectionType;
	}


	protected String idStartDigitRegex = "\\A\\d";
	protected String idInvalidCharRegex = "\\W";
	public static String cleanName(String name) {
@@ -95,7 +111,8 @@ public abstract class AbstractTranslator {
		name = name.replaceAll("-", "_")
				.replaceAll(" ", "_")
				.replaceAll(":", "_")
				.replaceAll("\\.", "_");
				.replaceAll("\\.", "_")
				.replaceFirst("^(\\d)", "_\\1");
		return name;
	}
	public String getCleanName(String name) {
@@ -182,14 +199,39 @@ public abstract class AbstractTranslator {
				.findFirst();
		return optional;
	}
	
	protected void annotateWith(final DataType generatedType, String annotationName) {
	protected Annotation getAnnotation(final Element element, String annotationName) {
		AnnotationType annotationType = getTypeFor(getCleanName(annotationName), tdlPackage.Literals.ANNOTATION_TYPE);
		if (!generatedType.getAnnotation().stream().anyMatch(a->a.getKey()==annotationType)) {
		Optional<Annotation> optional = element.getAnnotation().stream().filter(a->a.getKey()==annotationType).findFirst();
		return optional.orElseGet(() -> {
			Annotation annotation = tdlFactory.eINSTANCE.createAnnotation();
			annotation.setKey(annotationType);
			generatedType.getAnnotation().add(annotation);
			element.getAnnotation().add(annotation);
			return annotation;
		});
	}

	protected Comment getComment(final Element element, String noteName) {
		Optional<Comment> optional = element.getComment().stream().filter(a->a.getName()==noteName).findFirst();
		return optional.orElseGet(() -> {
			Comment comment = tdlFactory.eINSTANCE.createComment();
			comment.setName(noteName);
			element.getComment().add(comment);
			return comment;
		});
	}
	
	protected void annotateWith(final Element element, String annotationName, String annotationValue) {
		Annotation annotation = getAnnotation(element, annotationName);
		annotation.setValue(annotationValue);
	}
	
	protected void annotateWith(final Element element, String annotationName) {
		getAnnotation(element, annotationName);
	}

	protected void noteWith(final Element element, String commentName, String body) {
		Comment comment = getComment(element, commentName);
		comment.setBody(body);
	}

	protected void constrainWith(final DataType generatedType, String constraintName) {
+2 −1
Original line number Diff line number Diff line
@@ -19,7 +19,8 @@ Require-Bundle: org.eclipse.ui,
 org.etsi.mts.tdl.asn2tdl,
 org.etsi.mts.tdl.openapi2tdl.next,
 org.etsi.mts.tdl.to2tdl,
 org.etsi.mts.tdl.json2tdl
 org.etsi.mts.tdl.json2tdl,
 org.etsi.mts.tdl.yang2tdl
Bundle-ActivationPolicy: lazy
Import-Package: org.eclipse.emf.common.util
Bundle-RequiredExecutionEnvironment: JavaSE-11
Loading