Search in sources :

Example 1 with TemplateLanguageFileViewProvider

use of com.intellij.psi.templateLanguages.TemplateLanguageFileViewProvider in project intellij-community by JetBrains.

the class XPathEvalAction method execute.

private void execute(Editor editor) {
    final Project project = editor.getProject();
    final PsiFile psiFile = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument());
    if (psiFile == null) {
        return;
    }
    InputExpressionDialog.Context input;
    XmlElement contextNode = null;
    final Config cfg = XPathAppComponent.getInstance().getConfig();
    do {
        RangeHighlighter contextHighlighter = null;
        if (cfg.isUseContextAtCursor()) {
            // find out current context node
            contextNode = MyPsiUtil.findContextNode(psiFile, editor);
            if (contextNode != null) {
                contextHighlighter = HighlighterUtil.highlightNode(editor, contextNode, cfg.getContextAttributes(), cfg);
            }
        }
        if (contextNode == null) {
            // in XPath data model, / is the document itself, including comments, PIs and the root element
            contextNode = ((XmlFile) psiFile).getDocument();
            if (contextNode == null) {
                FileViewProvider fileViewProvider = psiFile.getViewProvider();
                if (fileViewProvider instanceof TemplateLanguageFileViewProvider) {
                    Language dataLanguage = ((TemplateLanguageFileViewProvider) fileViewProvider).getTemplateDataLanguage();
                    PsiFile templateDataFile = fileViewProvider.getPsi(dataLanguage);
                    if (templateDataFile instanceof XmlFile)
                        contextNode = ((XmlFile) templateDataFile).getDocument();
                }
            }
        }
        input = inputXPathExpression(project, contextNode);
        if (contextHighlighter != null) {
            contextHighlighter.dispose();
        }
        if (input == null) {
            return;
        }
        HighlighterUtil.clearHighlighters(editor);
    } while (contextNode != null && evaluateExpression(input, contextNode, editor, cfg));
}
Also used : Project(com.intellij.openapi.project.Project) RangeHighlighter(com.intellij.openapi.editor.markup.RangeHighlighter) TemplateLanguageFileViewProvider(com.intellij.psi.templateLanguages.TemplateLanguageFileViewProvider) FileViewProvider(com.intellij.psi.FileViewProvider) Language(com.intellij.lang.Language) XmlFile(com.intellij.psi.xml.XmlFile) XmlElement(com.intellij.psi.xml.XmlElement) PsiFile(com.intellij.psi.PsiFile) TemplateLanguageFileViewProvider(com.intellij.psi.templateLanguages.TemplateLanguageFileViewProvider) InputExpressionDialog(org.intellij.plugins.xpathView.ui.InputExpressionDialog)

Example 2 with TemplateLanguageFileViewProvider

use of com.intellij.psi.templateLanguages.TemplateLanguageFileViewProvider in project intellij-community by JetBrains.

the class AbstractXmlBlock method buildInjectedPsiBlocks.

protected boolean buildInjectedPsiBlocks(List<Block> result, final ASTNode child, Wrap wrap, Alignment alignment, Indent indent) {
    if (isBuildIndentsOnly())
        return false;
    if (myInjectedBlockBuilder.addInjectedBlocks(result, child, wrap, alignment, indent)) {
        return true;
    }
    PsiFile containingFile = child.getPsi().getContainingFile();
    FileViewProvider fileViewProvider = containingFile.getViewProvider();
    if (fileViewProvider instanceof TemplateLanguageFileViewProvider) {
        Language templateLanguage = ((TemplateLanguageFileViewProvider) fileViewProvider).getTemplateDataLanguage();
        PsiElement at = fileViewProvider.findElementAt(child.getStartOffset(), templateLanguage);
        if (at instanceof XmlToken) {
            at = at.getParent();
        }
        // TODO: several comments
        if (at instanceof PsiComment && at.getTextRange().equals(child.getTextRange()) && at.getNode() != child) {
            return buildInjectedPsiBlocks(result, at.getNode(), wrap, alignment, indent);
        }
    }
    return false;
}
Also used : TemplateLanguageFileViewProvider(com.intellij.psi.templateLanguages.TemplateLanguageFileViewProvider) XMLLanguage(com.intellij.lang.xml.XMLLanguage) TemplateLanguageFileViewProvider(com.intellij.psi.templateLanguages.TemplateLanguageFileViewProvider)

