Search in sources :

Example 26 with XmlFile

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

the class OverriddenDefineRenderer method getClickAction.

@Override
@Nullable
public AnAction getClickAction() {
    return new AnAction() {

        @Override
        public void actionPerformed(AnActionEvent e) {
            final PsiElement element = myDefine.getPsiElement();
            if (element == null || !element.isValid())
                return;
            final PsiElementProcessor.CollectElements<XmlFile> collector = new PsiElementProcessor.CollectElements<>();
            final XmlFile localFile = (XmlFile) element.getContainingFile();
            RelaxIncludeIndex.processBackwardDependencies(localFile, collector);
            final Collection<XmlFile> files = collector.getCollection();
            final List<Define> result = new SmartList<>();
            final OverriddenDefineSearcher searcher = new OverriddenDefineSearcher(myDefine, localFile, result);
            for (XmlFile file : files) {
                final Grammar grammar = GrammarFactory.getGrammar(file);
                if (grammar == null)
                    continue;
                grammar.acceptChildren(searcher);
            }
            if (result.size() > 0) {
                OverridingDefineRenderer.doClickAction(e, result, "Go to overriding define(s)");
            }
        }
    };
}
Also used : XmlFile(com.intellij.psi.xml.XmlFile) Grammar(org.intellij.plugins.relaxNG.model.Grammar) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) AnAction(com.intellij.openapi.actionSystem.AnAction) PsiElementProcessor(com.intellij.psi.search.PsiElementProcessor) Define(org.intellij.plugins.relaxNG.model.Define) SmartList(com.intellij.util.SmartList) PsiElement(com.intellij.psi.PsiElement) Nullable(org.jetbrains.annotations.Nullable)

Example 27 with XmlFile

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

the class NoNamespaceSchemaProvider method getSchema.

@Override
@Nullable
public XmlFile getSchema(@NotNull @NonNls String url, @Nullable Module module, @NotNull PsiFile baseFile) {
    if ("".equals(url)) {
        final Project project = baseFile.getProject();
        final VirtualFile file = NoNamespaceConfig.getInstance(project).getMappedFile(baseFile);
        if (file == null)
            return null;
        final PsiFile f = PsiManager.getInstance(project).findFile(file);
        if (f instanceof XmlFile) {
            return (XmlFile) f;
        }
    }
    return null;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) XmlFile(com.intellij.psi.xml.XmlFile) PsiFile(com.intellij.psi.PsiFile) Nullable(org.jetbrains.annotations.Nullable)

Example 28 with XmlFile

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

the class ResolvingVisitor method processInclude.

private void processInclude(XmlFile xmlFile, XmlAttribute attribute) {
    final Set<XmlFile> set = myProcessingContext.get(VISITED_KEY);
    if (set.contains(xmlFile)) {
        return;
    }
    set.add(xmlFile);
    final XmlDocument document = xmlFile.getDocument();
    if (document == null)
        return;
    final XmlTag rootTag = document.getRootTag();
    if (rootTag == null)
        return;
    rootTag.processElements(this, attribute);
}
Also used : XmlFile(com.intellij.psi.xml.XmlFile) XmlDocument(com.intellij.psi.xml.XmlDocument) XmlTag(com.intellij.psi.xml.XmlTag)

Example 29 with XmlFile

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

the class XsltExtractFunctionAction method extractImpl.

protected boolean extractImpl(XPathExpression expression, Set<XPathExpression> matchingExpressions, List<XmlTag> otherMatches, RefactoringOptions dlg) {
    final XmlAttribute attribute = PsiTreeUtil.getContextOfType(expression, XmlAttribute.class, true);
    assert attribute != null;
    try {
        final String name = dlg.getName();
        final XmlTag rootTag = ((XmlFile) attribute.getParent().getContainingFile()).getRootTag();
        final XmlTag[] templates = rootTag.findSubTags("template", XsltSupport.XSLT_NS);
        final XmlTag insertionPoint = templates.length > 0 ? templates[0] : rootTag.getSubTags()[0];
        final XmlTag parentTag = insertionPoint.getParentTag();
        assert parentTag != null : "Could not locate position to create function at";
        final XmlTag xmlTag = parentTag.createChildTag("function", XsltSupport.XSLT_NS, null, false);
        xmlTag.setAttribute("name", name);
        final XPathType type = ExpectedTypeUtil.mapType(expression, expression.getType());
        xmlTag.setAttribute("as", prefixedName(type, insertionPoint));
        final StringBuilder argList = new StringBuilder();
        final List<XPathVariableReference> references = RefactoringUtil.collectVariableReferences(expression);
        for (XPathVariableReference reference : references) {
            final XPathVariable variable = reference.resolve();
            if (variable instanceof XsltVariable) {
                // don't pass through global parameters and variables
                if (XsltCodeInsightUtil.getTemplateTag(variable, false) != null) {
                    final XmlTag param = parentTag.createChildTag("param", XsltSupport.XSLT_NS, null, false);
                    param.setAttribute("name", variable.getName());
                    if (!variable.getType().isAbstract()) {
                        param.setAttribute("as", prefixedName(ExpectedTypeUtil.mapType(expression, variable.getType()), parentTag));
                    }
                    RefactoringUtil.addParameter(xmlTag, param);
                    if (argList.length() > 0) {
                        argList.append(", ");
                    }
                    argList.append("$").append(variable.getName());
                }
            }
        }
        final XmlTag seqTag = parentTag.createChildTag("sequence", XsltSupport.XSLT_NS, null, false);
        seqTag.setAttribute("select", expression.getText());
        xmlTag.add(seqTag);
        // TODO: revisit the formatting
        final PsiElement element = parentTag.addBefore(xmlTag, insertionPoint);
        final ASTNode node1 = parentTag.getNode();
        assert node1 != null;
        final ASTNode node2 = element.getNode();
        assert node2 != null;
        CodeStyleManager.getInstance(xmlTag.getManager().getProject()).reformatNewlyAddedElement(node1, node2);
        final XPathExpression var = XPathChangeUtil.createExpression(expression, name + "(" + argList + ")");
        expression.replace(var);
        return true;
    } catch (IncorrectOperationException e) {
        Logger.getInstance(getClass().getName()).error(e);
        return false;
    }
}
Also used : XmlAttribute(com.intellij.psi.xml.XmlAttribute) XmlFile(com.intellij.psi.xml.XmlFile) XsltVariable(org.intellij.lang.xpath.xslt.psi.XsltVariable) ASTNode(com.intellij.lang.ASTNode) IncorrectOperationException(com.intellij.util.IncorrectOperationException) PsiElement(com.intellij.psi.PsiElement) XmlTag(com.intellij.psi.xml.XmlTag)

