1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-08 10:16:03 +02:00

Bug 323780: "Generate Getters and Setters..." crashes

https://bugs.eclipse.org/bugs/show_bug.cgi?id=323780 FIXED
This commit is contained in:
Emanuel Graf 2010-09-14 10:58:44 +00:00
parent 82850038be
commit 96b0cc259d
3 changed files with 88 additions and 6 deletions

View file

@ -76,11 +76,14 @@ public class ASTModificationHelper {
break;
case INSERT_BEFORE:
T insertedTNode = cast(parentModification.getNewNode(), clazz);
int targetNodeIndex = modifiedChildren.indexOf(parentModification.getTargetNode());
if(targetNodeIndex >= 0){
modifiedChildren.add(targetNodeIndex, insertedTNode);
newNode = parentModification.getNewNode();
if (newNode instanceof ContainerNode) {
ContainerNode contNode = (ContainerNode) newNode;
for (IASTNode node : contNode.getNodes()) {
insertNode(clazz, modifiedChildren, parentModification, node);
}
} else {
insertNode(clazz, modifiedChildren, parentModification, newNode);
}
break;
@ -92,6 +95,16 @@ public class ASTModificationHelper {
}
private <T> void insertNode(Class<T> clazz, ArrayList<T> modifiedChildren,
ASTModification parentModification, IASTNode newNode) {
T insertedTNode = cast(newNode, clazz);
int targetNodeIndex = modifiedChildren.indexOf(parentModification.getTargetNode());
if (targetNodeIndex >= 0) {
modifiedChildren.add(targetNodeIndex, insertedTNode);
}
}
@SuppressWarnings("unchecked")
private <T> T[] newArrayInstance(Class<T> clazz, int size) {
return (T[]) Array.newInstance(clazz, size);

View file

@ -1406,3 +1406,72 @@ void test::setI(int i)
#endif /* TEST_H_ */
//!Bug 323780 "Generate Getters and Setters..." crashes
//#org.eclipse.cdt.ui.tests.refactoring.gettersandsetters.GenerateGettersAndSettersTest
//@.config
filename=Test.h
getters=testField
setters=testField
//@Test.h
#ifndef TEST_H_
#define TEST_H_
namespace foo
{
class Test
{
int /*$*/testField/*$$*/;
void foo();
};
}
#endif
//=
#ifndef TEST_H_
#define TEST_H_
namespace foo
{
class Test
{
int testField;
void foo();
public:
int getTestField() const;
void setTestField(int testField);
};
}
#endif
//@Test.cpp
#include "Test.h"
namespace foo
{
void Test::foo()
{
}
}
//=
#include "Test.h"
namespace foo
{
int Test::getTestField() const
{
return testField;
}
void Test::setTestField(int testField)
{
this->testField = testField;
}
void Test::foo()
{
}
}

View file

@ -257,7 +257,7 @@ public class GenerateGettersAndSettersRefactoring extends CRefactoring {
for (IASTFunctionDefinition functionDefinition : definitions) {
cont.addNode(functionDefinition);
}
rewrite = rewrite.insertBefore(parent, nodeToInsertBefore, cont , null);
rewrite = rewrite.insertBefore(parent, nodeToInsertBefore, cont, null);
}
public GetterAndSetterContext getContext() {