From 15c366a8828cb69bd5442dcdd5cdc9fdce08c76c Mon Sep 17 00:00:00 2001 From: Alex Freidin Date: Sun, 1 Apr 2012 15:31:40 -0700 Subject: [PATCH] Bug 373503 - Auto-completion for C/C++ editor templates that start with # sign doesn't work. Patch by Alex Freidin --- .../internal/corext/template/c/CContext.java | 28 ++++++++----------- 1 file 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 d33107da398..cd757296f6c 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 == '#'; + } }