use of com.intellij.lang.Language in project intellij-community by JetBrains.
the class TabPostFormatProcessor method doProcess.
@NotNull
private static TextRange doProcess(@NotNull PsiElement source, @NotNull TextRange range, @NotNull CodeStyleSettings settings) {
ASTNode node = source.getNode();
if (node == null) {
return range;
}
Language language = source.getLanguage();
if (language != JavaLanguage.INSTANCE) {
// this logic to other languages as well.
return range;
}
if (!source.isValid())
return range;
PsiFile file = source.getContainingFile();
CommonCodeStyleSettings.IndentOptions indentOptions = settings.getIndentOptionsByFile(file, range);
boolean useTabs = indentOptions.USE_TAB_CHARACTER;
boolean smartTabs = indentOptions.SMART_TABS;
int tabWidth = indentOptions.TAB_SIZE;
return processViaPsi(node, range, new TreeHelperImpl(), useTabs, smartTabs, tabWidth);
}
use of com.intellij.lang.Language in project intellij-community by JetBrains.
the class InspectionEngine method addDialects.
private static void addDialects(@NotNull List<PsiElement> elements, @NotNull Set<Language> outProcessedLanguages, @NotNull Set<String> outDialectIds) {
for (PsiElement element : elements) {
Language language = element.getLanguage();
outDialectIds.add(language.getID());
if (outProcessedLanguages.add(language)) {
for (Language dialect : language.getDialects()) {
outDialectIds.add(dialect.getID());
}
}
}
}
use of com.intellij.lang.Language in project intellij-community by JetBrains.
the class ExternalAnnotatorBatchInspection method checkFile.
/**
* To be invoked during batch run
*/
@NotNull
default default ProblemDescriptor[] checkFile(@NotNull PsiFile file, @NotNull GlobalInspectionContext context, @NotNull InspectionManager manager) {
final String shortName = getShortName();
final FileViewProvider viewProvider = file.getViewProvider();
final Set<Language> relevantLanguages = viewProvider.getLanguages();
for (Language language : relevantLanguages) {
PsiFile psiRoot = viewProvider.getPsi(language);
final List<ExternalAnnotator> externalAnnotators = ExternalLanguageAnnotators.allForFile(language, psiRoot);
for (ExternalAnnotator annotator : externalAnnotators) {
if (shortName.equals(annotator.getPairedBatchInspectionShortName())) {
return ExternalAnnotatorInspectionVisitor.checkFileWithExternalAnnotator(file, manager, false, annotator);
}
}
}
return ProblemDescriptor.EMPTY_ARRAY;
}
use of com.intellij.lang.Language in project intellij-community by JetBrains.
the class DiffUtil method createEditorHighlighter.
@Nullable
private static EditorHighlighter createEditorHighlighter(@Nullable Project project, @NotNull DocumentContent content) {
FileType type = content.getContentType();
VirtualFile file = content.getHighlightFile();
Language language = content.getUserData(DiffUserDataKeys.LANGUAGE);
EditorHighlighterFactory highlighterFactory = EditorHighlighterFactory.getInstance();
if (language != null) {
SyntaxHighlighter syntaxHighlighter = SyntaxHighlighterFactory.getSyntaxHighlighter(language, project, file);
return highlighterFactory.createEditorHighlighter(syntaxHighlighter, EditorColorsManager.getInstance().getGlobalScheme());
}
if (file != null && file.isValid()) {
if ((type == null || type == PlainTextFileType.INSTANCE) || file.getFileType() == type || file instanceof LightVirtualFile) {
return highlighterFactory.createEditorHighlighter(project, file);
}
}
if (type != null) {
return highlighterFactory.createEditorHighlighter(project, type);
}
return null;
}
use of com.intellij.lang.Language in project intellij-community by JetBrains.
the class AutoFormatTypedHandler method isEnabled.
private static boolean isEnabled(Editor editor) {
boolean isEnabled = myIsEnabledInTests && ApplicationManager.getApplication().isUnitTestMode() || Registry.is("editor.reformat.on.typing");
if (!isEnabled) {
return false;
}
Project project = editor.getProject();
Language language = null;
if (project != null) {
PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument());
if (file != null) {
language = file.getLanguage();
}
}
return language == JavaLanguage.INSTANCE;
}
Aggregations