From e32c4a438075293b7cae0fbb82b3d7a0e312c528 Mon Sep 17 00:00:00 2001 From: Anton Leherbauer Date: Wed, 6 Jun 2007 09:00:30 +0000 Subject: [PATCH] Fix for 191178: todo variable for templates --- .../template/c/TemplateMessages.properties | 4 +- .../c/TranslationUnitContextType.java | 31 ++++++++++++++-- .../ui/codemanipulation/StubUtility.java | 37 +++++++++++++++++-- 3 files changed, 64 insertions(+), 8 deletions(-) diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/corext/template/c/TemplateMessages.properties b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/corext/template/c/TemplateMessages.properties index 9faa5488854..48e4f271229 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/corext/template/c/TemplateMessages.properties +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/corext/template/c/TemplateMessages.properties @@ -1,5 +1,5 @@ ######################################### -# Copyright (c) 2005 IBM Corporation and others. +# Copyright (c) 2005, 2007 IBM Corporation 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 @@ -8,6 +8,7 @@ # Contributors: # IBM Corporation - initial API and implementation # QnX Software System +# Anton Leherbauer (Wind River Systems) ######################################### GlobalVariables.variable.description.dollar=The dollar symbol @@ -34,3 +35,4 @@ CContextType.variable.description.enclosing.type=Enclosing type name CContextType.variable.description.enclosing.project=Enclosing project name CContextType.variable.description.enclosing.method.arguments=Argument names of enclosing method CContextType.variable.description.return.type=Enclosing method return type +CContextType.variable.description.todo=Todo task tag diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/corext/template/c/TranslationUnitContextType.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/corext/template/c/TranslationUnitContextType.java index 064279e8235..2f08ff386ce 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/corext/template/c/TranslationUnitContextType.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/corext/template/c/TranslationUnitContextType.java @@ -13,9 +13,6 @@ package org.eclipse.cdt.internal.corext.template.c; -import org.eclipse.cdt.core.model.ICElement; -import org.eclipse.cdt.core.model.IFunctionDeclaration; -import org.eclipse.cdt.core.model.ITranslationUnit; import org.eclipse.jface.text.IDocument; import org.eclipse.jface.text.Position; import org.eclipse.jface.text.templates.GlobalTemplateVariables; @@ -23,6 +20,13 @@ import org.eclipse.jface.text.templates.TemplateContext; import org.eclipse.jface.text.templates.TemplateContextType; import org.eclipse.jface.text.templates.TemplateVariableResolver; +import org.eclipse.cdt.core.model.ICElement; +import org.eclipse.cdt.core.model.ICProject; +import org.eclipse.cdt.core.model.IFunctionDeclaration; +import org.eclipse.cdt.core.model.ITranslationUnit; + +import org.eclipse.cdt.internal.ui.codemanipulation.StubUtility; + /** * A context type for translation units. */ @@ -144,6 +148,26 @@ public abstract class TranslationUnitContextType extends TemplateContextType { } } + protected static class Todo extends TemplateVariableResolver { + + public Todo() { + super("todo", TemplateMessages.getString("CContextType.variable.description.todo")); //$NON-NLS-1$ //$NON-NLS-2$ + } + protected String resolve(TemplateContext context) { + TranslationUnitContext cContext= (TranslationUnitContext) context; + ITranslationUnit tUnit= cContext.getTranslationUnit(); + if (tUnit == null) + return "XXX"; //$NON-NLS-1$ + + ICProject cProject= tUnit.getCProject(); + String todoTaskTag= StubUtility.getTodoTaskTag(cProject); + if (todoTaskTag == null) + return "XXX"; //$NON-NLS-1$ + + return todoTaskTag; + } + } + /* * @see TemplateContextType#TemplateContextType() */ @@ -165,6 +189,7 @@ public abstract class TranslationUnitContextType extends TemplateContextType { addResolver(new Method()); addResolver(new Project()); addResolver(new Arguments()); + addResolver(new Todo()); } public abstract TranslationUnitContext createContext(IDocument document, int offset, int length, ITranslationUnit translationUnit); diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/codemanipulation/StubUtility.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/codemanipulation/StubUtility.java index deaa56ad57d..052a90c257a 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/codemanipulation/StubUtility.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/codemanipulation/StubUtility.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2001, 2005 IBM Corporation and others. + * Copyright (c) 2001, 2007 IBM Corporation 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 @@ -7,15 +7,20 @@ * * Contributors: * Rational Software - initial implementation + * Anton Leherbauer (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.internal.ui.codemanipulation; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.swt.SWT; + +import org.eclipse.cdt.core.CCorePlugin; +import org.eclipse.cdt.core.CCorePreferenceConstants; import org.eclipse.cdt.core.model.CModelException; import org.eclipse.cdt.core.model.IBuffer; import org.eclipse.cdt.core.model.ICElement; +import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.model.ITranslationUnit; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.swt.SWT; public class StubUtility { @@ -65,5 +70,29 @@ public class StubUtility { return System.getProperty("line.separator", "\n"); //$NON-NLS-1$ //$NON-NLS-2$ } - + /** + * Get the default task tag for the given project. + * + * @param project + * @return the default task tag + */ + public static String getTodoTaskTag(ICProject project) { + String markers= null; + if (project == null) { + markers= CCorePlugin.getOption(CCorePreferenceConstants.TODO_TASK_TAGS); + } else { + markers= project.getOption(CCorePreferenceConstants.TODO_TASK_TAGS, true); + } + + if (markers != null && markers.length() > 0) { + int idx= markers.indexOf(','); + if (idx == -1) { + return markers; + } else { + return markers.substring(0, idx); + } + } + return CCorePreferenceConstants.DEFAULT_TASK_TAG; + } + }