1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Bug 341086 - Add a variable like 'base_filename' to the code template variables

This commit is contained in:
Anton Leherbauer 2011-03-31 14:08:24 +00:00
parent 6e469df334
commit 82aa60a838
3 changed files with 19 additions and 7 deletions

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2005, 2008 IBM Corporation and others. * Copyright (c) 2005, 2011 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -23,6 +23,7 @@ public final class TemplateMessages extends NLS {
} }
public static String CContextType_variable_description_file; public static String CContextType_variable_description_file;
public static String CContextType_variable_description_file_base;
public static String CContextType_variable_description_enclosing_method; public static String CContextType_variable_description_enclosing_method;
public static String CContextType_variable_description_enclosing_project; public static String CContextType_variable_description_enclosing_project;
public static String CContextType_variable_description_enclosing_method_arguments; public static String CContextType_variable_description_enclosing_method_arguments;

View file

@ -1,5 +1,5 @@
######################################### #########################################
# Copyright (c) 2005, 2008 IBM Corporation and others. # Copyright (c) 2005, 2011 IBM Corporation and others.
# All rights reserved. This program and the accompanying materials # All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v1.0 # are made available under the terms of the Eclipse Public License v1.0
# which accompanies this distribution, and is available at # which accompanies this distribution, and is available at
@ -11,7 +11,8 @@
# Anton Leherbauer (Wind River Systems) # Anton Leherbauer (Wind River Systems)
######################################### #########################################
CContextType_variable_description_file=Filename of translation unit CContextType_variable_description_file=Name of source file
CContextType_variable_description_file_base=Name of source file without extension
CContextType_variable_description_enclosing_method=Enclosing method name CContextType_variable_description_enclosing_method=Enclosing method name
CContextType_variable_description_enclosing_project=Enclosing project name CContextType_variable_description_enclosing_project=Enclosing project name
CContextType_variable_description_enclosing_method_arguments=Argument names of enclosing method CContextType_variable_description_enclosing_method_arguments=Argument names of enclosing method

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2000, 2010 IBM Corporation and others. * Copyright (c) 2000, 2011 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -13,6 +13,7 @@
package org.eclipse.cdt.internal.corext.template.c; package org.eclipse.cdt.internal.corext.template.c;
import org.eclipse.core.runtime.Path;
import org.eclipse.jface.text.IDocument; import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.Position; import org.eclipse.jface.text.Position;
import org.eclipse.jface.text.templates.GlobalTemplateVariables; import org.eclipse.jface.text.templates.GlobalTemplateVariables;
@ -61,11 +62,21 @@ public abstract class TranslationUnitContextType extends TemplateContextType {
@Override @Override
public String resolve(TemplateContext context) { public String resolve(TemplateContext context) {
ITranslationUnit unit= ((TranslationUnitContext) context).getTranslationUnit(); ITranslationUnit unit= ((TranslationUnitContext) context).getTranslationUnit();
return (unit == null) ? null : unit.getElementName(); return (unit == null) ? null : unit.getElementName();
} }
} }
protected static class FileBase extends TemplateVariableResolver {
public FileBase() {
super("file_base", TemplateMessages.CContextType_variable_description_file_base); //$NON-NLS-1$
}
@Override
public String resolve(TemplateContext context) {
ITranslationUnit unit= ((TranslationUnitContext) context).getTranslationUnit();
return (unit == null) ? null : new Path(unit.getElementName()).removeFileExtension().lastSegment();
}
}
protected static class EnclosingCElement extends TemplateVariableResolver { protected static class EnclosingCElement extends TemplateVariableResolver {
protected final int fElementType; protected final int fElementType;
@ -186,6 +197,7 @@ public abstract class TranslationUnitContextType extends TemplateContextType {
// translation unit // translation unit
addResolver(new File()); addResolver(new File());
addResolver(new FileBase());
addResolver(new ReturnType()); addResolver(new ReturnType());
addResolver(new Method()); addResolver(new Method());
addResolver(new Project()); addResolver(new Project());
@ -196,5 +208,3 @@ public abstract class TranslationUnitContextType extends TemplateContextType {
public abstract TranslationUnitContext createContext(IDocument document, int offset, int length, ITranslationUnit translationUnit); public abstract TranslationUnitContext createContext(IDocument document, int offset, int length, ITranslationUnit translationUnit);
public abstract TranslationUnitContext createContext(IDocument document, Position position, ITranslationUnit translationUnit); public abstract TranslationUnitContext createContext(IDocument document, Position position, ITranslationUnit translationUnit);
} }