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.implementmethod.ImplementMethodRefactoringTest;
|
||||
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;
|
||||
|
||||
/**
|
||||
|
@ -41,7 +41,7 @@ public class RefactoringTestSuite extends TestSuite {
|
|||
suite.addTest(GenerateGettersAndSettersTest.suite());
|
||||
suite.addTest(ImplementMethodRefactoringTest.suite());
|
||||
suite.addTest(ExtractLocalVariableRefactoringTest.suite());
|
||||
suite.addTest(ToogleRefactoringTest.suite());
|
||||
suite.addTest(ToggleRefactoringTest.suite());
|
||||
return suite;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,19 +24,19 @@ import org.eclipse.cdt.internal.ui.refactoring.togglefunction.ToggleRefactoring;
|
|||
/**
|
||||
* Tests for Generate Getters and Setters refactoring.
|
||||
*/
|
||||
public class ToogleRefactoringTest extends RefactoringTestBase {
|
||||
public class ToggleRefactoringTest extends RefactoringTestBase {
|
||||
private ToggleRefactoring refactoring;
|
||||
|
||||
public ToogleRefactoringTest() {
|
||||
public ToggleRefactoringTest() {
|
||||
super();
|
||||
}
|
||||
|
||||
public ToogleRefactoringTest(String name) {
|
||||
public ToggleRefactoringTest(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
public static Test suite() {
|
||||
TestSuite suite = suite(ToogleRefactoringTest.class);
|
||||
TestSuite suite = suite(ToggleRefactoringTest.class);
|
||||
suite.addTestSuite(ToggleNodeHelperTest.class);
|
||||
return suite;
|
||||
}
|
|
@ -44,7 +44,8 @@ public class ToggleFromClassToInHeaderStrategy implements IToggleRefactoringStra
|
|||
}
|
||||
|
||||
private boolean isInClass(IASTNode node) {
|
||||
return CPPVisitor.findAncestorWithType(node, ICPPASTCompositeTypeSpecifier.class) != null;
|
||||
return node != null &&
|
||||
CPPVisitor.findAncestorWithType(node, ICPPASTCompositeTypeSpecifier.class) != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -61,8 +62,8 @@ public class ToggleFromClassToInHeaderStrategy implements IToggleRefactoringStra
|
|||
private IASTNode getNewDefinition(IASTNode parentNamespace) {
|
||||
IASTNode newDefinition = ToggleNodeHelper.getQualifiedNameDefinition(
|
||||
context.getDefinition(), context.getDefinitionUnit(), parentNamespace);
|
||||
((IASTFunctionDefinition) newDefinition).setBody(context.getDefinition().getBody()
|
||||
.copy(CopyStyle.withLocations));
|
||||
((IASTFunctionDefinition) newDefinition).setBody(
|
||||
context.getDefinition().getBody().copy(CopyStyle.withLocations));
|
||||
if (newDefinition instanceof ICPPASTFunctionWithTryBlock) {
|
||||
ICPPASTFunctionWithTryBlock newTryFun = (ICPPASTFunctionWithTryBlock) newDefinition;
|
||||
ICPPASTFunctionWithTryBlock oldTryFun = (ICPPASTFunctionWithTryBlock) context.getDefinition();
|
||||
|
@ -80,7 +81,8 @@ public class ToggleFromClassToInHeaderStrategy implements IToggleRefactoringStra
|
|||
}
|
||||
|
||||
private IASTNode getParentNamespace() {
|
||||
IASTNode parentNamespace = CPPVisitor.findAncestorWithType(context.getDefinition(), ICPPASTNamespaceDefinition.class);
|
||||
IASTNode parentNamespace =
|
||||
CPPVisitor.findAncestorWithType(context.getDefinition(), ICPPASTNamespaceDefinition.class);
|
||||
if (parentNamespace == null)
|
||||
parentNamespace = context.getDefinitionUnit();
|
||||
return parentNamespace;
|
||||
|
@ -104,12 +106,12 @@ public class ToggleFromClassToInHeaderStrategy implements IToggleRefactoringStra
|
|||
|
||||
private IASTSimpleDeclaration getNewDeclaration() {
|
||||
INodeFactory factory = context.getDefinitionUnit().getASTNodeFactory();
|
||||
IASTDeclSpecifier newDeclSpecifier = context.getDefinition().getDeclSpecifier()
|
||||
.copy(CopyStyle.withLocations);
|
||||
IASTDeclSpecifier newDeclSpecifier =
|
||||
context.getDefinition().getDeclSpecifier().copy(CopyStyle.withLocations);
|
||||
newDeclSpecifier.setInline(false);
|
||||
IASTSimpleDeclaration newDeclaration = factory.newSimpleDeclaration(newDeclSpecifier);
|
||||
IASTFunctionDeclarator newDeclarator = context.getDefinition().getDeclarator()
|
||||
.copy(CopyStyle.withLocations);
|
||||
IASTFunctionDeclarator newDeclarator =
|
||||
context.getDefinition().getDeclarator().copy(CopyStyle.withLocations);
|
||||
newDeclaration.addDeclarator(newDeclarator);
|
||||
newDeclaration.setParent(context.getDefinition().getParent());
|
||||
return newDeclaration;
|
||||
|
|
Loading…
Add table
Reference in a new issue