mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-22 14:12:10 +02:00
Fixed NPE.
This commit is contained in:
parent
6a916ea3e5
commit
ac7ee03d25
3 changed files with 16 additions and 14 deletions
|
@ -23,7 +23,7 @@ import org.eclipse.cdt.ui.tests.refactoring.gettersandsetters.GenerateGettersAnd
|
||||||
import org.eclipse.cdt.ui.tests.refactoring.hidemethod.HideMethodRefactoringTest;
|
import org.eclipse.cdt.ui.tests.refactoring.hidemethod.HideMethodRefactoringTest;
|
||||||
import org.eclipse.cdt.ui.tests.refactoring.implementmethod.ImplementMethodRefactoringTest;
|
import org.eclipse.cdt.ui.tests.refactoring.implementmethod.ImplementMethodRefactoringTest;
|
||||||
import org.eclipse.cdt.ui.tests.refactoring.rename.RenameRegressionTests;
|
import org.eclipse.cdt.ui.tests.refactoring.rename.RenameRegressionTests;
|
||||||
import org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToogleRefactoringTest;
|
import org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest;
|
||||||
import org.eclipse.cdt.ui.tests.refactoring.utils.UtilTestSuite;
|
import org.eclipse.cdt.ui.tests.refactoring.utils.UtilTestSuite;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -41,7 +41,7 @@ public class RefactoringTestSuite extends TestSuite {
|
||||||
suite.addTest(GenerateGettersAndSettersTest.suite());
|
suite.addTest(GenerateGettersAndSettersTest.suite());
|
||||||
suite.addTest(ImplementMethodRefactoringTest.suite());
|
suite.addTest(ImplementMethodRefactoringTest.suite());
|
||||||
suite.addTest(ExtractLocalVariableRefactoringTest.suite());
|
suite.addTest(ExtractLocalVariableRefactoringTest.suite());
|
||||||
suite.addTest(ToogleRefactoringTest.suite());
|
suite.addTest(ToggleRefactoringTest.suite());
|
||||||
return suite;
|
return suite;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,19 +24,19 @@ import org.eclipse.cdt.internal.ui.refactoring.togglefunction.ToggleRefactoring;
|
||||||
/**
|
/**
|
||||||
* Tests for Generate Getters and Setters refactoring.
|
* Tests for Generate Getters and Setters refactoring.
|
||||||
*/
|
*/
|
||||||
public class ToogleRefactoringTest extends RefactoringTestBase {
|
public class ToggleRefactoringTest extends RefactoringTestBase {
|
||||||
private ToggleRefactoring refactoring;
|
private ToggleRefactoring refactoring;
|
||||||
|
|
||||||
public ToogleRefactoringTest() {
|
public ToggleRefactoringTest() {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
public ToogleRefactoringTest(String name) {
|
public ToggleRefactoringTest(String name) {
|
||||||
super(name);
|
super(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Test suite() {
|
public static Test suite() {
|
||||||
TestSuite suite = suite(ToogleRefactoringTest.class);
|
TestSuite suite = suite(ToggleRefactoringTest.class);
|
||||||
suite.addTestSuite(ToggleNodeHelperTest.class);
|
suite.addTestSuite(ToggleNodeHelperTest.class);
|
||||||
return suite;
|
return suite;
|
||||||
}
|
}
|
|
@ -44,7 +44,8 @@ public class ToggleFromClassToInHeaderStrategy implements IToggleRefactoringStra
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isInClass(IASTNode node) {
|
private boolean isInClass(IASTNode node) {
|
||||||
return CPPVisitor.findAncestorWithType(node, ICPPASTCompositeTypeSpecifier.class) != null;
|
return node != null &&
|
||||||
|
CPPVisitor.findAncestorWithType(node, ICPPASTCompositeTypeSpecifier.class) != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -61,8 +62,8 @@ public class ToggleFromClassToInHeaderStrategy implements IToggleRefactoringStra
|
||||||
private IASTNode getNewDefinition(IASTNode parentNamespace) {
|
private IASTNode getNewDefinition(IASTNode parentNamespace) {
|
||||||
IASTNode newDefinition = ToggleNodeHelper.getQualifiedNameDefinition(
|
IASTNode newDefinition = ToggleNodeHelper.getQualifiedNameDefinition(
|
||||||
context.getDefinition(), context.getDefinitionUnit(), parentNamespace);
|
context.getDefinition(), context.getDefinitionUnit(), parentNamespace);
|
||||||
((IASTFunctionDefinition) newDefinition).setBody(context.getDefinition().getBody()
|
((IASTFunctionDefinition) newDefinition).setBody(
|
||||||
.copy(CopyStyle.withLocations));
|
context.getDefinition().getBody().copy(CopyStyle.withLocations));
|
||||||
if (newDefinition instanceof ICPPASTFunctionWithTryBlock) {
|
if (newDefinition instanceof ICPPASTFunctionWithTryBlock) {
|
||||||
ICPPASTFunctionWithTryBlock newTryFun = (ICPPASTFunctionWithTryBlock) newDefinition;
|
ICPPASTFunctionWithTryBlock newTryFun = (ICPPASTFunctionWithTryBlock) newDefinition;
|
||||||
ICPPASTFunctionWithTryBlock oldTryFun = (ICPPASTFunctionWithTryBlock) context.getDefinition();
|
ICPPASTFunctionWithTryBlock oldTryFun = (ICPPASTFunctionWithTryBlock) context.getDefinition();
|
||||||
|
@ -80,7 +81,8 @@ public class ToggleFromClassToInHeaderStrategy implements IToggleRefactoringStra
|
||||||
}
|
}
|
||||||
|
|
||||||
private IASTNode getParentNamespace() {
|
private IASTNode getParentNamespace() {
|
||||||
IASTNode parentNamespace = CPPVisitor.findAncestorWithType(context.getDefinition(), ICPPASTNamespaceDefinition.class);
|
IASTNode parentNamespace =
|
||||||
|
CPPVisitor.findAncestorWithType(context.getDefinition(), ICPPASTNamespaceDefinition.class);
|
||||||
if (parentNamespace == null)
|
if (parentNamespace == null)
|
||||||
parentNamespace = context.getDefinitionUnit();
|
parentNamespace = context.getDefinitionUnit();
|
||||||
return parentNamespace;
|
return parentNamespace;
|
||||||
|
@ -104,12 +106,12 @@ public class ToggleFromClassToInHeaderStrategy implements IToggleRefactoringStra
|
||||||
|
|
||||||
private IASTSimpleDeclaration getNewDeclaration() {
|
private IASTSimpleDeclaration getNewDeclaration() {
|
||||||
INodeFactory factory = context.getDefinitionUnit().getASTNodeFactory();
|
INodeFactory factory = context.getDefinitionUnit().getASTNodeFactory();
|
||||||
IASTDeclSpecifier newDeclSpecifier = context.getDefinition().getDeclSpecifier()
|
IASTDeclSpecifier newDeclSpecifier =
|
||||||
.copy(CopyStyle.withLocations);
|
context.getDefinition().getDeclSpecifier().copy(CopyStyle.withLocations);
|
||||||
newDeclSpecifier.setInline(false);
|
newDeclSpecifier.setInline(false);
|
||||||
IASTSimpleDeclaration newDeclaration = factory.newSimpleDeclaration(newDeclSpecifier);
|
IASTSimpleDeclaration newDeclaration = factory.newSimpleDeclaration(newDeclSpecifier);
|
||||||
IASTFunctionDeclarator newDeclarator = context.getDefinition().getDeclarator()
|
IASTFunctionDeclarator newDeclarator =
|
||||||
.copy(CopyStyle.withLocations);
|
context.getDefinition().getDeclarator().copy(CopyStyle.withLocations);
|
||||||
newDeclaration.addDeclarator(newDeclarator);
|
newDeclaration.addDeclarator(newDeclarator);
|
||||||
newDeclaration.setParent(context.getDefinition().getParent());
|
newDeclaration.setParent(context.getDefinition().getParent());
|
||||||
return newDeclaration;
|
return newDeclaration;
|
||||||
|
|
Loading…
Add table
Reference in a new issue