Search in sources :

Example 36 with FileViewProvider

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

the class SimpleTemplateLanguageFormattingModelBuilder method createModel.

@Override
@NotNull
public FormattingModel createModel(final PsiElement element, final CodeStyleSettings settings) {
    if (element instanceof PsiFile) {
        final FileViewProvider viewProvider = ((PsiFile) element).getViewProvider();
        if (viewProvider instanceof TemplateLanguageFileViewProvider) {
            final Language language = ((TemplateLanguageFileViewProvider) viewProvider).getTemplateDataLanguage();
            FormattingModelBuilder builder = LanguageFormatting.INSTANCE.forLanguage(language);
            if (builder != null) {
                return builder.createModel(viewProvider.getPsi(language), settings);
            }
        }
    }
    final PsiFile file = element.getContainingFile();
    return new DocumentBasedFormattingModel(new AbstractBlock(element.getNode(), Wrap.createWrap(WrapType.NONE, false), Alignment.createAlignment()) {

        @Override
        protected List<Block> buildChildren() {
            return Collections.emptyList();
        }

        @Override
        public Spacing getSpacing(final Block child1, @NotNull final Block child2) {
            return Spacing.getReadOnlySpacing();
        }

        @Override
        public boolean isLeaf() {
            return true;
        }
    }, element.getProject(), settings, file.getFileType(), file);
}
Also used : DocumentBasedFormattingModel(com.intellij.psi.formatter.DocumentBasedFormattingModel) FileViewProvider(com.intellij.psi.FileViewProvider) Language(com.intellij.lang.Language) AbstractBlock(com.intellij.psi.formatter.common.AbstractBlock) PsiFile(com.intellij.psi.PsiFile) List(java.util.List) AbstractBlock(com.intellij.psi.formatter.common.AbstractBlock) NotNull(org.jetbrains.annotations.NotNull)

Example 37 with FileViewProvider

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

the class TemplateDataElementType method createPsiFileFromSource.

protected PsiFile createPsiFileFromSource(final Language language, CharSequence sourceCode, PsiManager manager) {
    @NonNls final LightVirtualFile virtualFile = new LightVirtualFile("foo", createTemplateFakeFileType(language), sourceCode, LocalTimeCounter.currentTime());
    FileViewProvider viewProvider = new SingleRootFileViewProvider(manager, virtualFile, false) {

        @Override
        @NotNull
        public Language getBaseLanguage() {
            return language;
        }
    };
    // Since we're already inside a template language PSI that was built regardless of the file size (for whatever reason), 
    // there should also be no file size checks for template data files.
    SingleRootFileViewProvider.doNotCheckFileSizeLimit(virtualFile);
    return viewProvider.getPsi(language);
}
Also used : NonNls(org.jetbrains.annotations.NonNls) FileViewProvider(com.intellij.psi.FileViewProvider) SingleRootFileViewProvider(com.intellij.psi.SingleRootFileViewProvider) LightVirtualFile(com.intellij.testFramework.LightVirtualFile) SingleRootFileViewProvider(com.intellij.psi.SingleRootFileViewProvider)

Example 38 with FileViewProvider

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

the class XmlTagTreeHighlightingPass method doCollectInformation.

@Override
public void doCollectInformation(@NotNull ProgressIndicator progress) {
    if (ApplicationManager.getApplication().isUnitTestMode()) {
        return;
    }
    if (!WebEditorOptions.getInstance().isTagTreeHighlightingEnabled()) {
        return;
    }
    final int offset = myEditor.getCaretModel().getOffset();
    PsiElement[] elements = BreadcrumbsXmlWrapper.getLinePsiElements(offset, myFile.getVirtualFile(), myProject, myInfoProvider);
    if (elements == null || elements.length == 0 || !XmlTagTreeHighlightingUtil.containsTagsWithSameName(elements)) {
        elements = PsiElement.EMPTY_ARRAY;
        final FileViewProvider provider = myFile.getViewProvider();
        for (Language language : provider.getLanguages()) {
            PsiElement element = provider.findElementAt(offset, language);
            if (!isTagStartOrEnd(element)) {
                element = null;
            }
            if (element == null && offset > 0) {
                element = provider.findElementAt(offset - 1, language);
                if (!isTagStartOrEnd(element))
                    element = null;
            }
            final XmlTag tag = PsiTreeUtil.getParentOfType(element, XmlTag.class);
            if (tag != null) {
                elements = new PsiElement[] { tag };
            }
        }
    }
    for (int i = elements.length - 1; i >= 0; i--) {
        if (elements[i] instanceof XmlTag) {
            myPairsToHighlight.add(getTagRanges((XmlTag) elements[i]));
        }
    }
}
Also used : FileViewProvider(com.intellij.psi.FileViewProvider) Language(com.intellij.lang.Language) PsiElement(com.intellij.psi.PsiElement) XmlTag(com.intellij.psi.xml.XmlTag)

