Deprecate common code style settings in CodeStyleSettings class

Common settings can be referenced only by language.
This commit is contained in:
Rustam Vishnyakov
2017-12-27 15:02:43 +03:00
parent d96d1e00d1
commit 22aa31baf8
13 changed files with 359 additions and 42 deletions
@@ -35,6 +35,8 @@ import java.util.*;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
import static com.intellij.psi.codeStyle.CommonCodeStyleSettings.IndentOptions;
/**
* <p>
* A container for global, language and custom code style settings and indent options. Global options are default options for multiple
@@ -51,7 +53,7 @@ import java.util.regex.PatternSyntaxException;
* <b>Note:</b> A direct use of any non-final public fields from {@code CodeStyleSettings} class is strongly discouraged. These fields,
* as well as the inheritance from {@code CommonCodeStyleSettings}, are left only for backwards compatibility and may be removed in the future.
*/
public class CodeStyleSettings extends CommonCodeStyleSettings
public class CodeStyleSettings extends LegacyCodeStyleSettings
implements Cloneable, JDOMExternalizable, ImportsLayoutSettings, CodeStyleConstraints {
public static final int CURR_VERSION = 173;
@@ -70,6 +72,8 @@ public class CodeStyleSettings extends CommonCodeStyleSettings
private UnknownElementWriter myUnknownElementWriter = UnknownElementWriter.EMPTY;
private SoftMargins mySoftMargins = new SoftMargins();
private int myVersion = CURR_VERSION;
public CodeStyleSettings() {
@@ -77,7 +81,6 @@ public class CodeStyleSettings extends CommonCodeStyleSettings
}
public CodeStyleSettings(boolean loadExtensions) {
super(null);
initTypeToName();
initImportsByDefault();
@@ -181,9 +184,9 @@ public class CodeStyleSettings extends CommonCodeStyleSettings
}
public void copyFrom(CodeStyleSettings from) {
copyPublicFields(from, this);
copyPublicFields(from.OTHER_INDENT_OPTIONS, OTHER_INDENT_OPTIONS);
mySoftMargins.setValues(from.getSoftMargins());
CommonCodeStyleSettings.copyPublicFields(from, this);
CommonCodeStyleSettings.copyPublicFields(from.OTHER_INDENT_OPTIONS, OTHER_INDENT_OPTIONS);
mySoftMargins.setValues(from.getDefaultSoftMargins());
copyCustomSettingsFrom(from);
}
@@ -897,7 +900,6 @@ public class CodeStyleSettings extends CommonCodeStyleSettings
return new IndentOptions();
}
@Override
@Nullable
public IndentOptions getIndentOptions() {
return OTHER_INDENT_OPTIONS;
@@ -1040,8 +1042,11 @@ public class CodeStyleSettings extends CommonCodeStyleSettings
@Nullable
private IndentOptions getIndentOptions(Language lang) {
CommonCodeStyleSettings langSettings = getCommonSettings(lang);
return langSettings == this ? null : langSettings.getIndentOptions();
final LanguageCodeStyleSettingsProvider provider = LanguageCodeStyleSettingsProvider.forLanguage(lang);
if (provider != null) {
return getCommonSettings(lang).getIndentOptions();
}
return null;
}
public boolean isSmartTabs(FileType fileType) {
@@ -1307,8 +1312,8 @@ public class CodeStyleSettings extends CommonCodeStyleSettings
if (language != null) {
CommonCodeStyleSettings langSettings = getCommonSettings(language);
if (langSettings != null) {
if (langSettings.WRAP_ON_TYPING != WrapOnTyping.DEFAULT.intValue) {
return langSettings.WRAP_ON_TYPING == WrapOnTyping.WRAP.intValue;
if (langSettings.WRAP_ON_TYPING != CommonCodeStyleSettings.WrapOnTyping.DEFAULT.intValue) {
return langSettings.WRAP_ON_TYPING == CommonCodeStyleSettings.WrapOnTyping.WRAP.intValue;
}
}
}
@@ -1425,7 +1430,7 @@ public class CodeStyleSettings extends CommonCodeStyleSettings
*/
@NotNull
public List<Integer> getDefaultSoftMargins() {
return getSoftMargins();
return mySoftMargins.getValues();
}
/**
@@ -1433,6 +1438,6 @@ public class CodeStyleSettings extends CommonCodeStyleSettings
* @param softMargins The default soft margins.
*/
public void setDefaultSoftMargins(List<Integer> softMargins) {
setSoftMargins(softMargins);
mySoftMargins.setValues(softMargins);
}
}
@@ -58,11 +58,11 @@ public class CommonCodeStyleSettings {
private ArrangementSettings myArrangementSettings;
private CodeStyleSettings myRootSettings;
private IndentOptions myIndentOptions;
private @Nullable IndentOptions myIndentOptions;
private final FileType myFileType;
private boolean myForceArrangeMenuAvailable;
protected SoftMargins mySoftMargins = new SoftMargins();
private SoftMargins mySoftMargins = new SoftMargins();
@NonNls private static final String INDENT_OPTIONS_TAG = "indentOptions";
@@ -138,7 +138,7 @@ public class CommonCodeStyleSettings {
return commonSettings;
}
protected static void copyPublicFields(Object from, Object to) {
static void copyPublicFields(Object from, Object to) {
assert from != to;
ReflectionUtil.copyFields(to.getClass().getFields(), from, to);
}
@@ -169,6 +169,9 @@ public class CommonCodeStyleSettings {
if (supportedFields != null) {
supportedFields.add("FORCE_REARRANGE_MODE");
}
else {
return;
}
DefaultJDOMExternalizer.writeExternal(this, element, new SupportedFieldsDiffFilter(this, supportedFields, defaultSettings));
mySoftMargins.serializeInto(element);
if (myIndentOptions != null) {
@@ -207,7 +210,7 @@ public class CommonCodeStyleSettings {
@Override
public boolean isAccept(@NotNull Field field) {
if (mySupportedFieldNames == null ||
if (mySupportedFieldNames != null &&
mySupportedFieldNames.contains(field.getName())) {
return super.isAccept(field);
}
@@ -16,12 +16,14 @@
package com.intellij.psi.codeStyle;
import com.intellij.lang.Language;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.extensions.Extensions;
import com.intellij.openapi.util.InvalidDataException;
import com.intellij.openapi.util.JDOMUtil;
import com.intellij.openapi.util.WriteExternalException;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.util.ArrayUtil;
import com.intellij.util.ObjectUtils;
import com.intellij.util.containers.ContainerUtil;
import gnu.trove.THashMap;
import org.jdom.Content;
@@ -48,6 +50,15 @@ public class CommonCodeStyleSettingsManager {
@NonNls static final String COMMON_SETTINGS_TAG = "codeStyleSettings";
private static final String LANGUAGE_ATTR = "language";
private static Logger LOG = Logger.getInstance(CommonCodeStyleSettingsManager.class);
private static class DefaultsHolder {
private final static CommonCodeStyleSettings SETTINGS = new CommonCodeStyleSettings(Language.ANY);
static {
SETTINGS.setRootSettings(CodeStyleSettings.getDefaults());
}
}
CommonCodeStyleSettingsManager(@NotNull CodeStyleSettings parentSettings) {
myParentSettings = parentSettings;
}
@@ -58,20 +69,21 @@ public class CommonCodeStyleSettingsManager {
* @param lang The language to get settings for.
* @return If the provider for the language exists and is able to create language-specific default settings
* ({@code LanguageCodeStyleSettingsProvider.getDefaultCommonSettings()} doesn't return null)
* returns the instance of settings for this language. Otherwise returns the instance of parent settings
* shared between several languages.
* returns the instance of settings for this language. Otherwise returns new instance of common code style settings
* with default values.
*/
public CommonCodeStyleSettings getCommonSettings(@Nullable Language lang) {
Map<Language, CommonCodeStyleSettings> commonSettingsMap = getCommonSettingsMap();
CommonCodeStyleSettings settings = commonSettingsMap.get(lang);
while (settings == null && lang != null) {
lang = lang.getBaseLanguage();
settings = commonSettingsMap.get(lang);
Language baseLang = ObjectUtils.notNull(lang, Language.ANY);
while (baseLang != null) {
CommonCodeStyleSettings settings = commonSettingsMap.get(baseLang);
if (settings != null) return settings;
baseLang = baseLang.getBaseLanguage();
}
if (settings != null) {
return settings;
if (lang != null) {
LOG.warn("Common code style settings for language '" + lang.getDisplayName() + "' not found, using defaults.");
}
return myParentSettings;
return DefaultsHolder.SETTINGS;
}
@NotNull
@@ -95,7 +107,7 @@ public class CommonCodeStyleSettingsManager {
* obtained by name.
*
* @param langName The display name of the language whose settings must be returned.
* @return Common code style settings for the given language or parent (shared) settings if not found.
* @return Common code style settings for the given language or a new instance with default values if not found.
*/
@NotNull
public CommonCodeStyleSettings getCommonSettings(@NotNull String langName) {
@@ -105,7 +117,7 @@ public class CommonCodeStyleSettingsManager {
return entry.getValue();
}
}
return myParentSettings;
return new CommonCodeStyleSettings(Language.ANY);
}
@@ -30,7 +30,7 @@ import java.util.ArrayList;
import java.util.Set;
/**
* Base class and extension point for code style settings shared between multiple languages
* Base class and extension point for common code style settings for a specific language.
*/
public abstract class LanguageCodeStyleSettingsProvider {
public static final ExtensionPointName<LanguageCodeStyleSettingsProvider> EP_NAME =
@@ -0,0 +1,282 @@
// Copyright 2000-2017 JetBrains s.r.o.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package com.intellij.psi.codeStyle;
import com.intellij.lang.Language;
import com.intellij.psi.PsiFile;
/**
* Contains fields which are left for compatibility with earlier versions. These fields shouldn't be used anymore. Every language must have
* its own settings which can be retrieved using {@link CodeStyleSettings#getCommonSettings(Language)} or
* {@link com.intellij.application.options.CodeStyle#getLanguageSettings(PsiFile)}.
*
* @see LanguageCodeStyleSettingsProvider
*/
@Deprecated
public class LegacyCodeStyleSettings {
/**
* @deprecated Use {@link CommonCodeStyleSettings#DO_NOT_WRAP}
*/
@Deprecated public static final int DO_NOT_WRAP = CommonCodeStyleSettings.DO_NOT_WRAP;
/**
* @deprecated Use {@link CommonCodeStyleSettings#WRAP_AS_NEEDED}
*/
@Deprecated public static final int WRAP_AS_NEEDED = CommonCodeStyleSettings.WRAP_AS_NEEDED;
/**
* @deprecated Use {@link CommonCodeStyleSettings#WRAP_ALWAYS}
*/
@Deprecated public static final int WRAP_ALWAYS = CommonCodeStyleSettings.WRAP_ALWAYS;
/**
* @deprecated Use {@link CommonCodeStyleSettings#WRAP_ON_EVERY_ITEM}
*/
@Deprecated public static final int WRAP_ON_EVERY_ITEM = CommonCodeStyleSettings.WRAP_ON_EVERY_ITEM;
/**
* @deprecated Use {@link CommonCodeStyleSettings#DO_NOT_FORCE}
*/
@Deprecated public static final int DO_NOT_FORCE = CommonCodeStyleSettings.DO_NOT_FORCE;
/**
* @deprecated Use {@link CommonCodeStyleSettings#FORCE_BRACES_IF_MULTILINE}
*/
@Deprecated public static final int FORCE_BRACES_IF_MULTILINE = CommonCodeStyleSettings.FORCE_BRACES_IF_MULTILINE;
/**
* @deprecated Use {@link CommonCodeStyleSettings#FORCE_BRACES_ALWAYS}
*/
@Deprecated public static final int FORCE_BRACES_ALWAYS = CommonCodeStyleSettings.FORCE_BRACES_ALWAYS;
/**
* @deprecated Use {@link CommonCodeStyleSettings#END_OF_LINE}
*/
@Deprecated public static final int END_OF_LINE = 1;
/**
* @deprecated Use {@link CommonCodeStyleSettings#NEXT_LINE}
*/
@Deprecated public static final int NEXT_LINE = 2;
/**
* @deprecated Use {@link CommonCodeStyleSettings#NEXT_LINE_SHIFTED}
*/
@Deprecated public static final int NEXT_LINE_SHIFTED = 3;
/**
* @deprecated Use {@link CommonCodeStyleSettings#NEXT_LINE_SHIFTED2}
*/
@Deprecated public static final int NEXT_LINE_SHIFTED2 = 4;
/**
* @deprecated Use {@link CommonCodeStyleSettings#NEXT_LINE_IF_WRAPPED}
*/
@Deprecated public static final int NEXT_LINE_IF_WRAPPED = 5;
/**
* @deprecated See {@link LegacyCodeStyleSettings}
*/
@Deprecated public int RIGHT_MARGIN = -1;
/**
* @deprecated See {@link LegacyCodeStyleSettings}
*/
@Deprecated public boolean KEEP_LINE_BREAKS = true;
/**
* @deprecated See {@link LegacyCodeStyleSettings}
*/
@Deprecated public boolean KEEP_FIRST_COLUMN_COMMENT = true;
/**
* @deprecated See {@link LegacyCodeStyleSettings}
*/
@Deprecated public boolean KEEP_CONTROL_STATEMENT_IN_ONE_LINE = true;
/**
* @deprecated See {@link LegacyCodeStyleSettings}
*/
@Deprecated public int KEEP_BLANK_LINES_IN_DECLARATIONS = 2;
/**
* @deprecated See {@link LegacyCodeStyleSettings}
*/
@Deprecated public int KEEP_BLANK_LINES_IN_CODE = 2;
/**
* @deprecated See {@link LegacyCodeStyleSettings}
*/
@Deprecated public int KEEP_BLANK_LINES_BEFORE_RBRACE = 2;
/**
* @deprecated See {@link LegacyCodeStyleSettings}
*/
@Deprecated public int BLANK_LINES_AROUND_CLASS = 1;
/**
* @deprecated See {@link LegacyCodeStyleSettings}
*/
@Deprecated public int BLANK_LINES_AROUND_METHOD = 1;
/**
* @deprecated See {@link LegacyCodeStyleSettings}
*/
@Deprecated public boolean INDENT_CASE_FROM_SWITCH = true;
/**
* @deprecated See {@link LegacyCodeStyleSettings}
*/
@Deprecated public boolean ALIGN_MULTILINE_PARAMETERS_IN_CALLS = false;
/**
* @deprecated See {@link LegacyCodeStyleSettings}
*/
@Deprecated public boolean ALIGN_MULTILINE_BINARY_OPERATION = false;
/**
* @deprecated See {@link LegacyCodeStyleSettings}
*/
@Deprecated public boolean ALIGN_GROUP_FIELD_DECLARATIONS = false;
/**
* @deprecated See {@link LegacyCodeStyleSettings}
*/
@Deprecated public boolean SPACE_AROUND_ASSIGNMENT_OPERATORS = true;
/**
* @deprecated See {@link LegacyCodeStyleSettings}
*/
@Deprecated public boolean SPACE_AROUND_LOGICAL_OPERATORS = true;
/**
* @deprecated See {@link LegacyCodeStyleSettings}
*/
@Deprecated public boolean SPACE_AROUND_EQUALITY_OPERATORS = true;
/**
* @deprecated See {@link LegacyCodeStyleSettings}
*/
@Deprecated public boolean SPACE_AROUND_RELATIONAL_OPERATORS = true;
/**
* @deprecated See {@link LegacyCodeStyleSettings}
*/
@Deprecated public boolean SPACE_AROUND_BITWISE_OPERATORS = true;
/**
* @deprecated See {@link LegacyCodeStyleSettings}
*/
@Deprecated public boolean SPACE_AROUND_ADDITIVE_OPERATORS = true;
/**
* @deprecated See {@link LegacyCodeStyleSettings}
*/
@Deprecated public boolean SPACE_AROUND_MULTIPLICATIVE_OPERATORS = true;
/**
* @deprecated See {@link LegacyCodeStyleSettings}
*/
@Deprecated public boolean SPACE_AROUND_SHIFT_OPERATORS = true;
/**
* @deprecated See {@link LegacyCodeStyleSettings}
*/
@Deprecated public boolean SPACE_AFTER_COMMA = true;
/**
* @deprecated See {@link LegacyCodeStyleSettings}
*/
@Deprecated public boolean SPACE_BEFORE_COMMA = false;
/**
* @deprecated See {@link LegacyCodeStyleSettings}
*/
@Deprecated public boolean SPACE_AFTER_SEMICOLON = true; // in for-statement
/**
* @deprecated See {@link LegacyCodeStyleSettings}
*/
@Deprecated public boolean SPACE_BEFORE_SEMICOLON = false; // in for-statement
/**
* @deprecated See {@link LegacyCodeStyleSettings}
*/
@Deprecated public boolean SPACE_WITHIN_PARENTHESES = false;
/**
* @deprecated See {@link LegacyCodeStyleSettings}
*/
@Deprecated public boolean SPACE_WITHIN_METHOD_CALL_PARENTHESES = false;
/**
* @deprecated See {@link LegacyCodeStyleSettings}
*/
@Deprecated public boolean SPACE_WITHIN_METHOD_PARENTHESES = false;
/**
* @deprecated See {@link LegacyCodeStyleSettings}
*/
@Deprecated public boolean SPACE_WITHIN_IF_PARENTHESES = false;
/**
* @deprecated See {@link LegacyCodeStyleSettings}
*/
@Deprecated public boolean SPACE_WITHIN_WHILE_PARENTHESES = false;
/**
* @deprecated See {@link LegacyCodeStyleSettings}
*/
@Deprecated public boolean SPACE_WITHIN_CAST_PARENTHESES = false;
/**
* @deprecated See {@link LegacyCodeStyleSettings}
*/
@Deprecated public boolean SPACE_WITHIN_BRACKETS = false;
/**
* @deprecated See {@link LegacyCodeStyleSettings}
*/
@Deprecated public boolean SPACE_AFTER_TYPE_CAST = true;
/**
* @deprecated See {@link LegacyCodeStyleSettings}
*/
@Deprecated public boolean SPACE_BEFORE_METHOD_CALL_PARENTHESES = false;
/**
* @deprecated See {@link LegacyCodeStyleSettings}
*/
@Deprecated public boolean SPACE_BEFORE_METHOD_PARENTHESES = false;
/**
* @deprecated See {@link LegacyCodeStyleSettings}
*/
@Deprecated public boolean SPACE_BEFORE_IF_PARENTHESES = true;
/**
* @deprecated See {@link LegacyCodeStyleSettings}
*/
@Deprecated public boolean SPACE_BEFORE_WHILE_PARENTHESES = true;
/**
* @deprecated See {@link LegacyCodeStyleSettings}
*/
@Deprecated public boolean SPACE_BEFORE_CLASS_LBRACE = true;
/**
* @deprecated See {@link LegacyCodeStyleSettings}
*/
@Deprecated public boolean SPACE_BEFORE_METHOD_LBRACE = true;
/**
* @deprecated See {@link LegacyCodeStyleSettings}
*/
@Deprecated public boolean SPACE_BEFORE_IF_LBRACE = true;
/**
* @deprecated See {@link LegacyCodeStyleSettings}
*/
@Deprecated public boolean SPACE_BEFORE_WHILE_LBRACE = true;
/**
* @deprecated See {@link LegacyCodeStyleSettings}
*/
@Deprecated public boolean SPACE_BEFORE_QUEST = true;
/**
* @deprecated See {@link LegacyCodeStyleSettings}
*/
@Deprecated public boolean SPACE_AFTER_QUEST = true;
/**
* @deprecated See {@link LegacyCodeStyleSettings}
*/
@Deprecated public boolean SPACE_BEFORE_COLON = true;
/**
* @deprecated See {@link LegacyCodeStyleSettings}
*/
@Deprecated public boolean SPACE_AFTER_COLON = true;
/**
* @deprecated See {@link LegacyCodeStyleSettings}
*/
@Deprecated public boolean KEEP_SIMPLE_BLOCKS_IN_ONE_LINE = false;
/**
* @deprecated See {@link LegacyCodeStyleSettings}
*/
@Deprecated public int ARRAY_INITIALIZER_WRAP = CommonCodeStyleSettings.DO_NOT_WRAP;
/**
* @deprecated See {@link LegacyCodeStyleSettings}
*/
@Deprecated public boolean ARRAY_INITIALIZER_LBRACE_ON_NEXT_LINE = false;
/**
* @deprecated See {@link LegacyCodeStyleSettings}
*/
@Deprecated public boolean ARRAY_INITIALIZER_RBRACE_ON_NEXT_LINE = false;
/**
* @deprecated See {@link LegacyCodeStyleSettings}
*/
@Deprecated public int BRACE_STYLE = CommonCodeStyleSettings.END_OF_LINE;
/**
* @deprecated See {@link LegacyCodeStyleSettings}
*/
@Deprecated public int CLASS_BRACE_STYLE = CommonCodeStyleSettings.END_OF_LINE;
}
@@ -386,6 +386,9 @@ public abstract class CodeStyleAbstractPanel implements Disposable {
try {
resetImpl(settings);
}
catch (Exception e) {
LOG.error(e);
}
finally {
myShouldUpdatePreview = true;
}
@@ -250,7 +250,7 @@ public class CodeStyleBlankLinesPanel extends CustomizableLanguageCodeStylePanel
private int myCurrValue = Integer.MAX_VALUE;
private IntOption(@NotNull String title, String fieldName) {
this(title, CodeStyleSettings.class, fieldName, false);
this(title, CommonCodeStyleSettings.class, fieldName, false);
}
private IntOption(@NotNull String title, Class<? extends CustomCodeStyleSettings> targetClass, String fieldName) {
@@ -374,7 +374,7 @@ public abstract class OptionTreeWithPreviewPanel extends CustomizableLanguageCod
private void doInitBooleanField(@NonNls String fieldName, String title, String groupName) {
try {
Class styleSettingsClass = CodeStyleSettings.class;
Class styleSettingsClass = CommonCodeStyleSettings.class;
Field field = styleSettingsClass.getField(fieldName);
String actualGroupName = getRemappedGroup(fieldName, groupName);
@@ -72,7 +72,7 @@ public class CodeFormatterFacade {
/**
* This key is used as a flag that indicates if {@code 'wrap long line during formatting'} activity is performed now.
*
* @see CodeStyleSettings#WRAP_LONG_LINES
* @see CommonCodeStyleSettings#WRAP_LONG_LINES
*/
public static final Key<Boolean> WRAP_LONG_LINE_DURING_FORMATTING_IN_PROGRESS_KEY
= new Key<>("WRAP_LONG_LINE_DURING_FORMATTING_IN_PROGRESS_KEY");
@@ -15,8 +15,10 @@
*/
package com.intellij.psi.impl.source.codeStyle;
import com.intellij.lang.Language;
import com.intellij.openapi.util.TextRange;
import com.intellij.psi.PsiElement;
import com.intellij.psi.codeStyle.CodeStyleSettings;
import com.intellij.psi.codeStyle.CommonCodeStyleSettings;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -29,6 +31,15 @@ public class PostFormatProcessorHelper {
private int myDelta;
private TextRange myResultTextRange;
/**
* @deprecated Use {@link #PostFormatProcessorHelper(CommonCodeStyleSettings)} first getting correct language settings
* with {@link CodeStyleSettings#getCommonSettings(Language)}!
*/
@Deprecated
public PostFormatProcessorHelper(final CodeStyleSettings rootSettings) {
mySettings = rootSettings.getCommonSettings("");
}
public PostFormatProcessorHelper(final CommonCodeStyleSettings settings) {
mySettings = settings;
}
@@ -11,7 +11,7 @@ import com.intellij.openapi.editor.impl.AbstractEditorTest;
import com.intellij.openapi.editor.impl.EditorImpl;
import com.intellij.openapi.editor.impl.SoftWrapModelImpl;
import com.intellij.openapi.editor.markup.TextAttributes;
import com.intellij.openapi.fileTypes.PlainTextLanguage;
import com.intellij.openapi.fileTypes.PlainTextFileType;
import com.intellij.psi.codeStyle.CommonCodeStyleSettings;
import com.intellij.testFramework.EditorTestUtil;
import com.intellij.testFramework.TestFileType;
@@ -807,9 +807,7 @@ public class SoftWrapApplianceOnDocumentModificationTest extends AbstractEditorT
VisualPosition caretPositionBefore = getEditor().getCaretModel().getVisualPosition();
// Change tab size.
final CommonCodeStyleSettings.IndentOptions indentOptions = getCurrentCodeStyleSettings()
.getCommonSettings(PlainTextLanguage.INSTANCE)
.getIndentOptions();
final CommonCodeStyleSettings.IndentOptions indentOptions = getCurrentCodeStyleSettings().getIndentOptions(PlainTextFileType.INSTANCE);
assertNotNull(indentOptions);
indentOptions.TAB_SIZE++;
@@ -16,10 +16,12 @@
package com.jetbrains.python.formatter;
import com.intellij.openapi.util.TextRange;
import com.intellij.psi.*;
import com.intellij.psi.PsiComment;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.psi.PsiWhiteSpace;
import com.intellij.psi.codeStyle.CodeStyleManager;
import com.intellij.psi.codeStyle.CodeStyleSettings;
import com.intellij.psi.codeStyle.CommonCodeStyleSettings;
import com.intellij.psi.impl.source.codeStyle.PostFormatProcessor;
import com.intellij.psi.impl.source.codeStyle.PostFormatProcessorHelper;
import com.intellij.util.containers.ContainerUtil;
@@ -53,8 +55,8 @@ public class PyFromImportPostFormatProcessor implements PostFormatProcessor {
private final List<PyFromImportStatement> myImportStatements = new ArrayList<>();
private PsiElement myRootElement;
public Visitor(@NotNull CommonCodeStyleSettings settings) {
myHelper = new PostFormatProcessorHelper(settings);
public Visitor(@NotNull CodeStyleSettings settings) {
myHelper = new PostFormatProcessorHelper(settings.getCommonSettings(PythonLanguage.getInstance()));
}
@Override
@@ -65,7 +67,7 @@ public class PyFromImportPostFormatProcessor implements PostFormatProcessor {
final List<PyImportElement> importedNames = ContainerUtil.filter(node.getImportElements(), elem -> elem.getTextLength() != 0);
if (importedNames.size() > 1) {
final PyCodeStyleSettings pySettings = ((CodeStyleSettings)myHelper.getSettings()).getCustomSettings(PyCodeStyleSettings.class);
final PyCodeStyleSettings pySettings = myHelper.getSettings().getRootSettings().getCustomSettings(PyCodeStyleSettings.class);
final boolean forcedParens = pySettings.FROM_IMPORT_PARENTHESES_FORCE_IF_MULTILINE && PostFormatProcessorHelper.isMultiline(node);
final boolean forcedComma = pySettings.FROM_IMPORT_TRAILING_COMMA_IF_MULTILINE && PostFormatProcessorHelper.isMultiline(node);
final PyImportElement lastImportedName = importedNames.get(importedNames.size() - 1);
@@ -138,7 +140,7 @@ public class PyFromImportPostFormatProcessor implements PostFormatProcessor {
}
lastElementWasComment = cur instanceof PsiComment;
}
final PyCodeStyleSettings pySettings = ((CodeStyleSettings)myHelper.getSettings()).getCustomSettings(PyCodeStyleSettings.class);
final PyCodeStyleSettings pySettings = myHelper.getSettings().getRootSettings().getCustomSettings(PyCodeStyleSettings.class);
if (lastVisibleNameCommaOffset != -1 && pySettings.FROM_IMPORT_TRAILING_COMMA_IF_MULTILINE) {
newStatementText.insert(lastVisibleNameCommaOffset, ",");
}
@@ -16,6 +16,7 @@
package com.intellij.lang.html;
import com.intellij.application.options.CodeStyle;
import com.intellij.lang.ASTNode;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.project.Project;
@@ -164,7 +165,7 @@ public class HtmlQuotesFormatPreprocessor implements PreFormatProcessor {
}
public static void runOnElement(@NotNull CodeStyleSettings.QuoteStyle quoteStyle, @NotNull PsiElement element) {
PostFormatProcessorHelper postFormatProcessorHelper = new PostFormatProcessorHelper(null);
PostFormatProcessorHelper postFormatProcessorHelper = new PostFormatProcessorHelper(CodeStyle.getDefaultSettings());
postFormatProcessorHelper.setResultTextRange(element.getTextRange());
new HtmlQuotesConverter(quoteStyle, element, postFormatProcessorHelper).run();
}