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

Fix for 191178: todo variable for templates

This commit is contained in:
Anton Leherbauer 2007-06-06 09:00:30 +00:00
parent 9c110c533f
commit e32c4a4380
3 changed files with 64 additions and 8 deletions

View file

@ -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

View file

@ -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);

View file

@ -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;
}
}