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;
}
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;
}
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;
}
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);
}
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;
}
Aggregations