Skip to content

Commit

Permalink
Support ? in parameter let section
Browse files Browse the repository at this point in the history
Fixes redhat-developer#904

Signed-off-by: azerr <azerr@redhat.com>
  • Loading branch information
angelozerr committed Jul 20, 2023
1 parent e9f7d94 commit 63c4341
Show file tree
Hide file tree
Showing 15 changed files with 103 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ public class Parameter extends Node implements JavaTypeInfoProvider {
private int startName;

private int endName;

private int startValue = -1;

private int endValue = -1;
Expand Down Expand Up @@ -108,7 +107,17 @@ public String getName() {
}
}
if (name == null) {
name = getText(getStartName(), getEndName());
int endName = getEndName();
Section section = getOwnerSection();
if (section != null && section.getSectionKind() == SectionKind.LET) {
String text = getOwnerTemplate().getText();
if (text.charAt(endName - 1) == '?') {
// ex : {#let name?"=main"}
// name? --> name
endName--;
}
}
name = getText(getStartName(), endName);
}
return name;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,14 @@ public class QuteAssert {

private static final String FILE_URI = "test.qute";

public static final int USER_TAG_SIZE = 8 /*
* #input, #form, #title, #simpleTitle, #user, #formElement,
public static final int USER_TAG_SIZE = 9 /*
* #input, #bundleStyle, #form, #title, #simpleTitle, #user, #formElement,
* #inputRequired, #myTag
*/;

public static final int SECTION_SNIPPET_SIZE = 15 /* #each, #for, ... #fragment ... */ + USER_TAG_SIZE;

public static final int RESOLVERS_SIZE = 9;
public static final int RESOLVERS_SIZE = 10;

public static String getFileUri(String templateFile) {
return Paths.get(TEMPLATE_BASE_DIR + templateFile).toUri().toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ protected List<ValueResolverInfo> createValueResolvers() {
"property(propertyName : java.lang.String) : java.lang.Object",
ValueResolverKind.TemplateExtensionOnMethod, false, true));

// Static meythod value resolvers
// Static method value resolvers
resolvers.add(createValueResolver(null, "VARCHAR_SIZE", null, "util.Globals", "VARCHAR_SIZE() : int",
ValueResolverKind.TemplateGlobal, true));

Expand All @@ -506,6 +506,10 @@ protected List<ValueResolverInfo> createValueResolvers() {
resolvers.add(createValueResolver("uri", "Login", null, "rest.Login", "rest.Login",
ValueResolverKind.Renarde, false, false));

// Web bundler 'bundle" field as global
resolvers.add(createValueResolver(null, "bundle", null, "util.Globals", "bundle : java.util.Map<java.lang.String,java.lang.String>",
ValueResolverKind.TemplateGlobal, true));

// Type-safe Message Bundles support
ValueResolverInfo hello_name = createValueResolver("msg", null, null, "org.acme.AppMessages",
"hello_name(name : java.lang.String) : java.lang.String",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,8 @@ public void completionInExpressionWithOnlyStartBracket() throws Exception {
c("VARCHAR_SIZE", "VARCHAR_SIZE", r(1, 7, 1, 7)), //
c("uri:Login", "uri:Login", r(1, 7, 1, 7)), //
c("msg:hello_name(name : String) : String", "msg:hello_name(${1:name})$0", r(1, 7, 1, 7)), //
c("msg2:hello() : String", "msg2:hello", r(1, 7, 1, 7)));
c("msg2:hello() : String", "msg2:hello", r(1, 7, 1, 7)), //
c("bundle", "bundle", r(1, 7, 1, 7)));
}

@Test
Expand Down Expand Up @@ -343,7 +344,8 @@ public void noCompletionInsideSeveralBrackets() throws Exception {
c("VARCHAR_SIZE", "VARCHAR_SIZE", r(1, 9, 1, 9)), //
c("uri:Login", "uri:Login", r(1, 9, 1, 9)), //
c("msg:hello_name(name : String) : String", "msg:hello_name(${1:name})$0", r(1, 9, 1, 9)), //
c("msg2:hello() : String", "msg2:hello", r(1, 9, 1, 9)));
c("msg2:hello() : String", "msg2:hello", r(1, 9, 1, 9)), //
c("bundle", "bundle", r(1, 9, 1, 9)));
}

