Skip to content

Commit

Permalink
Qute parser does not parse operator parameters with '=' correctly
Browse files Browse the repository at this point in the history
Fixes redhat-developer#742

Signed-off-by: azerr <azerr@redhat.com>
  • Loading branch information
angelozerr committed Sep 14, 2022
1 parent 50f76d7 commit 0e5302f
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ public String toString() {
* @return the parameter name.
*/
public String getName() {
if (name != null) {
return name;
}
if (!hasValueAssigned()) {
// ex : {#if foo?? }
Expression expression = getJavaTypeExpression();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import java.util.List;
import java.util.Map;

import com.redhat.qute.parser.parameter.ParameterParser;
import com.redhat.qute.parser.template.ASTVisitor;
import com.redhat.qute.parser.template.CaseOperator;
import com.redhat.qute.parser.template.Parameter;
Expand Down Expand Up @@ -87,12 +88,28 @@ public CaseSection(int start, int end) {

@Override
protected void initializeParameters(List<Parameter> parameters) {
// All parameters can have expression (ex : {#case OFF})
// All parameters can have expression.
// Ex :
// - {#case OFF}
// - {#case in ON OFF}
for (Parameter parameter : parameters) {
// We consider that case parameter has value to get the proper name when
// parameter#getName() is called for operator which could contains '='.
parameter.setStartValue(parameter.getEnd());
parameter.getName();
parameter.setStartValue(NULL_VALUE);
parameter.setCanHaveExpression(true);
}
}

protected List<Parameter> collectParameters() {
// Don't split parameters with '=' to support operator like
// !=
// >=
boolean splitWithEquals = false;
return ParameterParser.parse(this, false, splitWithEquals);
}

@Override
public SectionKind getSectionKind() {
return SectionKind.CASE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,26 @@ public void whenExpressionOperatorExpectedParam() {
testDiagnosticsFor(template);
}

@Test
public void whenExpressionOperatorWhichContainsEquals() {
String template = "{@org.acme.Machine Machine}\r\n" + //
" {#when Machine.getMachine()}\r\n" + //
" {#is != ON}\r\n" + //
" {#is <= ON}\r\n" + //
" {/when}";
testDiagnosticsFor(template);

template = "{@org.acme.Machine Machine}\r\n" + //
" {#when Machine.getMachine()}\r\n" + //
" {#is != ON OFF}\r\n" + //
" {#is <= ON}\r\n" + //
" {/when}";
testDiagnosticsFor(template, //
d(2, 13, 2, 16, QuteErrorCode.UnexpectedParameter,
"Unexpected operand `OFF`. The operator `!=` in the `#is` section expects only one parameter.",
DiagnosticSeverity.Error));
}

@Test
public void whenExpressionOperatorNoParameters() {
String template = "{@org.acme.Machine Machine}\r\n" + //
Expand Down

0 comments on commit 0e5302f

Please sign in to comment.