diff --git a/backend/application/syson-application/src/test/java/org/eclipse/syson/application/export/ImportExportTests.java b/backend/application/syson-application/src/test/java/org/eclipse/syson/application/export/ImportExportTests.java index ea680f2a2..09112540b 100644 --- a/backend/application/syson-application/src/test/java/org/eclipse/syson/application/export/ImportExportTests.java +++ b/backend/application/syson-application/src/test/java/org/eclipse/syson/application/export/ImportExportTests.java @@ -64,7 +64,7 @@ public void checkUseCaseTest() throws IOException { * The file has been modified because a problem has been detected during the export phase. * Those problem force us to use some full-length qualified name. This should be investigated. * - * for exemple: + * for example: include UseCaseTest::uc2; * instead of include uc2; @@ -151,7 +151,7 @@ public void checkImportTest() throws IOException { * The file has been modified because a problem has been detected during the export phase. * Those problem force us to use some full-length qualified name. This should be investigated. * - * for exemple: + * for example: private import Pkg2::Pkg21::Pkg211::*::**; * instead of private import Pkg211::*::**; diff --git a/backend/application/syson-sysml-export/src/main/java/org/eclipse/syson/sysml/export/SysMLElementSerializer.java b/backend/application/syson-sysml-export/src/main/java/org/eclipse/syson/sysml/export/SysMLElementSerializer.java index c1ef39f86..89cb1d9ac 100644 --- a/backend/application/syson-sysml-export/src/main/java/org/eclipse/syson/sysml/export/SysMLElementSerializer.java +++ b/backend/application/syson-sysml-export/src/main/java/org/eclipse/syson/sysml/export/SysMLElementSerializer.java @@ -137,8 +137,6 @@ */ public class SysMLElementSerializer extends SysmlSwitch { - private static final Predicate NOT_NULL = s -> s != null; - private final String lineSeparator; private final String indentation; @@ -152,7 +150,7 @@ public class SysMLElementSerializer extends SysmlSwitch { /** * Simple constructor. * - * @param newLine + * @param lineSeparator * the string used to separate line * @param indentation * the string used to indent the file @@ -680,10 +678,9 @@ public String caseFeatureChainExpression(FeatureChainExpression feature) { .map(ParameterMembership.class::cast) .findFirst() .map(ParameterMembership::getOwnedMemberParameter) - .filter(NOT_NULL) .map(Feature::getOwnedRelationship) - .map(Collection::stream) - .orElseGet(Stream::empty) + .stream() + .flatMap(Collection::stream) .filter(FeatureValue.class::isInstance) .map(FeatureValue.class::cast) .findFirst() @@ -768,7 +765,7 @@ public String caseActorMembership(ActorMembership actor) { if (ownedActorParameter != null) { VisibilityKind visibility = actor.getVisibility(); if (visibility != VisibilityKind.PUBLIC) { - builder.append(this.getVisivilityIndicator(visibility)); + builder.append(this.getVisibilityIndicator(visibility)); } this.appendDefaultUsage(builder, ownedActorParameter); @@ -785,7 +782,7 @@ public String caseSubjectMembership(SubjectMembership subject) { if (ownedSubjectParameter != null && !this.isImplicit(ownedSubjectParameter)) { VisibilityKind visibility = subject.getVisibility(); if (visibility != VisibilityKind.PUBLIC) { - builder.append(this.getVisivilityIndicator(visibility)); + builder.append(this.getVisibilityIndicator(visibility)); } builder.appendWithSpaceIfNeeded("subject"); @@ -803,7 +800,7 @@ public String caseObjectiveMembership(ObjectiveMembership objective) { if (ownedObjectiveRequirement != null && !this.isImplicit(ownedObjectiveRequirement)) { VisibilityKind visibility = objective.getVisibility(); if (visibility != VisibilityKind.PUBLIC) { - builder.append(this.getVisivilityIndicator(visibility)); + builder.append(this.getVisibilityIndicator(visibility)); } builder.append("objective"); @@ -880,7 +877,7 @@ public String caseReturnParameterMembership(ReturnParameterMembership parameter) if (ownedMemberParameter != null && !this.isImplicit(ownedMemberParameter) && ownedMemberParameter instanceof Usage usage) { VisibilityKind visibility = parameter.getVisibility(); if (visibility != VisibilityKind.PUBLIC) { - builder.append(this.getVisivilityIndicator(visibility)); + builder.append(this.getVisibilityIndicator(visibility)); } builder.append("return"); @@ -990,8 +987,7 @@ private void appendSubsettings(Appender builder, List subSettings, b .filter(this::nameNotNullAndNotBlank) .toList(); if (!subSettedDifference.isEmpty()) { - String subSettingPart = subSettedDifference.stream() - .collect(Collectors.joining(", ")); + String subSettingPart = String.join(", ", subSettedDifference); if (!subSettingPart.isBlank()) { builder.appendSpaceIfNeeded().append(LabelConstants.SUBSETTING); builder.appendSpaceIfNeeded().append(subSettingPart); @@ -1007,8 +1003,7 @@ private void appendRedefinition(Appender builder, List redefinitio .filter(this::nameNotNullAndNotBlank) .toList(); if (!redefinedFeatures.isEmpty()) { - String redefinitionPart = redefinedFeatures.stream() - .collect(Collectors.joining(", ")); + String redefinitionPart = String.join(", ", redefinedFeatures); if (!redefinitionPart.isBlank()) { builder.appendSpaceIfNeeded().append(LabelConstants.REDEFINITION); builder.appendSpaceIfNeeded().append(redefinitionPart); @@ -1056,8 +1051,7 @@ private void appendFeatureTyping(Appender builder, EList ownedTyp .filter(this::nameNotNullAndNotBlank) .toList(); if (!types.isEmpty()) { - String featureTypePart = types.stream() - .collect(Collectors.joining(", ")); + String featureTypePart = String.join(", ", types); if (!featureTypePart.isBlank()) { builder.appendSpaceIfNeeded().append(LabelConstants.COLON); builder.appendSpaceIfNeeded().append(featureTypePart); @@ -1139,7 +1133,7 @@ private void appendValuePart(Appender builder, Usage usage) { List ownedRelationship = usage.getOwnedRelationship().stream() .filter(FeatureValue.class::isInstance) .map(FeatureValue.class::cast) - .collect(Collectors.toList()); + .toList(); for (FeatureValue feature : ownedRelationship) { builder.appendSpaceIfNeeded(); @@ -1281,8 +1275,8 @@ private void appendSequenceExpressionListMember(Appender builder, List param.getOwnedMemberParameter() instanceof Feature) + .filter(param -> param.getOwnedMemberParameter() != null) .findFirst() .ifPresent(membership -> this.appendArgumentMember(builder, membership)); @@ -1448,7 +1442,7 @@ private void appendDefinitionDeclaration(Appender builder, Definition definition .toList(); List subClassificationClassifier = subClassification.stream() - .map(sub -> sub.getSuperclassifier()) + .map(Subclassification::getSuperclassifier) .filter(this::isNotNullAndNotAProxy) .toList(); if (!subClassificationClassifier.isEmpty()) { @@ -1550,7 +1544,7 @@ private void appendExtensionKeyword(Appender builder, Type type) { .filter(MetadataUsage.class::isInstance) .map(MetadataUsage.class::cast) .map(MetadataUsage::getMetadataDefinition) - .filter(NOT_NULL) + .filter(Objects::nonNull) .forEach(mDef -> this.appendPrefixMetadataMember(builder, mDef)); } } @@ -1634,7 +1628,7 @@ private void appendChildrenContent(Appender builder, Element element, List children, String prefix) { - return children.stream().map(rel -> this.doSwitch(rel)).filter(NOT_NULL).collect(joining(this.lineSeparator, prefix, "")); + return children.stream().map(this::doSwitch).filter(Objects::nonNull).collect(joining(this.lineSeparator, prefix, "")); } @Override @@ -1644,7 +1638,7 @@ public String caseImport(Import aImport) { VisibilityKind visibility = aImport.getVisibility(); if (visibility != VisibilityKind.PUBLIC) { - builder.append(this.getVisivilityIndicator(visibility)); + builder.append(this.getVisibilityIndicator(visibility)); } builder.appendSpaceIfNeeded().append("import "); @@ -1811,7 +1805,7 @@ public String caseOwningMembership(OwningMembership owningMembership) { this.appendMembershipPrefix(owningMembership, builder); - String content = owningMembership.getOwnedRelatedElement().stream().map(rel -> this.doSwitch(rel)).filter(NOT_NULL).collect(joining(builder.getNewLine())); + String content = owningMembership.getOwnedRelatedElement().stream().map(this::doSwitch).filter(Objects::nonNull).collect(joining(builder.getNewLine())); builder.appendSpaceIfNeeded().append(content); return builder.toString(); @@ -1868,7 +1862,7 @@ private void appendUsage(Appender builder, Usage portUsage) { private void appendMembershipPrefix(Membership membership, Appender builder) { VisibilityKind visibility = membership.getVisibility(); if (visibility != VisibilityKind.PUBLIC) { - builder.append(this.getVisivilityIndicator(visibility)); + builder.append(this.getVisibilityIndicator(visibility)); } } @@ -1884,7 +1878,7 @@ private void appendMembershipImport(Appender builder, MembershipImport membershi Membership importedMembership = membershipImport.getImportedMembership(); if (importedMembership != null) { - String qnName = Stream.concat(Stream.ofNullable(importedMembership.getMemberElement()), importedMembership.getOwnedRelatedElement().stream()).filter(e -> e != null).findFirst() + String qnName = Stream.concat(Stream.ofNullable(importedMembership.getMemberElement()), importedMembership.getOwnedRelatedElement().stream()).filter(Objects::nonNull).findFirst() .map(e -> this.buildImportContextRelativeQualifiedName(e, membershipImport)).orElse(""); builder.appendSpaceIfNeeded().append(qnName); @@ -1897,7 +1891,7 @@ private String buildImportContextRelativeQualifiedName(Element element, Element if (commonAncestor != null) { String prefix = commonAncestor.getQualifiedName() + "::"; if (qualifiedName.startsWith(prefix)) { - return qualifiedName.substring(prefix.length(), qualifiedName.length()); + return qualifiedName.substring(prefix.length()); } } return qualifiedName; @@ -1915,7 +1909,7 @@ private String appendNameWithShortName(Appender builder, Element element) { return builder.toString(); } - public String getVisivilityIndicator(VisibilityKind visibility) { + public String getVisibilityIndicator(VisibilityKind visibility) { if (visibility == null) { return ""; } diff --git a/backend/application/syson-sysml-export/src/main/java/org/eclipse/syson/sysml/export/utils/NameDeresolver.java b/backend/application/syson-sysml-export/src/main/java/org/eclipse/syson/sysml/export/utils/NameDeresolver.java index 16b8ca0e1..97860ca8f 100644 --- a/backend/application/syson-sysml-export/src/main/java/org/eclipse/syson/sysml/export/utils/NameDeresolver.java +++ b/backend/application/syson-sysml-export/src/main/java/org/eclipse/syson/sysml/export/utils/NameDeresolver.java @@ -13,11 +13,11 @@ package org.eclipse.syson.sysml.export.utils; import static java.util.stream.Collectors.toCollection; -import static java.util.stream.Collectors.toSet; import java.util.ArrayList; import java.util.Comparator; import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Optional; @@ -42,7 +42,7 @@ import org.slf4j.LoggerFactory; /** - * Object in charge of converting an Element to a resolvable qualified name depending of its context. This class tries + * Object in charge of converting an Element to a resolvable qualified name depending on its context. This class tries * its best to find the shortest resolvable name. Be aware that this element keeps a cache of the computation of * {@link Namespace#visibleMemberships(EList, boolean, boolean)}. It should be used on a static model, discard this * object if the model changes. @@ -88,11 +88,11 @@ public String getDeresolvedName(Element element, Element context) { for (Namespace deresolvingNamespace : deresolvingNamespaces) { // An element is either reachable form its containment tree or via a reference Membership#memberElement - Set elementAncestors = EMFUtils.getAncestors(Membership.class, element, null).stream().collect(toSet()); + Set elementAncestors = new HashSet<>(EMFUtils.getAncestors(Membership.class, element, null)); EMFUtils.getInverse(element, SysmlPackage.eINSTANCE.getMembership_MemberElement()).stream().map(s -> (Membership) s.getEObject()).forEach(elementAncestors::add); - String computedQualidiedName = this.deresolve(element, deresolvingNamespace, deresolvingNamespace, elementAncestors); - if (computedQualidiedName != null && !computedQualidiedName.isBlank()) { - qualifiedNames.add(computedQualidiedName); + String computedQualifiedName = this.deresolve(element, deresolvingNamespace, deresolvingNamespace, elementAncestors); + if (computedQualifiedName != null && !computedQualifiedName.isBlank()) { + qualifiedNames.add(computedQualifiedName); } } @@ -159,7 +159,7 @@ private String deresolve(Element element, Namespace sourceNamespace, Namespace d // Try to compute its qualified name qualifiedName = this.buildRelativeQualifiedName(element, deresolvingNamespace, importedContainer.get(), sourceNamespace); } else { - // Ask to the parent namespace + // Query the parent namespace qualifiedName = this.deresolve(element, sourceNamespace, deresolvingNamespace.getOwningNamespace(), ancestors); } @@ -172,13 +172,13 @@ private String deresolve(Element element, Namespace sourceNamespace, Namespace d } private int getPathLength(Element element, Membership ancestor) { - int lenght = 0; + int length = 0; EObject current = element; while (current != null && ancestor != current) { - lenght++; + length++; current = current.eContainer(); } - return lenght; + return length; } private boolean isContainerOrIdentity(Namespace ancestorObjectNamespace, Namespace namespace) { @@ -208,8 +208,8 @@ private EList getVisibleMemberships(Namespace deresolvingNamespace, private String buildRelativeQualifiedName(Element element, Namespace owningNamespace, Membership visibleMembership, Namespace sourceNamespace) { String elementQn = this.getQualifiedName(element); - if (elementQn == null || elementQn.isEmpty()) { - LOGGER.warn("No qualified name found for " + element.getElementId()); + if (elementQn.isEmpty()) { + LOGGER.warn("No qualified name found for {}", element.getElementId()); return ""; } @@ -223,8 +223,8 @@ private String buildRelativeQualifiedName(Element element, Namespace owningNames if (resolvedElement != null && !this.match(element, resolvedElement)) { // Last try if the element is in the containment tree find the shortest qualified name String qualifiedName = this.getQualifiedName(owningNamespace); - if (qualifiedName != null && !qualifiedName.isBlank() && elementQn.startsWith(qualifiedName)) { - relativeQualifiedName = owningNamespace.getName() + "::" + elementQn.substring(qualifiedName.length() + 2, elementQn.length()); + if (!qualifiedName.isBlank() && elementQn.startsWith(qualifiedName)) { + relativeQualifiedName = owningNamespace.getName() + "::" + elementQn.substring(qualifiedName.length() + 2); } else { relativeQualifiedName = elementQn; } @@ -236,19 +236,19 @@ private String buildRelativeQualifiedName(Element element, Namespace owningNames /** * Checks if the resolved element is either the resolved element member or if it implicitly matches the naming - * feature of unamed element which name computation used the resolved element. + * feature of unnamed element which name computation used the resolved element. * * @param element * the element to compute the name from * @param resolvedElement * the resolution tested name in the local namespace - * @return true if the elements matche + * @return true if the elements match */ private boolean match(Element element, Membership resolvedElement) { - return resolvedElement.getMemberElement() == element || this.matchImplicite(resolvedElement, element); + return resolvedElement.getMemberElement() == element || this.implicitMatch(resolvedElement, element); } - private boolean matchImplicite(Membership resolvedMembership, Element context) { + private boolean implicitMatch(Membership resolvedMembership, Element context) { Element resolvedElement = resolvedMembership.getMemberElement(); if (resolvedElement.getDeclaredName() == null && resolvedElement.getDeclaredShortName() == null && resolvedElement instanceof Feature feature) { @@ -262,9 +262,9 @@ private String getRelativeQualifiedName(String elementQn, Element element, Membe final String qn; Element importedElement = m.getMemberElement(); String importedElementQualifiedName = this.getQualifiedName(importedElement); - if (importedElement != element && importedElementQualifiedName != null && !importedElementQualifiedName.isEmpty()) { + if (importedElement != element && !importedElementQualifiedName.isEmpty()) { int partToRemove = importedElementQualifiedName.length() + 2; - qn = Appender.toPrintableName(importedElement.getName()) + "::" + elementQn.substring(partToRemove, elementQn.length()); + qn = Appender.toPrintableName(importedElement.getName()) + "::" + elementQn.substring(partToRemove); } else { qn = Appender.toPrintableName(element.getName()); }