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,9 +28,11 @@ 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) {
|
||||||
|
@ -2265,15 +2268,34 @@ public class RenameTypeTests extends RenameTests {
|
||||||
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$
|
||||||
|
|
|
@ -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,14 +1209,22 @@ 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;
|
||||||
|
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) {
|
for (IBinding renameBinding : fValidBindings) {
|
||||||
try {
|
try {
|
||||||
int cmp0= isSameBinding(index, binding, renameBinding);
|
int cmp0= isSameBinding(index, b, renameBinding);
|
||||||
if (cmp0 != FALSE) {
|
if (cmp0 != FALSE) {
|
||||||
cmp= cmp0;
|
cmp= cmp0;
|
||||||
}
|
}
|
||||||
if (cmp0 == TRUE) {
|
if (cmp0 == TRUE) {
|
||||||
break;
|
break outer;
|
||||||
}
|
}
|
||||||
} catch (DOMException e) {
|
} catch (DOMException e) {
|
||||||
handleDOMException(name.getTranslationUnit(), e, status);
|
handleDOMException(name.getTranslationUnit(), e, status);
|
||||||
|
@ -1223,6 +1232,7 @@ public class ASTManager implements IDisposable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
fKnownBindings.put(binding, new Integer(cmp));
|
fKnownBindings.put(binding, new Integer(cmp));
|
||||||
}
|
}
|
||||||
switch (cmp) {
|
switch (cmp) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue