From 1de6a3875b867e9a9269b3df44bfeb2116190a12 Mon Sep 17 00:00:00 2001 From: Florian Bossert Date: Sat, 24 Feb 2024 13:58:34 +0100 Subject: [PATCH] Fix TeaStore failure The Operation type was used as a key in a TreeSet without implementing Comparable. --- .../commonalities/EntireInterface.java | 8 ++--- .../extraction/commonalities/Operation.java | 6 ++-- .../commonalities/OperationInterface.java | 4 +-- .../commonalities/PCMDetectionResult.java | 10 +++--- .../extraction/commonalities/Provisions.java | 10 +++--- .../commonalities/Requirements.java | 10 +++--- .../extraction/engine/PCMInstanceCreator.java | 32 +++++++++++-------- .../retriever/test/model/InterfaceTest.java | 17 +++++----- 8 files changed, 47 insertions(+), 50 deletions(-) diff --git a/bundles/org.palladiosimulator.retriever.extraction/src/org/palladiosimulator/retriever/extraction/commonalities/EntireInterface.java b/bundles/org.palladiosimulator.retriever.extraction/src/org/palladiosimulator/retriever/extraction/commonalities/EntireInterface.java index 3d764214..0d9b579c 100644 --- a/bundles/org.palladiosimulator.retriever.extraction/src/org/palladiosimulator/retriever/extraction/commonalities/EntireInterface.java +++ b/bundles/org.palladiosimulator.retriever.extraction/src/org/palladiosimulator/retriever/extraction/commonalities/EntireInterface.java @@ -1,10 +1,10 @@ package org.palladiosimulator.retriever.extraction.commonalities; +import java.util.HashSet; import java.util.Map; import java.util.Objects; import java.util.Optional; -import java.util.SortedSet; -import java.util.TreeSet; +import java.util.Set; import org.eclipse.jdt.core.dom.ITypeBinding; @@ -32,8 +32,8 @@ public Name getName() { } @Override - public Map> simplified() { - return Map.of(this, new TreeSet<>()); + public Map> simplified() { + return Map.of(this, new HashSet<>()); } @Override diff --git a/bundles/org.palladiosimulator.retriever.extraction/src/org/palladiosimulator/retriever/extraction/commonalities/Operation.java b/bundles/org.palladiosimulator.retriever.extraction/src/org/palladiosimulator/retriever/extraction/commonalities/Operation.java index db5646fc..0ff8d74d 100644 --- a/bundles/org.palladiosimulator.retriever.extraction/src/org/palladiosimulator/retriever/extraction/commonalities/Operation.java +++ b/bundles/org.palladiosimulator.retriever.extraction/src/org/palladiosimulator/retriever/extraction/commonalities/Operation.java @@ -3,8 +3,6 @@ import java.util.Map; import java.util.Objects; import java.util.Set; -import java.util.SortedSet; -import java.util.TreeSet; import org.eclipse.jdt.core.dom.IMethodBinding; @@ -27,8 +25,8 @@ public OperationName getName() { } @Override - public Map> simplified() { - return Map.of(this, new TreeSet<>(Set.of(this))); + public Map> simplified() { + return Map.of(this, Set.of(this)); } @Override diff --git a/bundles/org.palladiosimulator.retriever.extraction/src/org/palladiosimulator/retriever/extraction/commonalities/OperationInterface.java b/bundles/org.palladiosimulator.retriever.extraction/src/org/palladiosimulator/retriever/extraction/commonalities/OperationInterface.java index b6d14dc5..afe0afa0 100644 --- a/bundles/org.palladiosimulator.retriever.extraction/src/org/palladiosimulator/retriever/extraction/commonalities/OperationInterface.java +++ b/bundles/org.palladiosimulator.retriever.extraction/src/org/palladiosimulator/retriever/extraction/commonalities/OperationInterface.java @@ -1,12 +1,12 @@ package org.palladiosimulator.retriever.extraction.commonalities; import java.util.Map; -import java.util.SortedSet; +import java.util.Set; public interface OperationInterface extends Comparable { Name getName(); - Map> simplified(); + Map> simplified(); /** * @returns the most specific interface name (and the interface name for java) diff --git a/bundles/org.palladiosimulator.retriever.extraction/src/org/palladiosimulator/retriever/extraction/commonalities/PCMDetectionResult.java b/bundles/org.palladiosimulator.retriever.extraction/src/org/palladiosimulator/retriever/extraction/commonalities/PCMDetectionResult.java index 119fd8d1..0cd38553 100644 --- a/bundles/org.palladiosimulator.retriever.extraction/src/org/palladiosimulator/retriever/extraction/commonalities/PCMDetectionResult.java +++ b/bundles/org.palladiosimulator.retriever.extraction/src/org/palladiosimulator/retriever/extraction/commonalities/PCMDetectionResult.java @@ -5,7 +5,6 @@ import java.util.List; import java.util.Map; import java.util.Set; -import java.util.SortedSet; import java.util.stream.Collectors; import org.palladiosimulator.retriever.extraction.engine.MapMerger; @@ -13,7 +12,7 @@ public class PCMDetectionResult { private final Set components; private final Set composites; - private final Map> operationInterfaces; + private final Map> operationInterfaces; public PCMDetectionResult(final Map components, final Map composites, final ProvisionsBuilder compositeProvisions, @@ -145,9 +144,8 @@ private static Set collectVisibleProvisions(final Set> createOperationInterfaces() { - // TODO: This has to include composite interfaces as well - final List>> constructedOperationInterfaces = this.getComponents() + private Map> createOperationInterfaces() { + final List>> constructedOperationInterfaces = this.getComponents() .stream() .map(x -> x.provisions() .simplified()) @@ -178,7 +176,7 @@ public Set getCompositeComponents() { return this.composites; } - public Map> getOperationInterfaces() { + public Map> getOperationInterfaces() { return this.operationInterfaces; } } diff --git a/bundles/org.palladiosimulator.retriever.extraction/src/org/palladiosimulator/retriever/extraction/commonalities/Provisions.java b/bundles/org.palladiosimulator.retriever.extraction/src/org/palladiosimulator/retriever/extraction/commonalities/Provisions.java index 915d2b59..a19752f6 100644 --- a/bundles/org.palladiosimulator.retriever.extraction/src/org/palladiosimulator/retriever/extraction/commonalities/Provisions.java +++ b/bundles/org.palladiosimulator.retriever.extraction/src/org/palladiosimulator/retriever/extraction/commonalities/Provisions.java @@ -10,8 +10,6 @@ import java.util.Map; import java.util.Objects; import java.util.Set; -import java.util.SortedSet; -import java.util.TreeSet; import java.util.stream.Collectors; import org.palladiosimulator.retriever.extraction.engine.MapMerger; @@ -49,8 +47,8 @@ public Iterator iterator() { return this.provisions.iterator(); } - public Map> simplified() { - final List>> simplifiedInterfaces = new LinkedList<>(); + public Map> simplified() { + final List>> simplifiedInterfaces = new LinkedList<>(); for (final OperationInterface root : this.groupedProvisions.keySet()) { final List simplifiedRoot = new ArrayList<>(root.simplified() .values() @@ -66,7 +64,7 @@ public Map> simplified() { } simplifiedInterfaces.add(Map.of(root, simplifiedRoot.stream() .distinct() - .collect(Collectors.toCollection(TreeSet::new)))); + .collect(Collectors.toCollection(HashSet::new)))); } return MapMerger.merge(simplifiedInterfaces); } @@ -91,7 +89,7 @@ public boolean equals(final Object obj) { @Override public String toString() { final StringBuilder builder = new StringBuilder(); - final Map> simplified = this.simplified(); + final Map> simplified = this.simplified(); for (final OperationInterface iface : simplified.keySet()) { builder.append(iface.getName()); diff --git a/bundles/org.palladiosimulator.retriever.extraction/src/org/palladiosimulator/retriever/extraction/commonalities/Requirements.java b/bundles/org.palladiosimulator.retriever.extraction/src/org/palladiosimulator/retriever/extraction/commonalities/Requirements.java index f2e8a341..7bb7d007 100644 --- a/bundles/org.palladiosimulator.retriever.extraction/src/org/palladiosimulator/retriever/extraction/commonalities/Requirements.java +++ b/bundles/org.palladiosimulator.retriever.extraction/src/org/palladiosimulator/retriever/extraction/commonalities/Requirements.java @@ -10,8 +10,6 @@ import java.util.Map; import java.util.Objects; import java.util.Set; -import java.util.SortedSet; -import java.util.TreeSet; import java.util.stream.Collectors; import org.palladiosimulator.retriever.extraction.engine.MapMerger; @@ -62,8 +60,8 @@ public Iterator iterator() { .iterator(); } - public Map> simplified() { - final List>> simplifiedInterfaces = new LinkedList<>(); + public Map> simplified() { + final List>> simplifiedInterfaces = new LinkedList<>(); for (final OperationInterface root : this.groupedRequirements.keySet()) { final List simplifiedRoot = new ArrayList<>(root.simplified() .values() @@ -79,7 +77,7 @@ public Map> simplified() { } simplifiedInterfaces.add(Map.of(root, simplifiedRoot.stream() .distinct() - .collect(Collectors.toCollection(TreeSet::new)))); + .collect(Collectors.toCollection(HashSet::new)))); } return MapMerger.merge(simplifiedInterfaces); } @@ -104,7 +102,7 @@ public boolean equals(final Object obj) { @Override public String toString() { final StringBuilder builder = new StringBuilder(); - final Map> simplified = this.simplified(); + final Map> simplified = this.simplified(); for (final OperationInterface iface : simplified.keySet()) { builder.append(iface.getName()); diff --git a/bundles/org.palladiosimulator.retriever.extraction/src/org/palladiosimulator/retriever/extraction/engine/PCMInstanceCreator.java b/bundles/org.palladiosimulator.retriever.extraction/src/org/palladiosimulator/retriever/extraction/engine/PCMInstanceCreator.java index 7f1ba8ae..f8ae7c90 100644 --- a/bundles/org.palladiosimulator.retriever.extraction/src/org/palladiosimulator/retriever/extraction/engine/PCMInstanceCreator.java +++ b/bundles/org.palladiosimulator.retriever.extraction/src/org/palladiosimulator/retriever/extraction/engine/PCMInstanceCreator.java @@ -8,7 +8,6 @@ import java.util.Map; import java.util.Optional; import java.util.Set; -import java.util.SortedSet; import org.apache.log4j.Logger; import org.eclipse.jdt.core.dom.ASTNode; @@ -40,7 +39,6 @@ import org.palladiosimulator.retriever.extraction.commonalities.OperationInterface; import org.palladiosimulator.retriever.extraction.commonalities.PCMDetectionResult; -// TODO Bug-fix, probably // Class to create a pcm instance out of all results from the detector class public class PCMInstanceCreator { private static final Logger LOG = Logger.getLogger(PCMInstanceCreator.class); @@ -108,7 +106,7 @@ public Repository createPCM(final Map> mapping) { final PCMDetectionResult detectionResult = this.blackboard.getPCMDetector() .getResult(); final Set components = detectionResult.getComponents(); - final Map> interfaces = detectionResult.getOperationInterfaces(); + final Map> interfaces = detectionResult.getOperationInterfaces(); final Set composites = detectionResult.getCompositeComponents(); this.createPCMInterfaces(interfaces); @@ -245,8 +243,9 @@ public Repository createPCM(final Map> mapping) { return this.repository.createRepositoryNow(); } - private void createPCMInterfaces(final Map> interfaces) { - final Map signatureNameCount = new HashMap<>(); + private void createPCMInterfaces(final Map> interfaces) { + final Map signatureNameRegistry = new HashMap<>(); + interfaces.forEach((inter, operations) -> { final String interName = inter.getName() .toString(); @@ -260,15 +259,8 @@ private void createPCMInterfaces(final Map 0) { - name = name + "$" + signatureNameCount.get(name); - } OperationSignatureCreator signature = this.create.newOperationSignature() - .withName(name); + .withName(prepareUniquePCMName(name, signatureNameRegistry)); final IMethodBinding method = operation.getBinding(); @@ -301,6 +293,20 @@ private void createPCMInterfaces(final Map registry) { + String pcmName = name.replace(".", "_"); + + Integer numberOfOccurences = registry.getOrDefault(pcmName, 0); + numberOfOccurences += 1; + registry.put(pcmName, numberOfOccurences); + + if (numberOfOccurences == 1) { + // Omit suffix for first occurrence. + return pcmName; + } + return pcmName + "$" + registry.get(name); + } + private Optional getDeclaration(final IMethodBinding binding) { return this.blackboard.getDiscoveredFiles(JAVA_DISCOVERER_ID, CompilationUnit.class) .values() diff --git a/tests/org.palladiosimulator.retriever.test/src/org/palladiosimulator/retriever/test/model/InterfaceTest.java b/tests/org.palladiosimulator.retriever.test/src/org/palladiosimulator/retriever/test/model/InterfaceTest.java index 932b9f62..5b380273 100644 --- a/tests/org.palladiosimulator.retriever.test/src/org/palladiosimulator/retriever/test/model/InterfaceTest.java +++ b/tests/org.palladiosimulator.retriever.test/src/org/palladiosimulator/retriever/test/model/InterfaceTest.java @@ -8,7 +8,6 @@ import java.util.Map; import java.util.Optional; import java.util.Set; -import java.util.SortedSet; import java.util.stream.Collectors; import org.junit.jupiter.api.Test; @@ -38,7 +37,7 @@ void singleJavaOperation() { assertTrue(builtComponent.provisions() .containsPartOf(expectedOperation)); - final Map> simplifiedProvisions = builtComponent.provisions() + final Map> simplifiedProvisions = builtComponent.provisions() .simplified(); final Set interfaces = simplifiedProvisions.keySet(); @@ -49,7 +48,7 @@ void singleJavaOperation() { .get(); assertEquals(expectedOperation, commonInterface, "operation does not have the correct interface"); - final SortedSet operations = simplifiedProvisions.get(expectedOperation); + final Set operations = simplifiedProvisions.get(expectedOperation); assertEquals(1, operations.size(), "more than one operation in the interface"); final List firstMethodCandidates = operations.stream() @@ -77,7 +76,7 @@ void singlePathOperation() { assertTrue(builtComponent.provisions() .containsPartOf(expectedOperation)); - final Map> simplifiedProvisions = builtComponent.provisions() + final Map> simplifiedProvisions = builtComponent.provisions() .simplified(); final Set interfaces = simplifiedProvisions.keySet(); @@ -88,7 +87,7 @@ void singlePathOperation() { .get(); assertEquals(expectedOperation, commonInterface, "operation does not have the correct interface"); - final SortedSet operations = simplifiedProvisions.get(commonInterface); + final Set operations = simplifiedProvisions.get(commonInterface); assertEquals(1, operations.size(), "more than one operation in the interface"); final List firstMethodCandidates = operations.stream() @@ -120,7 +119,7 @@ void entireJavaInterface() { assertTrue(builtComponent.provisions() .containsPartOf(expectedInterface)); - final Map> simplifiedProvisions = builtComponent.provisions() + final Map> simplifiedProvisions = builtComponent.provisions() .simplified(); final Set interfaces = simplifiedProvisions.keySet(); @@ -131,7 +130,7 @@ void entireJavaInterface() { .get(); assertEquals(expectedInterface, commonInterface, "common interface is not correct"); - final SortedSet operations = simplifiedProvisions.get(commonInterface); + final Set operations = simplifiedProvisions.get(commonInterface); assertEquals(2, operations.size(), "wrong number of operations in the interface"); final List firstMethodCandidates = operations.stream() @@ -176,7 +175,7 @@ void entirePathInterface() { assertTrue(builtComponent.provisions() .containsPartOf(expectedInterface)); - final Map> simplifiedProvisions = builtComponent.provisions() + final Map> simplifiedProvisions = builtComponent.provisions() .simplified(); final Set interfaces = simplifiedProvisions.keySet(); @@ -187,7 +186,7 @@ void entirePathInterface() { .get(); assertEquals(expectedInterface, commonInterface, "common interface is not correct"); - final SortedSet operations = simplifiedProvisions.get(commonInterface); + final Set operations = simplifiedProvisions.get(commonInterface); assertEquals(2, operations.size(), "wrong number of operations in the interface"); final List firstMethodCandidates = operations.stream()