@Test
Expand Down Expand Up @@ -382,8 +384,8 @@ public void globalVariablesObjectPart() throws Exception {
c("VARCHAR_SIZE", "VARCHAR_SIZE", r(0, 1, 0, 1)), //
c("uri:Login", "uri:Login", r(0, 1, 0, 1)), //
c("msg:hello_name(name : String) : String", "msg:hello_name(${1:name})$0", r(0, 1, 0, 1)), //
c("msg2:hello() : String", "msg2:hello", r(0, 1, 0, 1)));

c("msg2:hello() : String", "msg2:hello", r(0, 1, 0, 1)), //
c("bundle", "bundle", r(0, 1, 0, 1)));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,8 @@ public void inIterable() throws Exception {
c("VARCHAR_SIZE", "VARCHAR_SIZE", r(2, 7, 2, 7)), //
c("uri:Login", "uri:Login", r(2, 7, 2, 7)), //
c("msg:hello_name(name : String) : String", "msg:hello_name(${1:name})$0", r(2, 7, 2, 7)), //
c("msg2:hello() : String", "msg2:hello", r(2, 7, 2, 7)));
c("msg2:hello() : String", "msg2:hello", r(2, 7, 2, 7)), //
c("bundle", "bundle", r(2, 7, 2, 7)));

template = "{@java.util.List<org.acme.Item> items}\r\n" + //
" \r\n" + //
Expand All @@ -221,7 +222,8 @@ public void inIterable() throws Exception {
c("VARCHAR_SIZE", "VARCHAR_SIZE", r(2, 7, 2, 7)), //
c("uri:Login", "uri:Login", r(2, 7, 2, 7)), //
c("msg:hello_name(name : String) : String", "msg:hello_name(${1:name})$0", r(2, 7, 2, 7)), //
c("msg2:hello() : String", "msg2:hello", r(2, 7, 2, 7)));
c("msg2:hello() : String", "msg2:hello", r(2, 7, 2, 7)), //
c("bundle", "bundle", r(2, 7, 2, 7)));

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,8 @@ public void noCompletionInElseBlock() throws Exception {
c("VARCHAR_SIZE", "VARCHAR_SIZE", r(4, 2, 4, 2)), //
c("uri:Login", "uri:Login", r(4, 2, 4, 2)), //
c("msg:hello_name(name : String) : String", "msg:hello_name(${1:name})$0", r(4, 2, 4, 2)),//
c("msg2:hello() : String", "msg2:hello", r(4, 2, 4, 2)));
c("msg2:hello() : String", "msg2:hello", r(4, 2, 4, 2)), //
c("bundle", "bundle", r(4, 2, 4, 2)));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ public void completionInMethodParameter() throws Exception {
c("VARCHAR_SIZE", "VARCHAR_SIZE", r(1, 13, 1, 14)), //
c("uri:Login", "uri:Login", r(1, 13, 1, 14)), //
c("msg:hello_name(name : String) : String", "msg:hello_name(${1:name})$0", r(1, 13, 1, 14)),//
c("msg2:hello() : String", "msg2:hello", r(1, 13, 1, 14)));
c("msg2:hello() : String", "msg2:hello", r(1, 13, 1, 14)), //
c("bundle", "bundle", r(1, 13, 1, 14)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ public void dataNamespace() throws Exception {
c("VARCHAR_SIZE", "VARCHAR_SIZE", r(2, 3, 2, 3)), //
c("uri:Login", "uri:Login", r(2, 3, 2, 3)), //
c("msg:hello_name(name : String) : String", "msg:hello_name(${1:name})$0", r(2, 3, 2, 3)), //
c("msg2:hello() : String", "msg2:hello", r(2, 3, 2, 3)));
c("msg2:hello() : String", "msg2:hello", r(2, 3, 2, 3)), //
c("bundle", "bundle", r(2, 3, 2, 3)));

