Search in sources :

Example 1 with MultipleLangCommentProvider

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

the class CommentByBlockCommentHandler method getCommenter.

@Nullable
public static Commenter getCommenter(final PsiFile file, final Editor editor, final Language lineStartLanguage, final Language lineEndLanguage) {
    final FileViewProvider viewProvider = file.getViewProvider();
    for (MultipleLangCommentProvider provider : MultipleLangCommentProvider.EP_NAME.getExtensions()) {
        if (provider.canProcess(file, viewProvider)) {
            return provider.getLineCommenter(file, editor, lineStartLanguage, lineEndLanguage);
        }
    }
    final Language fileLanguage = file.getLanguage();
    Language lang = lineStartLanguage == null || LanguageCommenters.INSTANCE.forLanguage(lineStartLanguage) == null || // file language is a more specific dialect of the line language
    fileLanguage.getBaseLanguage() == lineStartLanguage ? fileLanguage : lineStartLanguage;
    if (viewProvider instanceof TemplateLanguageFileViewProvider && lang == ((TemplateLanguageFileViewProvider) viewProvider).getTemplateDataLanguage()) {
        lang = viewProvider.getBaseLanguage();
    }
    return LanguageCommenters.INSTANCE.forLanguage(lang);
}
Also used : TemplateLanguageFileViewProvider(com.intellij.psi.templateLanguages.TemplateLanguageFileViewProvider) Language(com.intellij.lang.Language) TemplateLanguageFileViewProvider(com.intellij.psi.templateLanguages.TemplateLanguageFileViewProvider) MultipleLangCommentProvider(com.intellij.psi.templateLanguages.MultipleLangCommentProvider) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

Language (com.intellij.lang.Language)1 MultipleLangCommentProvider (com.intellij.psi.templateLanguages.MultipleLangCommentProvider)1 TemplateLanguageFileViewProvider (com.intellij.psi.templateLanguages.TemplateLanguageFileViewProvider)1 Nullable (org.jetbrains.annotations.Nullable)1