diff --git a/bundles/org.palladiosimulator.retriever.extraction/src/org/palladiosimulator/retriever/extraction/commonalities/DependencyUtils.java b/bundles/org.palladiosimulator.retriever.extraction/src/org/palladiosimulator/retriever/extraction/commonalities/DependencyUtils.java index 6ce2941a..a8af8363 100644 --- a/bundles/org.palladiosimulator.retriever.extraction/src/org/palladiosimulator/retriever/extraction/commonalities/DependencyUtils.java +++ b/bundles/org.palladiosimulator.retriever.extraction/src/org/palladiosimulator/retriever/extraction/commonalities/DependencyUtils.java @@ -44,16 +44,23 @@ public static Map commonInterfaceName = grouplessDependency.getName() + final Optional commonName = grouplessDependency.getName() .getCommonInterface(rootInterface.getName()); boolean containsOtherDependency = false; - if (!commonInterfaceName.isPresent()) { + if (!commonName.isPresent()) { continue; } - final OperationInterface commonInterface = new EntireInterface(rootInterface.getName() - .createInterface(commonInterfaceName.get())); + Name commonInterfaceName = rootInterface.getName() + .createName(commonName.get()); + OperationInterface commonInterface; + + if (commonInterfaceName instanceof RESTOperationName restName) { + commonInterface = new RESTOperationUnion(restName); + } else { + commonInterface = new EntireInterface(commonInterfaceName); + } for (final OperationInterface dependency : allDependencies) { // Check all foreign dependencies @@ -68,8 +75,12 @@ public static Map interfaces = new HashSet<>( groupedDependencies.remove(rootInterface)); - interfaces.add(commonInterface); - interfaces.add(rootInterface); + if (!(commonInterface instanceof RESTOperationUnion)) { + interfaces.add(commonInterface); + } + if (!(rootInterface instanceof RESTOperationUnion)) { + interfaces.add(rootInterface); + } interfaces.add(grouplessDependency); groupedDependencies.put(commonInterface, new ArrayList<>(interfaces)); isRoot = false; 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 0d9b579c..9aef51e4 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 @@ -10,14 +10,14 @@ public class EntireInterface implements OperationInterface { private final Optional binding; - private final InterfaceName name; + private final Name name; - public EntireInterface(final InterfaceName name) { + public EntireInterface(final Name name) { this.binding = Optional.empty(); this.name = name; } - public EntireInterface(final ITypeBinding binding, final InterfaceName name) { + public EntireInterface(final ITypeBinding binding, final Name name) { this.binding = Optional.of(binding); this.name = name; } diff --git a/bundles/org.palladiosimulator.retriever.extraction/src/org/palladiosimulator/retriever/extraction/commonalities/JavaInterfaceName.java b/bundles/org.palladiosimulator.retriever.extraction/src/org/palladiosimulator/retriever/extraction/commonalities/JavaInterfaceName.java index 5f661674..975fef99 100644 --- a/bundles/org.palladiosimulator.retriever.extraction/src/org/palladiosimulator/retriever/extraction/commonalities/JavaInterfaceName.java +++ b/bundles/org.palladiosimulator.retriever.extraction/src/org/palladiosimulator/retriever/extraction/commonalities/JavaInterfaceName.java @@ -21,7 +21,7 @@ public List getInterfaces() { } @Override - public InterfaceName createInterface(final String name) { + public InterfaceName createName(final String name) { return new JavaInterfaceName(name); } diff --git a/bundles/org.palladiosimulator.retriever.extraction/src/org/palladiosimulator/retriever/extraction/commonalities/JavaOperationName.java b/bundles/org.palladiosimulator.retriever.extraction/src/org/palladiosimulator/retriever/extraction/commonalities/JavaOperationName.java index 6b0f35be..8e67a830 100644 --- a/bundles/org.palladiosimulator.retriever.extraction/src/org/palladiosimulator/retriever/extraction/commonalities/JavaOperationName.java +++ b/bundles/org.palladiosimulator.retriever.extraction/src/org/palladiosimulator/retriever/extraction/commonalities/JavaOperationName.java @@ -32,7 +32,7 @@ public String getInterface() { } @Override - public InterfaceName createInterface(final String name) { + public InterfaceName createName(final String name) { return new JavaInterfaceName(name); } diff --git a/bundles/org.palladiosimulator.retriever.extraction/src/org/palladiosimulator/retriever/extraction/commonalities/Name.java b/bundles/org.palladiosimulator.retriever.extraction/src/org/palladiosimulator/retriever/extraction/commonalities/Name.java index b87002e7..e39ed20a 100644 --- a/bundles/org.palladiosimulator.retriever.extraction/src/org/palladiosimulator/retriever/extraction/commonalities/Name.java +++ b/bundles/org.palladiosimulator.retriever.extraction/src/org/palladiosimulator/retriever/extraction/commonalities/Name.java @@ -6,7 +6,7 @@ import java.util.Set; public interface Name { - InterfaceName createInterface(String name); + Name createName(String name); /** * @returns interfaces that this name is part of, sorted from specific to general. 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 0ff8d74d..a2a78fa5 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 @@ -24,6 +24,15 @@ public OperationName getName() { return this.name; } + @Override + public boolean isPartOf(final OperationInterface other) { + if (other instanceof Operation otherOperation) { + return Objects.equals(this.binding, otherOperation.binding); + } else { + return OperationInterface.super.isPartOf(other); + } + } + @Override public Map> simplified() { return Map.of(this, Set.of(this)); diff --git a/bundles/org.palladiosimulator.retriever.extraction/src/org/palladiosimulator/retriever/extraction/commonalities/RESTName.java b/bundles/org.palladiosimulator.retriever.extraction/src/org/palladiosimulator/retriever/extraction/commonalities/RESTName.java index 42945d0a..f74a430f 100644 --- a/bundles/org.palladiosimulator.retriever.extraction/src/org/palladiosimulator/retriever/extraction/commonalities/RESTName.java +++ b/bundles/org.palladiosimulator.retriever.extraction/src/org/palladiosimulator/retriever/extraction/commonalities/RESTName.java @@ -57,7 +57,7 @@ public List getInterfaces() { } @Override - public InterfaceName createInterface(final String name) { + public InterfaceName createName(final String name) { return parse(name).orElseThrow(); } @@ -164,6 +164,10 @@ public boolean isPartOf(final String iface) { } public static Optional parse(final String iface) { + if (iface.contains("[")) { + // If a HTTP method is present, iface is not a RESTName. + return Optional.empty(); + } final Optional> interfacePathOption = parsePath(iface); if (interfacePathOption.isEmpty()) { return Optional.empty(); diff --git a/bundles/org.palladiosimulator.retriever.extraction/src/org/palladiosimulator/retriever/extraction/commonalities/RESTOperationName.java b/bundles/org.palladiosimulator.retriever.extraction/src/org/palladiosimulator/retriever/extraction/commonalities/RESTOperationName.java index e2590bf7..101bd10a 100644 --- a/bundles/org.palladiosimulator.retriever.extraction/src/org/palladiosimulator/retriever/extraction/commonalities/RESTOperationName.java +++ b/bundles/org.palladiosimulator.retriever.extraction/src/org/palladiosimulator/retriever/extraction/commonalities/RESTOperationName.java @@ -55,8 +55,8 @@ public List getInterfaces() { } @Override - public InterfaceName createInterface(final String name) { - return RESTName.parse(name) + public Name createName(final String name) { + return RESTOperationName.parse(name) .orElseThrow(); } @@ -113,6 +113,11 @@ public Optional getCommonInterface(final Name other) { @Override public boolean isPartOf(final String iface) { + if (RESTName.parse(iface) + .isPresent()) { + return restName.isPartOf(iface); + } + Optional parsedIface = parse(iface); if (parsedIface.isEmpty()) { return false; @@ -120,14 +125,14 @@ public boolean isPartOf(final String iface) { RESTOperationName restIface = parsedIface.get(); - if (!this.restName.isPartOf(restIface.restName.toString())) { + if (!this.restName.equals(restIface.restName)) { return false; } Set normalHttpMethods = new HashSet<>(this.httpMethods); normalHttpMethods.remove(HTTPMethod.WILDCARD); - if (this.restName.equals(restIface.restName) && !restIface.httpMethods.contains(HTTPMethod.WILDCARD) + if (!restIface.httpMethods.contains(HTTPMethod.WILDCARD) && !restIface.httpMethods.containsAll(this.httpMethods)) { return false; } diff --git a/bundles/org.palladiosimulator.retriever.extraction/src/org/palladiosimulator/retriever/extraction/commonalities/RESTOperationUnion.java b/bundles/org.palladiosimulator.retriever.extraction/src/org/palladiosimulator/retriever/extraction/commonalities/RESTOperationUnion.java index 8c5ab9cd..bae45f1f 100644 --- a/bundles/org.palladiosimulator.retriever.extraction/src/org/palladiosimulator/retriever/extraction/commonalities/RESTOperationUnion.java +++ b/bundles/org.palladiosimulator.retriever.extraction/src/org/palladiosimulator/retriever/extraction/commonalities/RESTOperationUnion.java @@ -1,6 +1,7 @@ package org.palladiosimulator.retriever.extraction.commonalities; import java.util.Map; +import java.util.Objects; import java.util.Set; public class RESTOperationUnion implements OperationInterface { @@ -24,4 +25,30 @@ public Map> simplified() { public String getInterface() { return name.getInterface(); } + + @Override + public String toString() { + return name.toString(); + } + + @Override + public int hashCode() { + return Objects.hash(name); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + RESTOperationUnion other = (RESTOperationUnion) obj; + return Objects.equals(name, other.name); + } + }