mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Bug 355006 - NPE using Implement method on template function
This commit is contained in:
parent
db272b5b00
commit
82272a7965
3 changed files with 37 additions and 12 deletions
|
@ -838,3 +838,22 @@ void TestClass::foo()
|
|||
{
|
||||
}
|
||||
|
||||
//!Bug 355006 - NPE implementing template function
|
||||
//#org.eclipse.cdt.ui.tests.refactoring.implementmethod.ImplementMethodRefactoringTest
|
||||
//@.config
|
||||
filename=A.h
|
||||
infos=1
|
||||
//@A.h
|
||||
|
||||
/*$*/template<typename T> void func(T&);/*$$*/
|
||||
|
||||
//=
|
||||
|
||||
template<typename T> void func(T&);
|
||||
|
||||
template<typename T> inline void func(T& )
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -260,15 +260,16 @@ public class ImplementMethodRefactoring extends CRefactoring2 {
|
|||
IASTFunctionDefinition functionDefinition = nodeFactory.newFunctionDefinition(declSpecifier, createdMethodDeclarator, nodeFactory.newCompoundStatement());
|
||||
functionDefinition.setParent(unit);
|
||||
|
||||
if (NodeHelper.isContainedInTemplateDeclaration(declarationParent)) {
|
||||
ICPPASTTemplateDeclaration templateDeclaration = nodeFactory.newTemplateDeclaration(functionDefinition);
|
||||
templateDeclaration.setParent(unit);
|
||||
ICPPASTTemplateDeclaration templateDeclaration = NodeHelper.findContainedTemplateDecalaration(declarationParent);
|
||||
if (templateDeclaration != null) {
|
||||
ICPPASTTemplateDeclaration newTemplateDeclaration = nodeFactory.newTemplateDeclaration(functionDefinition);
|
||||
newTemplateDeclaration.setParent(unit);
|
||||
|
||||
for (ICPPASTTemplateParameter templateParameter : ((ICPPASTTemplateDeclaration) declarationParent.getParent().getParent() ).getTemplateParameters()) {
|
||||
templateDeclaration.addTemplateParameter(templateParameter.copy(CopyStyle.withLocations));
|
||||
for (ICPPASTTemplateParameter templateParameter : templateDeclaration.getTemplateParameters()) {
|
||||
newTemplateDeclaration.addTemplateParameter(templateParameter.copy(CopyStyle.withLocations));
|
||||
}
|
||||
|
||||
return templateDeclaration;
|
||||
return newTemplateDeclaration;
|
||||
}
|
||||
return functionDefinition;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2008, 2009 Institute for Software, HSR Hochschule fuer Technik
|
||||
* Copyright (c) 2008, 2011 Institute for Software, HSR Hochschule fuer Technik
|
||||
* Rapperswil, University of applied sciences and others
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
|
@ -212,11 +212,16 @@ public class NodeHelper {
|
|||
}
|
||||
|
||||
public static boolean isContainedInTemplateDeclaration(IASTNode node) {
|
||||
if (node == null) {
|
||||
return false;
|
||||
} else if (node instanceof ICPPASTTemplateDeclaration) {
|
||||
return true;
|
||||
return findContainedTemplateDecalaration(node) != null;
|
||||
}
|
||||
|
||||
public static ICPPASTTemplateDeclaration findContainedTemplateDecalaration(IASTNode node) {
|
||||
while (node != null) {
|
||||
if (node instanceof ICPPASTTemplateDeclaration) {
|
||||
return (ICPPASTTemplateDeclaration) node;
|
||||
}
|
||||
node = node.getParent();
|
||||
}
|
||||
return isContainedInTemplateDeclaration(node.getParent());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue