From 7b976b1e80e730e9d77d10dcc2417282ac803b66 Mon Sep 17 00:00:00 2001 From: sweinreuter Date: Mon, 18 Apr 2011 19:12:05 +0200 Subject: [PATCH] IDEA-68394 XPath 2: wildcard in form of *:NCName in name test is red --- .../src/org/intellij/lang/xpath/XPath2Parser.java | 15 +++++++++++++++ .../src/org/intellij/lang/xpath/XPathParser.java | 10 +++++++--- .../intellij/lang/xpath/XPath2ParsingTest.java | 8 ++++++++ .../xpath2/parsing/invalidWildcard.xpath2 | 1 + .../xpath2/parsing/wildcardNamespace.xpath2 | 1 + 5 files changed, 32 insertions(+), 3 deletions(-) create mode 100644 plugins/xpath/xpath-lang/testData/xpath2/parsing/invalidWildcard.xpath2 create mode 100644 plugins/xpath/xpath-lang/testData/xpath2/parsing/wildcardNamespace.xpath2 diff --git a/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/XPath2Parser.java b/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/XPath2Parser.java index 830d7e450223..0dd6bdf6f408 100644 --- a/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/XPath2Parser.java +++ b/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/XPath2Parser.java @@ -515,6 +515,21 @@ public class XPath2Parser extends XPathParser { return true; } + @Override + protected boolean parseWildcard(PsiBuilder builder) { + builder.advanceLexer(); + + if (builder.getTokenType() == XPathTokenTypes.COL) { + builder.advanceLexer(); + if (builder.getTokenType() != XPathTokenTypes.NCNAME) { + builder.error("NCName expected"); + builder.advanceLexer(); + } + } + + return true; + } + @Override protected TokenSet unionOps() { return XPath2TokenTypes.UNION_OPS; diff --git a/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/XPathParser.java b/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/XPathParser.java index 5394c80e3d85..33342a1a22a1 100644 --- a/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/XPathParser.java +++ b/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/XPathParser.java @@ -453,10 +453,9 @@ public class XPathParser implements PsiParser { /** * [37] NameTest ::= '*' | NCName ':' '*' | QName */ - private static boolean parseNameTest(PsiBuilder builder) { + protected boolean parseNameTest(PsiBuilder builder) { if (builder.getTokenType() == XPathTokenTypes.STAR) { - builder.advanceLexer(); - return true; + return parseWildcard(builder); } else if (builder.getTokenType() == XPathTokenTypes.NCNAME) { builder.advanceLexer(); @@ -477,6 +476,11 @@ public class XPathParser implements PsiParser { return false; } + protected boolean parseWildcard(PsiBuilder builder) { + builder.advanceLexer(); + return true; + } + /** * [5] AxisSpecifier ::= AxisName '::' | AbbreviatedAxisSpecifier *

diff --git a/plugins/xpath/xpath-lang/test/org/intellij/lang/xpath/XPath2ParsingTest.java b/plugins/xpath/xpath-lang/test/org/intellij/lang/xpath/XPath2ParsingTest.java index c06ed53311af..aa5cabc37e0a 100644 --- a/plugins/xpath/xpath-lang/test/org/intellij/lang/xpath/XPath2ParsingTest.java +++ b/plugins/xpath/xpath-lang/test/org/intellij/lang/xpath/XPath2ParsingTest.java @@ -67,6 +67,14 @@ public class XPath2ParsingTest extends TestBase { doXPathHighlighting(); } + public void testWildcardNamespace() throws Throwable { + doXPathHighlighting(); + } + + public void testInvalidWildcard() throws Throwable { + doXPathHighlighting(); + } + private void doXPathHighlighting(String... moreFiles) throws Throwable { final String name = getTestFileName(); myFixture.testHighlighting(false, false, false, ArrayUtil.append(moreFiles, name + ".xpath2")); diff --git a/plugins/xpath/xpath-lang/testData/xpath2/parsing/invalidWildcard.xpath2 b/plugins/xpath/xpath-lang/testData/xpath2/parsing/invalidWildcard.xpath2 new file mode 100644 index 000000000000..c2ebba97569d --- /dev/null +++ b/plugins/xpath/xpath-lang/testData/xpath2/parsing/invalidWildcard.xpath2 @@ -0,0 +1 @@ +*:* \ No newline at end of file diff --git a/plugins/xpath/xpath-lang/testData/xpath2/parsing/wildcardNamespace.xpath2 b/plugins/xpath/xpath-lang/testData/xpath2/parsing/wildcardNamespace.xpath2 new file mode 100644 index 000000000000..655b73bb4aab --- /dev/null +++ b/plugins/xpath/xpath-lang/testData/xpath2/parsing/wildcardNamespace.xpath2 @@ -0,0 +1 @@ +./*:root/*:container[1] \ No newline at end of file