Search in sources :

Example 51 with Language

use of com.intellij.lang.Language in project intellij-community by JetBrains.

the class FoldingDescriptor method getPlaceholderText.

@Nullable
public String getPlaceholderText() {
    final PsiElement psiElement = myElement.getPsi();
    if (psiElement == null)
        return null;
    final Language lang = psiElement.getLanguage();
    final FoldingBuilder foldingBuilder = LanguageFolding.INSTANCE.forLanguage(lang);
    if (foldingBuilder != null) {
        return foldingBuilder instanceof FoldingBuilderEx ? ((FoldingBuilderEx) foldingBuilder).getPlaceholderText(myElement, myRange) : foldingBuilder.getPlaceholderText(myElement);
    }
    return null;
}
Also used : Language(com.intellij.lang.Language) PsiElement(com.intellij.psi.PsiElement) Nullable(org.jetbrains.annotations.Nullable)

Example 52 with Language

use of com.intellij.lang.Language in project intellij-community by JetBrains.

the class LangDiffIgnoredRangeProvider method getLanguage.

@Nullable
private static Language getLanguage(@NotNull Project project, @NotNull DiffContent content) {
    Language language = content.getUserData(DiffUserDataKeys.LANGUAGE);
    if (language != null)
        return language;
    FileType type = content.getContentType();
    if (type instanceof LanguageFileType)
        language = ((LanguageFileType) type).getLanguage();
    if (language != null && content instanceof DocumentContent) {
        VirtualFile highlightFile = ((DocumentContent) content).getHighlightFile();
        if (highlightFile != null)
            language = LanguageSubstitutors.INSTANCE.substituteLanguage(language, highlightFile, project);
    }
    return language;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) LanguageFileType(com.intellij.openapi.fileTypes.LanguageFileType) Language(com.intellij.lang.Language) FileType(com.intellij.openapi.fileTypes.FileType) LanguageFileType(com.intellij.openapi.fileTypes.LanguageFileType) DocumentContent(com.intellij.diff.contents.DocumentContent) Nullable(org.jetbrains.annotations.Nullable)

Example 53 with Language

use of com.intellij.lang.Language in project intellij-community by JetBrains.

the class XmlSurroundWithRangeAdjuster method getLanguage.

private static Language getLanguage(PsiElement element) {
    Language lang = element.getLanguage();
    if (lang == StdLanguages.XML) {
        PsiElement parent = element.getParent();
        lang = parent.getLanguage();
    }
    return lang;
}
Also used : Language(com.intellij.lang.Language) PsiElement(com.intellij.psi.PsiElement)

Example 54 with Language

use of com.intellij.lang.Language in project intellij-community by JetBrains.

the class XmlSurroundWithRangeAdjuster method adjustSurroundWithRange.

@Override
public TextRange adjustSurroundWithRange(final PsiFile file, final TextRange selectedRange) {
    if (!(file instanceof XmlFile))
        return selectedRange;
    int startOffset = selectedRange.getStartOffset();
    int endOffset = selectedRange.getEndOffset();
    PsiElement element1 = file.findElementAt(startOffset);
    PsiElement element2 = file.findElementAt(endOffset - 1);
    Language lang1 = getLanguage(element1);
    Language lang2 = getLanguage(element2);
    if (element1 instanceof PsiWhiteSpace && isLanguageWithWSSignificant(lang1)) {
        startOffset = element1.getTextRange().getEndOffset();
        element1 = file.findElementAt(startOffset);
    }
    if (element2 instanceof PsiWhiteSpace && isLanguageWithWSSignificant(lang2)) {
        endOffset = element2.getTextRange().getStartOffset();
        element2 = file.findElementAt(endOffset);
    }
    lang1 = getLanguage(element1);
    lang2 = getLanguage(element2);
    if (lang1 != lang2)
        return null;
    TextRange.assertProperRange(startOffset, endOffset, "Wrong offsets for " + selectedRange.substring(file.getText()));
    return new TextRange(startOffset, endOffset);
}
Also used : XmlFile(com.intellij.psi.xml.XmlFile) Language(com.intellij.lang.Language) TextRange(com.intellij.openapi.util.TextRange) PsiElement(com.intellij.psi.PsiElement) PsiWhiteSpace(com.intellij.psi.PsiWhiteSpace)

Example 55 with Language

use of com.intellij.lang.Language in project intellij-community by JetBrains.

the class SubstitutedFileType method substituteFileType.

@NotNull
public static FileType substituteFileType(@NotNull VirtualFile file, @NotNull FileType fileType, Project project) {
    if (project == null) {
        return fileType;
    }
    if (fileType instanceof LanguageFileType) {
        final Language language = ((LanguageFileType) fileType).getLanguage();
        final Language substitutedLanguage = LanguageSubstitutors.INSTANCE.substituteLanguage(language, file, project);
        LanguageFileType substFileType = substitutedLanguage.getAssociatedFileType();
        if (!substitutedLanguage.equals(language) && substFileType != null) {
            return new SubstitutedFileType(fileType, substFileType, substitutedLanguage);
        }
    }
    return fileType;
}
Also used : LanguageFileType(com.intellij.openapi.fileTypes.LanguageFileType) Language(com.intellij.lang.Language) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

Language (com.intellij.lang.Language)292 NotNull (org.jetbrains.annotations.NotNull)58 Nullable (org.jetbrains.annotations.Nullable)49 PsiElement (com.intellij.psi.PsiElement)46 PsiFile (com.intellij.psi.PsiFile)45 FileType (com.intellij.openapi.fileTypes.FileType)31 Project (com.intellij.openapi.project.Project)31 TextRange (com.intellij.openapi.util.TextRange)25 LanguageFileType (com.intellij.openapi.fileTypes.LanguageFileType)23 VirtualFile (com.intellij.openapi.vfs.VirtualFile)21 FileViewProvider (com.intellij.psi.FileViewProvider)21 HbLanguage (com.dmarcotte.handlebars.HbLanguage)20 JavaLanguage (com.intellij.lang.java.JavaLanguage)16 Editor (com.intellij.openapi.editor.Editor)14 XMLLanguage (com.intellij.lang.xml.XMLLanguage)12 TemplateLanguageFileViewProvider (com.intellij.psi.templateLanguages.TemplateLanguageFileViewProvider)11 List (java.util.List)11 HTMLLanguage (com.intellij.lang.html.HTMLLanguage)9 JavascriptLanguage (com.intellij.lang.javascript.JavascriptLanguage)9 Document (com.intellij.openapi.editor.Document)9