Migration to PsiFile-based code style API

This commit is contained in:
Rustam Vishnyakov
2017-12-29 17:39:43 +03:00
parent 6ede9d61a0
commit b87e08f706
2 changed files with 18 additions and 1 deletions
@@ -39,6 +39,7 @@ public class CodeStyle {
*/
@NotNull
public static CodeStyleSettings getDefaultSettings() {
//noinspection deprecation
return CodeStyleSettingsManager.getInstance().getCurrentSettings();
}
@@ -68,6 +69,19 @@ public class CodeStyle {
return getDefaultSettings();
}
public static CodeStyleSettings getSettings(@NotNull Editor editor) {
Project project = editor.getProject();
if (project != null) {
PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument());
if (file != null) {
return getSettings(file);
}
return getSettings(project);
}
return getDefaultSettings();
}
/**
* Returns language code style settings for the specified editor. If the editor has an associated document and PSI file, returns
* settings for the PSI file or {@code null} otherwise.
@@ -266,7 +266,10 @@ public class SettingsImpl implements EditorSettings {
@Override
public List<Integer> getSoftMargins() {
if (mySoftMargins != null) return mySoftMargins;
return CodeStyleSettingsManager.getSettings(myEditor == null ? null : myEditor.getProject()).getSoftMargins(myLanguage);
return
myEditor == null ?
CodeStyle.getDefaultSettings().getSoftMargins(myLanguage) :
CodeStyle.getSettings(myEditor).getSoftMargins(myLanguage);
}
@Override