Getting indent settings from CodeStyleSettings does not work.


When using CodeStyleSettings settings = CodeStyleSettingsManager.getInstance(project).getMainProjectCodeStyle(); with my style settings changed from the default (Tab Size: 2, Indent: 2), I still get a response of 4 (the default size) when calling any of the following:

  • settings.getTabSize(JavaFileType)
  • settings.getIndentOptions().TAB_SIZE
  • settings.getIndentOptions().INDENT_SIZE

even though they should all give a response of 2 due to the setting changes.

Has anyone experienced this before, or am I just using this incorrectly? 




Please provide more information.

Where do you change the settings? Please paste screenshot.

What is the full context of the code? Please share the whole method or class.



Settings are changed in the settings menu, have attached screenshot below. For the record, I have changed default, demo, and project settings all with the same results.

This is the method attempting to get the tab size, as mentioned I have tried many different methods to get the tab size.

public class SettingUtils {
  private SettingUtils() {

  public static String getDefaultTabCharacter(Project project) {
    var settings = CodeStyleSettingsManager.getInstance(project).getMainProjectCodeStyle();

    assert settings != null;
    var useSoftTabs = !settings.getIndentOptions(FileUtils.getJavaFileType()).USE_TAB_CHARACTER;

    if (useSoftTabs) {
      var tabSize = settings.getIndentOptions().TAB_SIZE;
      return " ".repeat(tabSize);
    } else {
      return "\t";

And  to get the project, I'm using the following line in my action:
this.project = e.getRequiredData(CommonDataKeys.PROJECT);

Let me know if you'd like any more context.



Please try one of com.intellij.application.options.CodeStyle's static methods, e.g., getSettings() or getLanguageSettings().


Great that worked. Thank you Kaorl


Please sign in to leave a comment.