template = "{@org.acme.Item item}\r\n" + //
"{#let name=123 }\r\n" + //
Expand Down Expand Up @@ -126,7 +127,8 @@ public void namespaceResolver() throws Exception {
c("VARCHAR_SIZE", "VARCHAR_SIZE", r(0, 1, 0, 1)), //
c("uri:Login", "uri:Login", r(0, 1, 0, 1)), //
c("msg:hello_name(name : String) : String", "msg:hello_name(${1:name})$0", r(0, 1, 0, 1)), //
c("msg2:hello() : String", "msg2:hello", r(0, 1, 0, 1)));
c("msg2:hello() : String", "msg2:hello", r(0, 1, 0, 1)), //
c("bundle", "bundle", r(0, 1, 0, 1)));
}

@Test
Expand Down Expand Up @@ -158,7 +160,8 @@ public void orpheanColonSpace() throws Exception {
c("VARCHAR_SIZE", "VARCHAR_SIZE", r(0, 10, 0, 10)), //
c("uri:Login", "uri:Login", r(0, 10, 0, 10)), //
c("msg:hello_name(name : String) : String", "msg:hello_name(${1:name})$0", r(0, 10, 0, 10)), //
c("msg2:hello() : String", "msg2:hello", r(0, 10, 0, 10)));
c("msg2:hello() : String", "msg2:hello", r(0, 10, 0, 10)), //
c("bundle", "bundle", r(0, 10, 0, 10)));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ public void elvisOperator() throws Exception {
c("VARCHAR_SIZE", "VARCHAR_SIZE", r(1, 14, 1, 14)), //
c("uri:Login", "uri:Login", r(1, 14, 1, 14)), //
c("msg:hello_name(name : String) : String", "msg:hello_name(${1:name})$0", r(1, 14, 1, 14)),//
c("msg2:hello() : String", "msg2:hello", r(1, 14, 1, 14)));
c("msg2:hello() : String", "msg2:hello", r(1, 14, 1, 14)), //
c("bundle", "bundle", r(1, 14, 1, 14)));

template = "{@org.acme.Item item}\r\n" + //
"{item.name ?: item.name :|}";
Expand All @@ -114,7 +115,8 @@ public void elvisOperator() throws Exception {
c("VARCHAR_SIZE", "VARCHAR_SIZE", r(1, 25, 1, 25)), //
c("uri:Login", "uri:Login", r(1, 25, 1, 25)), //
c("msg:hello_name(name : String) : String", "msg:hello_name(${1:name})$0", r(1, 25, 1, 25)),//
c("msg2:hello() : String", "msg2:hello", r(1, 25, 1, 25)));
c("msg2:hello() : String", "msg2:hello", r(1, 25, 1, 25)), //
c("bundle", "bundle", r(1, 25, 1, 25)));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ public void openBracket() throws Exception {
c("GLOBAL", "GLOBAL", r(0, 1, 0, 1)), //
c("VARCHAR_SIZE", "VARCHAR_SIZE", r(0, 1, 0, 1)), //
c("uri:Login", "uri:Login", r(0, 1, 0, 1)), //
c("msg:hello_name(name : String) : String", "msg:hello_name(name)", r(0, 1, 0, 1)),//
c("msg2:hello() : String", "msg2:hello", r(0, 1, 0, 1)));
c("msg:hello_name(name : String) : String", "msg:hello_name(name)", r(0, 1, 0, 1)), //
c("msg2:hello() : String", "msg2:hello", r(0, 1, 0, 1)), //
c("bundle", "bundle", r(0, 1, 0, 1)));

// With snippet support
testCompletionFor(template, //
Expand All @@ -57,8 +58,9 @@ public void openBracket() throws Exception {
c("GLOBAL", "GLOBAL", r(0, 1, 0, 1)), //
c("VARCHAR_SIZE", "VARCHAR_SIZE", r(0, 1, 0, 1)), //
c("uri:Login", "uri:Login", r(0, 1, 0, 1)), //
c("msg:hello_name(name : String) : String", "msg:hello_name(${1:name})$0", r(0, 1, 0, 1)),//
c("msg2:hello() : String", "msg2:hello", r(0, 1, 0, 1)));
c("msg:hello_name(name : String) : String", "msg:hello_name(${1:name})$0", r(0, 1, 0, 1)), //
c("msg2:hello() : String", "msg2:hello", r(0, 1, 0, 1)), //
c("bundle", "bundle", r(0, 1, 0, 1)));
}

