summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Freidin2012-04-01 18:31:40 (EDT)
committer Sergey Prigogin2012-04-01 18:31:40 (EDT)
commit15c366a8828cb69bd5442dcdd5cdc9fdce08c76c (patch)
treee574d59a07dd83a4ea5eb4524adcffde77cf4196
parent217a28a70682b8822937850652faf2152cebafbc (diff)
downloadorg.eclipse.cdt-15c366a8828cb69bd5442dcdd5cdc9fdce08c76c.zip
org.eclipse.cdt-15c366a8828cb69bd5442dcdd5cdc9fdce08c76c.tar.gz
org.eclipse.cdt-15c366a8828cb69bd5442dcdd5cdc9fdce08c76c.tar.bz2
Bug 373503 - Auto-completion for C/C++ editor templates that start with
# sign doesn't work. Patch by Alex Freidin
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/corext/template/c/CContext.java28
1 files changed, 11 insertions, 17 deletions
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/corext/template/c/CContext.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/corext/template/c/CContext.java
index d33107d..cd75729 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/corext/template/c/CContext.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/corext/template/c/CContext.java
@@ -7,7 +7,7 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
- * QnX Software System
+ * QNX Software Systems
* Anton Leherbauer (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.internal.corext.template.c;
@@ -28,12 +28,10 @@ import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.ui.PreferenceConstants;
-
/**
* A context for C/C++.
*/
-public class CContext extends TranslationUnitContext {
-
+public class CContext extends TranslationUnitContext {
/**
* Creates a C/C++ code template context.
*
@@ -43,8 +41,8 @@ public class CContext extends TranslationUnitContext {
* @param completionLength the length of the context
* @param translationUnit the translation unit represented by the document
*/
- public CContext(TemplateContextType type, IDocument document, int completionOffset, int completionLength,
- ITranslationUnit translationUnit) {
+ public CContext(TemplateContextType type, IDocument document, int completionOffset,
+ int completionLength, ITranslationUnit translationUnit) {
super(type, document, completionOffset, completionLength, translationUnit);
}
@@ -61,9 +59,6 @@ public class CContext extends TranslationUnitContext {
super(type, document, completionPosition, translationUnit);
}
- /*
- * @see DocumentTemplateContext#getStart()
- */
@Override
public int getStart() {
if (fIsManaged && getCompletionLength() > 0)
@@ -75,7 +70,7 @@ public class CContext extends TranslationUnitContext {
int start= getCompletionOffset();
int end= getCompletionOffset() + getCompletionLength();
- while (start != 0 && Character.isUnicodeIdentifierPart(document.getChar(start - 1)))
+ while (start != 0 && isUnicodeIdentifierPartOrPoundSign(document.getChar(start - 1)))
start--;
while (start != end && Character.isWhitespace(document.getChar(start)))
@@ -84,8 +79,7 @@ public class CContext extends TranslationUnitContext {
if (start == end)
start= getCompletionOffset();
- return start;
-
+ return start;
} catch (BadLocationException e) {
return super.getStart();
}
@@ -106,15 +100,11 @@ public class CContext extends TranslationUnitContext {
end--;
return end;
-
} catch (BadLocationException e) {
return super.getEnd();
}
}
- /*
- * @see TemplateContext#evaluate(Template)
- */
@Override
public TemplateBuffer evaluate(Template template) throws BadLocationException, TemplateException {
if (!canEvaluate(template))
@@ -130,10 +120,14 @@ public class CContext extends TranslationUnitContext {
ICProject project= getCProject();
int indentationLevel = isReadOnly() ? 0 : getIndentationLevel();
- CFormatter formatter= new CFormatter(TextUtilities.getDefaultLineDelimiter(getDocument()), indentationLevel, useCodeFormatter, project);
+ CFormatter formatter= new CFormatter(TextUtilities.getDefaultLineDelimiter(getDocument()),
+ indentationLevel, useCodeFormatter, project);
formatter.format(buffer, this);
return buffer;
}
+ private boolean isUnicodeIdentifierPartOrPoundSign(char c) {
+ return Character.isUnicodeIdentifierPart(c) || c == '#';
+ }
}