Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove redundant interfaces #68

Merged
merged 5 commits into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import org.palladiosimulator.retriever.extraction.commonalities.CompUnitOrName
import org.palladiosimulator.retriever.extraction.engine.Rule
import org.palladiosimulator.retriever.extraction.rules.data.GatewayRoute
import org.palladiosimulator.retriever.extraction.blackboard.RetrieverBlackboard
import org.palladiosimulator.retriever.extraction.commonalities.HTTPMethod
import org.palladiosimulator.retriever.extraction.commonalities.RESTOperationName

class EcmaScriptRules implements Rule {

Expand Down Expand Up @@ -86,7 +86,7 @@ class EcmaScriptRules implements Rule {
pcmDetector.detectRequiredInterface(GATEWAY_NAME, mappedURL)
}
pcmDetector.detectProvidedOperation(GATEWAY_NAME, null,
new RESTName(hostname, "/" + url, HTTPMethod.any))
new RESTOperationName(hostname, "/" + url))
}
}
}
Expand Down Expand Up @@ -279,7 +279,7 @@ class EcmaScriptRules implements Rule {
return route.applyTo(url)
}
}
return new RESTName(host, url, HTTPMethod.any)
return new RESTName(host, url)
}

override isBuildRule() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import static org.palladiosimulator.retriever.extraction.engine.RuleHelper.*
import org.palladiosimulator.retriever.extraction.commonalities.CompUnitOrName
import java.util.Set
import org.palladiosimulator.retriever.extraction.engine.Rule
import org.palladiosimulator.retriever.extraction.commonalities.RESTName
import org.palladiosimulator.retriever.extraction.rules.util.RESTHelper
import java.util.Map
import org.palladiosimulator.retriever.extraction.commonalities.HTTPMethod
import org.palladiosimulator.retriever.extraction.blackboard.RetrieverBlackboard
import org.palladiosimulator.retriever.extraction.commonalities.RESTOperationName

