diff options
Diffstat (limited to 'libjava/classpath/gnu/xml/xpath/Selector.java')
| -rw-r--r-- | libjava/classpath/gnu/xml/xpath/Selector.java | 41 |
1 files changed, 25 insertions, 16 deletions
diff --git a/libjava/classpath/gnu/xml/xpath/Selector.java b/libjava/classpath/gnu/xml/xpath/Selector.java index 93408e48b23..c7abb33e2ff 100644 --- a/libjava/classpath/gnu/xml/xpath/Selector.java +++ b/libjava/classpath/gnu/xml/xpath/Selector.java @@ -90,7 +90,7 @@ public final class Selector if (len > 0) tests.toArray(this.tests); else - this.tests[0] = new NameTest(null, true, true); + this.tests[0] = new NodeTypeTest((short) 0); if (axis == NAMESPACE && this.tests[0] instanceof NameTest) { NameTest nt = (NameTest) this.tests[0]; @@ -108,6 +108,14 @@ public final class Selector public boolean matches(Node context) { + // If called directly, selector is the top level of the path + return matches(context, + getContextPosition(context), + getContextSize(context)); + } + + boolean matches(Node context, int pos, int len) + { short nodeType = context.getNodeType(); switch (axis) { @@ -125,19 +133,11 @@ public final class Selector default: return false; } - int tlen = tests.length; - if (tlen > 0) + for (int j = 0; j < tests.length && len > 0; j++) { - int pos = getContextPosition(context); - int len = getContextSize(context); - if (len == 0) - System.err.println("WARNING: context size is 0"); - for (int j = 0; j < tlen && len > 0; j++) - { - Test test = tests[j]; - if (!test.matches(context, pos, len)) - return false; - } + Test test = tests[j]; + if (!test.matches(context, pos, len)) + return false; } return true; } @@ -147,7 +147,10 @@ public final class Selector int pos = 1; for (ctx = ctx.getPreviousSibling(); ctx != null; ctx = ctx.getPreviousSibling()) - pos++; + { + if (tests[0].matches(ctx, 1, 1)) + pos++; + } return pos; } @@ -161,10 +164,16 @@ public final class Selector int count = 1; Node sib = ctx.getPreviousSibling(); for (; sib != null; sib = sib.getPreviousSibling()) - count++; + { + if (tests[0].matches(ctx, 1, 1)) + count++; + } sib = ctx.getNextSibling(); for (; sib != null; sib = sib.getNextSibling()) - count++; + { + if (tests[0].matches(ctx, 1, 1)) + count++; + } return count; } |

