mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Per-language code style settings, more refactoring and test fixes
This commit is contained in:
@@ -39,6 +39,12 @@ public class CodeStyleSettings extends CommonCodeStyleSettings implements Clonea
|
||||
private final ClassMap<CustomCodeStyleSettings> myCustomSettings = new ClassMap<CustomCodeStyleSettings>();
|
||||
|
||||
@NonNls private static final String ADDITIONAL_INDENT_OPTIONS = "ADDITIONAL_INDENT_OPTIONS";
|
||||
|
||||
@Override
|
||||
public CodeStyleSettings getMainSettings() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@NonNls private static final String FILETYPE = "fileType";
|
||||
private final CommonCodeStyleSettingsManager myCommonSettingsManager = new CommonCodeStyleSettingsManager(this);
|
||||
|
||||
@@ -47,6 +53,7 @@ public class CodeStyleSettings extends CommonCodeStyleSettings implements Clonea
|
||||
}
|
||||
|
||||
public CodeStyleSettings(boolean loadExtensions) {
|
||||
super(null);
|
||||
initTypeToName();
|
||||
initImportsByDefault();
|
||||
|
||||
@@ -616,22 +623,6 @@ public class CodeStyleSettings extends CommonCodeStyleSettings implements Clonea
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
|
||||
//-------------- Annotation formatting settings-------------------------------------------
|
||||
|
||||
public int METHOD_ANNOTATION_WRAP = WRAP_ALWAYS;
|
||||
public int CLASS_ANNOTATION_WRAP = WRAP_ALWAYS;
|
||||
public int FIELD_ANNOTATION_WRAP = WRAP_ALWAYS;
|
||||
public int PARAMETER_ANNOTATION_WRAP = DO_NOT_WRAP;
|
||||
public int VARIABLE_ANNOTATION_WRAP = DO_NOT_WRAP;
|
||||
|
||||
public boolean SPACE_BEFORE_ANOTATION_PARAMETER_LIST = false;
|
||||
public boolean SPACE_WITHIN_ANNOTATION_PARENTHESES = false;
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
//-------------------------Enums----------------------------------------------------------
|
||||
public int ENUM_CONSTANTS_WRAP = DO_NOT_WRAP;
|
||||
//----------------------------------------------------------------------------------------
|
||||
|
||||
private CodeStyleSettings myParentSettings;
|
||||
@@ -997,4 +988,8 @@ public class CodeStyleSettings extends CommonCodeStyleSettings implements Clonea
|
||||
public CommonCodeStyleSettings getCommonSettings(Language lang) {
|
||||
return myCommonSettingsManager.getCommonSettings(lang);
|
||||
}
|
||||
|
||||
public CommonCodeStyleSettings createCommonSettings(Language lang) {
|
||||
return new CommonCodeStyleSettings(this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,8 @@
|
||||
*/
|
||||
package com.intellij.psi.codeStyle;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* Common code style settings can be used by several programming languages. Each language may have its own
|
||||
* instance of <code>CommonCodeStyleSettings</code>.
|
||||
@@ -23,6 +25,16 @@ package com.intellij.psi.codeStyle;
|
||||
*/
|
||||
public class CommonCodeStyleSettings {
|
||||
|
||||
private final CodeStyleSettings myMainSettings;
|
||||
|
||||
CommonCodeStyleSettings(@Nullable CodeStyleSettings mainSettings) {
|
||||
myMainSettings = mainSettings;
|
||||
}
|
||||
|
||||
public CodeStyleSettings getMainSettings() {
|
||||
return myMainSettings;
|
||||
}
|
||||
|
||||
//----------------- GENERAL --------------------
|
||||
|
||||
public boolean LINE_COMMENT_AT_FIRST_COLUMN = true;
|
||||
@@ -42,6 +54,39 @@ public class CommonCodeStyleSettings {
|
||||
*/
|
||||
public boolean KEEP_CONTROL_STATEMENT_IN_ONE_LINE = true;
|
||||
|
||||
//----------------- BLANK LINES --------------------
|
||||
|
||||
/**
|
||||
* Keep up to this amount of blank lines between declarations
|
||||
*/
|
||||
public int KEEP_BLANK_LINES_IN_DECLARATIONS = 2;
|
||||
|
||||
/**
|
||||
* Keep up to this amount of blank lines in code
|
||||
*/
|
||||
public int KEEP_BLANK_LINES_IN_CODE = 2;
|
||||
|
||||
public int KEEP_BLANK_LINES_BEFORE_RBRACE = 2;
|
||||
|
||||
public int BLANK_LINES_BEFORE_PACKAGE = 0;
|
||||
public int BLANK_LINES_AFTER_PACKAGE = 1;
|
||||
public int BLANK_LINES_BEFORE_IMPORTS = 1;
|
||||
public int BLANK_LINES_AFTER_IMPORTS = 1;
|
||||
|
||||
public int BLANK_LINES_AROUND_CLASS = 1;
|
||||
public int BLANK_LINES_AROUND_FIELD = 0;
|
||||
public int BLANK_LINES_AROUND_METHOD = 1;
|
||||
public int BLANK_LINES_BEFORE_METHOD_BODY = 0;
|
||||
|
||||
public int BLANK_LINES_AROUND_FIELD_IN_INTERFACE = 0;
|
||||
public int BLANK_LINES_AROUND_METHOD_IN_INTERFACE = 1;
|
||||
|
||||
|
||||
public int BLANK_LINES_AFTER_CLASS_HEADER = 0;
|
||||
public int BLANK_LINES_AFTER_ANONYMOUS_CLASS_HEADER = 0;
|
||||
//public int BLANK_LINES_BETWEEN_CASE_BLOCKS;
|
||||
|
||||
|
||||
//----------------- BRACES & INDENTS --------------------
|
||||
|
||||
/**
|
||||
@@ -196,37 +241,6 @@ public class CommonCodeStyleSettings {
|
||||
|
||||
public boolean ALIGN_GROUP_FIELD_DECLARATIONS = false;
|
||||
|
||||
//----------------- BLANK LINES --------------------
|
||||
|
||||
/**
|
||||
* Keep up to this amount of blank lines between declarations
|
||||
*/
|
||||
public int KEEP_BLANK_LINES_IN_DECLARATIONS = 2;
|
||||
|
||||
/**
|
||||
* Keep up to this amount of blank lines in code
|
||||
*/
|
||||
public int KEEP_BLANK_LINES_IN_CODE = 2;
|
||||
|
||||
public int KEEP_BLANK_LINES_BEFORE_RBRACE = 2;
|
||||
|
||||
public int BLANK_LINES_BEFORE_PACKAGE = 0;
|
||||
public int BLANK_LINES_AFTER_PACKAGE = 1;
|
||||
public int BLANK_LINES_BEFORE_IMPORTS = 1;
|
||||
public int BLANK_LINES_AFTER_IMPORTS = 1;
|
||||
|
||||
public int BLANK_LINES_AROUND_CLASS = 1;
|
||||
public int BLANK_LINES_AROUND_FIELD = 0;
|
||||
public int BLANK_LINES_AROUND_METHOD = 1;
|
||||
public int BLANK_LINES_BEFORE_METHOD_BODY = 0;
|
||||
|
||||
public int BLANK_LINES_AROUND_FIELD_IN_INTERFACE = 0;
|
||||
public int BLANK_LINES_AROUND_METHOD_IN_INTERFACE = 0;
|
||||
|
||||
|
||||
public int BLANK_LINES_AFTER_CLASS_HEADER = 0;
|
||||
public int BLANK_LINES_AFTER_ANONYMOUS_CLASS_HEADER = 0;
|
||||
//public int BLANK_LINES_BETWEEN_CASE_BLOCKS;
|
||||
|
||||
//----------------- SPACES --------------------
|
||||
|
||||
@@ -591,4 +605,22 @@ public class CommonCodeStyleSettings {
|
||||
public int WHILE_BRACE_FORCE = DO_NOT_FORCE;
|
||||
public int FOR_BRACE_FORCE = DO_NOT_FORCE;
|
||||
|
||||
//-------------- Annotation formatting settings-------------------------------------------
|
||||
|
||||
public int METHOD_ANNOTATION_WRAP = WRAP_ALWAYS;
|
||||
public int CLASS_ANNOTATION_WRAP = WRAP_ALWAYS;
|
||||
public int FIELD_ANNOTATION_WRAP = WRAP_ALWAYS;
|
||||
public int PARAMETER_ANNOTATION_WRAP = DO_NOT_WRAP;
|
||||
public int VARIABLE_ANNOTATION_WRAP = DO_NOT_WRAP;
|
||||
|
||||
public boolean SPACE_BEFORE_ANOTATION_PARAMETER_LIST = false;
|
||||
public boolean SPACE_WITHIN_ANNOTATION_PARENTHESES = false;
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
//-------------------------Enums----------------------------------------------------------
|
||||
public int ENUM_CONSTANTS_WRAP = DO_NOT_WRAP;
|
||||
|
||||
|
||||
}
|
||||
|
||||
+3
-3
@@ -31,9 +31,9 @@ import java.util.Map;
|
||||
public class CommonCodeStyleSettingsManager {
|
||||
|
||||
private Map<Language, CommonCodeStyleSettings> myCommonSettingsMap;
|
||||
private final CommonCodeStyleSettings myParentSettings;
|
||||
private final CodeStyleSettings myParentSettings;
|
||||
|
||||
public CommonCodeStyleSettingsManager(CommonCodeStyleSettings parentSettings) {
|
||||
public CommonCodeStyleSettingsManager(CodeStyleSettings parentSettings) {
|
||||
myParentSettings = parentSettings;
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ public class CommonCodeStyleSettingsManager {
|
||||
final LanguageCodeStyleSettingsProvider[] providers = Extensions.getExtensions(LanguageCodeStyleSettingsProvider.EP_NAME);
|
||||
for (final LanguageCodeStyleSettingsProvider provider : providers) {
|
||||
if (!myCommonSettingsMap.containsKey(provider.getLanguage())) {
|
||||
CommonCodeStyleSettings initialSettings = provider.getDefaultCommonSettings();
|
||||
CommonCodeStyleSettings initialSettings = provider.getDefaultCommonSettings(myParentSettings);
|
||||
if (initialSettings != null) {
|
||||
registerCommonSettings(provider.getLanguage(), initialSettings);
|
||||
}
|
||||
|
||||
+2
-1
@@ -46,11 +46,12 @@ public abstract class LanguageCodeStyleSettingsProvider {
|
||||
* Creates an instance of <code>CommonCodeStyleSettings</code> and sets initial default values for those
|
||||
* settings which differ from the original.
|
||||
*
|
||||
* @param settings Main settings containing the common code style settings.
|
||||
* @return Created instance of <code>CommonCodeStyleSettings</code> or null if associated language doesn't
|
||||
* use its own language-specific common settings (the settings are shared with other languages).
|
||||
*/
|
||||
@Nullable
|
||||
public CommonCodeStyleSettings getDefaultCommonSettings() {
|
||||
public CommonCodeStyleSettings getDefaultCommonSettings(CodeStyleSettings settings) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user