Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnton Leherbauer2008-09-05 06:21:47 -0400
committerAnton Leherbauer2008-09-05 06:21:47 -0400
commite1c3412afaf847cad9134b809f9bc5c160d94422 (patch)
tree1a84e1928e41dbe868411a223ed049b5b33defd5
parent54e73948e3071ffc9942fe0fa2f92a71efe4806c (diff)
downloadorg.eclipse.cdt-e1c3412afaf847cad9134b809f9bc5c160d94422.tar.gz
org.eclipse.cdt-e1c3412afaf847cad9134b809f9bc5c160d94422.tar.xz
org.eclipse.cdt-e1c3412afaf847cad9134b809f9bc5c160d94422.zip
Bug 244050 - AssertionFailedException in QuickDiff prevents savev200809050802
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CDocumentProvider.java122
1 files changed, 66 insertions, 56 deletions
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CDocumentProvider.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CDocumentProvider.java
index 61bd37a262..682f0780ea 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CDocumentProvider.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CDocumentProvider.java
@@ -934,62 +934,11 @@ public class CDocumentProvider extends TextFileDocumentProvider {
*/
@Override
protected DocumentProviderOperation createSaveOperation(final Object element, final IDocument document, final boolean overwrite) throws CoreException {
- //add a newline to the end of the document (if it is not already present)
- //-----------------------------------------------------------------------
- //for people who do not want auto-modification of their files,
- //this flag will prevent addition of a newline unless the user
- //explicitly sets the preference thru Window -> Preferences -> C/C++ -> Editor
- // -> Appearance Tab -> Ensure newline end of file when saving
- if (PreferenceConstants.getPreferenceStore().getBoolean(
- PreferenceConstants.ENSURE_NEWLINE_AT_EOF)) {
- // even if the document is empty, there will be at least one line in
- // it (the 0th one)
- int lastLineIndex = document.getNumberOfLines() - 1;
-
- try {
- // we have to ensure that the length of the last line is 0.
- // this will also take care of empty files. empty files have
- // only one line in them and the length of this one and only
- // line is 0.
- // Thus we do not need to append an extra line separator to
- // empty files.
- int lastLineLength = document.getLineLength(lastLineIndex);
- if (lastLineLength != 0) {
- document.replace(document.getLength(), 0,
- TextUtilities.getDefaultLineDelimiter(document));
- }
- } catch (BadLocationException e) {
- }
- }
-
- // Remove trailing whitespace when saving. Triggered by the flag
- // in Preferences -> C/C++ -> Editor
- if (PreferenceConstants.getPreferenceStore().getBoolean(
- PreferenceConstants.REMOVE_TRAILING_WHITESPACE)) {
- try {
- int lineCount= document.getNumberOfLines();
- for (int i= 0; i < lineCount; i++) {
-
- IRegion region= document.getLineInformation(i);
- if (region.getLength() == 0)
- continue;
-
- int lineStart= region.getOffset();
- int lineExclusiveEnd= lineStart + region.getLength();
-
- // Find the rightmost none-whitespace character
- int charPos= lineExclusiveEnd - 1;
- while (charPos >= lineStart && Character.isWhitespace(document.getChar(charPos)))
- charPos--;
-
- charPos++;
- if (charPos < lineExclusiveEnd) {
- DeleteEdit edit= new DeleteEdit(charPos, lineExclusiveEnd - charPos);
- edit.apply(document);
- }
- }
- } catch (BadLocationException e) {
- }
+ try {
+ performSaveActions(document);
+ } catch (Exception exc) {
+ // log any exeption, but perform save anyway
+ CUIPlugin.log(exc);
}
final FileInfo info= getFileInfo(element);
@@ -1022,6 +971,67 @@ public class CDocumentProvider extends TextFileDocumentProvider {
}
/**
+ * Perform configured document manipulations before save.
+ *
+ * @param document
+ * @throws BadLocationException
+ */
+ private void performSaveActions(final IDocument document) throws BadLocationException {
+ //add a newline to the end of the document (if it is not already present)
+ //-----------------------------------------------------------------------
+ //for people who do not want auto-modification of their files,
+ //this flag will prevent addition of a newline unless the user
+ //explicitly sets the preference thru Window -> Preferences -> C/C++ -> Editor
+ // -> Appearance Tab -> Ensure newline end of file when saving
+ if (PreferenceConstants.getPreferenceStore().getBoolean(
+ PreferenceConstants.ENSURE_NEWLINE_AT_EOF)) {
+ // even if the document is empty, there will be at least one line in
+ // it (the 0th one)
+ int lastLineIndex = document.getNumberOfLines() - 1;
+
+ // we have to ensure that the length of the last line is 0.
+ // this will also take care of empty files. empty files have
+ // only one line in them and the length of this one and only
+ // line is 0.
+ // Thus we do not need to append an extra line separator to
+ // empty files.
+ int lastLineLength = document.getLineLength(lastLineIndex);
+ if (lastLineLength != 0) {
+ document.replace(document.getLength(), 0,
+ TextUtilities.getDefaultLineDelimiter(document));
+ }
+ }
+
+ // Remove trailing whitespace when saving. Triggered by the flag
+ // in Preferences -> C/C++ -> Editor
+ if (PreferenceConstants.getPreferenceStore().getBoolean(
+ PreferenceConstants.REMOVE_TRAILING_WHITESPACE)) {
+
+ int lineCount= document.getNumberOfLines();
+ for (int i= 0; i < lineCount; i++) {
+
+ IRegion region= document.getLineInformation(i);
+ if (region.getLength() == 0)
+ continue;
+
+ int lineStart= region.getOffset();
+ int lineExclusiveEnd= lineStart + region.getLength();
+
+ // Find the rightmost none-whitespace character
+ int charPos= lineExclusiveEnd - 1;
+ while (charPos >= lineStart && Character.isWhitespace(document.getChar(charPos)))
+ charPos--;
+
+ charPos++;
+ if (charPos < lineExclusiveEnd) {
+ DeleteEdit edit= new DeleteEdit(charPos, lineExclusiveEnd - charPos);
+ edit.apply(document);
+ }
+ }
+ }
+ }
+
+ /**
* Returns the preference whether handling temporary problems is enabled.
*/
protected boolean isHandlingTemporaryProblems() {

Back to the top