Example 3 with TemplateLanguageFileViewProvider

use of com.intellij.psi.templateLanguages.TemplateLanguageFileViewProvider in project intellij-community by JetBrains.

the class XmlDocumentationProvider method generateHtmlAdditionalDocTemplate.

static String generateHtmlAdditionalDocTemplate(@NotNull PsiElement element) {
    StringBuilder buf = new StringBuilder();
    final PsiFile containingFile = element.getContainingFile();
    if (containingFile != null) {
        final XmlTag tag = PsiTreeUtil.getParentOfType(element, XmlTag.class, false);
        boolean append;
        if (tag instanceof HtmlTag) {
            append = true;
        } else {
            final FileViewProvider provider = containingFile.getViewProvider();
            Language language;
            if (provider instanceof TemplateLanguageFileViewProvider) {
                language = ((TemplateLanguageFileViewProvider) provider).getTemplateDataLanguage();
            } else {
                language = provider.getBaseLanguage();
            }
            append = language == XHTMLLanguage.INSTANCE;
        }
        if (tag != null) {
            EntityDescriptor descriptor = HtmlDescriptorsTable.getTagDescriptor(tag.getName());
            if (descriptor != null && append) {
                buf.append("<br>");
                buf.append(XmlBundle.message("html.quickdoc.additional.template", descriptor.getHelpRef(), BASE_SITEPOINT_URL + tag.getName()));
            }
        }
    }
    return buf.toString();
}
Also used : TemplateLanguageFileViewProvider(com.intellij.psi.templateLanguages.TemplateLanguageFileViewProvider) Language(com.intellij.lang.Language) XHTMLLanguage(com.intellij.lang.xhtml.XHTMLLanguage) HtmlTag(com.intellij.psi.html.HtmlTag) TemplateLanguageFileViewProvider(com.intellij.psi.templateLanguages.TemplateLanguageFileViewProvider)

Example 4 with TemplateLanguageFileViewProvider

use of com.intellij.psi.templateLanguages.TemplateLanguageFileViewProvider in project intellij-community by JetBrains.

the class XmlAutoPopupHandler method autoPopupXmlLookup.

public static void autoPopupXmlLookup(final Project project, final Editor editor) {
    AutoPopupController.getInstance(project).autoPopupMemberLookup(editor, file -> {
        int offset = editor.getCaretModel().getOffset();
        PsiElement lastElement = InjectedLanguageUtil.findElementAtNoCommit(file, offset - 1);
        if (lastElement instanceof PsiFile) {
            lastElement = file.findElementAt(offset - 1);
        }
        if (lastElement == null || !lastElement.isValid())
            return false;
        if (doCompleteIfNeeded(offset, file, lastElement)) {
            return true;
        }
        FileViewProvider fileViewProvider = file.getViewProvider();
        Language templateDataLanguage;
        final PsiElement parent = lastElement.getParent();
        if (fileViewProvider instanceof TemplateLanguageFileViewProvider && (templateDataLanguage = ((TemplateLanguageFileViewProvider) fileViewProvider).getTemplateDataLanguage()) != parent.getLanguage()) {
            lastElement = fileViewProvider.findElementAt(offset - 1, templateDataLanguage);
            if (lastElement == null || !lastElement.isValid())
                return false;
            return doCompleteIfNeeded(offset, file, lastElement);
        }
        return false;
    });
}
Also used : TemplateLanguageFileViewProvider(com.intellij.psi.templateLanguages.TemplateLanguageFileViewProvider) FileViewProvider(com.intellij.psi.FileViewProvider) Language(com.intellij.lang.Language) XMLLanguage(com.intellij.lang.xml.XMLLanguage) PsiFile(com.intellij.psi.PsiFile) TemplateLanguageFileViewProvider(com.intellij.psi.templateLanguages.TemplateLanguageFileViewProvider) PsiElement(com.intellij.psi.PsiElement)

