mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-123956 Anonymous class formatting moves all args to the next line [CR-IC-5212]
This commit is contained in:
@@ -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), false);
|
||||
final Wrap wrap = Wrap.createWrap(getWrapType(mySettings.ARRAY_INITIALIZER_WRAP), true);
|
||||
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), false);
|
||||
final Wrap wrap = Wrap.createWrap(getWrapType(mySettings.ARRAY_INITIALIZER_WRAP), true);
|
||||
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), false);
|
||||
final Wrap wrap = Wrap.createWrap(getWrapType(mySettings.CALL_PARAMETERS_WRAP), true);
|
||||
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), false);
|
||||
Wrap wrap = Wrap.createWrap(getWrapType(mySettings.METHOD_PARAMETERS_WRAP), true);
|
||||
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), false);
|
||||
Wrap wrap = Wrap.createWrap(getWrapType(mySettings.RESOURCE_LIST_WRAP), true);
|
||||
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), false);
|
||||
Wrap wrap = Wrap.createWrap(getWrapType(mySettings.CALL_PARAMETERS_WRAP), true);
|
||||
child = processParenthesisBlock(result, child,
|
||||
WrappingStrategy.createDoNotWrapCommaStrategy(wrap),
|
||||
mySettings.ALIGN_MULTILINE_PARAMETERS_IN_CALLS);
|
||||
@@ -915,6 +915,7 @@ 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;
|
||||
@@ -934,7 +935,11 @@ public abstract class AbstractJavaBlock extends AbstractBlock implements JavaBlo
|
||||
final IElementType elementType = child.getElementType();
|
||||
Indent indentToUse = enforceIndent ? internalIndentEnforcedToChildren : internalIndent;
|
||||
AlignmentStrategy alignmentStrategyToUse = canUseAnonymousClassAlignment(child) ? anonymousClassStrategy : alignmentStrategy;
|
||||
processChild(result, child, alignmentStrategyToUse.getAlignment(elementType), wrappingStrategy.getWrap(elementType), indentToUse);
|
||||
|
||||
Wrap wrap = currentChildIsFirstToWrap ? Wrap.createWrap(WrapType.NONE, true) : wrappingStrategy.getWrap(elementType);
|
||||
currentChildIsFirstToWrap = false;
|
||||
processChild(result, child, alignmentStrategyToUse.getAlignment(elementType), wrap, indentToUse);
|
||||
|
||||
if (to == null) {//process only one statement
|
||||
return child;
|
||||
}
|
||||
|
||||
@@ -931,13 +931,12 @@ 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(\n" + " 1);\n" + " }\n" + "}");
|
||||
"class Foo {\n" + " void foo() {\n" + " fooFooFooFoo(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(\n" +
|
||||
" 1,\n" +
|
||||
" fooFooFooFoo(1,\n" +
|
||||
" 2);\n" +
|
||||
" }\n" +
|
||||
"}");
|
||||
|
||||
@@ -47,8 +47,7 @@ public class JavaFormatterWrapTest extends AbstractJavaFormatterTest {
|
||||
"class Foo {\n" +
|
||||
"}",
|
||||
|
||||
"@AttributeOverrides({\n" +
|
||||
" @AttributeOverride(name = \"id\", column = @Column(name = \"recovery_id\")),\n" +
|
||||
"@AttributeOverrides({@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" +
|
||||
@@ -391,9 +390,8 @@ 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, call(\n" +
|
||||
" " + literal + "\n" +
|
||||
" )\n" +
|
||||
" Diagnostic.Kind.ERROR,\n" +
|
||||
" call(" + literal + ")\n" +
|
||||
");\n";
|
||||
|
||||
doMethodTest(before, after);
|
||||
@@ -448,4 +446,21 @@ 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" +
|
||||
"}"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user