@Test
Expand All @@ -76,8 +78,9 @@ public void openAndCloseBracket() throws Exception {
c("GLOBAL", "GLOBAL", r(0, 1, 0, 1)), //
c("VARCHAR_SIZE", "VARCHAR_SIZE", r(0, 1, 0, 1)), //
c("uri:Login", "uri:Login", r(0, 1, 0, 1)), //
c("msg:hello_name(name : String) : String", "msg:hello_name(name)", r(0, 1, 0, 1)),//
c("msg2:hello() : String", "msg2:hello", r(0, 1, 0, 1)));
c("msg:hello_name(name : String) : String", "msg:hello_name(name)", r(0, 1, 0, 1)), //
c("msg2:hello() : String", "msg2:hello", r(0, 1, 0, 1)), //
c("bundle", "bundle", r(0, 1, 0, 1)));

// With snippet support
testCompletionFor(template, //
Expand All @@ -91,8 +94,9 @@ public void openAndCloseBracket() throws Exception {
c("GLOBAL", "GLOBAL", r(0, 1, 0, 1)), //
c("VARCHAR_SIZE", "VARCHAR_SIZE", r(0, 1, 0, 1)), //
c("uri:Login", "uri:Login", r(0, 1, 0, 1)), //
c("msg:hello_name(name : String) : String", "msg:hello_name(${1:name})$0", r(0, 1, 0, 1)),//
c("msg2:hello() : String", "msg2:hello", r(0, 1, 0, 1)));
c("msg:hello_name(name : String) : String", "msg:hello_name(${1:name})$0", r(0, 1, 0, 1)), //
c("msg2:hello() : String", "msg2:hello", r(0, 1, 0, 1)), //
c("bundle", "bundle", r(0, 1, 0, 1)));
}

@Test
Expand All @@ -110,8 +114,9 @@ public void openAndCloseBracketWithSpaces() throws Exception {
c("GLOBAL", "GLOBAL", r(0, 1, 0, 1)), //
c("VARCHAR_SIZE", "VARCHAR_SIZE", r(0, 1, 0, 1)), //
c("uri:Login", "uri:Login", r(0, 1, 0, 1)), //
c("msg:hello_name(name : String) : String", "msg:hello_name(name)", r(0, 1, 0, 1)),//
c("msg2:hello() : String", "msg2:hello", r(0, 1, 0, 1)));
c("msg:hello_name(name : String) : String", "msg:hello_name(name)", r(0, 1, 0, 1)), //
c("msg2:hello() : String", "msg2:hello", r(0, 1, 0, 1)), //
c("bundle", "bundle", r(0, 1, 0, 1)));

// With snippet support
testCompletionFor(template, //
Expand All @@ -125,8 +130,9 @@ public void openAndCloseBracketWithSpaces() throws Exception {
c("GLOBAL", "GLOBAL", r(0, 1, 0, 1)), //
c("VARCHAR_SIZE", "VARCHAR_SIZE", r(0, 1, 0, 1)), //
c("uri:Login", "uri:Login", r(0, 1, 0, 1)), //
c("msg:hello_name(name : String) : String", "msg:hello_name(${1:name})$0", r(0, 1, 0, 1)),//
c("msg2:hello() : String", "msg2:hello", r(0, 1, 0, 1)));
c("msg:hello_name(name : String) : String", "msg:hello_name(${1:name})$0", r(0, 1, 0, 1)), //
c("msg2:hello() : String", "msg2:hello", r(0, 1, 0, 1)), //
c("bundle", "bundle", r(0, 1, 0, 1)));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,18 @@ public void specialKeys() throws Exception {
c("GLOBAL", "GLOBAL", r(1, 1, 1, 1)), //
c("VARCHAR_SIZE", "VARCHAR_SIZE", r(1, 1, 1, 1)), //
c("uri:Login", "uri:Login", r(1, 1, 1, 1)), //
c("msg:hello_name(name : String) : String", "msg:hello_name(${1:name})$0", r(1, 1, 1, 1)),//
c("msg2:hello() : String", "msg2:hello", r(1, 1, 1, 1)));
c("msg:hello_name(name : String) : String", "msg:hello_name(${1:name})$0", r(1, 1, 1, 1)), //
c("msg2:hello() : String", "msg2:hello", r(1, 1, 1, 1)), //
c("bundle", "bundle", r(1, 1, 1, 1)));

