Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSergey Prigogin2012-05-24 01:25:58 +0000
committerSergey Prigogin2012-05-24 01:29:53 +0000
commit506c347cd8ad3f49bede9fa466b39ca31a03e319 (patch)
tree22a0901a4d18d247106fe0c8066d459268bb7bb6
parente266e58f985427a340bbe7e01a321a2a00c19db9 (diff)
downloadorg.eclipse.cdt-506c347cd8ad3f49bede9fa466b39ca31a03e319.tar.gz
org.eclipse.cdt-506c347cd8ad3f49bede9fa466b39ca31a03e319.tar.xz
org.eclipse.cdt-506c347cd8ad3f49bede9fa466b39ca31a03e319.zip
Bug 380490 - Invalid auto indentation after a multiline function call
-rw-r--r--core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CIndenterTest.java24
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/CIndenter.java6
2 files changed, 27 insertions, 3 deletions
diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CIndenterTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CIndenterTest.java
index 9abe5b5291f..99588a8b8dc 100644
--- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CIndenterTest.java
+++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CIndenterTest.java
@@ -25,7 +25,6 @@ import org.eclipse.cdt.core.formatter.DefaultCodeFormatterConstants;
import org.eclipse.cdt.core.formatter.DefaultCodeFormatterOptions;
import org.eclipse.cdt.ui.tests.BaseUITestCase;
-
import org.eclipse.cdt.internal.ui.editor.CDocumentSetupParticipant;
import org.eclipse.cdt.internal.ui.editor.IndentUtil;
@@ -979,4 +978,27 @@ public class CIndenterTest extends BaseUITestCase {
public void testIndentationAfterFunctionHeaderWithPointerReturnType_Bug334805() throws Exception {
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();
+ }
}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/CIndenter.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/CIndenter.java
index a03e5b76fa9..910dc5468cf 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/CIndenter.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/CIndenter.java
@@ -39,7 +39,6 @@ import org.eclipse.cdt.internal.corext.util.CodeFormatterUtil;
* </p>
*/
public final class CIndenter {
-
/**
* The CDT Core preferences.
*/
@@ -1588,6 +1587,7 @@ public final class CIndenter {
private int skipToPreviousListItemOrListStart() {
int startLine= fLine;
int startPosition= fPosition;
+ int linesSkippedInsideScopes = 0;
boolean continuationLineCandidate =
fToken == Symbols.TokenEQUAL || fToken == Symbols.TokenSHIFTLEFT ||
fToken == Symbols.TokenRPAREN;
@@ -1596,7 +1596,7 @@ public final class CIndenter {
nextToken();
// If any line item comes with its own indentation, adapt to it
- if (fLine < startLine) {
+ if (fLine < startLine - linesSkippedInsideScopes) {
try {
int lineOffset= fDocument.getLineOffset(startLine);
int bound= Math.min(fDocument.getLength(), startPosition + 1);
@@ -1617,6 +1617,7 @@ public final class CIndenter {
return startPosition;
}
+ int line = fLine;
switch (fToken) {
// scopes: skip them
case Symbols.TokenRPAREN:
@@ -1625,6 +1626,7 @@ public final class CIndenter {
case Symbols.TokenRBRACKET:
case Symbols.TokenRBRACE:
skipScope();
+ linesSkippedInsideScopes = line - fLine;
break;
// scope introduction: special treat who special is

Back to the top