revert IDEA-123956 Anonymous class formatting moves all args to the next line (32ae79905c)

This commit is contained in:
Yaroslav Lepenkin
2014-05-06 16:26:45 +04:00
parent 404cf1a208
commit 6c5b423913
3 changed files with 15 additions and 34 deletions
@@ -480,7 +480,7 @@ public abstract class AbstractJavaBlock extends AbstractBlock implements JavaBlo
if (nodeType == JavaElementType.POLYADIC_EXPRESSION) nodeType = JavaElementType.BINARY_EXPRESSION;
if (childType == JavaTokenType.LBRACE && nodeType == JavaElementType.ARRAY_INITIALIZER_EXPRESSION) {
final Wrap wrap = Wrap.createWrap(getWrapType(mySettings.ARRAY_INITIALIZER_WRAP), true);
final Wrap wrap = Wrap.createWrap(getWrapType(mySettings.ARRAY_INITIALIZER_WRAP), false);
child = processParenthesisBlock(JavaTokenType.LBRACE, JavaTokenType.RBRACE,
result,
child,
@@ -488,7 +488,7 @@ public abstract class AbstractJavaBlock extends AbstractBlock implements JavaBlo
mySettings.ALIGN_MULTILINE_ARRAY_INITIALIZER_EXPRESSION);
}
else if (childType == JavaTokenType.LBRACE && nodeType == JavaElementType.ANNOTATION_ARRAY_INITIALIZER) {
final Wrap wrap = Wrap.createWrap(getWrapType(mySettings.ARRAY_INITIALIZER_WRAP), true);
final Wrap wrap = Wrap.createWrap(getWrapType(mySettings.ARRAY_INITIALIZER_WRAP), false);
child = processParenthesisBlock(JavaTokenType.LBRACE, JavaTokenType.RBRACE,
result,
child,
@@ -496,7 +496,7 @@ public abstract class AbstractJavaBlock extends AbstractBlock implements JavaBlo
mySettings.ALIGN_MULTILINE_ARRAY_INITIALIZER_EXPRESSION);
}
else if (childType == JavaTokenType.LPARENTH && nodeType == JavaElementType.EXPRESSION_LIST) {
final Wrap wrap = Wrap.createWrap(getWrapType(mySettings.CALL_PARAMETERS_WRAP), true);
final Wrap wrap = Wrap.createWrap(getWrapType(mySettings.CALL_PARAMETERS_WRAP), false);
if (mySettings.PREFER_PARAMETERS_WRAP) {
wrap.ignoreParentWraps();
}
@@ -507,19 +507,19 @@ public abstract class AbstractJavaBlock extends AbstractBlock implements JavaBlo
else if (childType == JavaTokenType.LPARENTH && nodeType == JavaElementType.PARAMETER_LIST) {
// There is a possible case that particular annotated method definition is too long. We may wrap either after annotation
// or after opening lbrace then. Our strategy is to wrap after annotation whenever possible.
Wrap wrap = Wrap.createWrap(getWrapType(mySettings.METHOD_PARAMETERS_WRAP), true);
Wrap wrap = Wrap.createWrap(getWrapType(mySettings.METHOD_PARAMETERS_WRAP), false);
child = processParenthesisBlock(result, child,
WrappingStrategy.createDoNotWrapCommaStrategy(wrap),
mySettings.ALIGN_MULTILINE_PARAMETERS);
}
else if (childType == JavaTokenType.LPARENTH && nodeType == JavaElementType.RESOURCE_LIST) {
Wrap wrap = Wrap.createWrap(getWrapType(mySettings.RESOURCE_LIST_WRAP), true);
Wrap wrap = Wrap.createWrap(getWrapType(mySettings.RESOURCE_LIST_WRAP), false);
child = processParenthesisBlock(result, child,
WrappingStrategy.createDoNotWrapCommaStrategy(wrap),
mySettings.ALIGN_MULTILINE_RESOURCES);
}
else if (childType == JavaTokenType.LPARENTH && nodeType == JavaElementType.ANNOTATION_PARAMETER_LIST) {
Wrap wrap = Wrap.createWrap(getWrapType(mySettings.CALL_PARAMETERS_WRAP), true);
Wrap wrap = Wrap.createWrap(getWrapType(mySettings.CALL_PARAMETERS_WRAP), false);
child = processParenthesisBlock(result, child,
WrappingStrategy.createDoNotWrapCommaStrategy(wrap),
mySettings.ALIGN_MULTILINE_PARAMETERS_IN_CALLS);
@@ -915,7 +915,6 @@ public abstract class AbstractJavaBlock extends AbstractBlock implements JavaBlo
ASTNode prev = child;
boolean afterAnonymousClass = false;
final boolean enforceIndent = shouldEnforceIndentToChildren();
boolean currentChildIsFirstToWrap = true;
while (child != null) {
isAfterIncomplete = isAfterIncomplete || child.getElementType() == TokenType.ERROR_ELEMENT ||
child.getElementType() == JavaElementType.EMPTY_EXPRESSION;
@@ -935,11 +934,7 @@ public abstract class AbstractJavaBlock extends AbstractBlock implements JavaBlo
final IElementType elementType = child.getElementType();
Indent indentToUse = enforceIndent ? internalIndentEnforcedToChildren : internalIndent;
AlignmentStrategy alignmentStrategyToUse = canUseAnonymousClassAlignment(child) ? anonymousClassStrategy : alignmentStrategy;
Wrap wrap = currentChildIsFirstToWrap ? Wrap.createWrap(WrapType.NONE, true) : wrappingStrategy.getWrap(elementType);
currentChildIsFirstToWrap = false;
processChild(result, child, alignmentStrategyToUse.getAlignment(elementType), wrap, indentToUse);
processChild(result, child, alignmentStrategyToUse.getAlignment(elementType), wrappingStrategy.getWrap(elementType), indentToUse);
if (to == null) {//process only one statement
return child;
}
@@ -931,12 +931,13 @@ public class JavaFormatterTest extends AbstractJavaFormatterTest {
getSettings().getRootSettings().RIGHT_MARGIN = 20;
getSettings().CALL_PARAMETERS_WRAP = CommonCodeStyleSettings.WRAP_AS_NEEDED;
doTextTest("class Foo {\n" + " void foo() {\n" + " fooFooFooFoo(1);" + " }\n" + "}",
"class Foo {\n" + " void foo() {\n" + " fooFooFooFoo(1);\n" + " }\n" + "}");
"class Foo {\n" + " void foo() {\n" + " fooFooFooFoo(\n" + " 1);\n" + " }\n" + "}");
getSettings().CALL_PARAMETERS_WRAP = CommonCodeStyleSettings.WRAP_ON_EVERY_ITEM;
doTextTest("class Foo {\n" + " void foo() {\n" + " fooFooFooFoo(1,2);" + " }\n" + "}", "class Foo {\n" +
" void foo() {\n" +
" fooFooFooFoo(1,\n" +
" fooFooFooFoo(\n" +
" 1,\n" +
" 2);\n" +
" }\n" +
"}");
@@ -47,7 +47,8 @@ public class JavaFormatterWrapTest extends AbstractJavaFormatterTest {
"class Foo {\n" +
"}",
"@AttributeOverrides({@AttributeOverride(name = \"id\", column = @Column(name = \"recovery_id\")),\n" +
"@AttributeOverrides({\n" +
" @AttributeOverride(name = \"id\", column = @Column(name = \"recovery_id\")),\n" +
" @AttributeOverride(name = \"transactionReference\", column = @Column(name = \"deal_reference\")),\n" +
" @AttributeOverride(name = \"eventDate\", column = @Column(name = \"recovery_date\")),\n" +
" @AttributeOverride(name = \"amount\", column = @Column(name = \"recovery_amount\")),\n" +
@@ -390,8 +391,9 @@ public class JavaFormatterWrapTest extends AbstractJavaFormatterTest {
String literal = "\"" + StringUtil.repeatSymbol('A', 128) + "\"";
before = "processingEnv.getMessenger().printMessage(Diagnostic.Kind.ERROR, call(" + literal + "));\n";
after = "processingEnv.getMessenger().printMessage(\n" +
" Diagnostic.Kind.ERROR,\n" +
" call(" + literal + ")\n" +
" Diagnostic.Kind.ERROR, call(\n" +
" " + literal + "\n" +
" )\n" +
");\n";
doMethodTest(before, after);
@@ -446,21 +448,4 @@ public class JavaFormatterWrapTest extends AbstractJavaFormatterTest {
" public @TA String m();\n" +
"}");
}
public void testIDEA123956() {
doMethodTest(
"final BaseAnalysisActionDialog dialog = new BaseAnalysisActionDialog(" +
"AnalysisScopeBundle.message(\"specify.analysis.scope\", InspectionsBundle.message(\"inspection.action.title\")),\n" +
" AnalysisScopeBundle.message(\"analysis.scope.title\", InspectionsBundle.message(\"inspection.action.noun\")),\n" +
" project, analysisScope, module != null ? module.getName() : null,\n" +
" true, AnalysisUIOptions.getInstance(project), psiElement) {\n" +
"}",
"final BaseAnalysisActionDialog dialog = new BaseAnalysisActionDialog(" +
"AnalysisScopeBundle.message(\"specify.analysis.scope\", InspectionsBundle.message(\"inspection.action.title\")),\n" +
" AnalysisScopeBundle.message(\"analysis.scope.title\", InspectionsBundle.message(\"inspection.action.noun\")),\n" +
" project, analysisScope, module != null ? module.getName() : null,\n" +
" true, AnalysisUIOptions.getInstance(project), psiElement) {\n" +
"}"
);
}
}