Search in sources :

Example 51 with XmlDocument

use of com.intellij.psi.xml.XmlDocument in project intellij-community by JetBrains.

the class XmlNSDescriptorImpl method addDependency.

private static void addDependency(final XmlFile file, final Set<PsiFile> visited) {
    if (file != null) {
        final XmlDocument document = file.getDocument();
        collectDependencies(document != null ? document.getRootTag() : null, file, visited);
    }
}
Also used : XmlDocument(com.intellij.psi.xml.XmlDocument)

Example 52 with XmlDocument

use of com.intellij.psi.xml.XmlDocument in project intellij-community by JetBrains.

the class XmlNSDescriptorImpl method findSpecialTagIn.

private static XmlTag findSpecialTagIn(final XmlTag[] tags, final String specialName, final String name, final XmlTag rootTag, final XmlNSDescriptorImpl descriptor, final HashSet<XmlTag> visited) {
    for (XmlTag tag : tags) {
        if (equalsToSchemaName(tag, specialName)) {
            String attribute = tag.getAttributeValue("name");
            if (name.equals(attribute) || name.contains(":") && name.substring(name.indexOf(":") + 1).equals(attribute)) {
                return tag;
            }
        } else if (equalsToSchemaName(tag, INCLUDE_TAG_NAME) || (equalsToSchemaName(tag, IMPORT_TAG_NAME) && rootTag.getNamespaceByPrefix(XmlUtil.findPrefixByQualifiedName(name)).equals(tag.getAttributeValue("namespace")))) {
            final String schemaLocation = tag.getAttributeValue("schemaLocation");
            if (schemaLocation != null) {
                final XmlFile xmlFile = XmlUtil.findNamespace(rootTag.getContainingFile(), schemaLocation);
                if (xmlFile != null) {
                    final XmlDocument document = xmlFile.getDocument();
                    if (document != null) {
                        final XmlTag rTag = findSpecialTag(name, specialName, document.getRootTag(), descriptor, visited);
                        if (rTag != null)
                            return rTag;
                    }
                }
            }
        } else if (equalsToSchemaName(tag, REDEFINE_TAG_NAME)) {
            XmlTag rTag = findSpecialTagIn(tag.getSubTags(), specialName, name, rootTag, descriptor, visited);
            if (rTag != null)
                return rTag;
            final XmlNSDescriptorImpl nsDescriptor = getRedefinedElementDescriptor(tag);
            if (nsDescriptor != null) {
                final XmlTag redefinedRootTag = ((XmlDocument) nsDescriptor.getDeclaration()).getRootTag();
                rTag = findSpecialTagIn(redefinedRootTag.getSubTags(), specialName, name, redefinedRootTag, nsDescriptor, visited);
                if (rTag != null)
                    return rTag;
            }
        }
    }
    return null;
}
Also used : XmlFile(com.intellij.psi.xml.XmlFile) XmlDocument(com.intellij.psi.xml.XmlDocument) XmlTag(com.intellij.psi.xml.XmlTag)

Example 53 with XmlDocument

use of com.intellij.psi.xml.XmlDocument in project intellij-community by JetBrains.

the class GenerateDTDAction method getHandler.

@Override
@NotNull
protected CodeInsightActionHandler getHandler() {
    return new CodeInsightActionHandler() {

        @Override
        public void invoke(@NotNull Project project, @NotNull Editor editor, @NotNull PsiFile file) {
            final XmlDocument document = findSuitableXmlDocument(file);
            if (document != null) {
                @NonNls final StringBuilder buffer = new StringBuilder();
                buffer.append("<!DOCTYPE " + document.getRootTag().getName() + " [\n");
                buffer.append(XmlUtil.generateDocumentDTD(document, true));
                buffer.append("]>\n");
                XmlFile tempFile;
                try {
                    final XmlProlog prolog = document.getProlog();
                    final PsiElement childOfType = PsiTreeUtil.getChildOfType(prolog, XmlProcessingInstruction.class);
                    if (childOfType != null) {
                        final String text = childOfType.getText();
                        buffer.insert(0, text);
                        final PsiElement nextSibling = childOfType.getNextSibling();
                        if (nextSibling instanceof PsiWhiteSpace) {
                            buffer.insert(text.length(), nextSibling.getText());
                        }
                    }
                    tempFile = (XmlFile) PsiFileFactory.getInstance(file.getProject()).createFileFromText("dummy.xml", buffer.toString());
                    prolog.replace(tempFile.getDocument().getProlog());
                } catch (IncorrectOperationException e) {
                    LOG.error(e);
                }
            }
        }
    };
}
Also used : NonNls(org.jetbrains.annotations.NonNls) XmlFile(com.intellij.psi.xml.XmlFile) CodeInsightActionHandler(com.intellij.codeInsight.CodeInsightActionHandler) XmlDocument(com.intellij.psi.xml.XmlDocument) XmlProlog(com.intellij.psi.xml.XmlProlog) NotNull(org.jetbrains.annotations.NotNull) Project(com.intellij.openapi.project.Project) PsiFile(com.intellij.psi.PsiFile) IncorrectOperationException(com.intellij.util.IncorrectOperationException) Editor(com.intellij.openapi.editor.Editor) PsiElement(com.intellij.psi.PsiElement) PsiWhiteSpace(com.intellij.psi.PsiWhiteSpace) NotNull(org.jetbrains.annotations.NotNull)

