1
0
Fork 0
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:
Sergey Prigogin 2012-04-24 18:24:05 -07:00
parent 10f7e547a1
commit c7be116351
2 changed files with 76 additions and 44 deletions

View file

@ -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
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -7,6 +7,7 @@
*
* Contributors:
* Markus Schorn - initial API and implementation
* Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.ui.tests.refactoring.rename;
@ -27,9 +28,11 @@ public class RenameTypeTests extends RenameTests {
public RenameTypeTests(String name) {
super(name);
}
public static Test suite() {
return suite(true);
}
public static Test suite(boolean cleanup) {
TestSuite suite = new TestSuite(RenameTypeTests.class);
if (cleanup) {
@ -2265,15 +2268,34 @@ public class RenameTypeTests extends RenameTests {
String contents = writer.toString();
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
RefactoringStatus status= checkConditions(cpp, offset1, "CString"); //$NON-NLS-1$
RefactoringStatus status= checkConditions(cpp, offset, "CString"); //$NON-NLS-1$
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$
}
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 {
StringWriter writer = new StringWriter();
writer.write("class MyEx {}; \n"); //$NON-NLS-1$

View file

@ -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
* are made available under the terms of the Eclipse Public License v1.0
* 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.ICPPReferenceType;
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.IIndexBinding;
import org.eclipse.cdt.core.index.IIndexName;
@ -1208,14 +1209,22 @@ public class ASTManager implements IDisposable {
} else {
final IASTTranslationUnit tu = name.getTranslationUnit();
final IIndex index= tu != null ? tu.getIndex() : null;
IBinding[] bindings = binding instanceof ICPPUsingDeclaration ?
((ICPPUsingDeclaration) binding).getDelegates() : new IBinding[] { binding };
// When a 'using' declaration has multiple delegate bindings and only some of them
// are being renamed, to preserve correctness of the code we would have to split
// 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
// renamed.
outer: for (IBinding b : bindings) {
for (IBinding renameBinding : fValidBindings) {
try {
int cmp0= isSameBinding(index, binding, renameBinding);
int cmp0= isSameBinding(index, b, renameBinding);
if (cmp0 != FALSE) {
cmp= cmp0;
}
if (cmp0 == TRUE) {
break;
break outer;
}
} catch (DOMException e) {
handleDOMException(name.getTranslationUnit(), e, status);
@ -1223,6 +1232,7 @@ public class ASTManager implements IDisposable {
}
}
}
}
fKnownBindings.put(binding, new Integer(cmp));
}
switch (cmp) {