// In user tag
testCompletionFor(template, //
"src/main/resources/templates/tags/form.html", //
"tags/form", //
RESOLVERS_SIZE /* item, inject:bean, config:getConfigProperty */ + 2 /* it, nested-content */ + 1 /*
* global
* variables
*/, //
* global
* variables
*/, //
c("item", "item", r(1, 1, 1, 1)), //
c("inject:bean", "inject:bean", r(1, 1, 1, 1)), //
c("inject:plexux", "inject:plexux", r(1, 1, 1, 1)), //
Expand All @@ -64,8 +65,9 @@ public void specialKeys() throws Exception {
c("it", "it", r(1, 1, 1, 1)), //
c("nested-content", "nested-content", r(1, 1, 1, 1)), //
c("uri:Login", "uri:Login", r(1, 1, 1, 1)), //
c("msg:hello_name(name : String) : String", "msg:hello_name(name)", r(1, 1, 1, 1)),//
c("msg2:hello() : String", "msg2:hello", r(1, 1, 1, 1)));
c("msg:hello_name(name : String) : String", "msg:hello_name(name)", r(1, 1, 1, 1)), //
c("msg2:hello() : String", "msg2:hello", r(1, 1, 1, 1)), //
c("bundle", "bundle", r(1, 1, 1, 1)));

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public void includeTemplateIds() throws Exception {
// Without snippet
testCompletionFor(template, //
false, // no snippet support
14 /* all files from src/test/resources/templates */ - 1 /* README.md */ - USER_TAG_SIZE, //
15 /* all files from src/test/resources/templates */ - 1 /* README.md */ - USER_TAG_SIZE, //
c("base", "base", r(0, 10, 0, 10)),
c("test.json", "test.json", r(0, 10, 0, 10)),
c("test.html", "test.html", r(0, 10, 0, 10)),
Expand All @@ -55,7 +55,7 @@ public void includeTemplateIdsSelf() throws Exception {
testCompletionFor(template, //
"src/test/resources/templates/base.html",
false, // no snippet support
14 /* all files from src/test/resources/templates */ - 1 /* base.html */ - 1 /* README.md */
15 /* all files from src/test/resources/templates */ - 1 /* base.html */ - 1 /* README.md */
- USER_TAG_SIZE, //
// c("base", "base", r(0, 10, 0, 10)),
c("test.json", "test.json", r(0, 10, 0, 10)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,27 @@
*/
public class QuteCompletionWithUserTagTest {

@Test
public void bundleStyle() throws Exception {
String template = "{#|";

// Without snippet
testCompletionFor(template, //
false, // no snippet support
SECTION_SNIPPET_SIZE, //
c("bundleStyle", //
"{#bundleStyle /}", //
r(0, 0, 0, 2)));

// With snippet support
testCompletionFor(template, //
true, // snippet support
SECTION_SNIPPET_SIZE, //
c("bundleStyle", //
"{#bundleStyle /}$0", //
r(0, 0, 0, 2)));
}

@Test
public void input() throws Exception {
String template = "{#|";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@
*/
public class QuteDiagnosticsWithUserTagTest {

@Test
public void bundleStyle() {
String template = "{#bundleStyle /}";
testDiagnosticsFor(template);
}

@Test
public void definedRequiredParameterName() {
String template = "{#input name='' /}";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{@java.util.Map<String,String> bundle}
{#let name?="main.css"}
<link rel="stylesheet" media="screen" href="/static/{bundle.get(name)}">
{/let}

0 comments on commit 63c4341

Please sign in to comment.