mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Bug 315365 - [templates] ClassCastException when using ${todo} in file template
This commit is contained in:
parent
21b37f0e95
commit
9c47fdf7ec
2 changed files with 19 additions and 5 deletions
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2001, 2008 IBM Corporation and others.
|
||||
* Copyright (c) 2001, 2010 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
|
||||
|
@ -130,10 +130,19 @@ public class StubUtility {
|
|||
}
|
||||
|
||||
public static String getFileContent(Template template, IFile file, String lineDelimiter) throws CoreException {
|
||||
FileTemplateContext context= new FileTemplateContext(template.getContextTypeId(), lineDelimiter);
|
||||
ICProject cproject = null;
|
||||
final IProject project = file.getProject();
|
||||
if (CoreModel.hasCNature(project)) {
|
||||
cproject = CoreModel.getDefault().create(project);
|
||||
}
|
||||
FileTemplateContext context;
|
||||
if (cproject != null) {
|
||||
context= new CodeTemplateContext(template.getContextTypeId(), cproject, lineDelimiter);
|
||||
} else {
|
||||
context= new FileTemplateContext(template.getContextTypeId(), lineDelimiter);
|
||||
}
|
||||
String fileComment= getFileComment(file, lineDelimiter);
|
||||
context.setVariable(CodeTemplateContextType.FILE_COMMENT, fileComment != null ? fileComment : ""); //$NON-NLS-1$
|
||||
ICProject cproject = CoreModel.getDefault().create(file.getProject());
|
||||
String includeGuardSymbol= generateIncludeGuardSymbol(file, cproject);
|
||||
context.setVariable(CodeTemplateContextType.INCLUDE_GUARD_SYMBOL, includeGuardSymbol != null ? includeGuardSymbol : ""); //$NON-NLS-1$
|
||||
context.setResourceVariables(file);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2000, 2008 IBM Corporation and others.
|
||||
* Copyright (c) 2000, 2010 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
|
||||
|
@ -17,6 +17,7 @@ import org.eclipse.jface.text.templates.TemplateException;
|
|||
import org.eclipse.jface.text.templates.TemplateVariableResolver;
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.model.ICProject;
|
||||
|
||||
import org.eclipse.cdt.internal.corext.codemanipulation.StubUtility;
|
||||
|
||||
|
@ -99,7 +100,11 @@ public class CodeTemplateContextType extends FileTemplateContextType {
|
|||
|
||||
@Override
|
||||
protected String resolve(TemplateContext context) {
|
||||
String todoTaskTag= StubUtility.getTodoTaskTag(((CodeTemplateContext) context).getCProject());
|
||||
ICProject cProject = null;
|
||||
if (context instanceof CodeTemplateContext) {
|
||||
cProject = ((CodeTemplateContext) context).getCProject();
|
||||
}
|
||||
String todoTaskTag= StubUtility.getTodoTaskTag(cProject);
|
||||
if (todoTaskTag == null)
|
||||
return "XXX"; //$NON-NLS-1$
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue