# HG changeset patch # User Alexander Simon # Date 1206972402 -14400 # Node ID 1b230feca924346b59cc5677d8e60e6150433360 # Parent b56a5f977f1a2a9803881ca112681c3b68b34b8c fixed IZ#131379:GNU style: formatter works wrong with functions if it returns struct diff -r b56a5f977f1a -r 1b230feca924 cnd.editor/src/org/netbeans/modules/cnd/editor/cplusplus/CCFormatSupport.java --- a/cnd.editor/src/org/netbeans/modules/cnd/editor/cplusplus/CCFormatSupport.java Mon Mar 31 09:09:48 2008 +0200 +++ b/cnd.editor/src/org/netbeans/modules/cnd/editor/cplusplus/CCFormatSupport.java Mon Mar 31 18:06:42 2008 +0400 @@ -504,14 +504,14 @@ public class CCFormatSupport extends Ext * the given token. */ public TokenItem findStatementStart(TokenItem token) { - TokenItem t = findStatementStart(token, true); + TokenItem t = findStatementStart(token, false); // preprocessor tokens are not important (bug#22570) while (t != null && isPreprocessorLine(t)) { TokenItem current = t.getPrevious(); if (current == null) { return null; } - t = findStatementStart(current, true); + t = findStatementStart(current, false); } return t; } @@ -968,7 +968,7 @@ public class CCFormatSupport extends Ext } } if (indent < 0) { - indent = computeStatementIndent(token); + indent = computeStatementIndent(t); } break; @@ -977,7 +977,7 @@ public class CCFormatSupport extends Ext indent = getTokenIndent(t); break; } - indent = computeStatementIndent(token); + indent = computeStatementIndent(t); break; case CCTokenContext.COMMA_ID: @@ -988,7 +988,7 @@ public class CCFormatSupport extends Ext indent = computeStatementIndent(t); break; default: - indent = computeStatementIndent(token); + indent = computeStatementIndent(t); break; } diff -r b56a5f977f1a -r 1b230feca924 cnd.editor/src/org/netbeans/modules/cnd/editor/cplusplus/CCFormatter.java --- a/cnd.editor/src/org/netbeans/modules/cnd/editor/cplusplus/CCFormatter.java Mon Mar 31 09:09:48 2008 +0200 +++ b/cnd.editor/src/org/netbeans/modules/cnd/editor/cplusplus/CCFormatter.java Mon Mar 31 18:06:42 2008 +0400 @@ -121,7 +121,7 @@ public class CCFormatter extends ExtForm typedText.length() == 1 && Character.isLetter(typedText.charAt(0))) { try { int fnw = Utilities.getRowFirstNonWhite(doc, dotPos); - if (checkCase(doc, fnw, typedText+"\n")) { // NOI18N + if (checkCase(doc, fnw, typedText+"\n") || dotPos == doc.getLength()) { // NOI18N ret = new int[]{fnw, fnw + 1}; } } catch (BadLocationException e) { diff -r b56a5f977f1a -r 1b230feca924 cnd.editor/src/org/netbeans/modules/cnd/editor/reformat/ReformatterImpl.java --- a/cnd.editor/src/org/netbeans/modules/cnd/editor/reformat/ReformatterImpl.java Mon Mar 31 09:09:48 2008 +0200 +++ b/cnd.editor/src/org/netbeans/modules/cnd/editor/reformat/ReformatterImpl.java Mon Mar 31 18:06:42 2008 +0400 @@ -39,6 +39,7 @@ package org.netbeans.modules.cnd.editor.reformat; +import java.util.ArrayList; import java.util.LinkedList; import org.netbeans.api.lexer.Token; import org.netbeans.api.lexer.TokenSequence; @@ -1069,25 +1070,50 @@ public class ReformatterImpl { case LPAREN: paren--; if (paren==0 && hasParen){ + ArrayList nlList = new ArrayList(); Token function = ts.lookPreviousImportant(); if (function != null && function.id()==IDENTIFIER) { int startName = -1; + boolean isPrevID = false; while (ts.movePrevious()) { switch(ts.token().id()){ case COMMA: case COLON: return; + case NEW_LINE: + nlList.add(ts.index()); + break; + case BLOCK_COMMENT: case WHITESPACE: break; - case IDENTIFIER: - case SCOPE: case TILDE: startName = ts.index(); + isPrevID = true; break; + case SCOPE: + startName = ts.index(); + isPrevID = false; + break; + case IDENTIFIER: + if (!isPrevID) { + startName = ts.index(); + isPrevID = true; + break; + } + // nobreak default: ts.moveIndex(startName); ts.moveNext(); - newLineBefore(false); + newLineBefore(braces.getIndent()); + for(int i = 0; i < nlList.size(); i++){ + int nl = nlList.get(i); + if (startName < nl) { + ts.moveIndex(nl); + ts.moveNext(); + ts.moveNext(); + removeLineBefore(false); + } + } return; } } @@ -1640,6 +1666,10 @@ public class ReformatterImpl { } else { spaces = getIndent(); } + newLineBefore(spaces); + } + + private void newLineBefore(int spaces) { if (!ts.isFirstLineToken()) { Token previous = ts.lookPrevious(); if (previous != null) { diff -r b56a5f977f1a -r 1b230feca924 cnd.editor/test/unit/src/org/netbeans/modules/cnd/editor/cplusplus/CCBracketCompletionUnitTestCase.java --- a/cnd.editor/test/unit/src/org/netbeans/modules/cnd/editor/cplusplus/CCBracketCompletionUnitTestCase.java Mon Mar 31 09:09:48 2008 +0200 +++ b/cnd.editor/test/unit/src/org/netbeans/modules/cnd/editor/cplusplus/CCBracketCompletionUnitTestCase.java Mon Mar 31 18:06:42 2008 +0400 @@ -49,16 +49,19 @@ public class CCBracketCompletionUnitTest // ------- Tests for completion of right parenthesis ')' ------------- public void testRightParenSimpleMethodCall() { + setDefaultsOptions(); setLoadDocumentText("m()|)"); assertTrue(isSkipRightParen()); } public void testRightParenSwingInvokeLaterRunnable() { + setDefaultsOptions(); setLoadDocumentText("SwingUtilities.invokeLater(new Runnable()|))"); assertTrue(isSkipRightParen()); } public void testRightParenSwingInvokeLaterRunnableRun() { + setDefaultsOptions(); setLoadDocumentText( "SwingUtilities.invokeLater(new Runnable() {\n" + " public void run()|)\n" @@ -69,6 +72,7 @@ public class CCBracketCompletionUnitTest } public void testRightParenIfMethodCall() { + setDefaultsOptions(); setLoadDocumentText( " if (a()|) + 5 > 6) {\n" + " }" @@ -77,11 +81,13 @@ public class CCBracketCompletionUnitTest } public void testRightParenNoSkipNonBracketChar() { + setDefaultsOptions(); setLoadDocumentText("m()| "); assertFalse(isSkipRightParen()); } public void testRightParenNoSkipDocEnd() { + setDefaultsOptions(); setLoadDocumentText("m()|"); assertFalse(isSkipRightParen()); } @@ -90,26 +96,31 @@ public class CCBracketCompletionUnitTest // ------- Tests for completion of right brace '}' ------------- public void testAddRightBraceIfLeftBrace() { + setDefaultsOptions(); setLoadDocumentText("if (true) {|"); assertTrue(isAddRightBrace()); } public void testAddRightBraceIfLeftBraceWhiteSpace() { + setDefaultsOptions(); setLoadDocumentText("if (true) { \t|\n"); assertTrue(isAddRightBrace()); } public void testAddRightBraceIfLeftBraceLineComment() { + setDefaultsOptions(); setLoadDocumentText("if (true) { // line-comment|\n"); assertTrue(isAddRightBrace()); } public void testAddRightBraceIfLeftBraceBlockComment() { + setDefaultsOptions(); setLoadDocumentText("if (true) { /* block-comment */|\n"); assertTrue(isAddRightBrace()); } public void testAddRightBraceIfLeftBraceAlreadyPresent() { + setDefaultsOptions(); setLoadDocumentText( "if (true) {|\n" + "}" @@ -118,6 +129,7 @@ public class CCBracketCompletionUnitTest } public void testAddRightBraceCaretInComment() { + setDefaultsOptions(); setLoadDocumentText( "if (true) { /* in-block-comment |\n" ); @@ -125,6 +137,7 @@ public class CCBracketCompletionUnitTest } public void testSimpleAdditionOfOpeningParenthesisAfterWhile () throws Exception { + setDefaultsOptions(); setLoadDocumentText ( "while |" ); @@ -137,6 +150,7 @@ public class CCBracketCompletionUnitTest // ------- Tests for completion of quote (") ------------- public void testSimpleQuoteInEmptyDoc () throws Exception { + setDefaultsOptions(); setLoadDocumentText ( "|" ); @@ -147,6 +161,7 @@ public class CCBracketCompletionUnitTest } public void testSimpleQuoteAtBeginingOfDoc () throws Exception { + setDefaultsOptions(); setLoadDocumentText ( "| " ); @@ -157,6 +172,7 @@ public class CCBracketCompletionUnitTest } public void testSimpleQuoteAtEndOfDoc () throws Exception { + setDefaultsOptions(); setLoadDocumentText ( " |" ); @@ -167,6 +183,7 @@ public class CCBracketCompletionUnitTest } public void testSimpleQuoteInWhiteSpaceArea () throws Exception { + setDefaultsOptions(); setLoadDocumentText ( " | " ); @@ -177,6 +194,7 @@ public class CCBracketCompletionUnitTest } public void testQuoteAtEOL () throws Exception { + setDefaultsOptions(); setLoadDocumentText ( " |\n" ); @@ -187,6 +205,7 @@ public class CCBracketCompletionUnitTest } public void testQuoteWithUnterminatedStringLiteral () throws Exception { + setDefaultsOptions(); setLoadDocumentText ( " \"unterminated string| \n" ); @@ -197,6 +216,7 @@ public class CCBracketCompletionUnitTest } public void testQuoteAtEOLWithUnterminatedStringLiteral () throws Exception { + setDefaultsOptions(); setLoadDocumentText ( " \"unterminated string |\n" ); @@ -207,6 +227,7 @@ public class CCBracketCompletionUnitTest } public void testQuoteInsideStringLiteral () throws Exception { + setDefaultsOptions(); setLoadDocumentText ( " \"stri|ng literal\" " ); @@ -217,6 +238,7 @@ public class CCBracketCompletionUnitTest } public void testQuoteInsideEmptyParentheses () throws Exception { + setDefaultsOptions(); setLoadDocumentText ( " printf(|) " ); @@ -227,6 +249,7 @@ public class CCBracketCompletionUnitTest } public void testQuoteInsideNonEmptyParentheses () throws Exception { + setDefaultsOptions(); setLoadDocumentText ( " printf(|some text) " ); @@ -237,6 +260,7 @@ public class CCBracketCompletionUnitTest } public void testQuoteInsideNonEmptyParenthesesBeforeClosingParentheses () throws Exception { + setDefaultsOptions(); setLoadDocumentText ( " printf(i+|) " ); @@ -247,6 +271,7 @@ public class CCBracketCompletionUnitTest } public void testQuoteInsideNonEmptyParenthesesBeforeClosingParenthesesAndUnterminatedStringLiteral () throws Exception { + setDefaultsOptions(); setLoadDocumentText ( " printf(\"unterminated string literal |); " ); @@ -257,6 +282,7 @@ public class CCBracketCompletionUnitTest } public void testQuoteBeforePlus () throws Exception { + setDefaultsOptions(); setLoadDocumentText ( " printf(|+\"string literal\"); " ); @@ -267,6 +293,7 @@ public class CCBracketCompletionUnitTest } public void testQuoteBeforeComma () throws Exception { + setDefaultsOptions(); setLoadDocumentText ( "String s[] = new String[]{|,\"two\"};" ); @@ -277,6 +304,7 @@ public class CCBracketCompletionUnitTest } public void testQuoteBeforeBrace () throws Exception { + setDefaultsOptions(); setLoadDocumentText ( "String s[] = new String[]{\"one\",|};" ); @@ -287,6 +315,7 @@ public class CCBracketCompletionUnitTest } public void testQuoteBeforeSemicolon() throws Exception { + setDefaultsOptions(); setLoadDocumentText ( "String s = \"\" + |;" ); @@ -297,6 +326,7 @@ public class CCBracketCompletionUnitTest } public void testQuoteBeforeSemicolonWithWhitespace() throws Exception { + setDefaultsOptions(); setLoadDocumentText ( "String s = \"\" +| ;" ); @@ -307,6 +337,7 @@ public class CCBracketCompletionUnitTest } public void testQuoteAfterEscapeSequence() throws Exception { + setDefaultsOptions(); setLoadDocumentText ( "\\|" ); @@ -318,6 +349,7 @@ public class CCBracketCompletionUnitTest /** issue #69524 */ public void testQuoteEaten() throws Exception { + setDefaultsOptions(); setLoadDocumentText ( "|" ); @@ -330,6 +362,7 @@ public class CCBracketCompletionUnitTest /** issue #69935 */ public void testQuoteInsideComments() throws Exception { + setDefaultsOptions(); setLoadDocumentText ( "/** |\n */" ); @@ -341,6 +374,7 @@ public class CCBracketCompletionUnitTest /** issue #71880 */ public void testQuoteAtTheEndOfLineCommentLine() throws Exception { + setDefaultsOptions(); setLoadDocumentText ( "// test line comment |\n" ); @@ -354,6 +388,7 @@ public class CCBracketCompletionUnitTest // ------- Tests for completion of single quote (') ------------- public void testSingleQuoteInEmptyDoc () throws Exception { + setDefaultsOptions(); setLoadDocumentText ( "|" ); @@ -364,6 +399,7 @@ public class CCBracketCompletionUnitTest } public void testSingleQuoteAtBeginingOfDoc () throws Exception { + setDefaultsOptions(); setLoadDocumentText ( "| " ); @@ -374,6 +410,7 @@ public class CCBracketCompletionUnitTest } public void testSingleQuoteAtEndOfDoc () throws Exception { + setDefaultsOptions(); setLoadDocumentText ( " |" ); @@ -384,6 +421,7 @@ public class CCBracketCompletionUnitTest } public void testSingleQuoteInWhiteSpaceArea () throws Exception { + setDefaultsOptions(); setLoadDocumentText ( " | " ); @@ -394,6 +432,7 @@ public class CCBracketCompletionUnitTest } public void testSingleQuoteAtEOL () throws Exception { + setDefaultsOptions(); setLoadDocumentText ( " |\n" ); @@ -404,6 +443,7 @@ public class CCBracketCompletionUnitTest } public void testSingleQuoteWithUnterminatedCharLiteral () throws Exception { + setDefaultsOptions(); setLoadDocumentText ( " '| \n" ); @@ -414,6 +454,7 @@ public class CCBracketCompletionUnitTest } public void testSingleQuoteAtEOLWithUnterminatedCharLiteral () throws Exception { + setDefaultsOptions(); setLoadDocumentText ( " ' |\n" ); @@ -424,6 +465,7 @@ public class CCBracketCompletionUnitTest } public void testSingleQuoteInsideCharLiteral () throws Exception { + setDefaultsOptions(); setLoadDocumentText ( " '| ' " ); @@ -434,6 +476,7 @@ public class CCBracketCompletionUnitTest } public void testSingleQuoteInsideEmptyParentheses () throws Exception { + setDefaultsOptions(); setLoadDocumentText ( " printf(|) " ); @@ -444,6 +487,7 @@ public class CCBracketCompletionUnitTest } public void testSingleQuoteInsideNonEmptyParentheses () throws Exception { + setDefaultsOptions(); setLoadDocumentText ( " printf(|some text) " ); @@ -454,6 +498,7 @@ public class CCBracketCompletionUnitTest } public void testSingleQuoteInsideNonEmptyParenthesesBeforeClosingParentheses () throws Exception { + setDefaultsOptions(); setLoadDocumentText ( " printf(i+|) " ); @@ -464,6 +509,7 @@ public class CCBracketCompletionUnitTest } public void testSingleQuoteInsideNonEmptyParenthesesBeforeClosingParenthesesAndUnterminatedCharLiteral () throws Exception { + setDefaultsOptions(); setLoadDocumentText ( " printf(' |); " ); @@ -474,6 +520,7 @@ public class CCBracketCompletionUnitTest } public void testSingleQuoteBeforePlus () throws Exception { + setDefaultsOptions(); setLoadDocumentText ( " printf(|+\"string literal\"); " ); @@ -484,6 +531,7 @@ public class CCBracketCompletionUnitTest } public void testSingleQuoteBeforeComma () throws Exception { + setDefaultsOptions(); setLoadDocumentText ( "String s[] = new String[]{|,\"two\"};" ); @@ -494,6 +542,7 @@ public class CCBracketCompletionUnitTest } public void testSingleQuoteBeforeBrace () throws Exception { + setDefaultsOptions(); setLoadDocumentText ( "String s[] = new String[]{\"one\",|};" ); @@ -504,6 +553,7 @@ public class CCBracketCompletionUnitTest } public void testSingleQuoteBeforeSemicolon() throws Exception { + setDefaultsOptions(); setLoadDocumentText ( "String s = \"\" + |;" ); @@ -514,6 +564,7 @@ public class CCBracketCompletionUnitTest } public void testsingleQuoteBeforeSemicolonWithWhitespace() throws Exception { + setDefaultsOptions(); setLoadDocumentText ( "String s = \"\" +| ;" ); @@ -524,6 +575,7 @@ public class CCBracketCompletionUnitTest } public void testSingleQuoteAfterEscapeSequence() throws Exception { + setDefaultsOptions(); setLoadDocumentText ( "\\|" ); @@ -535,6 +587,7 @@ public class CCBracketCompletionUnitTest /** issue #69524 */ public void testSingleQuoteEaten() throws Exception { + setDefaultsOptions(); setLoadDocumentText ( "|" ); @@ -547,6 +600,7 @@ public class CCBracketCompletionUnitTest /** issue #69935 */ public void testSingleQuoteInsideComments() throws Exception { + setDefaultsOptions(); setLoadDocumentText ( "/* |\n */" ); @@ -558,6 +612,7 @@ public class CCBracketCompletionUnitTest /** issue #71880 */ public void testSingleQuoteAtTheEndOfLineCommentLine() throws Exception { + setDefaultsOptions(); setLoadDocumentText ( "// test line comment |\n" ); @@ -568,6 +623,7 @@ public class CCBracketCompletionUnitTest } public void testSystemInclude() throws Exception { + setDefaultsOptions(); setLoadDocumentText ( "#include |\n" ); @@ -578,6 +634,7 @@ public class CCBracketCompletionUnitTest } public void testUserInclude() throws Exception { + setDefaultsOptions(); setLoadDocumentText ( "#include |\n" ); @@ -588,6 +645,7 @@ public class CCBracketCompletionUnitTest } public void testArray() throws Exception { + setDefaultsOptions(); setLoadDocumentText ( "int a|\n" ); @@ -598,6 +656,7 @@ public class CCBracketCompletionUnitTest } public void testRightBracePreprocessor() { + setDefaultsOptions(); setLoadDocumentText( "void foo(){\n" + "#if A\n" + @@ -612,6 +671,7 @@ public class CCBracketCompletionUnitTest } public void testRightBracePreprocessor2() { + setDefaultsOptions(); setLoadDocumentText( "void foo(){\n" + "#if A\n" + @@ -626,6 +686,7 @@ public class CCBracketCompletionUnitTest } public void testRightBracePreprocessor3() { + setDefaultsOptions(); setLoadDocumentText( "void foo(){\n" + "#if A\n" + @@ -640,6 +701,7 @@ public class CCBracketCompletionUnitTest } public void testRightBracePreprocessor4() { + setDefaultsOptions(); setLoadDocumentText( "void foo(){\n" + "#if A\n" + @@ -655,6 +717,7 @@ public class CCBracketCompletionUnitTest } public void testRightBracePreprocessor5() { + setDefaultsOptions(); setLoadDocumentText( "void foo(){\n" + "#define PAREN {\n" + @@ -666,40 +729,48 @@ public class CCBracketCompletionUnitTest } public void testIZ102091() throws Exception { + setDefaultsOptions(); EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)). put(EditorOptions.newLineBeforeBrace, CodeStyle.BracePlacement.NEW_LINE.name()); - try { - setLoadDocumentText ( - "if(i)\n"+ - " |" - ); - typeChar('{', true); - assertDocumentTextAndCaret ("IZ102091\n", - "if(i)\n"+ - "{|" - ); - } finally { - EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)). - put(EditorOptions.newLineBeforeBrace, - CodeStyle.BracePlacement.SAME_LINE.name()); - } + setLoadDocumentText ( + "if(i)\n"+ + " |" + ); + typeChar('{', true); + assertDocumentTextAndCaret ("IZ102091\n", + "if(i)\n"+ + "{|" + ); } -// public void testColonAfterPublic() throws Exception { -// setLoadDocumentText ( -// "class A{\n" + -// " public|\n" + -// "}\n" -// ); -// typeChar(':'); -// assertDocumentTextAndCaret ("Colon After Public", -// "class A{\n" + -// "public:|\n" + -// "}\n" -// ); -// } + public void testColonAfterPublic() throws Exception { + setDefaultsOptions(); + setLoadDocumentText ( + "class A{\n" + + " public|\n" + + "}\n" + ); + typeChar(':', true); + assertDocumentText("Colon After Public", + "class A{\n" + + "public:\n" + + "}\n" + ); + } + public void testIdentFunctionName() throws Exception { + setDefaultsOptions("GNU"); + setLoadDocumentText( + "tree\n" + + " |" + ); + typeChar('d',true); + assertDocumentTextAndCaret("Incorrect identing of main", + "tree\n" + + "d|" + ); + } // ------- Private methods ------------- diff -r b56a5f977f1a -r 1b230feca924 cnd.editor/test/unit/src/org/netbeans/modules/cnd/editor/cplusplus/CCIndentUnitTestCase.java --- a/cnd.editor/test/unit/src/org/netbeans/modules/cnd/editor/cplusplus/CCIndentUnitTestCase.java Mon Mar 31 09:09:48 2008 +0200 +++ b/cnd.editor/test/unit/src/org/netbeans/modules/cnd/editor/cplusplus/CCIndentUnitTestCase.java Mon Mar 31 18:06:42 2008 +0400 @@ -47,6 +47,7 @@ public class CCIndentUnitTestCase extend // indent new line tests public void testJavadocEnterNothingAfterCaret() { + setDefaultsOptions(); setLoadDocumentText( "/**\n" + " * text|\n" @@ -63,6 +64,7 @@ public class CCIndentUnitTestCase extend } public void testJavadocEnterTextAfterCaret() { + setDefaultsOptions(); setLoadDocumentText( "/**\n" + " * break|text\n" @@ -79,6 +81,7 @@ public class CCIndentUnitTestCase extend } public void testJavadocEnterStarAfterCaret() { + setDefaultsOptions(); setLoadDocumentText( "/**\n" + " * text|*/\n" @@ -93,6 +96,7 @@ public class CCIndentUnitTestCase extend } public void testEnterInMultiLineSystemOutPrintln() { + setDefaultsOptions(); setLoadDocumentText( "void m() {\n" + " printf(|\n" @@ -109,6 +113,7 @@ public class CCIndentUnitTestCase extend } public void testEnterInMultiLineSystemOutPrintlnLineThree() { + setDefaultsOptions(); setLoadDocumentText( "void m() {\n" + " printf(\n" @@ -127,6 +132,7 @@ public class CCIndentUnitTestCase extend } public void testEnterInMultiLineSystemOutPrintlnAfterSemiColon() { + setDefaultsOptions(); setLoadDocumentText( "void m() {\n" + " printf(\n" @@ -161,6 +167,7 @@ public class CCIndentUnitTestCase extend // } public void testEnterAfterIf() { + setDefaultsOptions(); setLoadDocumentText( "if (true)|\n" ); @@ -172,10 +179,10 @@ public class CCIndentUnitTestCase extend } public void testEnterAfterIfHalf() { + setDefaultsOptions(); EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)). put(EditorOptions.newLineBeforeBrace, CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name()); - try { setLoadDocumentText( "if (true)|\n" ); @@ -184,16 +191,13 @@ public class CCIndentUnitTestCase extend "if (true)\n" + " |\n" ); - } finally{ - setDefaultsOptions(); - } } public void testEnterAfterIfBraceHalf() { + setDefaultsOptions(); EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)). put(EditorOptions.newLineBeforeBrace, CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name()); - try { setLoadDocumentText( "if (true)\n" + " {|\n" + @@ -206,19 +210,16 @@ public class CCIndentUnitTestCase extend " |\n" + " }\n" ); - } finally{ - setDefaultsOptions(); - } } public void testEnterAfterIfBraceHalf2() { + setDefaultsOptions(); EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)). put(EditorOptions.newLineBeforeBraceDeclaration, CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name()); EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)). put(EditorOptions.newLineBeforeBrace, CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name()); - try { setLoadDocumentText( "int foo()\n" + "{\n" + @@ -237,12 +238,10 @@ public class CCIndentUnitTestCase extend " }\n" + "}\n" ); - } finally{ - setDefaultsOptions(); - } } public void testEnterAfterFor() { + setDefaultsOptions(); setLoadDocumentText( "for (int i = 0; i < 10; i++)|\n" ); @@ -254,10 +253,10 @@ public class CCIndentUnitTestCase extend } public void testEnterAfterForHalf() { + setDefaultsOptions(); EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)). put(EditorOptions.newLineBeforeBrace, CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name()); - try { setLoadDocumentText( "for (int i = 0; i < 10; i++)|\n" ); @@ -266,12 +265,10 @@ public class CCIndentUnitTestCase extend "for (int i = 0; i < 10; i++)\n" + " |\n" ); - } finally{ - setDefaultsOptions(); - } } public void testEnterAfterWhile() { + setDefaultsOptions(); setLoadDocumentText( "while (true)|\n" ); @@ -283,10 +280,10 @@ public class CCIndentUnitTestCase extend } public void testEnterAfterWhileHalf() { + setDefaultsOptions(); EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)). put(EditorOptions.newLineBeforeBrace, CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name()); - try { setLoadDocumentText( "while (true)|\n" ); @@ -295,12 +292,10 @@ public class CCIndentUnitTestCase extend "while (true)\n" + " |\n" ); - } finally{ - setDefaultsOptions(); - } } public void testEnterAfterDo() { + setDefaultsOptions(); setLoadDocumentText( "do|\n" ); @@ -312,24 +307,22 @@ public class CCIndentUnitTestCase extend } public void testEnterAfterDoHalf() { + setDefaultsOptions(); EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)). put(EditorOptions.newLineBeforeBrace, CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name()); - try { - setLoadDocumentText( - "do|\n" - ); - indentNewLine(); - assertDocumentTextAndCaret("Incorrect new-line indent", - "do\n" + - " |\n" - ); - } finally{ - setDefaultsOptions(); - } + setLoadDocumentText( + "do|\n" + ); + indentNewLine(); + assertDocumentTextAndCaret("Incorrect new-line indent", + "do\n" + + " |\n" + ); } public void testEnterAfterIfStmt() { + setDefaultsOptions(); setLoadDocumentText( "if (true)\n" + " stmt;|\n" @@ -343,10 +336,10 @@ public class CCIndentUnitTestCase extend } public void testEnterAfterIfStmtHalf() { + setDefaultsOptions(); EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)). put(EditorOptions.newLineBeforeBrace, CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name()); - try { setLoadDocumentText( "if (true)\n" + " stmt;|\n" @@ -357,12 +350,10 @@ public class CCIndentUnitTestCase extend + " stmt;\n" + "|\n" ); - } finally{ - setDefaultsOptions(); - } } public void testEnterAfterIfElse() { + setDefaultsOptions(); setLoadDocumentText( "if (true)\n" + " stmt;\n" @@ -378,10 +369,10 @@ public class CCIndentUnitTestCase extend } public void testEnterAfterIfElseHalf() { + setDefaultsOptions(); EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)). put(EditorOptions.newLineBeforeBrace, CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name()); - try { setLoadDocumentText( "if (true)\n" + " stmt;\n" @@ -394,12 +385,10 @@ public class CCIndentUnitTestCase extend + "else\n" + " |\n" ); - } finally{ - setDefaultsOptions(); - } } public void testEnterAfterIfElseStmt() { + setDefaultsOptions(); setLoadDocumentText( "if (true)\n" + " stmt;\n" @@ -417,6 +406,7 @@ public class CCIndentUnitTestCase extend } public void testEnterAfterIfMultiLine() { + setDefaultsOptions(); setLoadDocumentText( "if (1 < 5|\n" ); @@ -428,6 +418,7 @@ public class CCIndentUnitTestCase extend } public void testEnterAfterIfMultiLine2() { + setDefaultsOptions(); setLoadDocumentText( "if (1 < 5|)\n" ); @@ -443,6 +434,7 @@ public class CCIndentUnitTestCase extend * @see http://www.netbeans.org/issues/show_bug.cgi?id=91561 */ public void testIdentUnbalancedBraces() { + setDefaultsOptions(); setLoadDocumentText( "void foo() {\n" + "#if A\n" + @@ -470,6 +462,7 @@ public class CCIndentUnitTestCase extend * @see http://www.netbeans.org/issues/show_bug.cgi?id=91561 */ public void testIdentUnbalancedBraces2() { + setDefaultsOptions(); setLoadDocumentText( "void foo() {\n" + "#if A\n" + @@ -522,6 +515,7 @@ public class CCIndentUnitTestCase extend public void testIdentMain() { setCppEditorKit(false); + setDefaultsOptions(); setLoadDocumentText( "int main() {|\n"); indentNewLine(); @@ -531,45 +525,39 @@ public class CCIndentUnitTestCase extend } public void testIdentMainHalf() { + setCppEditorKit(false); + setDefaultsOptions(); EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.C)). put(EditorOptions.newLineBeforeBraceDeclaration, CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name()); - try { - setCppEditorKit(false); setLoadDocumentText( "int main() {|\n"); indentNewLine(); assertDocumentText("Incorrect identing of main", "int main() {\n" + " \n"); - } finally{ - setDefaultsOptions(); - } } public void testIdentMainHalf2() { + setCppEditorKit(false); + setDefaultsOptions(); EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.C)). put(EditorOptions.newLineBeforeBraceDeclaration, CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name()); - try { - setCppEditorKit(false); setLoadDocumentText( "int main()|\n"); indentNewLine(); assertDocumentText("Incorrect identing of main", "int main()\n" + "\n"); - } finally{ - setDefaultsOptions(); - } } public void testIdentMainHalf3() { + setCppEditorKit(false); + setDefaultsOptions(); EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.C)). put(EditorOptions.newLineBeforeBraceDeclaration, CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name()); - try { - setCppEditorKit(false); setLoadDocumentText( "int main()\n"+ "{|\n"); @@ -578,12 +566,10 @@ public class CCIndentUnitTestCase extend "int main()\n" + "{\n" + " \n"); - } finally{ - setDefaultsOptions(); - } } public void testIZ101099() { + setDefaultsOptions(); setLoadDocumentText( "template |\n" ); @@ -595,6 +581,7 @@ public class CCIndentUnitTestCase extend } public void testIZ122489() { + setDefaultsOptions(); setLoadDocumentText( "Cpu::Cpu(int units) :\n"+ " Module(units) {\n"+ @@ -614,6 +601,7 @@ public class CCIndentUnitTestCase extend */ public void testIdentMethodParameters() { setCppEditorKit(false); + setDefaultsOptions(); setLoadDocumentText( "int longmain(int a,|\n"); indentNewLine(); @@ -626,20 +614,16 @@ public class CCIndentUnitTestCase extend * test parameter aligning */ public void testIdentMethodParameters2() { + setCppEditorKit(false); + setDefaultsOptions(); EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.C)). putBoolean(EditorOptions.alignMultilineMethodParams, true); - try { - setCppEditorKit(false); - setLoadDocumentText( - "int longmain(int a,|\n"); - indentNewLine(); - assertDocumentText("Incorrect identing of main", - "int longmain(int a,\n" + - " \n"); - } finally{ - EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.C)). - putBoolean(EditorOptions.alignMultilineMethodParams, false); - } + setLoadDocumentText( + "int longmain(int a,|\n"); + indentNewLine(); + assertDocumentText("Incorrect identing of main", + "int longmain(int a,\n" + + " \n"); } /** @@ -647,6 +631,7 @@ public class CCIndentUnitTestCase extend */ public void testIdentCallParameters() { setCppEditorKit(false); + setDefaultsOptions(); setLoadDocumentText( "a = longmain(a,|\n"); indentNewLine(); @@ -659,18 +644,108 @@ public class CCIndentUnitTestCase extend * test parameter aligning */ public void testIdentCallParameters2() { + setDefaultsOptions(); EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)). putBoolean(EditorOptions.alignMultilineCallArgs, true); - try { - setLoadDocumentText( - "a = longmain(a,|\n"); - indentNewLine(); - assertDocumentText("Incorrect identing of main", - "a = longmain(a,\n" + - " \n"); - } finally{ - EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)). - putBoolean(EditorOptions.alignMultilineCallArgs, false); - } + setLoadDocumentText( + "a = longmain(a,|\n"); + indentNewLine(); + assertDocumentText("Incorrect identing of main", + "a = longmain(a,\n" + + " \n"); + } + + public void testIdentNewLineLocalDeclararion() throws Exception { + setDefaultsOptions("GNU"); + setLoadDocumentText( + "tree\n" + + "disp(int i){\n" + + " int i = |\n" + + "}" + ); + indentNewLine(); + assertDocumentTextAndCaret("Incorrect identing of New Line Local Declararion", + "tree\n" + + "disp(int i){\n" + + " int i = \n" + + " |\n" + + "}" + ); + } + + public void testIdentNewLineLocalStatement() throws Exception { + setDefaultsOptions("GNU"); + setLoadDocumentText( + "tree\n" + + "disp(int i){\n" + + " i = |\n" + + "}" + ); + indentNewLine(); + assertDocumentTextAndCaret("Incorrect identing of New Line Local Statement", + "tree\n" + + "disp(int i){\n" + + " i = \n" + + " |\n" + + "}" + ); + } + + public void testIdentNewLineLocalStatement2() throws Exception { + setDefaultsOptions("GNU"); + setLoadDocumentText( + "tree\n" + + "disp(int i){\n" + + " i = f(i,|)\n" + + "}" + ); + indentNewLine(); + assertDocumentTextAndCaret("Incorrect identing of New Line Local Statement", + "tree\n" + + "disp(int i){\n" + + " i = f(i,\n" + + " |)\n" + + "}" + ); + } + + public void testIdentNewLineLocalStatement3() throws Exception { + setDefaultsOptions("GNU"); + setLoadDocumentText( + "tree\n" + + "disp(int i){\n" + + " i = f(i,\n" + + " i+|)\n" + + "}" + ); + indentNewLine(); + assertDocumentTextAndCaret("Incorrect identing of New Line Local Statement", + "tree\n" + + "disp(int i){\n" + + " i = f(i,\n" + + " i+\n" + + " |)\n" + + "}" + ); + } + + public void testIdentNewLineLocalStatement4() throws Exception { + setDefaultsOptions("GNU"); + setLoadDocumentText( + "tree\n" + + "disp(int i){\n" + + " i = f(i,\n" + + " i+foo(a,|))\n" + + "}" + ); + indentNewLine(); + assertDocumentTextAndCaret("Incorrect identing of New Line Local Statement", + "tree\n" + + "disp(int i){\n" + + " i = f(i,\n" + + " i+foo(a,\n" + + " |))\n" + + "}" + ); } } diff -r b56a5f977f1a -r 1b230feca924 cnd.editor/test/unit/src/org/netbeans/modules/cnd/editor/cplusplus/CCIndentUnitTestCaseSingleTestCase.java --- a/cnd.editor/test/unit/src/org/netbeans/modules/cnd/editor/cplusplus/CCIndentUnitTestCaseSingleTestCase.java Mon Mar 31 09:09:48 2008 +0200 +++ b/cnd.editor/test/unit/src/org/netbeans/modules/cnd/editor/cplusplus/CCIndentUnitTestCaseSingleTestCase.java Mon Mar 31 18:06:42 2008 +0400 @@ -44,56 +44,4 @@ public class CCIndentUnitTestCaseSingleT super(testMethodName); } - public void testEnterAfterIfBraceHalf() { - EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)). - put(EditorOptions.newLineBeforeBrace, - CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name()); - try { - setLoadDocumentText( - "if (true)\n" + - " {|\n" + - " }\n" - ); - indentNewLine(); - assertDocumentTextAndCaret("Incorrect new-line indent", - "if (true)\n" + - " {\n" + - " |\n" + - " }\n" - ); - } finally{ - setDefaultsOptions(); - } - } - - public void testEnterAfterIfBraceHalf2() { - EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)). - put(EditorOptions.newLineBeforeBraceDeclaration, - CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name()); - EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)). - put(EditorOptions.newLineBeforeBrace, - CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name()); - try { - setLoadDocumentText( - "int foo()\n" + - "{\n" + - " if (true)\n" + - " {|\n" + - " }\n" + - "}\n" - ); - indentNewLine(); - assertDocumentTextAndCaret("Incorrect new-line indent", - "int foo()\n" + - "{\n" + - " if (true)\n" + - " {\n" + - " |\n" + - " }\n" + - "}\n" - ); - } finally{ - setDefaultsOptions(); - } - } } diff -r b56a5f977f1a -r 1b230feca924 cnd.editor/test/unit/src/org/netbeans/modules/cnd/editor/cplusplus/CCNewFormatterUnitTestCase.java --- a/cnd.editor/test/unit/src/org/netbeans/modules/cnd/editor/cplusplus/CCNewFormatterUnitTestCase.java Mon Mar 31 09:09:48 2008 +0200 +++ b/cnd.editor/test/unit/src/org/netbeans/modules/cnd/editor/cplusplus/CCNewFormatterUnitTestCase.java Mon Mar 31 18:06:42 2008 +0400 @@ -4177,6 +4177,44 @@ public class CCNewFormatterUnitTestCase ", env_ (env) { }\n" ); } + + public void testGnuStuleNewLineName5() { + setDefaultsOptions("GNU"); + setLoadDocumentText( + "tree decl_shadowed_for_var_lookup (tree from)\n" + + "{\n" + + " return NULL_TREE;\n" + + "}\n" + ); + reformat(); + assertDocumentText("Incorrect formatting GNU new line name", + "tree\n" + + "decl_shadowed_for_var_lookup (tree from)\n" + + "{\n" + + " return NULL_TREE;\n" + + "}\n" + ); + } + + public void testGnuStuleNewLineName6() { + setDefaultsOptions("GNU"); + setLoadDocumentText( + "B::tree A::\n" + + "decl_shadowed_for_var_lookup (tree from)\n" + + "{\n" + + " return NULL_TREE;\n" + + "}\n" + ); + reformat(); + assertDocumentText("Incorrect formatting GNU new line name", + "B::tree\n" + + "A::decl_shadowed_for_var_lookup (tree from)\n" + + "{\n" + + " return NULL_TREE;\n" + + "}\n" + ); + } + //IZ#131158:"Spaces Within Parenthesis|Braces" checkbox works wrongly public void testSpaceWithinBraces() { setDefaultsOptions();