Example 30 with XmlFile

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

the class XsltImplicitUsagesProvider method isImplicitUsage.

public boolean isImplicitUsage(PsiElement element) {
    if (!(element instanceof XmlAttribute)) {
        return false;
    }
    final XmlAttribute attr = (XmlAttribute) element;
    if (!attr.isNamespaceDeclaration()) {
        return false;
    }
    final PsiFile file = attr.getContainingFile();
    if (!(file instanceof XmlFile)) {
        return false;
    }
    // ContextProvider.hasXPathInjections() is an optimization that avoids to run the references search on totally XPath-free XML files
    if (!ContextProvider.hasXPathInjections((XmlFile) file) && !XsltSupport.isXsltFile(file)) {
        return false;
    }
    // This need to catch both prefix references from injected XPathFiles and prefixes from mode declarations/references:
    // <xsl:template match="*" mode="prefix:name" />
    // BTW: Almost the same logic applies to other XML dialects (RELAX-NG).
    // Pull this class into the platform?
    final String prefix = attr.getLocalName();
    final SchemaPrefix target = new SchemaPrefix(attr, TextRange.from("xmlns:".length(), prefix.length()), prefix);
    final Query<PsiReference> q = ReferencesSearch.search(target, new LocalSearchScope(attr.getParent()));
    return !q.forEach(psiReference -> {
        if (psiReference.getElement() == attr) {
            return true;
        }
        return false;
    });
}
Also used : LocalSearchScope(com.intellij.psi.search.LocalSearchScope) ReferencesSearch(com.intellij.psi.search.searches.ReferencesSearch) SchemaPrefix(com.intellij.psi.impl.source.xml.SchemaPrefix) XmlAttribute(com.intellij.psi.xml.XmlAttribute) XmlFile(com.intellij.psi.xml.XmlFile) XsltSupport(org.intellij.lang.xpath.xslt.XsltSupport) PsiReference(com.intellij.psi.PsiReference) TextRange(com.intellij.openapi.util.TextRange) LocalSearchScope(com.intellij.psi.search.LocalSearchScope) Query(com.intellij.util.Query) Processor(com.intellij.util.Processor) PsiElement(com.intellij.psi.PsiElement) PsiFile(com.intellij.psi.PsiFile) ImplicitUsageProvider(com.intellij.codeInsight.daemon.ImplicitUsageProvider) ContextProvider(org.intellij.lang.xpath.context.ContextProvider) XmlAttribute(com.intellij.psi.xml.XmlAttribute) XmlFile(com.intellij.psi.xml.XmlFile) SchemaPrefix(com.intellij.psi.impl.source.xml.SchemaPrefix) PsiReference(com.intellij.psi.PsiReference) PsiFile(com.intellij.psi.PsiFile)

Aggregations

XmlFile (com.intellij.psi.xml.XmlFile)409 XmlTag (com.intellij.psi.xml.XmlTag)155 PsiFile (com.intellij.psi.PsiFile)121 VirtualFile (com.intellij.openapi.vfs.VirtualFile)102 Nullable (org.jetbrains.annotations.Nullable)74 Project (com.intellij.openapi.project.Project)69 NotNull (org.jetbrains.annotations.NotNull)66 PsiElement (com.intellij.psi.PsiElement)64 XmlAttribute (com.intellij.psi.xml.XmlAttribute)39 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)34 Module (com.intellij.openapi.module.Module)34 XmlDocument (com.intellij.psi.xml.XmlDocument)32 Result (com.intellij.openapi.application.Result)28 XmlElementDescriptor (com.intellij.xml.XmlElementDescriptor)23 XmlAttributeValue (com.intellij.psi.xml.XmlAttributeValue)22 XmlNSDescriptor (com.intellij.xml.XmlNSDescriptor)21 ArrayList (java.util.ArrayList)20 Document (com.intellij.openapi.editor.Document)19 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)18 Editor (com.intellij.openapi.editor.Editor)15