Example 39 with FileViewProvider

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

the class CollapseTagIntention method getTag.

private static XmlTag getTag(Editor editor, PsiFile file) {
    int offset = editor.getCaretModel().getOffset();
    FileViewProvider provider = file.getViewProvider();
    for (Language language : provider.getLanguages()) {
        PsiElement element = provider.findElementAt(offset, language);
        XmlTag tag = PsiTreeUtil.getParentOfType(element, XmlTag.class);
        if (tag != null && XmlChildRole.START_TAG_END_FINDER.findChild(tag.getNode()) != null) {
            return tag;
        }
    }
    return null;
}
Also used : FileViewProvider(com.intellij.psi.FileViewProvider) Language(com.intellij.lang.Language) PsiElement(com.intellij.psi.PsiElement) XmlTag(com.intellij.psi.xml.XmlTag)

Example 40 with FileViewProvider

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

the class HtmlUtil method isHtmlTagContainingFile.

public static boolean isHtmlTagContainingFile(PsiElement element) {
    if (element == null) {
        return false;
    }
    final PsiFile containingFile = element.getContainingFile();
    if (containingFile != null) {
        final XmlTag tag = PsiTreeUtil.getParentOfType(element, XmlTag.class, false);
        if (tag instanceof HtmlTag) {
            return true;
        }
        final XmlDocument document = PsiTreeUtil.getParentOfType(element, XmlDocument.class, false);
        if (document instanceof HtmlDocumentImpl) {
            return true;
        }
        final FileViewProvider provider = containingFile.getViewProvider();
        Language language;
        if (provider instanceof TemplateLanguageFileViewProvider) {
            language = ((TemplateLanguageFileViewProvider) provider).getTemplateDataLanguage();
        } else {
            language = provider.getBaseLanguage();
        }
        return language == XHTMLLanguage.INSTANCE;
    }
    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) XHTMLLanguage(com.intellij.lang.xhtml.XHTMLLanguage) HTMLLanguage(com.intellij.lang.html.HTMLLanguage) HtmlDocumentImpl(com.intellij.psi.impl.source.html.HtmlDocumentImpl) PsiFile(com.intellij.psi.PsiFile) HtmlTag(com.intellij.psi.html.HtmlTag) TemplateLanguageFileViewProvider(com.intellij.psi.templateLanguages.TemplateLanguageFileViewProvider)

Aggregations

FileViewProvider (com.intellij.psi.FileViewProvider)41 PsiFile (com.intellij.psi.PsiFile)22 Language (com.intellij.lang.Language)21 PsiElement (com.intellij.psi.PsiElement)15 NotNull (org.jetbrains.annotations.NotNull)12 TextRange (com.intellij.openapi.util.TextRange)6 VirtualFile (com.intellij.openapi.vfs.VirtualFile)5 TemplateLanguageFileViewProvider (com.intellij.psi.templateLanguages.TemplateLanguageFileViewProvider)5 Project (com.intellij.openapi.project.Project)4 ASTNode (com.intellij.lang.ASTNode)3 Document (com.intellij.openapi.editor.Document)3 Pair (com.intellij.openapi.util.Pair)3 Nullable (org.jetbrains.annotations.Nullable)3 HighlightingLevelManager (com.intellij.codeInsight.daemon.impl.analysis.HighlightingLevelManager)2 FileASTNode (com.intellij.lang.FileASTNode)2 ExternalAnnotator (com.intellij.lang.annotation.ExternalAnnotator)2 XMLLanguage (com.intellij.lang.xml.XMLLanguage)2 FileType (com.intellij.openapi.fileTypes.FileType)2 SingleRootFileViewProvider (com.intellij.psi.SingleRootFileViewProvider)2 IStubFileElementType (com.intellij.psi.tree.IStubFileElementType)2