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:
parent
217a28a706
commit
15c366a882
1 changed files with 11 additions and 17 deletions
|
@ -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 == '#';
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue