mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Bug 332895 - Rename does not change using-declarations
This commit is contained in:
parent
10f7e547a1
commit
c7be116351
2 changed files with 76 additions and 44 deletions
|
@ -1,5 +1,5 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2005, 2008 Wind River Systems, Inc.
|
* Copyright (c) 2005, 2012 Wind River Systems, Inc.
|
||||||
* 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
|
||||||
|
@ -7,6 +7,7 @@
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* Markus Schorn - initial API and implementation
|
* Markus Schorn - initial API and implementation
|
||||||
|
* Sergey Prigogin (Google)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.ui.tests.refactoring.rename;
|
package org.eclipse.cdt.ui.tests.refactoring.rename;
|
||||||
|
|
||||||
|
@ -27,13 +28,15 @@ public class RenameTypeTests extends RenameTests {
|
||||||
public RenameTypeTests(String name) {
|
public RenameTypeTests(String name) {
|
||||||
super(name);
|
super(name);
|
||||||
}
|
}
|
||||||
public static Test suite(){
|
|
||||||
|
public static Test suite() {
|
||||||
return suite(true);
|
return suite(true);
|
||||||
}
|
}
|
||||||
public static Test suite( boolean cleanup ) {
|
|
||||||
|
public static Test suite(boolean cleanup) {
|
||||||
TestSuite suite = new TestSuite(RenameTypeTests.class);
|
TestSuite suite = new TestSuite(RenameTypeTests.class);
|
||||||
if (cleanup) {
|
if (cleanup) {
|
||||||
suite.addTest( new RefactoringTests("cleanupProject") ); //$NON-NLS-1$
|
suite.addTest(new RefactoringTests("cleanupProject")); //$NON-NLS-1$
|
||||||
}
|
}
|
||||||
return suite;
|
return suite;
|
||||||
}
|
}
|
||||||
|
@ -73,7 +76,7 @@ public class RenameTypeTests extends RenameTests {
|
||||||
writer.write(" } \n"); //$NON-NLS-1$
|
writer.write(" } \n"); //$NON-NLS-1$
|
||||||
writer.write("} \n"); //$NON-NLS-1$
|
writer.write("} \n"); //$NON-NLS-1$
|
||||||
String contents = writer.toString();
|
String contents = writer.toString();
|
||||||
IFile cpp= importFile("test.cpp", contents ); //$NON-NLS-1$
|
IFile cpp= importFile("test.cpp", contents); //$NON-NLS-1$
|
||||||
|
|
||||||
int offset1= contents.indexOf("v1"); //$NON-NLS-1$
|
int offset1= contents.indexOf("v1"); //$NON-NLS-1$
|
||||||
int offset2= contents.indexOf("v2"); //$NON-NLS-1$
|
int offset2= contents.indexOf("v2"); //$NON-NLS-1$
|
||||||
|
@ -415,7 +418,7 @@ public class RenameTypeTests extends RenameTests {
|
||||||
writer.write(" } \n"); //$NON-NLS-1$
|
writer.write(" } \n"); //$NON-NLS-1$
|
||||||
writer.write("} \n"); //$NON-NLS-1$
|
writer.write("} \n"); //$NON-NLS-1$
|
||||||
String contents = writer.toString();
|
String contents = writer.toString();
|
||||||
IFile cpp= importFile("test.cpp", contents ); //$NON-NLS-1$
|
IFile cpp= importFile("test.cpp", contents); //$NON-NLS-1$
|
||||||
|
|
||||||
int offset1= contents.indexOf("v1"); //$NON-NLS-1$
|
int offset1= contents.indexOf("v1"); //$NON-NLS-1$
|
||||||
int offset2= contents.indexOf("v2"); //$NON-NLS-1$
|
int offset2= contents.indexOf("v2"); //$NON-NLS-1$
|
||||||
|
@ -753,7 +756,7 @@ public class RenameTypeTests extends RenameTests {
|
||||||
writer.write(" } \n"); //$NON-NLS-1$
|
writer.write(" } \n"); //$NON-NLS-1$
|
||||||
writer.write("} \n"); //$NON-NLS-1$
|
writer.write("} \n"); //$NON-NLS-1$
|
||||||
String contents = writer.toString();
|
String contents = writer.toString();
|
||||||
IFile cpp= importFile("test.cpp", contents ); //$NON-NLS-1$
|
IFile cpp= importFile("test.cpp", contents); //$NON-NLS-1$
|
||||||
|
|
||||||
int offset1= contents.indexOf("v1"); //$NON-NLS-1$
|
int offset1= contents.indexOf("v1"); //$NON-NLS-1$
|
||||||
int offset2= contents.indexOf("v2"); //$NON-NLS-1$
|
int offset2= contents.indexOf("v2"); //$NON-NLS-1$
|
||||||
|
@ -1077,7 +1080,7 @@ public class RenameTypeTests extends RenameTests {
|
||||||
writer.write(" } \n"); //$NON-NLS-1$
|
writer.write(" } \n"); //$NON-NLS-1$
|
||||||
writer.write("} \n"); //$NON-NLS-1$
|
writer.write("} \n"); //$NON-NLS-1$
|
||||||
String contents = writer.toString();
|
String contents = writer.toString();
|
||||||
IFile cpp= importFile("test.cpp", contents ); //$NON-NLS-1$
|
IFile cpp= importFile("test.cpp", contents); //$NON-NLS-1$
|
||||||
|
|
||||||
int offset1= contents.indexOf("v1"); //$NON-NLS-1$
|
int offset1= contents.indexOf("v1"); //$NON-NLS-1$
|
||||||
|
|
||||||
|
@ -1174,7 +1177,7 @@ public class RenameTypeTests extends RenameTests {
|
||||||
writer.write(" } \n"); //$NON-NLS-1$
|
writer.write(" } \n"); //$NON-NLS-1$
|
||||||
writer.write("} \n"); //$NON-NLS-1$
|
writer.write("} \n"); //$NON-NLS-1$
|
||||||
String contents = writer.toString();
|
String contents = writer.toString();
|
||||||
IFile cpp= importFile("test.cpp", contents ); //$NON-NLS-1$
|
IFile cpp= importFile("test.cpp", contents); //$NON-NLS-1$
|
||||||
|
|
||||||
int offset1= contents.indexOf("v1"); //$NON-NLS-1$
|
int offset1= contents.indexOf("v1"); //$NON-NLS-1$
|
||||||
int offset2= contents.indexOf("v2"); //$NON-NLS-1$
|
int offset2= contents.indexOf("v2"); //$NON-NLS-1$
|
||||||
|
@ -1491,7 +1494,7 @@ public class RenameTypeTests extends RenameTests {
|
||||||
writer.write(" int w1; vv1.v++; \n"); //$NON-NLS-1$
|
writer.write(" int w1; vv1.v++; \n"); //$NON-NLS-1$
|
||||||
writer.write("} \n"); //$NON-NLS-1$
|
writer.write("} \n"); //$NON-NLS-1$
|
||||||
String contents = writer.toString();
|
String contents = writer.toString();
|
||||||
IFile cpp= importFile("test.c", contents ); //$NON-NLS-1$
|
IFile cpp= importFile("test.c", contents); //$NON-NLS-1$
|
||||||
|
|
||||||
int offset1= contents.indexOf("v1"); //$NON-NLS-1$
|
int offset1= contents.indexOf("v1"); //$NON-NLS-1$
|
||||||
|
|
||||||
|
@ -1578,7 +1581,7 @@ public class RenameTypeTests extends RenameTests {
|
||||||
writer.write(" int w3; v3 v; \n"); //$NON-NLS-1$
|
writer.write(" int w3; v3 v; \n"); //$NON-NLS-1$
|
||||||
writer.write("} \n"); //$NON-NLS-1$
|
writer.write("} \n"); //$NON-NLS-1$
|
||||||
String contents = writer.toString();
|
String contents = writer.toString();
|
||||||
IFile cpp= importFile("test.cpp", contents ); //$NON-NLS-1$
|
IFile cpp= importFile("test.cpp", contents); //$NON-NLS-1$
|
||||||
|
|
||||||
int offset1= contents.indexOf("v1"); //$NON-NLS-1$
|
int offset1= contents.indexOf("v1"); //$NON-NLS-1$
|
||||||
int offset2= contents.indexOf("v2"); //$NON-NLS-1$
|
int offset2= contents.indexOf("v2"); //$NON-NLS-1$
|
||||||
|
@ -1835,7 +1838,7 @@ public class RenameTypeTests extends RenameTests {
|
||||||
writer.write(" int w1; enum v1 v; \n"); //$NON-NLS-1$
|
writer.write(" int w1; enum v1 v; \n"); //$NON-NLS-1$
|
||||||
writer.write("} \n"); //$NON-NLS-1$
|
writer.write("} \n"); //$NON-NLS-1$
|
||||||
String contents = writer.toString();
|
String contents = writer.toString();
|
||||||
IFile cpp= importFile("test.c", contents ); //$NON-NLS-1$
|
IFile cpp= importFile("test.c", contents); //$NON-NLS-1$
|
||||||
|
|
||||||
int offset1= contents.indexOf("v1"); //$NON-NLS-1$
|
int offset1= contents.indexOf("v1"); //$NON-NLS-1$
|
||||||
|
|
||||||
|
@ -1923,7 +1926,7 @@ public class RenameTypeTests extends RenameTests {
|
||||||
writer.write(" } \n"); //$NON-NLS-1$
|
writer.write(" } \n"); //$NON-NLS-1$
|
||||||
writer.write("} \n"); //$NON-NLS-1$
|
writer.write("} \n"); //$NON-NLS-1$
|
||||||
String contents = writer.toString();
|
String contents = writer.toString();
|
||||||
IFile cpp= importFile("test.cpp", contents ); //$NON-NLS-1$
|
IFile cpp= importFile("test.cpp", contents); //$NON-NLS-1$
|
||||||
|
|
||||||
int offset1= contents.indexOf("v1"); //$NON-NLS-1$
|
int offset1= contents.indexOf("v1"); //$NON-NLS-1$
|
||||||
int offset2= contents.indexOf("v2"); //$NON-NLS-1$
|
int offset2= contents.indexOf("v2"); //$NON-NLS-1$
|
||||||
|
@ -2174,7 +2177,7 @@ public class RenameTypeTests extends RenameTests {
|
||||||
writer.write(" int w1; v1 v; \n"); //$NON-NLS-1$
|
writer.write(" int w1; v1 v; \n"); //$NON-NLS-1$
|
||||||
writer.write("} \n"); //$NON-NLS-1$
|
writer.write("} \n"); //$NON-NLS-1$
|
||||||
String contents = writer.toString();
|
String contents = writer.toString();
|
||||||
IFile cpp= importFile("test.c", contents ); //$NON-NLS-1$
|
IFile cpp= importFile("test.c", contents); //$NON-NLS-1$
|
||||||
|
|
||||||
int offset1= contents.indexOf("v1"); //$NON-NLS-1$
|
int offset1= contents.indexOf("v1"); //$NON-NLS-1$
|
||||||
|
|
||||||
|
@ -2255,42 +2258,61 @@ public class RenameTypeTests extends RenameTests {
|
||||||
writer.write(" String(); \n"); //$NON-NLS-1$
|
writer.write(" String(); \n"); //$NON-NLS-1$
|
||||||
writer.write(" String(const String &other); \n"); //$NON-NLS-1$
|
writer.write(" String(const String &other); \n"); //$NON-NLS-1$
|
||||||
writer.write(" ~String(); \n"); //$NON-NLS-1$
|
writer.write(" ~String(); \n"); //$NON-NLS-1$
|
||||||
writer.write(" String &operator=( const String &other ); \n"); //$NON-NLS-1$
|
writer.write(" String &operator=(const String &other); \n"); //$NON-NLS-1$
|
||||||
writer.write("}; \n"); //$NON-NLS-1$
|
writer.write("}; \n"); //$NON-NLS-1$
|
||||||
writer.write(" String::String(){} \n"); //$NON-NLS-1$
|
writer.write(" String::String() {} \n"); //$NON-NLS-1$
|
||||||
writer.write(" String::String(const String &other){}; \n"); //$NON-NLS-1$
|
writer.write(" String::String(const String &other) {}; \n"); //$NON-NLS-1$
|
||||||
writer.write(" String::~String(){}; \n"); //$NON-NLS-1$
|
writer.write(" String::~String() {}; \n"); //$NON-NLS-1$
|
||||||
writer.write(" String& String::operator=( const String &other ) \n"); //$NON-NLS-1$
|
writer.write(" String& String::operator=(const String &other) \n"); //$NON-NLS-1$
|
||||||
writer.write(" {return *this;} \n"); //$NON-NLS-1$
|
writer.write(" {return *this;} \n"); //$NON-NLS-1$
|
||||||
String contents = writer.toString();
|
String contents = writer.toString();
|
||||||
IFile cpp= importFile("test.cpp", contents ); //$NON-NLS-1$
|
IFile cpp= importFile("test.cpp", contents); //$NON-NLS-1$
|
||||||
|
|
||||||
int offset1= contents.indexOf("String"); //$NON-NLS-1$
|
int offset= contents.indexOf("String"); //$NON-NLS-1$
|
||||||
|
|
||||||
// conflicting renamings
|
// conflicting renamings
|
||||||
RefactoringStatus status= checkConditions(cpp, offset1, "CString"); //$NON-NLS-1$
|
RefactoringStatus status= checkConditions(cpp, offset, "CString"); //$NON-NLS-1$
|
||||||
assertRefactoringOk(status);
|
assertRefactoringOk(status);
|
||||||
Change ch= getRefactorChanges(cpp, offset1, "CString"); //$NON-NLS-1$
|
Change ch= getRefactorChanges(cpp, offset, "CString"); //$NON-NLS-1$
|
||||||
assertTotalChanges(countOccurrences(contents, "String"), ch); //$NON-NLS-1$
|
assertTotalChanges(countOccurrences(contents, "String"), ch); //$NON-NLS-1$
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testUsingDeclaration_332895() throws Exception {
|
||||||
|
StringWriter writer = new StringWriter();
|
||||||
|
writer.write("namespace ns { \n"); //$NON-NLS-1$
|
||||||
|
writer.write("typedef int MyType; \n"); //$NON-NLS-1$
|
||||||
|
writer.write("} \n"); //$NON-NLS-1$
|
||||||
|
writer.write(" \n"); //$NON-NLS-1$
|
||||||
|
writer.write("using ns::MyType; \n"); //$NON-NLS-1$
|
||||||
|
writer.write("MyType a; \n"); //$NON-NLS-1$
|
||||||
|
String contents = writer.toString();
|
||||||
|
IFile cpp= importFile("test.cpp", contents); //$NON-NLS-1$
|
||||||
|
|
||||||
|
int offset= contents.indexOf("MyType"); //$NON-NLS-1$
|
||||||
|
|
||||||
|
RefactoringStatus status= checkConditions(cpp, offset, "YourType"); //$NON-NLS-1$
|
||||||
|
assertRefactoringOk(status);
|
||||||
|
Change ch= getRefactorChanges(cpp, offset, "YourType"); //$NON-NLS-1$
|
||||||
|
assertTotalChanges(countOccurrences(contents, "MyType"), ch); //$NON-NLS-1$
|
||||||
|
}
|
||||||
|
|
||||||
public void testBug72888() throws Exception {
|
public void testBug72888() throws Exception {
|
||||||
StringWriter writer = new StringWriter();
|
StringWriter writer = new StringWriter();
|
||||||
writer.write("class MyEx {}; \n"); //$NON-NLS-1$
|
writer.write("class MyEx {}; \n"); //$NON-NLS-1$
|
||||||
writer.write("void someFunc() { \n"); //$NON-NLS-1$
|
writer.write("void someFunc() { \n"); //$NON-NLS-1$
|
||||||
writer.write(" throw MyEx(); \n"); //$NON-NLS-1$
|
writer.write(" throw MyEx(); \n"); //$NON-NLS-1$
|
||||||
writer.write("}; \n"); //$NON-NLS-1$
|
writer.write("}; \n"); //$NON-NLS-1$
|
||||||
writer.write("int main(){ \n"); //$NON-NLS-1$
|
writer.write("int main(){ \n"); //$NON-NLS-1$
|
||||||
writer.write(" try{ \n"); //$NON-NLS-1$
|
writer.write(" try { \n"); //$NON-NLS-1$
|
||||||
writer.write(" someFunc(); \n"); //$NON-NLS-1$
|
writer.write(" someFunc(); \n"); //$NON-NLS-1$
|
||||||
writer.write(" } catch(MyEx &e) {} \n"); //$NON-NLS-1$
|
writer.write(" } catch(MyEx &e) {} \n"); //$NON-NLS-1$
|
||||||
writer.write(" return 0; \n"); //$NON-NLS-1$
|
writer.write(" return 0; \n"); //$NON-NLS-1$
|
||||||
writer.write("} \n"); //$NON-NLS-1$
|
writer.write("} \n"); //$NON-NLS-1$
|
||||||
String contents = writer.toString();
|
String contents = writer.toString();
|
||||||
IFile cpp= importFile("test.cpp", contents ); //$NON-NLS-1$
|
IFile cpp= importFile("test.cpp", contents); //$NON-NLS-1$
|
||||||
|
|
||||||
int offset = contents.indexOf("MyEx") ; //$NON-NLS-1$
|
int offset = contents.indexOf("MyEx") ; //$NON-NLS-1$
|
||||||
Change changes = getRefactorChanges(cpp, offset, "xx"); //$NON-NLS-1$
|
Change changes = getRefactorChanges(cpp, offset, "xx"); //$NON-NLS-1$
|
||||||
assertTotalChanges( 3, changes );
|
assertTotalChanges(3, changes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2005, 2011 Wind River Systems, Inc. and others.
|
* Copyright (c) 2005, 2012 Wind River Systems, Inc. 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
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
|
@ -97,6 +97,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespaceScope;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespaceScope;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPReferenceType;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPReferenceType;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateTypeParameter;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateTypeParameter;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDeclaration;
|
||||||
import org.eclipse.cdt.core.index.IIndex;
|
import org.eclipse.cdt.core.index.IIndex;
|
||||||
import org.eclipse.cdt.core.index.IIndexBinding;
|
import org.eclipse.cdt.core.index.IIndexBinding;
|
||||||
import org.eclipse.cdt.core.index.IIndexName;
|
import org.eclipse.cdt.core.index.IIndexName;
|
||||||
|
@ -1208,18 +1209,27 @@ public class ASTManager implements IDisposable {
|
||||||
} else {
|
} else {
|
||||||
final IASTTranslationUnit tu = name.getTranslationUnit();
|
final IASTTranslationUnit tu = name.getTranslationUnit();
|
||||||
final IIndex index= tu != null ? tu.getIndex() : null;
|
final IIndex index= tu != null ? tu.getIndex() : null;
|
||||||
for (IBinding renameBinding : fValidBindings) {
|
IBinding[] bindings = binding instanceof ICPPUsingDeclaration ?
|
||||||
try {
|
((ICPPUsingDeclaration) binding).getDelegates() : new IBinding[] { binding };
|
||||||
int cmp0= isSameBinding(index, binding, renameBinding);
|
// When a 'using' declaration has multiple delegate bindings and only some of them
|
||||||
if (cmp0 != FALSE) {
|
// are being renamed, to preserve correctness of the code we would have to split
|
||||||
cmp= cmp0;
|
// the 'using' declaration into two separate ones. We currently don't do that and
|
||||||
}
|
// rename the 'using' declaration if at least one of its delegate bindings is being
|
||||||
if (cmp0 == TRUE) {
|
// renamed.
|
||||||
break;
|
outer: for (IBinding b : bindings) {
|
||||||
}
|
for (IBinding renameBinding : fValidBindings) {
|
||||||
} catch (DOMException e) {
|
try {
|
||||||
handleDOMException(name.getTranslationUnit(), e, status);
|
int cmp0= isSameBinding(index, b, renameBinding);
|
||||||
cmp= UNKNOWN;
|
if (cmp0 != FALSE) {
|
||||||
|
cmp= cmp0;
|
||||||
|
}
|
||||||
|
if (cmp0 == TRUE) {
|
||||||
|
break outer;
|
||||||
|
}
|
||||||
|
} catch (DOMException e) {
|
||||||
|
handleDOMException(name.getTranslationUnit(), e, status);
|
||||||
|
cmp= UNKNOWN;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue