mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Final fix for 192412: [Indenter] Improve indenter heuristics
This commit is contained in:
parent
f0b4d7ac80
commit
5adf724d8e
3 changed files with 46 additions and 3 deletions
|
@ -68,7 +68,7 @@ public class CIndenterTest extends BaseUITestCase {
|
|||
|
||||
//foo(arg,
|
||||
// "string");
|
||||
public void testIndentationOfStringAsLastArgument_Bug192412() throws Exception {
|
||||
public void testIndentationOfStringLiteralAsLastArgument_Bug192412() throws Exception {
|
||||
assertIndenterResult();
|
||||
}
|
||||
|
||||
|
@ -82,4 +82,37 @@ public class CIndenterTest extends BaseUITestCase {
|
|||
public void testIndentationAfterArrowOperator_Bug192412() throws Exception {
|
||||
assertIndenterResult();
|
||||
}
|
||||
|
||||
//if (1)
|
||||
//foo>>bar;
|
||||
// dontIndent();
|
||||
|
||||
//if (1)
|
||||
// foo>>bar;
|
||||
//dontIndent();
|
||||
public void testIndentationAfterShiftRight_Bug192412() throws Exception {
|
||||
assertIndenterResult();
|
||||
}
|
||||
|
||||
//if (1)
|
||||
//foo >= bar();
|
||||
// dontIndent();
|
||||
|
||||
//if (1)
|
||||
// foo >= bar();
|
||||
//dontIndent();
|
||||
public void testIndentationAfterGreaterOrEquals_Bug192412() throws Exception {
|
||||
assertIndenterResult();
|
||||
}
|
||||
|
||||
//int x;
|
||||
//
|
||||
//int y;
|
||||
|
||||
//int x;
|
||||
//
|
||||
//int y;
|
||||
public void testIndentationOfEmptyLine_Bug192412() throws Exception {
|
||||
assertIndenterResult();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -102,11 +102,11 @@ public class IndentAction extends TextEditorAction {
|
|||
fCaretOffset= -1;
|
||||
|
||||
try {
|
||||
document.addPosition(end);
|
||||
firstLine= document.getLineOfOffset(offset);
|
||||
// check for marginal (zero-length) lines
|
||||
int minusOne= length == 0 ? 0 : 1;
|
||||
nLines= document.getLineOfOffset(offset + length - minusOne) - firstLine + 1;
|
||||
document.addPosition(end);
|
||||
} catch (BadLocationException e) {
|
||||
// will only happen on concurrent modification
|
||||
CUIPlugin.getDefault().log(new Status(IStatus.ERROR, CUIPlugin.getPluginId(), IStatus.OK, "", e)); //$NON-NLS-1$
|
||||
|
@ -144,11 +144,11 @@ public class IndentAction extends TextEditorAction {
|
|||
if (newOffset != -1 && (hasChanged || newOffset != offset || newLength != length))
|
||||
selectAndReveal(newOffset, newLength);
|
||||
|
||||
document.removePosition(end);
|
||||
} catch (BadLocationException e) {
|
||||
// will only happen on concurrent modification
|
||||
CUIPlugin.getDefault().log(new Status(IStatus.ERROR, CUIPlugin.getPluginId(), IStatus.OK, "ConcurrentModification in IndentAction", e)); //$NON-NLS-1$
|
||||
} finally {
|
||||
document.removePosition(end);
|
||||
if (target != null)
|
||||
target.endCompoundChange();
|
||||
}
|
||||
|
|
|
@ -345,6 +345,9 @@ public final class CHeuristicScanner implements Symbols {
|
|||
case RANGLE:
|
||||
++fPos;
|
||||
return TokenSHIFTRIGHT;
|
||||
case EQUAL:
|
||||
++fPos;
|
||||
return TokenOTHER;
|
||||
}
|
||||
return TokenGREATERTHAN;
|
||||
case DOT:
|
||||
|
@ -425,6 +428,13 @@ public final class CHeuristicScanner implements Symbols {
|
|||
case QUESTIONMARK:
|
||||
return TokenQUESTIONMARK;
|
||||
case EQUAL:
|
||||
switch (peekPreviousChar()) {
|
||||
case RANGLE:
|
||||
--fPos;
|
||||
case LANGLE:
|
||||
--fPos;
|
||||
return TokenOTHER;
|
||||
}
|
||||
return TokenEQUAL;
|
||||
case LANGLE:
|
||||
return TokenLESSTHAN;
|
||||
|
|
Loading…
Add table
Reference in a new issue