1
0
Fork 0
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:
Marc-Andre Laperle 2011-08-28 14:38:02 -04:00
parent db272b5b00
commit 82272a7965
3 changed files with 37 additions and 12 deletions

View file

@ -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& )
{
}

View file

@ -260,15 +260,16 @@ public class ImplementMethodRefactoring extends CRefactoring2 {
IASTFunctionDefinition functionDefinition = nodeFactory.newFunctionDefinition(declSpecifier, createdMethodDeclarator, nodeFactory.newCompoundStatement()); IASTFunctionDefinition functionDefinition = nodeFactory.newFunctionDefinition(declSpecifier, createdMethodDeclarator, nodeFactory.newCompoundStatement());
functionDefinition.setParent(unit); functionDefinition.setParent(unit);
if (NodeHelper.isContainedInTemplateDeclaration(declarationParent)) { ICPPASTTemplateDeclaration templateDeclaration = NodeHelper.findContainedTemplateDecalaration(declarationParent);
ICPPASTTemplateDeclaration templateDeclaration = nodeFactory.newTemplateDeclaration(functionDefinition); if (templateDeclaration != null) {
templateDeclaration.setParent(unit); ICPPASTTemplateDeclaration newTemplateDeclaration = nodeFactory.newTemplateDeclaration(functionDefinition);
newTemplateDeclaration.setParent(unit);
for (ICPPASTTemplateParameter templateParameter : ((ICPPASTTemplateDeclaration) declarationParent.getParent().getParent() ).getTemplateParameters()) { for (ICPPASTTemplateParameter templateParameter : templateDeclaration.getTemplateParameters()) {
templateDeclaration.addTemplateParameter(templateParameter.copy(CopyStyle.withLocations)); newTemplateDeclaration.addTemplateParameter(templateParameter.copy(CopyStyle.withLocations));
} }
return templateDeclaration; return newTemplateDeclaration;
} }
return functionDefinition; return functionDefinition;
} }

View file

@ -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 * Rapperswil, University of applied sciences 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
@ -212,11 +212,16 @@ public class NodeHelper {
} }
public static boolean isContainedInTemplateDeclaration(IASTNode node) { public static boolean isContainedInTemplateDeclaration(IASTNode node) {
if (node == null) { return findContainedTemplateDecalaration(node) != null;
return false; }
} else if (node instanceof ICPPASTTemplateDeclaration) {
return true; 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;
} }
} }