1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-22 06:02:11 +02:00

Bug 373503 - Auto-completion for C/C++ editor templates that start with

# sign doesn't work. Patch by Alex Freidin
This commit is contained in:
Alex Freidin 2012-04-01 15:31:40 -07:00 committed by Sergey Prigogin
parent 217a28a706
commit 15c366a882

View file

@ -7,7 +7,7 @@
* *
* Contributors: * Contributors:
* IBM Corporation - initial API and implementation * IBM Corporation - initial API and implementation
* QnX Software System * QNX Software Systems
* Anton Leherbauer (Wind River Systems) * Anton Leherbauer (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.corext.template.c; 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.CUIPlugin;
import org.eclipse.cdt.ui.PreferenceConstants; import org.eclipse.cdt.ui.PreferenceConstants;
/** /**
* A context for C/C++. * A context for C/C++.
*/ */
public class CContext extends TranslationUnitContext { public class CContext extends TranslationUnitContext {
/** /**
* Creates a C/C++ code template context. * Creates a C/C++ code template context.
* *
@ -43,8 +41,8 @@ public class CContext extends TranslationUnitContext {
* @param completionLength the length of the context * @param completionLength the length of the context
* @param translationUnit the translation unit represented by the document * @param translationUnit the translation unit represented by the document
*/ */
public CContext(TemplateContextType type, IDocument document, int completionOffset, int completionLength, public CContext(TemplateContextType type, IDocument document, int completionOffset,
ITranslationUnit translationUnit) { int completionLength, ITranslationUnit translationUnit) {
super(type, document, completionOffset, completionLength, translationUnit); super(type, document, completionOffset, completionLength, translationUnit);
} }
@ -61,9 +59,6 @@ public class CContext extends TranslationUnitContext {
super(type, document, completionPosition, translationUnit); super(type, document, completionPosition, translationUnit);
} }
/*
* @see DocumentTemplateContext#getStart()
*/
@Override @Override
public int getStart() { public int getStart() {
if (fIsManaged && getCompletionLength() > 0) if (fIsManaged && getCompletionLength() > 0)
@ -75,7 +70,7 @@ public class CContext extends TranslationUnitContext {
int start= getCompletionOffset(); int start= getCompletionOffset();
int end= getCompletionOffset() + getCompletionLength(); int end= getCompletionOffset() + getCompletionLength();
while (start != 0 && Character.isUnicodeIdentifierPart(document.getChar(start - 1))) while (start != 0 && isUnicodeIdentifierPartOrPoundSign(document.getChar(start - 1)))
start--; start--;
while (start != end && Character.isWhitespace(document.getChar(start))) while (start != end && Character.isWhitespace(document.getChar(start)))
@ -84,8 +79,7 @@ public class CContext extends TranslationUnitContext {
if (start == end) if (start == end)
start= getCompletionOffset(); start= getCompletionOffset();
return start; return start;
} catch (BadLocationException e) { } catch (BadLocationException e) {
return super.getStart(); return super.getStart();
} }
@ -106,15 +100,11 @@ public class CContext extends TranslationUnitContext {
end--; end--;
return end; return end;
} catch (BadLocationException e) { } catch (BadLocationException e) {
return super.getEnd(); return super.getEnd();
} }
} }
/*
* @see TemplateContext#evaluate(Template)
*/
@Override @Override
public TemplateBuffer evaluate(Template template) throws BadLocationException, TemplateException { public TemplateBuffer evaluate(Template template) throws BadLocationException, TemplateException {
if (!canEvaluate(template)) if (!canEvaluate(template))
@ -130,10 +120,14 @@ public class CContext extends TranslationUnitContext {
ICProject project= getCProject(); ICProject project= getCProject();
int indentationLevel = isReadOnly() ? 0 : getIndentationLevel(); 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); formatter.format(buffer, this);
return buffer; return buffer;
} }
private boolean isUnicodeIdentifierPartOrPoundSign(char c) {
return Character.isUnicodeIdentifierPart(c) || c == '#';
}
} }