IDEA-68391 XPath 2: cast expression: completion shows "No suggestions"

This commit is contained in:
sweinreuter
2011-04-18 19:38:40 +02:00
parent c9bdb105b2
commit 8af4dc4fe6
51 changed files with 92 additions and 7 deletions
@@ -24,6 +24,7 @@ import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.util.Function;
import com.intellij.util.ProcessingContext;
import com.intellij.util.containers.ContainerUtil;
import org.intellij.lang.xpath.context.NamespaceContext;
import org.intellij.lang.xpath.psi.*;
import org.jetbrains.annotations.NotNull;
@@ -81,7 +82,24 @@ public class XPathCompletionContributor extends CompletionContributor {
extend(CompletionType.BASIC, psiElement().withParent(psiElement(XPath2TypeElement.class).without(prefix())), new CompletionProvider<CompletionParameters>() {
protected void addCompletions(@NotNull CompletionParameters parameters, ProcessingContext context, @NotNull CompletionResultSet result) {
final XPathElement parent = PsiTreeUtil.getParentOfType(parameters.getPosition(), XPathElement.class);
addResult(result, CompletionLists.getNodeTypeCompletions(parent), parameters.getPosition(), parameters.getOffset());
assert parent != null;
if (parent.getParent() instanceof XPath2TreatAs || parent.getParent() instanceof XPath2InstanceOf) {
addResult(result, CompletionLists.getNodeTypeCompletions(parent), parameters.getPosition(), parameters.getOffset());
}
final NamespaceContext namespaceContext = parent.getXPathContext().getNamespaceContext();
if (namespaceContext != null) {
final String prefixForURI = namespaceContext.getPrefixForURI(XPath2Type.XMLSCHEMA_NS, parent.getXPathContext().getContextElement());
if (prefixForURI != null && prefixForURI.length() > 0) {
addResult(result, ContainerUtil.map(XPath2Type.SchemaType.listSchemaTypes(), new Function<XPath2Type, Lookup>() {
@Override
public Lookup fun(XPath2Type type) {
return new MyLookup(prefixForURI + ":" + type.getQName().getLocalPart());
}
}), parameters.getPosition(), parameters.getOffset());
}
}
}
});
extend(CompletionType.BASIC, psiElement().withParent(psiElement(XPath2TypeElement.class).with(prefix())), new CompletionProvider<CompletionParameters>() {
@@ -94,8 +112,7 @@ public class XPathCompletionContributor extends CompletionContributor {
addResult(result, ContainerUtil.map(XPath2Type.SchemaType.listSchemaTypes(), new Function<XPath2Type, Lookup>() {
@Override
public Lookup fun(XPath2Type type) {
return new AbstractLookup(type.getQName().getLocalPart(), type.getName()) {
};
return new MyLookup(type.getQName().getLocalPart());
}
}), parameters.getPosition(), parameters.getOffset());
}
@@ -130,7 +147,6 @@ public class XPathCompletionContributor extends CompletionContributor {
String prefix = CompletionData.findPrefixStatic(element, i);
if (element.getParent() instanceof XPathVariableReference) {
final String text = element.getText();
prefix = "$" + prefix;
}
@@ -155,4 +171,10 @@ public class XPathCompletionContributor extends CompletionContributor {
return prefix;
}
private static class MyLookup extends AbstractLookup {
public MyLookup(String name) {
super(name, name);
}
}
}
@@ -0,0 +1,37 @@
/*
* Copyright 2000-2011 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.intellij.lang.xpath;
public class XPath2CompletionTest extends TestBase {
public void testCastInsert() throws Throwable {
doXPathCompletion();
}
public void testTreatInsert() throws Throwable {
doXPathCompletion();
}
private void doXPathCompletion() throws Throwable {
final String name = getTestFileName();
myFixture.testCompletion(name + ".xpath2", name + "_after.xpath2");
}
@Override
protected String getSubPath() {
return "xpath2/completion";
}
}
@@ -51,6 +51,6 @@ public class XPath2HighlightingTest extends XPath2HighlightingTestBase {
@Override
protected String getSubPath() {
return "xpath/highlighting";
return "xpath2/highlighting";
}
}
@@ -74,6 +74,6 @@ public class XPath2ParsingTest extends TestBase {
@Override
protected String getSubPath() {
return "xpath/parsing";
return "xpath2/parsing";
}
}
@@ -99,6 +99,6 @@ public class XPath2TypeTest extends XPath2HighlightingTestBase {
@Override
protected String getSubPath() {
return "xpath/highlighting/types";
return "xpath2/highlighting/types";
}
}
@@ -28,6 +28,10 @@ public class Xslt2CompletionTest extends TestBase {
doXsltCompletion();
}
public void testTypeCompletion() throws Throwable {
doXsltCompletion();
}
private void doXsltCompletion(String... moreFiles) throws Throwable {
final String name = getTestFileName();
myFixture.testCompletion(name + ".xsl", name + "_after.xsl", moreFiles);
@@ -0,0 +1 @@
1 cast as a<caret>
@@ -0,0 +1 @@
1 cast as a<caret>
@@ -0,0 +1 @@
1 treat as a<caret>
@@ -0,0 +1 @@
1 treat as attribute()
@@ -0,0 +1,9 @@
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xss="http://www.w3.org/2001/XMLSchema"
xmlns:n="urn:my">
<xsl:template match="/">
<xsl:value-of select="1 treat as xss:boo<caret>" />
</xsl:template>
</xsl:stylesheet>
@@ -0,0 +1,9 @@
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xss="http://www.w3.org/2001/XMLSchema"
xmlns:n="urn:my">
<xsl:template match="/">
<xsl:value-of select="1 treat as xss:boolean" />
</xsl:template>
</xsl:stylesheet>