mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Bug 380490 - Invalid auto indentation after a multiline function call
This commit is contained in:
parent
e266e58f98
commit
506c347cd8
2 changed files with 27 additions and 3 deletions
|
@ -25,7 +25,6 @@ import org.eclipse.cdt.core.formatter.DefaultCodeFormatterConstants;
|
||||||
import org.eclipse.cdt.core.formatter.DefaultCodeFormatterOptions;
|
import org.eclipse.cdt.core.formatter.DefaultCodeFormatterOptions;
|
||||||
import org.eclipse.cdt.ui.tests.BaseUITestCase;
|
import org.eclipse.cdt.ui.tests.BaseUITestCase;
|
||||||
|
|
||||||
|
|
||||||
import org.eclipse.cdt.internal.ui.editor.CDocumentSetupParticipant;
|
import org.eclipse.cdt.internal.ui.editor.CDocumentSetupParticipant;
|
||||||
import org.eclipse.cdt.internal.ui.editor.IndentUtil;
|
import org.eclipse.cdt.internal.ui.editor.IndentUtil;
|
||||||
|
|
||||||
|
@ -979,4 +978,27 @@ public class CIndenterTest extends BaseUITestCase {
|
||||||
public void testIndentationAfterFunctionHeaderWithPointerReturnType_Bug334805() throws Exception {
|
public void testIndentationAfterFunctionHeaderWithPointerReturnType_Bug334805() throws Exception {
|
||||||
assertIndenterResult();
|
assertIndenterResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//void test(int arg1, int arg2) {
|
||||||
|
//if (BooleanFunction1(arg1,
|
||||||
|
//arg2) ||
|
||||||
|
//BooleanFunction2(arg1, arg2)) {
|
||||||
|
//x++;
|
||||||
|
//}
|
||||||
|
//}
|
||||||
|
|
||||||
|
//void test(int arg1, int arg2) {
|
||||||
|
// if (BooleanFunction1(arg1,
|
||||||
|
// arg2) ||
|
||||||
|
// BooleanFunction2(arg1, arg2)) {
|
||||||
|
// x++;
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
public void testMultilineFunctionCall_Bug380490() throws Exception {
|
||||||
|
fOptions.put(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR, CCorePlugin.SPACE);
|
||||||
|
fOptions.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_ARGUMENTS_IN_METHOD_INVOCATION,
|
||||||
|
DefaultCodeFormatterConstants.createAlignmentValue(false, DefaultCodeFormatterConstants.WRAP_COMPACT,
|
||||||
|
DefaultCodeFormatterConstants.INDENT_ON_COLUMN));
|
||||||
|
assertIndenterResult();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,7 +39,6 @@ import org.eclipse.cdt.internal.corext.util.CodeFormatterUtil;
|
||||||
* </p>
|
* </p>
|
||||||
*/
|
*/
|
||||||
public final class CIndenter {
|
public final class CIndenter {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The CDT Core preferences.
|
* The CDT Core preferences.
|
||||||
*/
|
*/
|
||||||
|
@ -1588,6 +1587,7 @@ public final class CIndenter {
|
||||||
private int skipToPreviousListItemOrListStart() {
|
private int skipToPreviousListItemOrListStart() {
|
||||||
int startLine= fLine;
|
int startLine= fLine;
|
||||||
int startPosition= fPosition;
|
int startPosition= fPosition;
|
||||||
|
int linesSkippedInsideScopes = 0;
|
||||||
boolean continuationLineCandidate =
|
boolean continuationLineCandidate =
|
||||||
fToken == Symbols.TokenEQUAL || fToken == Symbols.TokenSHIFTLEFT ||
|
fToken == Symbols.TokenEQUAL || fToken == Symbols.TokenSHIFTLEFT ||
|
||||||
fToken == Symbols.TokenRPAREN;
|
fToken == Symbols.TokenRPAREN;
|
||||||
|
@ -1596,7 +1596,7 @@ public final class CIndenter {
|
||||||
nextToken();
|
nextToken();
|
||||||
|
|
||||||
// If any line item comes with its own indentation, adapt to it
|
// If any line item comes with its own indentation, adapt to it
|
||||||
if (fLine < startLine) {
|
if (fLine < startLine - linesSkippedInsideScopes) {
|
||||||
try {
|
try {
|
||||||
int lineOffset= fDocument.getLineOffset(startLine);
|
int lineOffset= fDocument.getLineOffset(startLine);
|
||||||
int bound= Math.min(fDocument.getLength(), startPosition + 1);
|
int bound= Math.min(fDocument.getLength(), startPosition + 1);
|
||||||
|
@ -1617,6 +1617,7 @@ public final class CIndenter {
|
||||||
return startPosition;
|
return startPosition;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int line = fLine;
|
||||||
switch (fToken) {
|
switch (fToken) {
|
||||||
// scopes: skip them
|
// scopes: skip them
|
||||||
case Symbols.TokenRPAREN:
|
case Symbols.TokenRPAREN:
|
||||||
|
@ -1625,6 +1626,7 @@ public final class CIndenter {
|
||||||
case Symbols.TokenRBRACKET:
|
case Symbols.TokenRBRACKET:
|
||||||
case Symbols.TokenRBRACE:
|
case Symbols.TokenRBRACE:
|
||||||
skipScope();
|
skipScope();
|
||||||
|
linesSkippedInsideScopes = line - fLine;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// scope introduction: special treat who special is
|
// scope introduction: special treat who special is
|
||||||
|
|
Loading…
Add table
Reference in a new issue