IDEA-67727: XPath 2: numeric literal immediately followed with letter is green

This commit is contained in:
sweinreuter
2011-04-08 22:25:17 +02:00
parent cae7e39bd8
commit ffdb58eb66
5 changed files with 23 additions and 3 deletions
@@ -26,6 +26,7 @@ import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiReference;
import com.intellij.psi.util.PsiTreeUtil;
import org.intellij.lang.xpath.XPath2TokenTypes;
import org.intellij.lang.xpath.XPathElementType;
import org.intellij.lang.xpath.XPathFileType;
import org.intellij.lang.xpath.context.functions.Function;
import org.jetbrains.annotations.NotNull;
@@ -104,9 +105,18 @@ public final class XPathAnnotator extends XPath2ElementVisitor implements Annota
@Override
public void visitXPathBinaryExpression(final XPathBinaryExpression o) {
if (XPath2TokenTypes.COMP_OPS.contains(o.getOperator())) {
if (o.getContainingFile().getLanguage() == XPathFileType.XPATH2.getLanguage()) {
final XPathExpression operand = o.getLOperand();
if (o.getContainingFile().getLanguage() == XPathFileType.XPATH2.getLanguage()) {
final XPathExpression operand = o.getLOperand();
final XPathElementType operator = o.getOperator();
if (operand instanceof XPathNumber) {
if (operator != XPathTokenTypes.STAR && XPath2TokenTypes.KEYWORDS.contains(operator)) {
final String op = o.getOperationSign();
if (o.getText().startsWith(operand.getText() + op)) {
myHolder.createErrorAnnotation(o, "Number literal must be followed by whitespace in XPath 2");
}
}
}
if (XPath2TokenTypes.COMP_OPS.contains(operator)) {
if (operand instanceof XPathBinaryExpression && XPath2TokenTypes.COMP_OPS.contains(((XPathBinaryExpression)operand).getOperator())) {
final Annotation annotation = myHolder.createErrorAnnotation(o, "Consecutive comparison is not allowed in XPath 2");
@@ -29,6 +29,10 @@ public class XPath2HighlightingTest extends XPath2HighlightingTestBase {
doXPathHighlighting();
}
public void testNumberFollowedByToken() throws Throwable {
doXPathHighlighting();
}
@Override
protected String getSubPath() {
return "xpath/highlighting";
@@ -56,6 +56,10 @@ public class XPathHighlightingTest extends TestBase {
doXPathHighlighting();
}
public void testNumberFollowedByToken() throws Throwable {
doXPathHighlighting();
}
private void doXPathHighlighting(String... moreFiles) throws Throwable {
final String name = getTestFileName();
myFixture.testHighlighting(true, false, false, ArrayUtil.append(moreFiles, name + ".xpath"));
@@ -0,0 +1 @@
10div 2 + 3 mod 2
@@ -0,0 +1 @@
<error descr="Number literal must be followed by whitespace in XPath 2">10div 2</error> + 3 mod 2