From 8b262a1f4d8701948903bc780ba9635c99aea11d Mon Sep 17 00:00:00 2001 From: Anton Leherbauer Date: Mon, 26 Apr 2010 12:16:32 +0000 Subject: [PATCH] Bug 309099 - BadLocationException thrown during code type in a cpp file --- .../eclipse/cdt/ui/tests/text/BracketInserterTest.java | 10 ++++++++++ .../org/eclipse/cdt/internal/ui/editor/CEditor.java | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/BracketInserterTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/BracketInserterTest.java index 1bba6821a4d..54f11358671 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/BracketInserterTest.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/BracketInserterTest.java @@ -376,6 +376,16 @@ public class BracketInserterTest extends TestCase { assertSingleLinkedPosition(INCLUDE_OFFSET + 1); } + public void testInsertClosingQuoteInIncludeAtDocumentEnd_Bug309099() throws Exception { + int startOffset = TU_CONTENTS.length(); + setCaret(startOffset); + type("#include "); + type('"'); + assertEquals(startOffset + 11, fDocument.getLength()); + assertEquals("#include \"\"", fDocument.get(startOffset, 11)); + assertSingleLinkedPosition(startOffset + 10); + } + public void testAngleBrackets_165837() throws Exception { setCaret(BODY_OFFSET); type("cout << \n\"aaa\" "); diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CEditor.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CEditor.java index e3c05d5cc43..c2adf580ac6 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CEditor.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CEditor.java @@ -715,7 +715,7 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IC } private boolean isInsideStringInPreprocessorDirective(ITypedRegion partition, IDocument document, int offset) throws BadLocationException { - if (ICPartitions.C_PREPROCESSOR.equals(partition.getType())) { + if (ICPartitions.C_PREPROCESSOR.equals(partition.getType()) && offset < document.getLength()) { // use temporary document to test whether offset is inside non-default partition String directive = document.get(partition.getOffset(), offset - partition.getOffset() + 1); int hashIdx = directive.indexOf('#');