1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Bug 434917 - Rename refactoring misses macro reference.

This commit is contained in:
Sergey Prigogin 2014-05-14 20:37:45 -07:00
parent b75e994cb1
commit c8b14a3c3e
9 changed files with 58 additions and 27 deletions

View file

@ -1125,6 +1125,14 @@ public class PDOM extends PlatformObject implements IPDOM {
if (linkage != null) {
return findBindingInLinkage(linkage, binding, includeLocal);
}
if (binding instanceof IMacroBinding) {
for (PDOMLinkage linkage2 : fLinkageIDCache.values()) {
IIndexFragmentBinding pdomBinding = findBindingInLinkage(linkage2, binding, includeLocal);
if (pdomBinding != null)
return pdomBinding;
}
}
return null;
}

View file

@ -19,7 +19,7 @@ import org.eclipse.core.resources.IFile;
import org.eclipse.ltk.core.refactoring.Change;
import org.eclipse.ltk.core.refactoring.RefactoringStatus;
public class RenameFunctionTests extends RenameTests {
public class RenameFunctionTests extends RenameTestBase {
public RenameFunctionTests(String name) {
super(name);

View file

@ -1,12 +1,13 @@
/*******************************************************************************
* Copyright (c) 2005, 2008 Wind River Systems, Inc.
* Copyright (c) 2005, 2014 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
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Markus Schorn - initial API and implementation
* Markus Schorn - initial API and implementation
* Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.ui.tests.refactoring.rename;
@ -17,7 +18,7 @@ import org.eclipse.core.resources.IFile;
import org.eclipse.ltk.core.refactoring.Change;
import org.eclipse.ltk.core.refactoring.RefactoringStatus;
public class RenameMacroTests extends RenameTests {
public class RenameMacroTests extends RenameTestBase {
public RenameMacroTests(String name) {
super(name);
@ -173,6 +174,23 @@ public class RenameMacroTests extends RenameTests {
assertTotalChanges(2, ch);
}
public void testMacroRename_434917() throws Exception {
StringBuilder buf = new StringBuilder();
buf.append("#define CC mm\n"); //$NON-NLS-1$
String contents = buf.toString();
IFile header= importFile("test.h", contents); //$NON-NLS-1$
buf = new StringBuilder();
buf.append("#include \"test.h\"\n");
buf.append("int CC;\n"); //$NON-NLS-1$
String contents2 = buf.toString();
IFile source= importFile("test.cpp", contents2); //$NON-NLS-1$
int offset= contents.indexOf("CC"); //$NON-NLS-1$
Change ch= getRefactorChanges(header, offset, "CCC"); //$NON-NLS-1$
assertTotalChanges(2, ch);
}
public void testIncludeGuard() throws Exception {
StringBuilder buf = new StringBuilder();
buf.append("#ifndef _guard \n"); //$NON-NLS-1$

View file

@ -25,7 +25,7 @@ import org.eclipse.ltk.core.refactoring.participants.RenameArguments;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.tests.FailingTest;
public class RenameRegressionTests extends RenameTests {
public class RenameRegressionTests extends RenameTestBase {
public RenameRegressionTests() {
super();
}

View file

@ -22,7 +22,7 @@ import org.eclipse.ltk.core.refactoring.RefactoringStatus;
/**
* @author markus.schorn@windriver.com
*/
public class RenameTemplatesTests extends RenameTests {
public class RenameTemplatesTests extends RenameTestBase {
public RenameTemplatesTests(String name) {
super(name);

View file

@ -1,12 +1,13 @@
/*******************************************************************************
* Copyright (c) 2005, 2010 Wind River Systems, Inc.
* Copyright (c) 2005, 2014 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
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Markus Schorn - initial API and implementation
* Contributors:
* Markus Schorn - initial API and implementation
* Sergey Prigogin (Google)
******************************************************************************/
package org.eclipse.cdt.ui.tests.refactoring.rename;
@ -27,19 +28,19 @@ import org.eclipse.cdt.internal.ui.refactoring.rename.TextSearchWrapper;
/**
* @author markus.schorn@windriver.com
*/
public class RenameTests extends RefactoringTests {
public class RenameTestBase extends RefactoringTests {
private static final IProgressMonitor NPM = new NullProgressMonitor();
public RenameTests(String name) {
public RenameTestBase(String name) {
super(name);
}
public RenameTests() {
public RenameTestBase() {
}
/**
* @param element The CElement to rename
* @param newName The new name for the element
* @param element the CElement to rename
* @param newName the new name for the element
* @return
* @throws Exception
*/
@ -54,11 +55,11 @@ public class RenameTests extends RefactoringTests {
return change;
}
fail ("Input check on " + newName + " failed. "+rs.getEntryMatchingSeverity(RefactoringStatus.ERROR)); //$NON-NLS-1$ //$NON-NLS-2$
//rs.getFirstMessage(RefactoringStatus.ERROR) is not the message displayed in
//the UI for renaming a method to a constructor, the first message which is only
//a warning is shown in the UI. If you click preview, then the error and the warning
//is shown.
fail("Input check on " + newName + " failed. " + rs.getEntryMatchingSeverity(RefactoringStatus.ERROR));
// rs.getFirstMessage(RefactoringStatus.ERROR) is not the message displayed in
// the UI for renaming a method to a constructor, the first message which is only
// a warning is shown in the UI. If you click preview, then the error and the warning
// is shown.
return null;
} finally {
((CRenameProcessor) proc.getProcessor()).unlockIndex();
@ -69,7 +70,7 @@ public class RenameTests extends RefactoringTests {
CRefactoringArgument arg= new CRefactoringArgument(file, offset, 0);
CRenameProcessor proc= new CRenameProcessor(CRefactory.getInstance(), arg);
proc.setReplacementText(newName);
proc.setSelectedOptions(-1);
proc.setSelectedOptions(0xFFFF & ~CRefactory.OPTION_EXHAUSTIVE_FILE_SEARCH);
proc.setExhaustiveSearchScope(TextSearchWrapper.SCOPE_WORKSPACE);
return new CRenameRefactoring(proc);
}
@ -81,7 +82,7 @@ public class RenameTests extends RefactoringTests {
try {
RefactoringStatus rs = checkConditions(proc);
if (!rs.hasWarning()) {
fail ("Input check on "+ newName + " passed. There should have been warnings or errors.") ; //$NON-NLS-1$ //$NON-NLS-2$
fail("Input check on "+ newName + " passed. There should have been warnings or errors.");
return null;
}
RefactoringStatusEntry[] rse = rs.getEntries();
@ -108,7 +109,7 @@ public class RenameTests extends RefactoringTests {
}
private RefactoringStatus checkConditions(CRenameRefactoring proc) throws CoreException {
RefactoringStatus rs =proc.checkInitialConditions(new NullProgressMonitor());
RefactoringStatus rs = proc.checkInitialConditions(new NullProgressMonitor());
if (!rs.hasError()) {
rs= proc.checkFinalConditions(new NullProgressMonitor());
}
@ -131,7 +132,7 @@ public class RenameTests extends RefactoringTests {
int count= 0;
while (idx >= 0) {
count++;
idx= contents.indexOf(lookup, idx+lookup.length());
idx= contents.indexOf(lookup, idx + lookup.length());
}
return count;
}

View file

@ -23,7 +23,7 @@ import org.eclipse.ltk.core.refactoring.RefactoringStatus;
/**
* @author markus.schorn@windriver.com
*/
public class RenameTypeTests extends RenameTests {
public class RenameTypeTests extends RenameTestBase {
public RenameTypeTests(String name) {
super(name);

View file

@ -22,7 +22,7 @@ import org.eclipse.ltk.core.refactoring.RefactoringStatus;
/**
* @author markus.schorn@windriver.com
*/
public class RenameVariableTests extends RenameTests {
public class RenameVariableTests extends RenameTestBase {
public RenameVariableTests(String name) {
super(name);

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2005, 2010 Wind River Systems, Inc and others.
* Copyright (c) 2005, 2014 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
@ -41,7 +41,11 @@ public class CRenameMacroProcessor extends CRenameGlobalProcessor {
protected void analyzeTextMatches(IBinding[] renameBindings, Collection<CRefactoringMatch> matches,
IProgressMonitor monitor, RefactoringStatus status) {
for (CRefactoringMatch m : matches) {
if ((m.getLocation() & CRefactory.OPTION_IN_PREPROCESSOR_DIRECTIVE) != 0) {
if ((m.getLocation() & CRefactory.OPTION_IN_PREPROCESSOR_DIRECTIVE) != 0 ||
// Occurrences in code are reliable only when exhaustive file search is not used.
// TODO(sprigogin): Use index matches to endorse matches obtained from the file search.
(getSelectedOptions() & CRefactory.OPTION_EXHAUSTIVE_FILE_SEARCH) == 0 &&
(m.getLocation() & CRefactory.OPTION_IN_CODE_REFERENCES) != 0) {
m.setASTInformation(CRefactoringMatch.AST_REFERENCE);
}
}