Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnton Leherbauer2007-10-16 11:38:54 +0000
committerAnton Leherbauer2007-10-16 11:38:54 +0000
commitf9d0d47ba365cd97bfe0bdcd0810c464672000f9 (patch)
tree6983bf2ad3b28529628c345bb8d46d7b5f270864
parentf7f62c4ee474b0b6e65310d5b6bbe6f4e06987cd (diff)
downloadorg.eclipse.cdt-f9d0d47ba365cd97bfe0bdcd0810c464672000f9.tar.gz
org.eclipse.cdt-f9d0d47ba365cd97bfe0bdcd0810c464672000f9.tar.xz
org.eclipse.cdt-f9d0d47ba365cd97bfe0bdcd0810c464672000f9.zip
Fix for 205984: Comment Code templates do not work
-rw-r--r--core/org.eclipse.cdt.ui/plugin.xml21
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/CTextTools.java3
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/FastCPartitioner.java53
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/TemplateCompletionProposalComputer.java2
4 files changed, 61 insertions, 18 deletions
diff --git a/core/org.eclipse.cdt.ui/plugin.xml b/core/org.eclipse.cdt.ui/plugin.xml
index 2cf064725bd..46b65d15af3 100644
--- a/core/org.eclipse.cdt.ui/plugin.xml
+++ b/core/org.eclipse.cdt.ui/plugin.xml
@@ -1833,12 +1833,8 @@
<completionProposalComputer
categoryId="org.eclipse.cdt.ui.parserProposalCategory"
class="org.eclipse.cdt.internal.ui.text.contentassist.DOMCompletionProposalComputer">
- <partition
- type="__dftl_partition_content_type">
- </partition>
- <partition
- type="__c_preprocessor">
- </partition>
+ <partition type="__dftl_partition_content_type"/>
+ <partition type="__c_preprocessor"/>
</completionProposalComputer>
</extension>
@@ -1859,12 +1855,8 @@
<completionProposalComputer
categoryId="org.eclipse.cdt.ui.parserProposalCategory"
class="org.eclipse.cdt.internal.ui.text.contentassist.KeywordCompletionProposalComputer">
- <partition
- type="__dftl_partition_content_type">
- </partition>
- <partition
- type="__c_preprocessor">
- </partition>
+ <partition type="__dftl_partition_content_type"/>
+ <partition type="__c_preprocessor"/>
</completionProposalComputer>
</extension>
<extension
@@ -1873,9 +1865,7 @@
<completionProposalComputer
categoryId="org.eclipse.cdt.ui.parserProposalCategory"
class="org.eclipse.cdt.internal.ui.text.contentassist.HelpCompletionProposalComputer">
- <partition
- type="__dftl_partition_content_type">
- </partition>
+ <partition type="__dftl_partition_content_type"/>
</completionProposalComputer>
</extension>
<!-- template proposals -->
@@ -1887,6 +1877,7 @@
categoryId="org.eclipse.cdt.ui.templateProposalCategory">
<partition type="__dftl_partition_content_type"/>
<partition type="__c_multiline_comment"/>
+ <partition type="__c_singleline_comment"/>
</completionProposalComputer>
</extension>
<!-- hippie word completions -->
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/CTextTools.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/CTextTools.java
index 0ee1700ed70..d41a3051b04 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/CTextTools.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/CTextTools.java
@@ -17,7 +17,6 @@ import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IDocumentExtension3;
import org.eclipse.jface.text.IDocumentPartitioner;
-import org.eclipse.jface.text.rules.FastPartitioner;
import org.eclipse.jface.text.rules.IPartitionTokenScanner;
import org.eclipse.jface.text.rules.RuleBasedScanner;
import org.eclipse.jface.util.IPropertyChangeListener;
@@ -203,7 +202,7 @@ public class CTextTools {
ICPartitions.C_PREPROCESSOR
};
- return new FastPartitioner(getPartitionScanner(), types);
+ return new FastCPartitioner(getPartitionScanner(), types);
}
/**
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/FastCPartitioner.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/FastCPartitioner.java
new file mode 100644
index 00000000000..8439d665db3
--- /dev/null
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/FastCPartitioner.java
@@ -0,0 +1,53 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Wind River Systems, Inc. and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Anton Leherbauer (Wind River Systems) - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.internal.ui.text;
+
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.ITypedRegion;
+import org.eclipse.jface.text.rules.FastPartitioner;
+import org.eclipse.jface.text.rules.IPartitionTokenScanner;
+
+import org.eclipse.cdt.ui.text.ICPartitions;
+
+/**
+ * A slightly adapted FastPartitioner.
+ */
+public class FastCPartitioner extends FastPartitioner {
+
+ /**
+ * Creates a new partitioner for the given content types.
+ *
+ * @param scanner
+ * @param legalContentTypes
+ */
+ public FastCPartitioner(IPartitionTokenScanner scanner, String[] legalContentTypes) {
+ super(scanner, legalContentTypes);
+ }
+
+ public ITypedRegion getPartition(int offset, boolean preferOpenPartitions) {
+ if (preferOpenPartitions && offset == fDocument.getLength() && offset > 0) {
+ ITypedRegion region = super.getPartition(offset - 1, false);
+ try {
+ if (ICPartitions.C_MULTI_LINE_COMMENT.equals(region.getType())) {
+ if (!fDocument.get(offset - 2, 2).equals("*/")) { //$NON-NLS-1$
+ return region;
+ }
+ } else if (ICPartitions.C_SINGLE_LINE_COMMENT.equals(region .getType())) {
+ if (fDocument.getChar(offset - 1) != '\n') {
+ return region;
+ }
+ }
+ } catch (BadLocationException exc) {
+ }
+ }
+ return super.getPartition(offset, preferOpenPartitions);
+ }
+}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/TemplateCompletionProposalComputer.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/TemplateCompletionProposalComputer.java
index c203cf53ba0..37fa52978d0 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/TemplateCompletionProposalComputer.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/TemplateCompletionProposalComputer.java
@@ -75,7 +75,7 @@ public class TemplateCompletionProposalComputer implements ICompletionProposalCo
TemplateEngine engine= null;
try {
String partition= TextUtilities.getContentType(viewer.getDocument(), ICPartitions.C_PARTITIONING, offset, true);
- if (partition.equals(ICPartitions.C_MULTI_LINE_COMMENT)) {
+ if (partition.equals(ICPartitions.C_MULTI_LINE_COMMENT) || partition.equals(ICPartitions.C_SINGLE_LINE_COMMENT)) {
engine= fCommentTemplateEngine;
} else {
if (isValidContext(context)) {

Back to the top