Loading plugins/org.etsi.mts.tdl.common/src/org/etsi/mts/tdl/transform/AbstractTranslator.java +41 −5 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -87,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) { Loading Loading @@ -188,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) { Loading Loading
plugins/org.etsi.mts.tdl.common/src/org/etsi/mts/tdl/transform/AbstractTranslator.java +41 −5 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -87,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) { Loading Loading @@ -188,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) { Loading