mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-04 23:05:47 +02:00
Bug 515545 - NPE when using Extract Function in the presence of auto variable
Change-Id: Id13e7afadbd3c92f1ab5a1448b9851f2d0c7d4df Signed-off-by: Marc-Andre Laperle <marc-andre.laperle@ericsson.com>
This commit is contained in:
parent
8da9b7a0b8
commit
765960cec6
2 changed files with 22 additions and 4 deletions
|
@ -1,5 +1,5 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2010, 2016 Tomasz Wesolowski
|
* Copyright (c) 2010, 2017 Tomasz Wesolowski
|
||||||
* 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
|
||||||
|
@ -134,12 +134,12 @@ public class DeclarationGeneratorImpl extends DeclarationGenerator {
|
||||||
public IASTDeclarator createDeclaratorFromType(IType type, char[] name, boolean changeInitialFunctionToFuncPtr) {
|
public IASTDeclarator createDeclaratorFromType(IType type, char[] name, boolean changeInitialFunctionToFuncPtr) {
|
||||||
IASTDeclarator returnedDeclarator = null;
|
IASTDeclarator returnedDeclarator = null;
|
||||||
|
|
||||||
|
IASTName newName = name != null ? factory.newName(name) : factory.newName();
|
||||||
try {
|
try {
|
||||||
// Addition of pointer operators has to be in reverse order, so it's deferred until
|
// Addition of pointer operators has to be in reverse order, so it's deferred until
|
||||||
// the end.
|
// the end.
|
||||||
Map<IASTDeclarator, LinkedList<IASTPointerOperator>> pointerOperatorMap = new HashMap<IASTDeclarator, LinkedList<IASTPointerOperator>>();
|
Map<IASTDeclarator, LinkedList<IASTPointerOperator>> pointerOperatorMap = new HashMap<IASTDeclarator, LinkedList<IASTPointerOperator>>();
|
||||||
|
|
||||||
IASTName newName = name != null ? factory.newName(name) : factory.newName();
|
|
||||||
|
|
||||||
// If the type is an array of something, create a declaration of a pointer to something
|
// If the type is an array of something, create a declaration of a pointer to something
|
||||||
// instead (to allow assignment, etc).
|
// instead (to allow assignment, etc).
|
||||||
|
@ -220,7 +220,7 @@ public class DeclarationGeneratorImpl extends DeclarationGenerator {
|
||||||
|
|
||||||
// Fallback
|
// Fallback
|
||||||
if (returnedDeclarator == null) {
|
if (returnedDeclarator == null) {
|
||||||
returnedDeclarator = factory.newDeclarator(factory.newName(name));
|
returnedDeclarator = factory.newDeclarator(newName);
|
||||||
}
|
}
|
||||||
|
|
||||||
return returnedDeclarator;
|
return returnedDeclarator;
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2008, 2014 Institute for Software, HSR Hochschule fuer Technik
|
* Copyright (c) 2008, 2017 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
|
||||||
|
@ -4721,4 +4721,22 @@ public class ExtractFunctionRefactoringTest extends RefactoringTestBase {
|
||||||
public void testExtractArrayInitializer_Bug412380() throws Exception {
|
public void testExtractArrayInitializer_Bug412380() throws Exception {
|
||||||
assertRefactoringSuccess();
|
assertRefactoringSuccess();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//main.cpp
|
||||||
|
//int main() {
|
||||||
|
// auto var = 1;
|
||||||
|
// /*$*/var;/*$$*/
|
||||||
|
//}
|
||||||
|
//====================
|
||||||
|
//void extracted(int var) {
|
||||||
|
// var;
|
||||||
|
//}
|
||||||
|
//
|
||||||
|
//int main() {
|
||||||
|
// auto var = 1;
|
||||||
|
// extracted(var);
|
||||||
|
//}
|
||||||
|
public void testExtractWithAutoVar() throws Exception {
|
||||||
|
assertRefactoringSuccess();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue