diff --git a/core/org.eclipse.cdt.ui.tests/resources/refactoring/ExtractConstant.rts b/core/org.eclipse.cdt.ui.tests/resources/refactoring/ExtractConstant.rts index 8743b71dcbb..b0b02fd4774 100644 --- a/core/org.eclipse.cdt.ui.tests/resources/refactoring/ExtractConstant.rts +++ b/core/org.eclipse.cdt.ui.tests/resources/refactoring/ExtractConstant.rts @@ -449,3 +449,25 @@ int A::foo() return theAnswer; } +//!Bug 246062 [Refactoring] NPE extracting a constant from an inlined method +//#org.eclipse.cdt.ui.tests.refactoring.extractconstant.ExtractConstantRefactoringTest +//@.config +filename=A.h +//@A.h +class X { + void method() { + int a= /*$*/1/*$$*/; + } +}; + +//= +namespace +{ + const int theAnswer = 1; +} +class X { + void method() { + int a= theAnswer; + } +}; + diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractconstant/ExtractConstantRefactoring.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractconstant/ExtractConstantRefactoring.java index 4b3dec63187..04f1725233d 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractconstant/ExtractConstantRefactoring.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractconstant/ExtractConstantRefactoring.java @@ -170,7 +170,14 @@ public class ExtractConstantRefactoring extends CRefactoring { if (binding instanceof CPPMethod) { CPPMethod methode = (CPPMethod) binding; - IASTNode decl = methode.getDeclarations()[0]; + IASTNode[] declarations = methode.getDeclarations(); + + IASTNode decl; + if(declarations != null) { + decl = declarations[0]; + }else { + decl = methode.getDefinition(); + } IASTNode spec = decl.getParent().getParent(); if (spec instanceof ICPPASTCompositeTypeSpecifier) {