Child pages
  • New Code Style API in Intellij IDEA 2018.1
Skip to end of metadata
Go to start of metadata

There is a new code style API which requires providing a PsiFile to get code style settings rather than a project in cases where PSI file context makes sense. The ultimate goal of the change is to make it possible to specify code style settings per scope as requested, for example, in IDEA-69685. Besides the API provides a shorter form of getting a code style. So, for example, instead of writing CodeStyleSettings.getSettings(project).getCommonSettings(language) you can write CodeStyle.getLanguageSettings(file). Please check CodeStyle class for more information on methods.

Currently (within 2018.1 time frame) a migration to new CodeStyle API is ongoing. There is quite a big number of changes required both in Intellij IDEA platform and plug-ins. For now CodeStyle.getLanguageSettings(file) is equivalent to old CodeStyleSettings.getSettings(file.getProject()).getCommonSettings(file.getLanguage()) but this may change in the future when the most essential parts are migrated.

Please note: using CodeStyle.getSettings(project) instead of CodeStyle.getSettings(file) and etc. should be used only in cases when using main project settings is logically the only choice in a given context. It shouldn't be used just because an existing code doesn't allow to easily retrieve a PsiFile. Otherwise the code will not catch up with per file settings when they become available.

  • No labels

1 Comment

  1. The api should be consistent with inspection profiles