From 9eb51ef54f7b9ce7e37571c77885b4618ac4cdc2 Mon Sep 17 00:00:00 2001 From: Florian Bossert Date: Mon, 22 Apr 2024 13:49:03 +0200 Subject: [PATCH] Support multiple routes per file and HTTP method --- .../extraction/rules/EcmaScriptRules.xtend | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/bundles/org.palladiosimulator.retriever.extraction.rules/src/org/palladiosimulator/retriever/extraction/rules/EcmaScriptRules.xtend b/bundles/org.palladiosimulator.retriever.extraction.rules/src/org/palladiosimulator/retriever/extraction/rules/EcmaScriptRules.xtend index 7a586c6b..d11242f7 100644 --- a/bundles/org.palladiosimulator.retriever.extraction.rules/src/org/palladiosimulator/retriever/extraction/rules/EcmaScriptRules.xtend +++ b/bundles/org.palladiosimulator.retriever.extraction.rules/src/org/palladiosimulator/retriever/extraction/rules/EcmaScriptRules.xtend @@ -85,8 +85,7 @@ class EcmaScriptRules implements Rule { if (!mappedURL.isPartOf("/" + hostname)) { pcmDetector.detectRequiredInterface(GATEWAY_NAME, mappedURL) } - pcmDetector.detectProvidedOperation(GATEWAY_NAME, null, - new RESTOperationName(hostname, "/" + url)) + pcmDetector.detectProvidedOperation(GATEWAY_NAME, null, new RESTOperationName(hostname, "/" + url)) } } } @@ -121,7 +120,7 @@ class EcmaScriptRules implements Rule { return normalizedRequests } - def findDirectHttpRequest(Tree element) { + def Map> findDirectHttpRequest(Tree element) { val calls = new HashMap() element.accept(new SimpleTreeVisitorES6() { override visitFunctionCall(FunctionCallTree node, Void v) { @@ -137,7 +136,11 @@ class EcmaScriptRules implements Rule { val caller = identifier.getName() + SEPARATOR + member.getIdentifier() val urls = findLiteralsInArguments(node.getArguments()) if (!urls.isEmpty()) { - calls.put(caller, urls) + if (calls.containsKey(caller)) { + calls.get(caller).addAll(urls) + } else { + calls.put(caller, urls) + } } } return super.visitFunctionCall(node, null) @@ -180,13 +183,17 @@ class EcmaScriptRules implements Rule { return calls; } - def findFunctionDeclarationsWithUrls(Tree element) { + def Map> findFunctionDeclarationsWithUrls(Tree element) { val declarations = new HashMap(); element.accept(new SimpleTreeVisitorES6() { override visitFunctionDeclaration(FunctionDeclarationTree functionDeclaration, Void v) { val urls = findLiteralsForIdentifier(functionDeclaration, URL_KEYWORD) if (!urls.empty) { - declarations.put(functionDeclaration.name.name, urls) + if (declarations.containsKey(functionDeclaration)) { + declarations.get(functionDeclaration.name.name).addAll(urls) + } else { + declarations.put(functionDeclaration.name.name, urls) + } } return super.visitFunctionDeclaration(functionDeclaration, null) }