Skip to content

Commit

Permalink
fix: Collect data model for Qute doesn't support fluent API (redhat-d…
Browse files Browse the repository at this point in the history
…eveloper#876)

Fixes redhat-developer#876

Signed-off-by: azerr <azerr@redhat.com>
  • Loading branch information
angelozerr committed May 23, 2023
1 parent e756b0b commit 17da7c1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ private Template requireNonNull(Template page2, String string) {
@GET
@Produces(MediaType.TEXT_HTML)
public TemplateInstance get(@QueryParam("name") String name) {
hello.data("age", 12);
hello.data("height", 1.50, "weight", 50L);
return hello.data("name", name);
return hello.data("height", 1.50, "weight", 50L)
.data("age", 12)
.data("name", name);
}

@GET
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package com.redhat.devtools.intellij.qute.psi.internal.template;

import com.intellij.psi.JavaElementVisitor;
import com.intellij.psi.PsiExpression;
import com.intellij.psi.PsiMethod;
import com.intellij.psi.PsiMethodCallExpression;
import com.intellij.psi.*;
import com.intellij.psi.util.PsiTreeUtil;

public abstract class TemplateDataVisitor extends JavaElementVisitor {

Expand All @@ -15,7 +13,9 @@ public abstract class TemplateDataVisitor extends JavaElementVisitor {
public void visitMethodCallExpression(PsiMethodCallExpression node) {
String methodName = node.resolveMethod().getName();
if (DATA_METHOD.equals(methodName)) {
// .data("book", book)
// collect the first data method
// ex : hello.data("height", 1.50, "weight", 50L);
// will collect data model parameters for "height" and "weight"
@SuppressWarnings("rawtypes")
PsiExpression[] arguments = node.getArgumentList().getExpressions();
Object paramName = null;
Expand All @@ -31,6 +31,17 @@ public void visitMethodCallExpression(PsiMethodCallExpression node) {
}
}
}

// Fluent API support
PsiMethodCallExpression nextCallExpression = PsiTreeUtil.getParentOfType(node, PsiMethodCallExpression.class);
if (nextCallExpression != null){
// collect the other data methods
// ex : hello.data("height", 1.50, "weight", 50L)
// .data("age", 12)
// .data("name", name)
// will collect data model parameters for "age" and "name"
visitMethodCallExpression(nextCallExpression);
}
super.visitMethodCallExpression(node);
}

Expand Down

0 comments on commit 17da7c1

Please sign in to comment.