Skip to content

Commit

Permalink
Reserved variables
Browse files Browse the repository at this point in the history
  • Loading branch information
idegtiarenko committed Sep 30, 2015
1 parent f1befab commit 7fd0646
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
public class ConcordionVariableUsage {

private static final Set<String> COMMANDS_THAT_CAN_SET_VARIABLE = setOf("set", "execute", "verifyRows", "verify-rows");
private static final Set<String> RESERVED_VARIABLES = setOf("TEXT", "HREF", "LEVEL");

@Nullable private XmlAttribute attribute;
@Nullable private XmlAttributeValue attributeValue;
Expand Down Expand Up @@ -95,6 +96,9 @@ public boolean isDeclaration() {
if (attribute == null) {
return false;
}
if (variable != null && RESERVED_VARIABLES.contains(variable.getName())) {
return true;
}
if (!COMMANDS_THAT_CAN_SET_VARIABLE.contains(attribute.getLocalName())) {
return false;
}
Expand All @@ -118,6 +122,9 @@ public PsiType determineType() {
if (variable == null || variableParent == null) {
return null;
}
if (RESERVED_VARIABLES.contains(variable.getName())) {
return PsiType.NULL;
}
if (variableParent instanceof ConcordionSetExpression) {
ConcordionOgnlExpressionStart expr = findChildOfType(variableParent, ConcordionOgnlExpressionStart.class);
return expr != null ? typeOfExpression(expr) : null;
Expand Down
10 changes: 10 additions & 0 deletions testData/reference/ReservedVariable.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<html xmlns:c="http://www.concordion.org/2007/concordion">
<head>
<title>Test spec</title>
</head>
<body>

<span c:execute="consumeString(#TEXT<caret>)">execute</span>

</body>
</html>
11 changes: 11 additions & 0 deletions testData/reference/ReservedVariable.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.test;

import org.concordion.integration.junit4.ConcordionRunner;
import org.junit.runner.RunWith;

@RunWith(ConcordionRunner.class)
public class ReservedVariable {

public void consumeString(String s) {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,21 @@ public void testShouldResolveVariableFromVerifyRowsCommand() {
assertThat(declaration).isNotEqualTo(variable);
}

public void testShouldResolveReservedVariable() {

copyJavaRunnerToConcordionProject("ReservedVariable.java");
VirtualFile htmlSpec = copyHtmlSpecToConcordionProject("ReservedVariable.html");

myFixture.configureFromExistingVirtualFile(htmlSpec);

ConcordionVariable variable = elementUnderCaret();
ConcordionVariable declaration = resolveReferences(variable);

assertThat(declaration).isNotNull();
assertThat(declaration.getName()).isEqualTo("TEXT");
assertThat(declaration).isEqualTo(variable);
}

private <T extends PsiElement> T elementUnderCaret() {
return (T) myFixture.getFile().findElementAt(myFixture.getCaretOffset() - 1).getParent();
}
Expand Down

0 comments on commit 7fd0646

Please sign in to comment.