From b7df295fedfe94a79906fd9fa1be45c7575da052 Mon Sep 17 00:00:00 2001 From: Anton Leherbauer Date: Mon, 27 Nov 2006 08:56:34 +0000 Subject: [PATCH] Fix for 165837 - Inappropriate auto closing of angle brackets (Patch by Sergey Prigogin) --- .../ui/tests/text/BracketInserterTest.java | 9 +++ .../cdt/internal/ui/editor/CEditor.java | 58 ++++++++++--------- 2 files changed, 40 insertions(+), 27 deletions(-) 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 0085e359ff4..267c7863d15 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 @@ -336,6 +336,15 @@ public class BracketInserterTest extends TestCase { assertSingleLinkedPosition(INCLUDE_OFFSET + 1); } + public void testAngleBrackets_165837() throws Exception { + setCaret(BODY_OFFSET); + type("cout << \n\"aaa\" "); + type('<'); + int caretOffset= getCaret(); + assertFalse(">".equals(fDocument.get(caretOffset, 1))); + assertFalse(LinkedModeModel.hasInstalledModel(fDocument)); + } + /* utilities */ private void assertSingleLinkedPosition(int offset) { 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 c6abf80a866..e71f7132097 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 @@ -17,9 +17,11 @@ package org.eclipse.cdt.internal.ui.editor; import java.text.CharacterIterator; import java.util.HashMap; +import java.util.HashSet; import java.util.Iterator; import java.util.Map; import java.util.ResourceBundle; +import java.util.Set; import java.util.Stack; import org.eclipse.core.resources.IFile; @@ -560,21 +562,8 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IR private boolean isAngularIntroducer(String identifier) { return identifier.length() > 0 && (Character.isUpperCase(identifier.charAt(0)) - || identifier.equals("template") //$NON-NLS-1$ - || identifier.equals("vector") //$NON-NLS-1$ - || identifier.equals("list") //$NON-NLS-1$ - || identifier.equals("slist") //$NON-NLS-1$ - || identifier.equals("map") //$NON-NLS-1$ - || identifier.equals("set") //$NON-NLS-1$ - || identifier.equals("multimap") //$NON-NLS-1$ - || identifier.equals("multiset") //$NON-NLS-1$ - || identifier.equals("hash_map") //$NON-NLS-1$ - || identifier.equals("hash_set") //$NON-NLS-1$ - || identifier.equals("hash_multimap") //$NON-NLS-1$ - || identifier.equals("hash_multiset") //$NON-NLS-1$ - || identifier.equals("pair") //$NON-NLS-1$ - || identifier.endsWith("_ptr") //$NON-NLS-1$ - || identifier.endsWith("include")); //$NON-NLS-1$ + || angularIntroducers.contains(identifier) + || identifier.endsWith("_ptr")); //$NON-NLS-1$ } /* @@ -607,7 +596,13 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IR IRegion startLine = document.getLineInformationOfOffset(offset); IRegion endLine = document.getLineInformationOfOffset(offset + length); - CHeuristicScanner scanner = new CHeuristicScanner(document); + ITypedRegion partition = TextUtilities.getPartition(document, ICPartitions.C_PARTITIONING, offset, true); + if (!IDocument.DEFAULT_CONTENT_TYPE.equals(partition.getType()) + && !ICPartitions.C_PREPROCESSOR.equals(partition.getType())) { + return; + } + + CHeuristicScanner scanner = new CHeuristicScanner(document, ICPartitions.C_PARTITIONING, partition.getType()); int nextToken = scanner.nextToken(offset + length, endLine.getOffset() + endLine.getLength()); String next = nextToken == Symbols.TokenEOF ? null : document.get(offset, scanner.getPosition() - offset).trim(); int prevToken = scanner.previousToken(offset - 1, startLine.getOffset()); @@ -626,12 +621,7 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IR case '<': if (!(fCloseAngularBrackets && fCloseBrackets) || nextToken == Symbols.TokenLESSTHAN - || prevToken != Symbols.TokenLBRACE - && prevToken != Symbols.TokenRBRACE - && prevToken != Symbols.TokenSEMICOLON - && prevToken != Symbols.TokenSTATIC - && (prevToken != Symbols.TokenIDENT || !isAngularIntroducer(previous)) - && prevToken != Symbols.TokenEOF) + || prevToken != Symbols.TokenIDENT || !isAngularIntroducer(previous)) return; break; @@ -657,11 +647,6 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IR return; } - ITypedRegion partition = TextUtilities.getPartition(document, ICPartitions.C_PARTITIONING, offset, true); - if (!IDocument.DEFAULT_CONTENT_TYPE.equals(partition.getType()) - && !ICPartitions.C_PREPROCESSOR.equals(partition.getType())) - return; - if (!validateEditorInputState()) return; @@ -1555,6 +1540,25 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IR */ private SemanticHighlightingManager fSemanticManager; + private static final Set angularIntroducers = new HashSet(); + static { + angularIntroducers.add("template"); //$NON-NLS-1$ + angularIntroducers.add("vector"); //$NON-NLS-1$ + angularIntroducers.add("deque"); //$NON-NLS-1$ + angularIntroducers.add("list"); //$NON-NLS-1$ + angularIntroducers.add("slist"); //$NON-NLS-1$ + angularIntroducers.add("map"); //$NON-NLS-1$ + angularIntroducers.add("set"); //$NON-NLS-1$ + angularIntroducers.add("multimap"); //$NON-NLS-1$ + angularIntroducers.add("multiset"); //$NON-NLS-1$ + angularIntroducers.add("hash_map"); //$NON-NLS-1$ + angularIntroducers.add("hash_set"); //$NON-NLS-1$ + angularIntroducers.add("hash_multimap"); //$NON-NLS-1$ + angularIntroducers.add("hash_multiset"); //$NON-NLS-1$ + angularIntroducers.add("pair"); //$NON-NLS-1$ + angularIntroducers.add("include"); //$NON-NLS-1$ + } + /** * Default constructor.