IDEA-119640 Problem with goto declaration of XML attribute defined in XSD: re-fixed, completion fixed

This commit is contained in:
Dmitry Avdeev
2014-05-27 11:55:53 +04:00
parent ee89d4f65f
commit 1913bdc2ec
7 changed files with 66 additions and 19 deletions
@@ -17,6 +17,7 @@ import com.intellij.psi.statistics.StatisticsManager;
import com.intellij.psi.statistics.impl.StatisticsManagerImpl;
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase;
import com.intellij.xml.util.XmlUtil;
import org.jetbrains.annotations.NotNull;
import java.util.List;
@@ -67,7 +68,7 @@ public class XmlCompletionTest extends LightCodeInsightFixtureTestCase {
protected void runTest() throws Throwable {
new WriteCommandAction(getProject()) {
@Override
protected void run(Result result) throws Throwable {
protected void run(@NotNull Result result) throws Throwable {
XmlCompletionTest.super.runTest();
}
}.execute();
@@ -686,5 +687,15 @@ public class XmlCompletionTest extends LightCodeInsightFixtureTestCase {
myFixture.testCompletionVariants("tagValue/completeEnum.xml", "none", "standard");
myFixture.testCompletionVariants("tagValue/completeBoolean.xml", "false", "true");
}
public void testInheritedAttribute() throws Exception {
myFixture.configureByFiles("InheritedAttr/test.xsd", "InheritedAttr/library.xsd");
myFixture.testCompletionVariants("InheritedAttr/test.xml", "buz",
"library:boo",
"xml:base",
"xml:id",
"xml:lang",
"xml:space");
}
}
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema attributeFormDefault="unqualified"
elementFormDefault="qualified"
targetNamespace="http://library"
xmlns:library="http://library"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="bar" type='library:barType'/>
<xs:complexType name="barType">
<xs:attribute type='xs:string' name="buz"/>
<xs:anyAttribute namespace="##any"/>
</xs:complexType>
<xs:attribute type='xs:string' name="boo"/>
</xs:schema>
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<test:foo xmlns:test="http://test"
xmlns:library="http://library"
<caret>/>
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema attributeFormDefault="unqualified"
elementFormDefault="qualified"
targetNamespace="http://test"
xmlns:local="http://test"
xmlns:library="http://library"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:import namespace="http://library"/>
<xs:element name="foo" type='local:fooType'/>
<xs:complexType name="fooType">
<xs:complexContent>
<xs:extension base='library:barType'/>
</xs:complexContent>
</xs:complexType>
</xs:schema>
@@ -233,6 +233,9 @@ public class ComplexTypeDescriptor extends TypeDescriptor {
else {
XmlAttributeDescriptorImpl descriptor = myDocumentDescriptor.createAttributeDescriptor(tag);
descriptor.myUse = use;
if (ref != null) {
descriptor.myReferenceName = ref.getAttributeValue(REF_ATTR_NAME);
}
addAttributeDescriptor(result, descriptor);
}
}
@@ -33,6 +33,7 @@ import org.jetbrains.annotations.Nullable;
public class XmlAttributeDescriptorImpl extends XsdEnumerationDescriptor implements PsiWritableMetaData, XmlAttributeDescriptor {
private XmlTag myTag;
String myUse;
String myReferenceName;
@NonNls
public static final String REQUIRED_ATTR_VALUE = "required";
@@ -114,8 +115,6 @@ public class XmlAttributeDescriptorImpl extends XsdEnumerationDescriptor impleme
if (context == null) {
return name;
}
final String form = myTag.getAttributeValue("form");
boolean isQualifiedAttr = QUALIFIED_ATTR_VALUE.equals(form);
final XmlTag rootTag = (((XmlFile) myTag.getContainingFile())).getRootTag();
assert rootTag != null;
@@ -123,6 +122,19 @@ public class XmlAttributeDescriptorImpl extends XsdEnumerationDescriptor impleme
if (targetNs == null) return name;
XmlTag contextTag = (XmlTag)context;
if (QUALIFIED_ATTR_VALUE.equals(myTag.getAttributeValue("form")) ||
QUALIFIED_ATTR_VALUE.equals(rootTag.getAttributeValue("attributeFormDefault")) ||
shouldBeQualified(targetNs, contextTag)) {
final String prefixByNamespace = contextTag.getPrefixByNamespace(targetNs);
if (prefixByNamespace!= null && prefixByNamespace.length() > 0) {
name = prefixByNamespace + ":" + name;
}
}
return name;
}
private boolean shouldBeQualified(String targetNs, XmlTag contextTag) {
boolean attributeShouldBeQualified = false;
String contextNs = contextTag.getNamespace();
@@ -135,6 +147,10 @@ public class XmlAttributeDescriptorImpl extends XsdEnumerationDescriptor impleme
if (type instanceof ComplexTypeDescriptor) {
final ComplexTypeDescriptor typeDescriptor = (ComplexTypeDescriptor)type;
XmlAttributeDescriptor[] attributes = ((ComplexTypeDescriptor)type).getAttributes(contextTag);
if ((myReferenceName == null || myReferenceName.indexOf(':') == -1) && ArrayUtil.contains(this, attributes)) {
return false;
}
attributeShouldBeQualified = typeDescriptor.canContainAttribute(targetNs, null) != ComplexTypeDescriptor.CanContainAttributeType.CanNotContain;
}
@@ -143,17 +159,7 @@ public class XmlAttributeDescriptorImpl extends XsdEnumerationDescriptor impleme
}
}
}
if (isQualifiedAttr ||
QUALIFIED_ATTR_VALUE.equals(rootTag.getAttributeValue("attributeFormDefault")) ||
attributeShouldBeQualified) {
final String prefixByNamespace = contextTag.getPrefixByNamespace(targetNs);
if (prefixByNamespace!= null && prefixByNamespace.length() > 0) {
name = prefixByNamespace + ":" + name;
}
}
return name;
return attributeShouldBeQualified;
}
public void setName(String name) throws IncorrectOperationException {
@@ -377,11 +377,6 @@ public class XmlElementDescriptorImpl extends XsdEnumerationDescriptor<XmlTag>
final ComplexTypeDescriptor.CanContainAttributeType containAttributeType = descriptor.canContainAttribute(namespace, qName);
if (containAttributeType != ComplexTypeDescriptor.CanContainAttributeType.CanNotContain) {
for (XmlAttributeDescriptor attributeDescriptor : descriptors) {
if (attributeDescriptor.getName().equals(attributeName)) {
return attributeDescriptor;
}
}
return new AnyXmlAttributeDescriptor(attributeName, containAttributeType);
}
}