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 125362f2c4a..7b148112a47 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 @@ -68,7 +68,25 @@ public class CIndenterTest extends BaseUITestCase { //foo(arg, // "string"); - public void testIndentationOfStringLiteralAsLastArgument_Bug192412() throws Exception { + public void testIndentationOfStringLiteralAsLastArgument1_Bug192412() throws Exception { + assertIndenterResult(); + } + + //a::foo(arg, + //"string"); + + //a::foo(arg, + // "string"); + public void testIndentationOfStringLiteralAsLastArgument2_Bug192412() throws Exception { + assertIndenterResult(); + } + + //a::foo(arg, + // "string"); + + //a::foo(arg, + // "string"); + public void testIndentationOfStringLiteralAsLastArgument3_Bug192412() throws Exception { assertIndenterResult(); } @@ -105,6 +123,19 @@ public class CIndenterTest extends BaseUITestCase { assertIndenterResult(); } + //std::ostream& operator<<(std::ostream& stream, + //const BinFileParser::Exception& exp) + //{ + //} + + //std::ostream& operator<<(std::ostream& stream, + // const BinFileParser::Exception& exp) + //{ + //} + public void testIndentationOfOperatorMethodBody_Bug192412() throws Exception { + assertIndenterResult(); + } + //struct x { // int f1 : 1; // int f2 : 1; @@ -120,4 +151,58 @@ public class CIndenterTest extends BaseUITestCase { assertIndenterResult(); } + //class A { + //A(int a, + //int b) + //{ + //} + //}; + + //class A { + // A(int a, + // int b) + // { + // } + //}; + public void testIndentationOfConstructorBody_Bug194586() throws Exception { + assertIndenterResult(); + } + + //class A { + //A(int a, + //int b) + //throw() + //{ + //} + //}; + + //class A { + // A(int a, + // int b) + // throw() + // { + // } + //}; + public void testIndentationOfConstructorBodyWithThrow_Bug194586() throws Exception { + assertIndenterResult(); + } + + //class A { + //A(int a, + //int b) + //:f(0) + //{ + //} + //}; + + //class A { + // A(int a, + // int b) + // :f(0) + // { + // } + //}; + public void testIndentationOfConstructorBodyWithInitializer_Bug194586() throws Exception { + assertIndenterResult(); + } } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/CHeuristicScanner.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/CHeuristicScanner.java index 7a13443bd75..8114fea5b2a 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/CHeuristicScanner.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/CHeuristicScanner.java @@ -301,17 +301,20 @@ public final class CHeuristicScanner implements Symbols { * @return a constant from {@link Symbols} describing the next token */ public int nextToken(int start, int bound) { + int pos= scanForward(start, bound, fNonWS); + if (pos == NOT_FOUND) + return TokenEOF; try { // check for string or char literal - char ch = fDocument.getChar(start); + char ch = fDocument.getChar(pos); if (ch == '"' || ch == '\'') { fChar= ch; - fPos= fNonWSDefaultPart.nextPosition(start, true); + fPos= fNonWSDefaultPart.nextPosition(pos, true); return TokenOTHER; } } catch (BadLocationException exc) { } - int pos= scanForward(start, bound, fNonWSDefaultPart); + pos= scanForward(pos, bound, fNonWSDefaultPart); if (pos == NOT_FOUND) return TokenEOF; @@ -346,6 +349,14 @@ public final class CHeuristicScanner implements Symbols { case EQUAL: return TokenEQUAL; case LANGLE: + switch (peekNextChar()) { + case LANGLE: + ++fPos; + return TokenSHIFTLEFT; + case EQUAL: + ++fPos; + return TokenOTHER; + } return TokenLESSTHAN; case RANGLE: switch (peekNextChar()) { @@ -442,13 +453,17 @@ public final class CHeuristicScanner implements Symbols { case EQUAL: switch (peekPreviousChar()) { case RANGLE: - --fPos; case LANGLE: --fPos; return TokenOTHER; } return TokenEQUAL; case LANGLE: + switch (peekPreviousChar()) { + case LANGLE: + --fPos; + return TokenSHIFTLEFT; + } return TokenLESSTHAN; case RANGLE: switch (peekPreviousChar()) { @@ -566,6 +581,10 @@ public final class CHeuristicScanner implements Symbols { return TokenWHILE; if ("union".equals(s)) //$NON-NLS-1$ return TokenUNION; + if ("throw".equals(s)) //$NON-NLS-1$ + return TokenTHROW; + if ("const".equals(s)) //$NON-NLS-1$ + return TokenCONST; break; case 6: if ("delete".equals(s)) //$NON-NLS-1$ @@ -589,6 +608,10 @@ public final class CHeuristicScanner implements Symbols { if ("virtual".equals(s)) //$NON-NLS-1$ return TokenVIRTUAL; break; + case 8: + if ("operator".equals(s)) //$NON-NLS-1$ + return TokenOPERATOR; + break; case 9: if ("namespace".equals(s)) //$NON-NLS-1$ return TokenNAMESPACE; 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 ce520f1c5ad..e4dbc3900d0 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 @@ -1653,6 +1653,25 @@ public final class CIndenter { return false; } + + /** + * Skips pointer operators if the current token is a pointer operator. + * + * @return true if a * or & could be scanned, the + * current token is left at the operator. + */ + private boolean skipPointerOperators() { + if (fToken == Symbols.TokenOTHER) { + CharSequence token= getTokenContent(); + if (token.length() == 1 && token.charAt(0) == '*' || token.charAt(0) == '&') { + return true; + } + } else if (fToken == Symbols.TokenCONST) { + return true; + } + return false; + } + /** * Skips brackets if the current token is a RBRACKET. There can be nothing * but whitespace in between, this is only to be used for [] elements. @@ -1724,7 +1743,9 @@ public final class CIndenter { */ private boolean looksLikeMethodDecl() { nextToken(); - if (fToken == Symbols.TokenIDENT) { // method name + switch (fToken) { + case Symbols.TokenIDENT: // method name + int pos= fPosition; nextToken(); // check destructor tilde if (fToken == Symbols.TokenTILDE) { @@ -1737,8 +1758,72 @@ public final class CIndenter { while (skipBrackets()) { nextToken(); } - return fToken == Symbols.TokenIDENT; - + while (skipPointerOperators()) { + nextToken(); + } + switch (fToken) { + case Symbols.TokenIDENT: + return true; + case Symbols.TokenSEMICOLON: + case Symbols.TokenRBRACE: + fPosition= pos; + return true; + case Symbols.TokenLBRACE: + if (fScanner.looksLikeCompositeTypeDefinitionBackward(fPosition, CHeuristicScanner.UNBOUND)) { + fPosition= pos; + return true; + } + break; + case Symbols.TokenGREATERTHAN: + return skipScope(); + case Symbols.TokenCOLON: + nextToken(); + switch (fToken) { + case Symbols.TokenPUBLIC: + case Symbols.TokenPROTECTED: + case Symbols.TokenPRIVATE: + fPosition= pos; + return true; + case Symbols.TokenRPAREN: + // constructor initializer + if (skipScope()) { + nextToken(); + // optional throw + if (fToken == Symbols.TokenTHROW) { + nextToken(); + if (fToken != Symbols.TokenRPAREN || !skipScope()) { + return false; + } + } + return looksLikeMethodDecl(); + } + break; + } + } + break; + case Symbols.TokenARROW: + case Symbols.TokenCOMMA: + case Symbols.TokenEQUAL: + case Symbols.TokenGREATERTHAN: + case Symbols.TokenLESSTHAN: + case Symbols.TokenMINUS: + case Symbols.TokenSHIFTRIGHT: + case Symbols.TokenSHIFTLEFT: + case Symbols.TokenDELETE: + case Symbols.TokenNEW: + nextToken(); + return fToken == Symbols.TokenOPERATOR; + case Symbols.TokenOTHER: + if (getTokenContent().length() == 1) { + nextToken(); + if (fToken == Symbols.TokenOPERATOR) + return true; + } + if (getTokenContent().length() == 1) { + nextToken(); + if (fToken == Symbols.TokenOPERATOR) + return true; + } } return false; } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/Symbols.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/Symbols.java index 9196516c2b7..13408f383d2 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/Symbols.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/Symbols.java @@ -37,6 +37,7 @@ public interface Symbols { int TokenSHIFTRIGHT= 18; int TokenARROW= 19; int TokenDOUBLECOLON= 20; + int TokenSHIFTLEFT= 21; int TokenIF= 109; int TokenDO= 1010; int TokenFOR= 1011; @@ -62,5 +63,8 @@ public interface Symbols { int TokenENUM= 1031; int TokenVIRTUAL= 1032; int TokenNAMESPACE= 1033; + int TokenOPERATOR= 1034; + int TokenTHROW= 1035; + int TokenCONST= 1036; int TokenIDENT= 2000; }