Java formatter: add setting for spaces within record header: IDEA-244728

GitOrigin-RevId: fce07de6760107d83fc4794da1eb1c8d1a446ca5
This commit is contained in:
Roman.Ivanov
2020-06-29 13:10:43 +07:00
committed by intellij-monorepo-bot
parent 4bb26e3227
commit 1d2725756c
6 changed files with 19 additions and 2 deletions

View File

@@ -91,6 +91,8 @@ public class JavaLanguageCodeStyleSettingsProvider extends LanguageCodeStyleSett
if (settingsType == SettingsType.SPACING_SETTINGS) {
consumer.showAllStandardOptions();
consumer.showCustomOption(JavaCodeStyleSettings.class, "SPACES_WITHIN_ANGLE_BRACKETS", "Angle brackets",CodeStyleSettingsCustomizable.SPACES_WITHIN);
consumer.showCustomOption(JavaCodeStyleSettings.class, "SPACE_WITHIN_RECORD_HEADER",
JavaBundle.message("checkbox.spaces.record.header"),CodeStyleSettingsCustomizable.SPACES_WITHIN);
String groupName = CodeStyleSettingsCustomizable.SPACES_IN_TYPE_ARGUMENTS;
consumer.moveStandardOption("SPACE_AFTER_COMMA_IN_TYPE_ARGUMENTS", groupName);

View File

@@ -152,6 +152,12 @@ public class JavaCodeStyleSettings extends CustomCodeStyleSettings implements Im
public boolean ALIGN_MULTILINE_RECORDS = true;
public boolean NEW_LINE_AFTER_LPAREN_IN_RECORD_HEADER = false;
public boolean RPAREN_ON_NEW_LINE_IN_RECORD_HEADER = false;
/**
* "record R( String s )"
* or
* "record R(String s)"
*/
public boolean SPACE_WITHIN_RECORD_HEADER = false;
// region JavaDoc

View File

@@ -1228,10 +1228,10 @@ public final class JavaSpacePropertyProcessor extends JavaElementVisitor {
@Override
public void visitRecordHeader(PsiRecordHeader recordHeader) {
if (myType2 == JavaTokenType.RPARENTH) {
createParenthSpace(myJavaSettings.RPAREN_ON_NEW_LINE_IN_RECORD_HEADER, false);
createParenthSpace(myJavaSettings.RPAREN_ON_NEW_LINE_IN_RECORD_HEADER, myJavaSettings.SPACE_WITHIN_RECORD_HEADER);
}
else if (myType1 == JavaTokenType.LPARENTH) {
createParenthSpace(myJavaSettings.NEW_LINE_AFTER_LPAREN_IN_RECORD_HEADER, false);
createParenthSpace(myJavaSettings.NEW_LINE_AFTER_LPAREN_IN_RECORD_HEADER, myJavaSettings.SPACE_WITHIN_RECORD_HEADER);
}
else if (myChild1.getElementType() == JavaTokenType.COMMA) {
createSpaceInCode(mySettings.SPACE_AFTER_COMMA);

View File

@@ -229,6 +229,7 @@
"spaces_within_method_call_parentheses": false,
"spaces_within_method_parentheses": false,
"spaces_within_parentheses": false,
"spaces_within_record_header": false,
"spaces_within_switch_parentheses": false,
"spaces_within_synchronized_parentheses": false,
"spaces_within_try_parentheses": false,

View File

@@ -791,6 +791,13 @@ public class JavaFormatterSpaceTest extends AbstractJavaFormatterTest {
"}");
}
public void testSpaceWithinRecordHeader() {
getJavaSettings().SPACE_WITHIN_RECORD_HEADER = true;
doTextTest("record A(String string){}",
"record A( String string ) {\n" +
"}");
}
public void testSpacesAroundRelationalOperators() {
getSettings().SPACE_AROUND_RELATIONAL_OPERATORS = true;
doMethodTest(

View File

@@ -94,6 +94,7 @@ checkbox.param.description.on.new.line=Parameter descriptions on new line
checkbox.param.indent.on.continuation=Indent continuation lines
checkbox.prefer.longer.names=Prefer longer names
checkbox.preserve.line.feeds=Preserve line feeds
checkbox.spaces.record.header=Record header
checkbox.spaces.before.colon.in.foreach=Before colon in foreach
checkbox.spaces.inside.one.line.enum=Inside one line enum braces
checkbox.suggest.conversion.to.map.computeifabsent=Suggest conversion to Map.computeIfAbsent