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,
|
//foo(arg,
|
||||||
// "string");
|
// "string");
|
||||||
public void testIndentationOfStringAsLastArgument_Bug192412() throws Exception {
|
public void testIndentationOfStringLiteralAsLastArgument_Bug192412() throws Exception {
|
||||||
assertIndenterResult();
|
assertIndenterResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -82,4 +82,37 @@ public class CIndenterTest extends BaseUITestCase {
|
||||||
public void testIndentationAfterArrowOperator_Bug192412() throws Exception {
|
public void testIndentationAfterArrowOperator_Bug192412() throws Exception {
|
||||||
assertIndenterResult();
|
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;
|
fCaretOffset= -1;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
document.addPosition(end);
|
|
||||||
firstLine= document.getLineOfOffset(offset);
|
firstLine= document.getLineOfOffset(offset);
|
||||||
// check for marginal (zero-length) lines
|
// check for marginal (zero-length) lines
|
||||||
int minusOne= length == 0 ? 0 : 1;
|
int minusOne= length == 0 ? 0 : 1;
|
||||||
nLines= document.getLineOfOffset(offset + length - minusOne) - firstLine + 1;
|
nLines= document.getLineOfOffset(offset + length - minusOne) - firstLine + 1;
|
||||||
|
document.addPosition(end);
|
||||||
} catch (BadLocationException e) {
|
} catch (BadLocationException e) {
|
||||||
// will only happen on concurrent modification
|
// will only happen on concurrent modification
|
||||||
CUIPlugin.getDefault().log(new Status(IStatus.ERROR, CUIPlugin.getPluginId(), IStatus.OK, "", e)); //$NON-NLS-1$
|
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))
|
if (newOffset != -1 && (hasChanged || newOffset != offset || newLength != length))
|
||||||
selectAndReveal(newOffset, newLength);
|
selectAndReveal(newOffset, newLength);
|
||||||
|
|
||||||
document.removePosition(end);
|
|
||||||
} catch (BadLocationException e) {
|
} catch (BadLocationException e) {
|
||||||
// will only happen on concurrent modification
|
// will only happen on concurrent modification
|
||||||
CUIPlugin.getDefault().log(new Status(IStatus.ERROR, CUIPlugin.getPluginId(), IStatus.OK, "ConcurrentModification in IndentAction", e)); //$NON-NLS-1$
|
CUIPlugin.getDefault().log(new Status(IStatus.ERROR, CUIPlugin.getPluginId(), IStatus.OK, "ConcurrentModification in IndentAction", e)); //$NON-NLS-1$
|
||||||
} finally {
|
} finally {
|
||||||
|
document.removePosition(end);
|
||||||
if (target != null)
|
if (target != null)
|
||||||
target.endCompoundChange();
|
target.endCompoundChange();
|
||||||
}
|
}
|
||||||
|
|
|
@ -345,6 +345,9 @@ public final class CHeuristicScanner implements Symbols {
|
||||||
case RANGLE:
|
case RANGLE:
|
||||||
++fPos;
|
++fPos;
|
||||||
return TokenSHIFTRIGHT;
|
return TokenSHIFTRIGHT;
|
||||||
|
case EQUAL:
|
||||||
|
++fPos;
|
||||||
|
return TokenOTHER;
|
||||||
}
|
}
|
||||||
return TokenGREATERTHAN;
|
return TokenGREATERTHAN;
|
||||||
case DOT:
|
case DOT:
|
||||||
|
@ -425,6 +428,13 @@ public final class CHeuristicScanner implements Symbols {
|
||||||
case QUESTIONMARK:
|
case QUESTIONMARK:
|
||||||
return TokenQUESTIONMARK;
|
return TokenQUESTIONMARK;
|
||||||
case EQUAL:
|
case EQUAL:
|
||||||
|
switch (peekPreviousChar()) {
|
||||||
|
case RANGLE:
|
||||||
|
--fPos;
|
||||||
|
case LANGLE:
|
||||||
|
--fPos;
|
||||||
|
return TokenOTHER;
|
||||||
|
}
|
||||||
return TokenEQUAL;
|
return TokenEQUAL;
|
||||||
case LANGLE:
|
case LANGLE:
|
||||||
return TokenLESSTHAN;
|
return TokenLESSTHAN;
|
||||||
|
|
Loading…
Add table
Reference in a new issue