class JaxRSRules implements Rule {

Expand Down Expand Up @@ -67,7 +67,7 @@ class JaxRSRules implements Rule {
methodPath = RESTHelper.replaceArgumentsWithWildcards(methodPath)
// TODO: HTTP method switch-case
pcmDetector.detectCompositeProvidedOperation(identifier, m.resolveBinding,
new RESTName("SERVICE-HOST", methodPath, HTTPMethod.all))
new RESTOperationName("SERVICE-HOST", methodPath))
}
]
getFields(unit).forEach[f|pcmDetector.detectRequiredInterfaceWeakly(identifier, f)]
Expand All @@ -82,7 +82,7 @@ class JaxRSRules implements Rule {
getMethods(unit).forEach [ m |
if (SERVLET_METHODS.containsKey(m.name.identifier)) {
pcmDetector.detectProvidedOperation(identifier, m.resolveBinding,
new RESTName("SERVICE-HOST", path, Set.of(SERVLET_METHODS.get(m.name.identifier))))
new RESTOperationName("SERVICE-HOST", path, Set.of(SERVLET_METHODS.get(m.name.identifier))))
}
]
getFields(unit).forEach[f|pcmDetector.detectRequiredInterfaceWeakly(identifier, f)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import org.palladiosimulator.retriever.extraction.engine.Rule
import org.palladiosimulator.retriever.extraction.rules.util.SpringHelper
import org.palladiosimulator.retriever.extraction.rules.util.RESTHelper
import org.palladiosimulator.retriever.extraction.blackboard.RetrieverBlackboard
import org.palladiosimulator.retriever.extraction.commonalities.RESTOperationName

class SpringRules implements Rule {
static final Logger LOG = Logger.getLogger(SpringRules)
Expand Down Expand Up @@ -188,7 +189,7 @@ class SpringRules implements Rule {
methodName = RESTHelper.replaceArgumentsWithWildcards(methodName);
val httpMethod = getHTTPMethod(m);
pcmDetector.detectCompositeProvidedOperation(identifier, m.resolveBinding,
new RESTName(applicationName, methodName, httpMethod));
new RESTOperationName(applicationName, methodName, httpMethod));
}
}
}
Expand All @@ -210,9 +211,10 @@ class SpringRules implements Rule {
requestedMapping = substituteVariables(requestedMapping, contextVariables);
var methodName = ifaceName + "/" + requestedMapping;
methodName = RESTHelper.replaceArgumentsWithWildcards(methodName);
val httpMethod = getHTTPMethod(m);
// Ignore HTTPMethod, only entire interfaces can be required right now.
// TODO: Find a way around this.
pcmDetector.detectCompositeRequiredInterface(identifier,
new RESTName(serviceIdentifier, methodName, httpMethod));
new RESTName(serviceIdentifier, methodName));
}
}
}
Expand Down Expand Up @@ -292,32 +294,32 @@ class SpringRules implements Rule {
def getHTTPMethod(MethodDeclaration m) {
val requestMapping = getMappingString(m, "RequestMapping");
if (requestMapping !== null) {
return HTTPMethod.any();
return HTTPMethod.WILDCARD;
}

val getMapping = getMappingString(m, "GetMapping");
if (getMapping !== null) {
return Set.of(HTTPMethod.GET);
return HTTPMethod.GET;
}

val postMapping = getMappingString(m, "PostMapping");
if (postMapping !== null) {
return Set.of(HTTPMethod.POST);
return HTTPMethod.POST;
}

val putMapping = getMappingString(m, "PutMapping");
if (putMapping !== null) {
return Set.of(HTTPMethod.PUT);
return HTTPMethod.PUT;
}

val deleteMapping = getMappingString(m, "DeleteMapping");
if (deleteMapping !== null) {
return Set.of(HTTPMethod.DELETE);
return HTTPMethod.DELETE;
}

val patchMapping = getMappingString(m, "PatchMapping");
if (patchMapping !== null) {
return Set.of(HTTPMethod.PATCH);
return HTTPMethod.PATCH;
}

return null;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.palladiosimulator.retriever.extraction.rules.data

import org.palladiosimulator.retriever.extraction.commonalities.RESTName
import org.palladiosimulator.retriever.extraction.commonalities.HTTPMethod

class GatewayRoute {
static final String TRAILING_WILDCARD = "/**"
Expand Down Expand Up @@ -42,7 +41,7 @@ class GatewayRoute {
val newUrlSegments = urlSegments.subList(stripPrefixLength, urlSegments.length)
newUrl = toPath(newUrlSegments)
}
return new RESTName(targetHost, newUrl, HTTPMethod.any)
return new RESTName(targetHost, newUrl)
}

private static def calculateStripPrefixLength(String pathPattern) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,32 +44,44 @@ public static <T extends OperationInterface> Map<OperationInterface, List<Operat
}
if (isRoot) {
for (final OperationInterface rootInterface : groupedDependencies.keySet()) {
final Optional<String> commonInterfaceName = grouplessDependency.getName()
final Optional<String> 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
if (!dependencies.contains(dependency)) {
// If a foreign dependency is part of the new common interface, it must
// not be created
containsOtherDependency |= dependency.isPartOf(commonInterface);
containsOtherDependency |= dependency.isPartOf(commonInterface)
&& !commonInterface.isPartOf(dependency);
}
}

if (!containsOtherDependency) {
// De-duplicate interfaces.
final Set<OperationInterface> 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@

public class EntireInterface implements OperationInterface {
private final Optional<ITypeBinding> 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;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
package org.palladiosimulator.retriever.extraction.commonalities;

import java.util.Collection;
import java.util.HashSet;
import java.util.Set;

public enum HTTPMethod {
GET, POST, PUT, DELETE, PATCH;
GET, POST, PUT, DELETE, PATCH,
/**
* Special value signaling all HTTPMethods are provided/required.
*/
WILDCARD;

public static boolean areAllPresent(Collection<HTTPMethod> httpMethods) {
return httpMethods.containsAll(all());
}

public static Set<HTTPMethod> all() {
return Set.of(values());
}
if (httpMethods.contains(HTTPMethod.WILDCARD)) {
return true;
}

public static Set<HTTPMethod> any() {
return Set.of();
Set<HTTPMethod> normalValues = new HashSet<>(Set.of(values()));
normalValues.remove(WILDCARD);
return httpMethods.containsAll(normalValues);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public List<String> getInterfaces() {
}

@Override
public InterfaceName createInterface(final String name) {
public InterfaceName createName(final String name) {
return new JavaInterfaceName(name);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public String getInterface() {
}

@Override
public InterfaceName createInterface(final String name) {
public InterfaceName createName(final String name) {
return new JavaInterfaceName(name);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ public OperationName getName() {
return this.name;
}

@Override
public boolean isPartOf(final OperationInterface other) {
if (other instanceof Operation otherOperation) {
return this.equals(other);
} else {
return OperationInterface.super.isPartOf(other);
}
}

@Override
public Map<OperationInterface, Set<Operation>> simplified() {
return Map.of(this, Set.of(this));
Expand Down
Loading
Loading