use of com.intellij.psi.xml.XmlFile in project intellij-community by JetBrains.
the class TreeIncrementalUpdateTest method testRemoveAttributeParent.
public void testRemoveAttributeParent() throws Throwable {
final XmlFile file = (XmlFile) createFile("file.xml", "<?xml version='1.0' encoding='UTF-8'?>\n" + "<!DOCTYPE ejb-jar PUBLIC \"-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN\" \"http://java.sun.com/dtd/ejb-jar_2_0.dtd\">\n" + "<a>\n" + " <child-element xxx=\"239\"/>\n" + "</a>");
final DomFileElementImpl<MyElement> fileElement = getDomManager().getFileElement(file, MyElement.class, "a");
myCallRegistry.clear();
final MyElement rootElement = fileElement.getRootElement();
final MyElement oldLeaf = rootElement.getChildElements().get(0);
final GenericAttributeValue<String> xxx = oldLeaf.getXxx();
final XmlTag oldLeafTag = oldLeaf.getXmlTag();
new WriteCommandAction(getProject()) {
@Override
protected void run(@NotNull Result result) throws Throwable {
oldLeafTag.delete();
}
}.execute();
assertFalse(oldLeaf.isValid());
assertFalse(xxx.isValid());
}
use of com.intellij.psi.xml.XmlFile in project intellij-community by JetBrains.
the class TreeIncrementalUpdateTest method testTypeBeforeRootTag.
public void testTypeBeforeRootTag() throws Throwable {
getDomManager().registerFileDescription(new DomFileDescription<>(MyElement.class, "a"), getTestRootDisposable());
final XmlFile file = (XmlFile) createFile("file.xml", "<?xml version='1.0' encoding='UTF-8'?>\n" + "<a/>");
assertTrue(getDomManager().isDomFile(file));
final DomFileElementImpl<MyElement> fileElement = getDomManager().getFileElement(file, MyElement.class);
assertTrue(fileElement.isValid());
myCallRegistry.clear();
putExpected(new DomEvent(fileElement, false));
new WriteCommandAction(getProject()) {
@Override
protected void run(@NotNull Result result) throws Throwable {
final Document document = getDocument(file);
final int i = document.getText().indexOf("<a");
document.insertString(i, "a");
commitDocument(document);
}
}.execute();
assertFalse(getDomManager().isDomFile(file));
assertFalse(fileElement.isValid());
assertResultsAndClear();
}
use of com.intellij.psi.xml.XmlFile in project intellij-community by JetBrains.
the class TypeOrElementOrAttributeReference method getVariants.
public static Object[] getVariants(XmlTag tag, ReferenceType type, String prefix) {
String[] tagNames = null;
switch(type) {
case GroupReference:
tagNames = new String[] { SchemaReferencesProvider.GROUP_TAG_NAME };
break;
case AttributeGroupReference:
tagNames = new String[] { SchemaReferencesProvider.ATTRIBUTE_GROUP_TAG_NAME };
break;
case AttributeReference:
tagNames = new String[] { SchemaReferencesProvider.ATTRIBUTE_TAG_NAME };
break;
case ElementReference:
tagNames = new String[] { SchemaReferencesProvider.ELEMENT_TAG_NAME };
break;
case TypeReference:
tagNames = new String[] { SchemaReferencesProvider.SIMPLE_TYPE_TAG_NAME, SchemaReferencesProvider.COMPLEX_TYPE_TAG_NAME };
break;
}
final XmlDocument document = ((XmlFile) tag.getContainingFile()).getDocument();
if (document == null) {
return ArrayUtil.EMPTY_OBJECT_ARRAY;
}
final XmlTag rootTag = document.getRootTag();
String ourNamespace = rootTag != null ? rootTag.getAttributeValue(TARGET_NAMESPACE) : "";
if (ourNamespace == null)
ourNamespace = "";
CompletionProcessor processor = new CompletionProcessor(tag, prefix);
for (String namespace : tag.knownNamespaces()) {
if (ourNamespace.equals(namespace))
continue;
final XmlNSDescriptor nsDescriptor = tag.getNSDescriptor(namespace, true);
if (nsDescriptor instanceof XmlNSDescriptorImpl) {
processNamespace(namespace, processor, (XmlNSDescriptorImpl) nsDescriptor, tagNames);
}
}
XmlNSDescriptor nsDescriptor = (XmlNSDescriptor) document.getMetaData();
if (nsDescriptor instanceof XmlNSDescriptorImpl) {
processNamespace(ourNamespace, processor, (XmlNSDescriptorImpl) nsDescriptor, tagNames);
}
return ArrayUtil.toStringArray(processor.myElements);
}
use of com.intellij.psi.xml.XmlFile in project intellij-community by JetBrains.
the class TypeOrElementOrAttributeReference method getNamespace.
private static String getNamespace(final XmlTag tag, final String text) {
final String namespacePrefix = XmlUtil.findPrefixByQualifiedName(text);
final String namespaceByPrefix = tag.getNamespaceByPrefix(namespacePrefix);
if (!namespaceByPrefix.isEmpty())
return namespaceByPrefix;
final XmlTag rootTag = ((XmlFile) tag.getContainingFile()).getRootTag();
if (rootTag != null && "schema".equals(rootTag.getLocalName()) && XmlUtil.ourSchemaUrisList.indexOf(rootTag.getNamespace()) != -1) {
final String targetNS = rootTag.getAttributeValue(TARGET_NAMESPACE);
if (targetNS != null) {
final String targetNsPrefix = rootTag.getPrefixByNamespace(targetNS);
if (namespacePrefix.equals(targetNsPrefix) || (namespaceByPrefix.isEmpty() && targetNsPrefix == null)) {
return targetNS;
}
}
}
return namespaceByPrefix;
}
use of com.intellij.psi.xml.XmlFile in project intellij-community by JetBrains.
the class XmlDuplicatedIdInspection method buildVisitor.
@NotNull
@Override
public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, final boolean isOnTheFly) {
return new XmlElementVisitor() {
@Override
public void visitXmlAttributeValue(final XmlAttributeValue value) {
if (value.getTextRange().isEmpty()) {
return;
}
final PsiFile file = value.getContainingFile();
if (!(file instanceof XmlFile)) {
return;
}
PsiFile baseFile = PsiUtilCore.getTemplateLanguageFile(file);
if (baseFile != file && !(baseFile instanceof XmlFile)) {
return;
}
final XmlRefCountHolder refHolder = XmlRefCountHolder.getRefCountHolder((XmlFile) file);
if (refHolder == null)
return;
final PsiElement parent = value.getParent();
if (!(parent instanceof XmlAttribute))
return;
final XmlTag tag = (XmlTag) parent.getParent();
if (tag == null)
return;
checkValue(value, (XmlFile) file, refHolder, tag, holder);
}
};
}
Aggregations