Example 54 with XmlDocument

use of com.intellij.psi.xml.XmlDocument in project intellij-community by JetBrains.

the class XmlTextContextType method isInContext.

@Override
public boolean isInContext(@NotNull PsiFile file, int offset) {
    if (!XmlContextType.isInXml(file, offset))
        return false;
    PsiElement element = file.findElementAt(offset);
    if (element == null)
        return false;
    if (PsiTreeUtil.getParentOfType(element, XmlText.class, false) != null) {
        return true;
    }
    PsiElement parent = element.getParent();
    if (parent instanceof PsiErrorElement) {
        parent = parent.getParent();
    }
    return parent instanceof XmlDocument;
}
Also used : PsiErrorElement(com.intellij.psi.PsiErrorElement) XmlText(com.intellij.psi.xml.XmlText) XmlDocument(com.intellij.psi.xml.XmlDocument) PsiElement(com.intellij.psi.PsiElement)

Example 55 with XmlDocument

use of com.intellij.psi.xml.XmlDocument in project intellij-community by JetBrains.

the class XmlElementSignatureProvider method restoreBySignatureTokens.

@Override
protected PsiElement restoreBySignatureTokens(@NotNull PsiFile file, @NotNull PsiElement parent, @NotNull String type, @NotNull StringTokenizer tokenizer, @Nullable StringBuilder processingInfoStorage) {
    if (type.equals("tag")) {
        String name = tokenizer.nextToken();
        if (parent instanceof XmlFile) {
            parent = ((XmlFile) parent).getDocument();
            if (parent == null) {
                return null;
            }
        }
        try {
            int index = Integer.parseInt(tokenizer.nextToken());
            String unescapedName = unescape(name);
            PsiElement result = restoreElementInternal(parent, unescapedName, index, XmlTag.class);
            if (result == null && file.getFileType() == StdFileTypes.JSP) {
                //TODO: FoldingBuilder API, psi roots, etc?
                if (parent instanceof XmlDocument) {
                    // html tag, not found in jsp tree
                    result = restoreElementInternal(HtmlUtil.getRealXmlDocument((XmlDocument) parent), unescapedName, index, XmlTag.class);
                } else if (name.equals("<unnamed>") && parent != null) {
                    // scriplet/declaration missed because null name
                    result = restoreElementInternal(parent, "", index, XmlTag.class);
                }
            }
            return result;
        } catch (NumberFormatException e) {
            LOG.error(e);
            return null;
        }
    }
    return null;
}
Also used : XmlFile(com.intellij.psi.xml.XmlFile) XmlDocument(com.intellij.psi.xml.XmlDocument) PsiElement(com.intellij.psi.PsiElement) XmlTag(com.intellij.psi.xml.XmlTag)

Aggregations

XmlDocument (com.intellij.psi.xml.XmlDocument)57 XmlTag (com.intellij.psi.xml.XmlTag)39 XmlFile (com.intellij.psi.xml.XmlFile)32 PsiElement (com.intellij.psi.PsiElement)13 Nullable (org.jetbrains.annotations.Nullable)11 XmlNSDescriptor (com.intellij.xml.XmlNSDescriptor)9 PsiFile (com.intellij.psi.PsiFile)8 VirtualFile (com.intellij.openapi.vfs.VirtualFile)6 ArrayList (java.util.ArrayList)6 XmlAttribute (com.intellij.psi.xml.XmlAttribute)5 PsiMetaData (com.intellij.psi.meta.PsiMetaData)4 IncorrectOperationException (com.intellij.util.IncorrectOperationException)4 NotNull (org.jetbrains.annotations.NotNull)4 Project (com.intellij.openapi.project.Project)3 XmlText (com.intellij.psi.xml.XmlText)3 XmlElementDescriptor (com.intellij.xml.XmlElementDescriptor)3 JSClass (com.intellij.lang.javascript.psi.ecmal4.JSClass)2 Editor (com.intellij.openapi.editor.Editor)2 PsiErrorElement (com.intellij.psi.PsiErrorElement)2 FilterElementProcessor (com.intellij.psi.scope.processor.FilterElementProcessor)2