From ec61bd4736e25e8f9deaf99e369575fa59b8d894 Mon Sep 17 00:00:00 2001 From: Mikhail Golubev Date: Mon, 27 Apr 2015 18:56:41 +0300 Subject: [PATCH] PY-12360 Fix test data in remaining tests, commit document after modification --- ...TrailingBlankLinesPostFormatProcessor.java | 25 +++++++++++-------- .../hangingIndentInKeyValuePair_after.py | 2 +- .../methodCallInlinedAsQualifier.after.py | 2 +- .../refactoring/inlinelocal/multiple.after.py | 2 +- .../refactoring/inlinelocal/priority.after.py | 2 +- .../refactoring/inlinelocal/py5832.after.py | 2 +- .../refactoring/inlinelocal/py994.after.py | 2 +- .../referenceInParenthesis.after.py | 2 +- .../resultExceedsRightMargin.after.py | 2 +- .../refactoring/inlinelocal/simple.after.py | 2 +- 10 files changed, 24 insertions(+), 19 deletions(-) diff --git a/python/src/com/jetbrains/python/formatter/PyTrailingBlankLinesPostFormatProcessor.java b/python/src/com/jetbrains/python/formatter/PyTrailingBlankLinesPostFormatProcessor.java index aad5b31e68cf..362d01ac8565 100644 --- a/python/src/com/jetbrains/python/formatter/PyTrailingBlankLinesPostFormatProcessor.java +++ b/python/src/com/jetbrains/python/formatter/PyTrailingBlankLinesPostFormatProcessor.java @@ -64,7 +64,7 @@ public class PyTrailingBlankLinesPostFormatProcessor implements PostFormatProces if (rangeToReformat.intersects(oldWhitespaceRange)) { final TextRange newWhitespaceRange = replaceOrDeleteTrailingWhitespaces((PyFile)source, oldWhitespaceRange); final int delta = newWhitespaceRange.getLength() - oldWhitespaceRange.getLength(); - if (newWhitespaceRange.contains(oldWhitespaceRange)) { + if (oldWhitespaceRange.contains(rangeToReformat)) { return newWhitespaceRange; } else if (rangeToReformat.contains(oldWhitespaceRange)) { @@ -109,19 +109,24 @@ public class PyTrailingBlankLinesPostFormatProcessor implements PostFormatProces numLineFeeds = 1; } documentManager.doPostponedOperationsAndUnblockDocument(document); - final String text = StringUtil.repeat("\n", numLineFeeds); - if (numLineFeeds > 0 && whitespaceRange.getStartOffset() != 0) { - if (!whitespaceRange.isEmpty()) { - document.replaceString(whitespaceRange.getStartOffset(), whitespaceRange.getEndOffset(), text); + try { + final String text = StringUtil.repeat("\n", numLineFeeds); + if (numLineFeeds > 0 && whitespaceRange.getStartOffset() != 0) { + if (!whitespaceRange.isEmpty()) { + document.replaceString(whitespaceRange.getStartOffset(), whitespaceRange.getEndOffset(), text); + } + else { + document.insertString(document.getTextLength(), text); + } } - else { - document.insertString(document.getTextLength(), text); + else if (!whitespaceRange.isEmpty()) { + document.deleteString(whitespaceRange.getStartOffset(), whitespaceRange.getEndOffset()); } + return TextRange.from(whitespaceRange.getStartOffset(), text.length()); } - else if (!whitespaceRange.isEmpty()) { - document.deleteString(whitespaceRange.getStartOffset(), whitespaceRange.getEndOffset()); + finally { + documentManager.commitDocument(document); } - return TextRange.from(whitespaceRange.getStartOffset(), text.length()); } return whitespaceRange; } diff --git a/python/testData/formatter/hangingIndentInKeyValuePair_after.py b/python/testData/formatter/hangingIndentInKeyValuePair_after.py index 057ebe6a340d..d545b722f23d 100644 --- a/python/testData/formatter/hangingIndentInKeyValuePair_after.py +++ b/python/testData/formatter/hangingIndentInKeyValuePair_after.py @@ -2,4 +2,4 @@ example = {'breakfast': { 'eggs': 1, 'spam': 2 } -} \ No newline at end of file +} diff --git a/python/testData/refactoring/inlinelocal/methodCallInlinedAsQualifier.after.py b/python/testData/refactoring/inlinelocal/methodCallInlinedAsQualifier.after.py index 1a3f524e748a..1da5c834763a 100644 --- a/python/testData/refactoring/inlinelocal/methodCallInlinedAsQualifier.after.py +++ b/python/testData/refactoring/inlinelocal/methodCallInlinedAsQualifier.after.py @@ -1 +1 @@ -a.method().strip() \ No newline at end of file +a.method().strip() diff --git a/python/testData/refactoring/inlinelocal/multiple.after.py b/python/testData/refactoring/inlinelocal/multiple.after.py index 72cca7219274..8fc65c63ccc4 100644 --- a/python/testData/refactoring/inlinelocal/multiple.after.py +++ b/python/testData/refactoring/inlinelocal/multiple.after.py @@ -22,4 +22,4 @@ voo = 10 + 10 woo = 10 + 10 xoo = 10 + 10 yoo = 10 + 10 -zoo = 10 + 10 \ No newline at end of file +zoo = 10 + 10 diff --git a/python/testData/refactoring/inlinelocal/priority.after.py b/python/testData/refactoring/inlinelocal/priority.after.py index 02364b4122e5..665b7d377859 100644 --- a/python/testData/refactoring/inlinelocal/priority.after.py +++ b/python/testData/refactoring/inlinelocal/priority.after.py @@ -1 +1 @@ -boo = (100 + 100) * 100 \ No newline at end of file +boo = (100 + 100) * 100 diff --git a/python/testData/refactoring/inlinelocal/py5832.after.py b/python/testData/refactoring/inlinelocal/py5832.after.py index bde7ba338a65..c5dfc43efcbc 100644 --- a/python/testData/refactoring/inlinelocal/py5832.after.py +++ b/python/testData/refactoring/inlinelocal/py5832.after.py @@ -2,4 +2,4 @@ def foo(arg): print arg -foo(('a', 'b')) \ No newline at end of file +foo(('a', 'b')) diff --git a/python/testData/refactoring/inlinelocal/py994.after.py b/python/testData/refactoring/inlinelocal/py994.after.py index 393bb3e15efa..8959e543935e 100644 --- a/python/testData/refactoring/inlinelocal/py994.after.py +++ b/python/testData/refactoring/inlinelocal/py994.after.py @@ -1,3 +1,3 @@ class C: def foo(self): - return Conference() \ No newline at end of file + return Conference() diff --git a/python/testData/refactoring/inlinelocal/referenceInParenthesis.after.py b/python/testData/refactoring/inlinelocal/referenceInParenthesis.after.py index 67bea27b020e..97c9be0eaa42 100644 --- a/python/testData/refactoring/inlinelocal/referenceInParenthesis.after.py +++ b/python/testData/refactoring/inlinelocal/referenceInParenthesis.after.py @@ -1,3 +1,3 @@ print ('spam!' * 42) ('spam!' * 42) -hex('spam!' * 42) \ No newline at end of file +hex('spam!' * 42) diff --git a/python/testData/refactoring/inlinelocal/resultExceedsRightMargin.after.py b/python/testData/refactoring/inlinelocal/resultExceedsRightMargin.after.py index acc61d6ec5ae..7d9a415403d1 100644 --- a/python/testData/refactoring/inlinelocal/resultExceedsRightMargin.after.py +++ b/python/testData/refactoring/inlinelocal/resultExceedsRightMargin.after.py @@ -1,3 +1,3 @@ result = '123456789|123456789|123456789|123456789|123456789|' + \ '123456789|123456789|123456789|123456789|123456789|' + \ - '123456789|123456789|123456789|123456789|123456789|' \ No newline at end of file + '123456789|123456789|123456789|123456789|123456789|' diff --git a/python/testData/refactoring/inlinelocal/simple.after.py b/python/testData/refactoring/inlinelocal/simple.after.py index 51da5a308ef9..f40a7880c65c 100644 --- a/python/testData/refactoring/inlinelocal/simple.after.py +++ b/python/testData/refactoring/inlinelocal/simple.after.py @@ -1 +1 @@ -boo = 10 \ No newline at end of file +boo = 10