Example 5 with TemplateLanguageFileViewProvider

use of com.intellij.psi.templateLanguages.TemplateLanguageFileViewProvider in project intellij-community by JetBrains.

the class HtmlUnknownTagInspection method createChangeTemplateDataFix.

@Nullable
@Override
protected LocalQuickFix createChangeTemplateDataFix(PsiFile file) {
    if (file != TemplateLanguageUtil.getTemplateFile(file))
        return null;
    FileViewProvider vp = file.getViewProvider();
    if (vp instanceof ConfigurableTemplateLanguageFileViewProvider) {
        final TemplateLanguageFileViewProvider viewProvider = (TemplateLanguageFileViewProvider) vp;
        final String text = LangBundle.message("quickfix.change.template.data.language.text", viewProvider.getTemplateDataLanguage().getDisplayName());
        return new LocalQuickFixOnPsiElement(file) {

            @NotNull
            @Override
            public String getText() {
                return text;
            }

            @Override
            public void invoke(@NotNull Project project, @NotNull PsiFile file, @NotNull PsiElement startElement, @NotNull PsiElement endElement) {
                ChangeTemplateDataLanguageAction.editSettings(project, file.getVirtualFile());
            }

            @Nls
            @NotNull
            @Override
            public String getFamilyName() {
                return "Change template data language";
            }
        };
    }
    return null;
}
Also used : LocalQuickFixOnPsiElement(com.intellij.codeInspection.LocalQuickFixOnPsiElement) Project(com.intellij.openapi.project.Project) TemplateLanguageFileViewProvider(com.intellij.psi.templateLanguages.TemplateLanguageFileViewProvider) ConfigurableTemplateLanguageFileViewProvider(com.intellij.psi.templateLanguages.ConfigurableTemplateLanguageFileViewProvider) FileViewProvider(com.intellij.psi.FileViewProvider) PsiFile(com.intellij.psi.PsiFile) TemplateLanguageFileViewProvider(com.intellij.psi.templateLanguages.TemplateLanguageFileViewProvider) ConfigurableTemplateLanguageFileViewProvider(com.intellij.psi.templateLanguages.ConfigurableTemplateLanguageFileViewProvider) ConfigurableTemplateLanguageFileViewProvider(com.intellij.psi.templateLanguages.ConfigurableTemplateLanguageFileViewProvider) NotNull(org.jetbrains.annotations.NotNull) PsiElement(com.intellij.psi.PsiElement) LocalQuickFixOnPsiElement(com.intellij.codeInspection.LocalQuickFixOnPsiElement) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

TemplateLanguageFileViewProvider (com.intellij.psi.templateLanguages.TemplateLanguageFileViewProvider)13 Language (com.intellij.lang.Language)11 PsiFile (com.intellij.psi.PsiFile)6 FileViewProvider (com.intellij.psi.FileViewProvider)5 PsiElement (com.intellij.psi.PsiElement)4 XMLLanguage (com.intellij.lang.xml.XMLLanguage)3 Project (com.intellij.openapi.project.Project)3 NotNull (org.jetbrains.annotations.NotNull)3 Nullable (org.jetbrains.annotations.Nullable)3 XHTMLLanguage (com.intellij.lang.xhtml.XHTMLLanguage)2 HtmlTag (com.intellij.psi.html.HtmlTag)2 InspectionProfile (com.intellij.codeInspection.InspectionProfile)1 LocalQuickFixOnPsiElement (com.intellij.codeInspection.LocalQuickFixOnPsiElement)1 InspectionToolWrapper (com.intellij.codeInspection.ex.InspectionToolWrapper)1 XHtmlFileType (com.intellij.ide.highlighter.XHtmlFileType)1 XmlFileType (com.intellij.ide.highlighter.XmlFileType)1 ASTNode (com.intellij.lang.ASTNode)1 HTMLLanguage (com.intellij.lang.html.HTMLLanguage)1 RangeHighlighter (com.intellij.openapi.editor.markup.RangeHighlighter)1 FileType (com.intellij.openapi.fileTypes.FileType)1