mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Allow nullable project but with optional code style settings returned
This commit is contained in:
@@ -55,6 +55,17 @@ public class CodeStyle {
|
||||
return CodeStyleSettingsManager.getInstance(project).getCurrentSettings();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns either project settings if the project is not null or default application-wide settings otherwise.
|
||||
*
|
||||
* @param project The project to return the settings for or {@code null} for default settings.
|
||||
* @return Project or default code style settings.
|
||||
*/
|
||||
@NotNull
|
||||
public static CodeStyleSettings getProjectOrDefaultSettings(@Nullable Project project) {
|
||||
return project != null ? getSettings(project) : getDefaultSettings();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns root code style settings for the given PSI file. For configurable language settings use {@link #getLanguageSettings(PsiFile)} or
|
||||
* {@link #getLanguageSettings(PsiFile, Language)}.
|
||||
|
||||
+3
-6
@@ -17,7 +17,7 @@ package com.intellij.openapi.fileEditor.impl;
|
||||
|
||||
import com.intellij.AppTopics;
|
||||
import com.intellij.CommonBundle;
|
||||
import com.intellij.codeStyle.CodeStyleFacade;
|
||||
import com.intellij.application.options.CodeStyle;
|
||||
import com.intellij.openapi.Disposable;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.application.TransactionGuard;
|
||||
@@ -113,7 +113,7 @@ public class FileDocumentManagerImpl extends FileDocumentManager implements Virt
|
||||
Project project = currentCommand == null ? null : CommandProcessor.getInstance().getCurrentCommandProject();
|
||||
if (project == null)
|
||||
project = ProjectUtil.guessProjectForFile(getFile(document));
|
||||
String lineSeparator = CodeStyleFacade.getInstance(project).getLineSeparator();
|
||||
String lineSeparator = CodeStyle.getProjectOrDefaultSettings(project).getLineSeparator();
|
||||
document.putUserData(LINE_SEPARATOR_KEY, lineSeparator);
|
||||
|
||||
// avoid documents piling up during batch processing
|
||||
@@ -493,10 +493,7 @@ public class FileDocumentManagerImpl extends FileDocumentManager implements Virt
|
||||
public String getLineSeparator(@Nullable VirtualFile file, @Nullable Project project) {
|
||||
String lineSeparator = file == null ? null : LoadTextUtil.getDetectedLineSeparator(file);
|
||||
if (lineSeparator == null) {
|
||||
CodeStyleFacade settingsManager = project == null
|
||||
? CodeStyleFacade.getInstance()
|
||||
: CodeStyleFacade.getInstance(project);
|
||||
lineSeparator = settingsManager.getLineSeparator();
|
||||
lineSeparator = CodeStyle.getProjectOrDefaultSettings(project).getLineSeparator();
|
||||
}
|
||||
return lineSeparator;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user