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

Extract resource name for http filters #27861

Closed
wants to merge 1 commit into from
Closed
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 @@ -53,6 +53,7 @@
import org.wso2.ballerinalang.compiler.tree.BLangIdentifier;
import org.wso2.ballerinalang.compiler.tree.BLangImportPackage;
import org.wso2.ballerinalang.compiler.tree.BLangNode;
import org.wso2.ballerinalang.compiler.tree.BLangResourceFunction;
import org.wso2.ballerinalang.compiler.tree.BLangSimpleVariable;
import org.wso2.ballerinalang.compiler.tree.expressions.BLangBinaryExpr;
import org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression;
Expand Down Expand Up @@ -201,7 +202,7 @@ private BLangSimpleVariable addFilterContextCreation(BLangFunction resourceNode,
serviceRef.pos = resourceNode.pos;

BLangLiteral resourceName = new BLangLiteral();
resourceName.value = resourceNode.name.value;
resourceName.value = extractResourceName(resourceNode);
resourceName.type = symTable.stringType;
resourceName.pos = resourceNode.pos;

Expand Down Expand Up @@ -233,6 +234,11 @@ private BLangSimpleVariable addFilterContextCreation(BLangFunction resourceNode,
return filterContextVar;
}

private String extractResourceName(BLangFunction resourceNode) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this method supposed to extract the resource paths?
say we have a resource function such as resource function get foo/bar/[int i]/[int j]() { } what is the expected behavior?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The objective of this function is to extract the resource name by removing the accessor part attached to it. The expected value for the given resource signature is "foo$bar$*$*" and this function returns that.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ack, I was confused with the term resourceName as resource functions doesn't have a name anymore. Shall we concatenate the text parts of this instead of removing from the generated string.

String resourceName = resourceNode.name.value;
return resourceName.replace("$" + ((BLangResourceFunction) resourceNode).accessorName.value + "$", "");
}

private void addStatementToResourceBody(BLangFunctionBody body, BLangStatement stmt, int index) {
NodeKind bodyKind = body.getKind();

Expand Down