Search in sources :

Example 11 with TemplateLanguageFileViewProvider

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

the class ExternalDocumentValidator method doValidation.

public static synchronized void doValidation(final XmlDocument document, final Validator.ValidationHost host) {
    final PsiFile containingFile = document.getContainingFile();
    if (containingFile == null) {
        return;
    }
    if (containingFile.getViewProvider() instanceof TemplateLanguageFileViewProvider) {
        return;
    }
    final FileType fileType = containingFile.getViewProvider().getFileType();
    if (fileType != XmlFileType.INSTANCE && fileType != XHtmlFileType.INSTANCE) {
        return;
    }
    for (Language lang : containingFile.getViewProvider().getLanguages()) {
        if ("ANT".equals(lang.getID()))
            return;
    }
    final XmlTag rootTag = document.getRootTag();
    if (rootTag == null)
        return;
    String namespace = rootTag.getNamespace();
    if (XmlUtil.ANT_URI.equals(namespace))
        return;
    final Project project = document.getProject();
    final InspectionProfile profile = InspectionProjectProfileManager.getInstance(project).getCurrentProfile();
    final InspectionToolWrapper toolWrapper = profile.getInspectionTool(INSPECTION_SHORT_NAME, containingFile);
    if (toolWrapper == null)
        return;
    if (!profile.isToolEnabled(HighlightDisplayKey.find(INSPECTION_SHORT_NAME), containingFile))
        return;
    SoftReference<ExternalDocumentValidator> validatorReference = project.getUserData(validatorInstanceKey);
    ExternalDocumentValidator validator = SoftReference.dereference(validatorReference);
    if (validator == null) {
        validator = new ExternalDocumentValidator();
        project.putUserData(validatorInstanceKey, new SoftReference<>(validator));
    }
    validator.runJaxpValidation(document, host);
}
Also used : Project(com.intellij.openapi.project.Project) Language(com.intellij.lang.Language) XHtmlFileType(com.intellij.ide.highlighter.XHtmlFileType) XmlFileType(com.intellij.ide.highlighter.XmlFileType) FileType(com.intellij.openapi.fileTypes.FileType) InspectionProfile(com.intellij.codeInspection.InspectionProfile) PsiFile(com.intellij.psi.PsiFile) TemplateLanguageFileViewProvider(com.intellij.psi.templateLanguages.TemplateLanguageFileViewProvider) InspectionToolWrapper(com.intellij.codeInspection.ex.InspectionToolWrapper)

Example 12 with TemplateLanguageFileViewProvider

use of com.intellij.psi.templateLanguages.TemplateLanguageFileViewProvider 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)

Example 13 with TemplateLanguageFileViewProvider

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

the class EmmetEditPointUtil method moveToNextPoint.

private static void moveToNextPoint(Editor editor, PsiFile file, int offset, int inc) {
    final Document doc = editor.getDocument();
    final TemplateLanguageFileViewProvider provider = ObjectUtils.tryCast(file.getViewProvider(), TemplateLanguageFileViewProvider.class);
    final Language additionalLanguage = provider != null ? provider.getTemplateDataLanguage() : null;
    PsiDocumentManager.getInstance(file.getProject()).commitDocument(doc);
    for (int i = offset + inc; i < doc.getTextLength() && i >= 0; i += inc) {
        PsiElement current = InjectedLanguageUtil.findElementAtNoCommit(file, i);
        if (checkAndMove(editor, doc, i, current))
            return;
        if (additionalLanguage != null) {
            current = provider.findElementAt(i, additionalLanguage);
            if (checkAndMove(editor, doc, i, current))
                return;
        }
    }
}
Also used : Language(com.intellij.lang.Language) TemplateLanguageFileViewProvider(com.intellij.psi.templateLanguages.TemplateLanguageFileViewProvider) PsiElement(com.intellij.psi.PsiElement)

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