Search in sources :

Example 36 with XmlFile

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

the class XsltNamespaceContext method getUnresolvedNamespaceFixesStatic.

public static IntentionAction[] getUnresolvedNamespaceFixesStatic(PsiReference reference, String localName) {
    final XmlElementFactory factory = XmlElementFactory.getInstance(reference.getElement().getProject());
    final XmlTag tag = factory.createTagFromText("<" + reference.getCanonicalText() + ":" + localName + " />", XMLLanguage.INSTANCE);
    final XmlFile xmlFile = PsiTreeUtil.getContextOfType(reference.getElement(), XmlFile.class, true);
    return new IntentionAction[] { new MyCreateNSDeclarationAction(tag, reference.getCanonicalText(), xmlFile) };
}
Also used : XmlFile(com.intellij.psi.xml.XmlFile) XmlElementFactory(com.intellij.psi.XmlElementFactory) IntentionAction(com.intellij.codeInsight.intention.IntentionAction) XmlTag(com.intellij.psi.xml.XmlTag)

Example 37 with XmlFile

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

the class XsltVariableContext method resolveInner.

@Nullable
private XPathVariable resolveInner(XPathVariableReference reference) {
    final XmlTag context = getContextTagImpl(reference);
    final VariableResolveProcessor processor = new VariableResolveProcessor(reference.getReferencedName(), context);
    final XPathVariable variable = (XPathVariable) ResolveUtil.treeWalkUp(processor, context);
    if (variable != null) {
        return variable;
    }
    if (!processForwardGlobals(context, processor)) {
        final XmlFile file = PsiTreeUtil.getParentOfType(context, XmlFile.class, true);
        if (file != null) {
            XsltIncludeIndex.processBackwardDependencies(file, xmlFile -> {
                processor.processExternalFile(xmlFile, context);
                return processor.shouldContinue();
            });
        }
    }
    return (XPathVariable) processor.getResult();
}
Also used : XPathVariable(org.intellij.lang.xpath.psi.XPathVariable) XmlFile(com.intellij.psi.xml.XmlFile) XmlTag(com.intellij.psi.xml.XmlTag) Nullable(org.jetbrains.annotations.Nullable)

Example 38 with XmlFile

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

the class XsltParameterImpl method getLocalUseScope.

@NotNull
@Override
public SearchScope getLocalUseScope() {
    final XmlTag tag = getTag();
    if (!tag.isValid()) {
        return getDefaultUseScope();
    }
    final XsltTemplate template = getTemplate();
    if (template == null) {
        return getDefaultUseScope();
    }
    if (template.getName() == null) {
        return getDefaultUseScope();
    }
    final XmlFile file = (XmlFile) tag.getContainingFile();
    if (!XsltIncludeIndex.processBackwardDependencies(file, new CommonProcessors.FindFirstProcessor<>())) {
        // processor found something
        return getDefaultUseScope();
    }
    return new LocalSearchScope(file);
}
Also used : LocalSearchScope(com.intellij.psi.search.LocalSearchScope) XmlFile(com.intellij.psi.xml.XmlFile) XsltTemplate(org.intellij.lang.xpath.xslt.psi.XsltTemplate) XmlTag(com.intellij.psi.xml.XmlTag) NotNull(org.jetbrains.annotations.NotNull)

Example 39 with XmlFile

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

the class EmmetPreviewUtil method calculateTemplateText.

@Nullable
public static String calculateTemplateText(@NotNull Editor editor, @NotNull PsiFile file, boolean expandPrimitiveAbbreviations) {
    if (file instanceof XmlFile) {
        PsiDocumentManager.getInstance(file.getProject()).commitDocument(editor.getDocument());
        CollectCustomTemplateCallback callback = new CollectCustomTemplateCallback(editor, file);
        PsiElement context = callback.getContext();
        ZenCodingGenerator generator = ZenCodingTemplate.findApplicableDefaultGenerator(context, false);
        if (generator != null && generator instanceof XmlZenCodingGenerator) {
            final String templatePrefix = new ZenCodingTemplate().computeTemplateKeyWithoutContextChecking(callback);
            if (templatePrefix != null) {
                try {
                    ZenCodingTemplate.expand(templatePrefix, callback, generator, Collections.<ZenCodingFilter>emptyList(), expandPrimitiveAbbreviations, 0);
                    TemplateImpl template = callback.getGeneratedTemplate();
                    String templateText = template != null ? template.getTemplateText() : null;
                    if (!StringUtil.isEmpty(templateText)) {
                        return template.isToReformat() ? reformatTemplateText(file, templateText) : templateText;
                    }
                } catch (EmmetException e) {
                    return e.getMessage();
                }
            }
        }
    }
    return null;
}
Also used : TemplateImpl(com.intellij.codeInsight.template.impl.TemplateImpl) XmlFile(com.intellij.psi.xml.XmlFile) XmlZenCodingGenerator(com.intellij.codeInsight.template.emmet.generators.XmlZenCodingGenerator) XmlZenCodingGenerator(com.intellij.codeInsight.template.emmet.generators.XmlZenCodingGenerator) ZenCodingGenerator(com.intellij.codeInsight.template.emmet.generators.ZenCodingGenerator) PsiElement(com.intellij.psi.PsiElement) Nullable(org.jetbrains.annotations.Nullable)

Example 40 with XmlFile

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

the class EmmetUpdateTagAction method processTags.

private static void processTags(@NotNull Project project, @Nullable String templateText, @NotNull PairProcessor<XmlTag, Boolean> processor) {
    if (StringUtil.isNotEmpty(templateText)) {
        final PsiFileFactory psiFileFactory = PsiFileFactory.getInstance(project);
        XmlFile xmlFile = (XmlFile) psiFileFactory.createFileFromText("dummy.xml", StdFileTypes.HTML, templateText);
        XmlTag tag = xmlFile.getRootTag();
        boolean firstTag = true;
        while (tag != null) {
            processor.process(tag, firstTag);
            firstTag = false;
            tag = PsiTreeUtil.getNextSiblingOfType(tag, XmlTag.class);
        }
    }
}
Also used : PsiFileFactory(com.intellij.psi.PsiFileFactory) XmlFile(com.intellij.psi.xml.XmlFile) XmlTag(com.intellij.psi.xml.XmlTag)

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