Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
小 白蛋
Intellij Community
Commits
75a2b0cd
Commit
75a2b0cd
authored
7 years ago
by
Rustam Vishnyakov
1
Browse files
Options
Download
Email Patches
Plain Diff
Support old and new project code style settings in import & command line
See also IDEA-164602
parent
2dad4d6c
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
platform/lang-impl/src/com/intellij/psi/impl/source/codeStyle/CodeStyleSchemeXmlImporter.java
+3
-17
...psi/impl/source/codeStyle/CodeStyleSchemeXmlImporter.java
platform/lang-impl/src/com/intellij/psi/impl/source/codeStyle/CodeStyleSettingsLoader.java
+32
-2
...ij/psi/impl/source/codeStyle/CodeStyleSettingsLoader.java
platform/platform-tests/testData/codeStyle/importSettings/newProjectSettings.xml
+52
-0
.../testData/codeStyle/importSettings/newProjectSettings.xml
platform/platform-tests/testSrc/com/intellij/ide/codeStyleSettings/CodeStyleXmlImporterTest.java
+6
-0
...ellij/ide/codeStyleSettings/CodeStyleXmlImporterTest.java
with
93 additions
and
19 deletions
+93
-19
platform/lang-impl/src/com/intellij/psi/impl/source/codeStyle/CodeStyleSchemeXmlImporter.java
+
3
-
17
View file @
75a2b0cd
...
...
@@ -51,7 +51,7 @@ public class CodeStyleSchemeXmlImporter extends CodeStyleSettingsLoader implemen
@NotNull
CodeStyleScheme
currentScheme
,
@NotNull
SchemeFactory
<
CodeStyleScheme
>
schemeFactory
)
throws
SchemeImportException
{
Element
rootElement
=
SchemeImportUtil
.
loadSchemeDom
(
selectedFile
);
Element
schemeRoot
=
get
SchemeRoot
(
rootElement
);
Element
schemeRoot
=
find
SchemeRoot
(
rootElement
);
final
Pair
<
String
,
CodeStyleScheme
>
importPair
=
!
ApplicationManager
.
getApplication
().
isUnitTestMode
()
?
ImportSchemeChooserDialog
.
selectOrCreateTargetScheme
(
project
,
currentScheme
,
schemeFactory
,
getSchemeName
(
schemeRoot
))
:
...
...
@@ -75,23 +75,9 @@ public class CodeStyleSchemeXmlImporter extends CodeStyleSettingsLoader implemen
}
return
schemeNameAttr
.
getValue
();
}
private
static
Element
getSchemeRoot
(
@NotNull
Element
rootElement
)
throws
SchemeImportException
{
if
(
"project"
.
equals
(
rootElement
.
getName
()))
{
Element
child
=
rootElement
.
getChild
(
"component"
);
if
(
child
!=
null
&&
"ProjectCodeStyleSettingsManager"
.
equals
(
child
.
getAttributeValue
(
"name"
)))
{
child
=
child
.
getChild
(
"option"
);
if
(
child
!=
null
&&
"PER_PROJECT_SETTINGS"
.
equals
(
child
.
getAttributeValue
(
"name"
)))
{
child
=
child
.
getChild
(
"value"
);
if
(
child
!=
null
)
return
child
;
}
}
throw
new
SchemeImportException
(
"Invalid scheme root: "
+
rootElement
.
getName
());
}
return
rootElement
;
}
private
CodeStyleScheme
readSchemeFromDom
(
@NotNull
Element
rootElement
,
@NotNull
CodeStyleScheme
scheme
)
private
static
CodeStyleScheme
readSchemeFromDom
(
@NotNull
Element
rootElement
,
@NotNull
CodeStyleScheme
scheme
)
throws
SchemeImportException
{
CodeStyleSettings
newSettings
=
new
CodeStyleSettings
();
loadSettings
(
rootElement
,
newSettings
);
...
...
This diff is collapsed.
Click to expand it.
platform/lang-impl/src/com/intellij/psi/impl/source/codeStyle/CodeStyleSettingsLoader.java
+
32
-
2
View file @
75a2b0cd
...
...
@@ -33,13 +33,43 @@ public class CodeStyleSettingsLoader {
return
settings
;
}
protected
void
loadSettings
(
@NotNull
Element
rootElement
,
@NotNull
CodeStyleSettings
settings
)
throws
SchemeImportException
{
protected
static
void
loadSettings
(
@NotNull
Element
rootElement
,
@NotNull
CodeStyleSettings
settings
)
throws
SchemeImportException
{
try
{
settings
.
readExternal
(
rootElement
);
settings
.
readExternal
(
findSchemeRoot
(
rootElement
)
)
;
}
catch
(
InvalidDataException
e
)
{
throw
new
SchemeImportException
(
ApplicationBundle
.
message
(
"settings.code.style.import.xml.error.can.not.load"
,
e
.
getMessage
()));
}
}
protected
static
Element
findSchemeRoot
(
@NotNull
Element
rootElement
)
throws
SchemeImportException
{
String
rootName
=
rootElement
.
getName
();
//
// Project code style 172.x and earlier
//
if
(
"project"
.
equals
(
rootName
))
{
Element
child
=
rootElement
.
getChild
(
"component"
);
if
(
child
!=
null
&&
"ProjectCodeStyleSettingsManager"
.
equals
(
child
.
getAttributeValue
(
"name"
)))
{
child
=
child
.
getChild
(
"option"
);
if
(
child
!=
null
&&
"PER_PROJECT_SETTINGS"
.
equals
(
child
.
getAttributeValue
(
"name"
)))
{
child
=
child
.
getChild
(
"value"
);
if
(
child
!=
null
)
return
child
;
}
}
throw
new
SchemeImportException
(
"Invalid scheme root: "
+
rootName
);
}
//
// Project code style 173.x and later
//
else
if
(
"component"
.
equals
(
rootName
))
{
if
(
"ProjectCodeStyleConfiguration"
.
equals
(
rootElement
.
getAttributeValue
(
"name"
)))
{
Element
child
=
rootElement
.
getChild
(
"code_scheme"
);
if
(
child
!=
null
)
{
return
child
;
}
}
throw
new
SchemeImportException
(
"Invalid scheme root: "
+
rootName
);
}
return
rootElement
;
}
}
This diff is collapsed.
Click to expand it.
platform/platform-tests/testData/codeStyle/importSettings/newProjectSettings.xml
0 → 100644
+
52
-
0
View file @
75a2b0cd
<component
name=
"ProjectCodeStyleConfiguration"
>
<code_scheme
name=
"Project"
version=
"173"
>
<option
name=
"LINE_SEPARATOR"
value=
" "
/>
<option
name=
"RIGHT_MARGIN"
value=
"140"
/>
<option
name=
"FORMATTER_TAGS_ENABLED"
value=
"true"
/>
<option
name=
"LINE_COMMENT_AT_FIRST_COLUMN"
value=
"false"
/>
<option
name=
"BLOCK_COMMENT_AT_FIRST_COLUMN"
value=
"false"
/>
<codeStyleSettings
language=
"JAVA"
>
<option
name=
"LINE_COMMENT_AT_FIRST_COLUMN"
value=
"false"
/>
<option
name=
"BLOCK_COMMENT_AT_FIRST_COLUMN"
value=
"false"
/>
<option
name=
"KEEP_FIRST_COLUMN_COMMENT"
value=
"false"
/>
<option
name=
"KEEP_BLANK_LINES_BEFORE_RBRACE"
value=
"0"
/>
<option
name=
"ELSE_ON_NEW_LINE"
value=
"true"
/>
<option
name=
"WHILE_ON_NEW_LINE"
value=
"true"
/>
<option
name=
"CATCH_ON_NEW_LINE"
value=
"true"
/>
<option
name=
"FINALLY_ON_NEW_LINE"
value=
"true"
/>
<option
name=
"ALIGN_MULTILINE_PARAMETERS_IN_CALLS"
value=
"true"
/>
<option
name=
"ALIGN_MULTILINE_BINARY_OPERATION"
value=
"true"
/>
<option
name=
"ALIGN_MULTILINE_ASSIGNMENT"
value=
"true"
/>
<option
name=
"ALIGN_MULTILINE_TERNARY_OPERATION"
value=
"true"
/>
<option
name=
"ALIGN_MULTILINE_THROWS_LIST"
value=
"true"
/>
<option
name=
"ALIGN_MULTILINE_EXTENDS_LIST"
value=
"true"
/>
<option
name=
"ALIGN_MULTILINE_PARENTHESIZED_EXPRESSION"
value=
"true"
/>
<option
name=
"SPACE_WITHIN_BRACES"
value=
"true"
/>
<option
name=
"SPACE_AFTER_TYPE_CAST"
value=
"false"
/>
<option
name=
"CALL_PARAMETERS_WRAP"
value=
"1"
/>
<option
name=
"METHOD_PARAMETERS_WRAP"
value=
"5"
/>
<option
name=
"EXTENDS_LIST_WRAP"
value=
"1"
/>
<option
name=
"THROWS_LIST_WRAP"
value=
"5"
/>
<option
name=
"EXTENDS_KEYWORD_WRAP"
value=
"1"
/>
<option
name=
"THROWS_KEYWORD_WRAP"
value=
"1"
/>
<option
name=
"METHOD_CALL_CHAIN_WRAP"
value=
"1"
/>
<option
name=
"BINARY_OPERATION_WRAP"
value=
"5"
/>
<option
name=
"TERNARY_OPERATION_WRAP"
value=
"5"
/>
<option
name=
"TERNARY_OPERATION_SIGNS_ON_NEXT_LINE"
value=
"true"
/>
<option
name=
"KEEP_SIMPLE_METHODS_IN_ONE_LINE"
value=
"true"
/>
<option
name=
"FOR_STATEMENT_WRAP"
value=
"5"
/>
<option
name=
"ARRAY_INITIALIZER_WRAP"
value=
"1"
/>
<option
name=
"ASSIGNMENT_WRAP"
value=
"1"
/>
<option
name=
"IF_BRACE_FORCE"
value=
"1"
/>
<option
name=
"DOWHILE_BRACE_FORCE"
value=
"1"
/>
<option
name=
"WHILE_BRACE_FORCE"
value=
"1"
/>
<option
name=
"FOR_BRACE_FORCE"
value=
"1"
/>
<option
name=
"FIELD_ANNOTATION_WRAP"
value=
"0"
/>
<indentOptions>
<option
name=
"INDENT_SIZE"
value=
"2"
/>
<option
name=
"CONTINUATION_INDENT_SIZE"
value=
"2"
/>
<option
name=
"TAB_SIZE"
value=
"8"
/>
</indentOptions>
</codeStyleSettings>
</code_scheme>
</component>
\ No newline at end of file
This diff is collapsed.
Click to expand it.
platform/platform-tests/testSrc/com/intellij/ide/codeStyleSettings/CodeStyleXmlImporterTest.java
+
6
-
0
View file @
75a2b0cd
...
...
@@ -41,6 +41,12 @@ public class CodeStyleXmlImporterTest extends CodeStyleTestCase {
assertEquals
(
true
,
settings
.
FORMATTER_TAGS_ENABLED
);
assertEquals
(
true
,
settings
.
FORMATTER_TAGS_ACCEPT_REGEXP
);
}
public
void
testNewProjectSettings
()
throws
SchemeImportException
{
CodeStyleSettings
settings
=
importSettings
();
assertEquals
(
140
,
settings
.
getDefaultRightMargin
());
assertEquals
(
true
,
settings
.
FORMATTER_TAGS_ENABLED
);
}
private
CodeStyleSettings
importSettings
()
throws
SchemeImportException
{
final
CodeStyleScheme
targetScheme
=
new
CodeStyleSchemeImpl
(
"Test"
,
false
,
null
);
...
...
This diff is collapsed.
Click to expand it.
小 白蛋
@baidan
mentioned in commit
8e212664
·
2 years ago
mentioned in commit
8e212664
mentioned in commit 8e212664ea353826d34868c08f07fa1c7a88f3e8
Toggle commit list
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Projects
Groups
Snippets
Help