mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-07 17:56:01 +02:00
Bug 434917 - Rename refactoring misses macro reference.
This commit is contained in:
parent
b75e994cb1
commit
c8b14a3c3e
9 changed files with 58 additions and 27 deletions
|
@ -1125,6 +1125,14 @@ public class PDOM extends PlatformObject implements IPDOM {
|
||||||
if (linkage != null) {
|
if (linkage != null) {
|
||||||
return findBindingInLinkage(linkage, binding, includeLocal);
|
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;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,7 @@ import org.eclipse.core.resources.IFile;
|
||||||
import org.eclipse.ltk.core.refactoring.Change;
|
import org.eclipse.ltk.core.refactoring.Change;
|
||||||
import org.eclipse.ltk.core.refactoring.RefactoringStatus;
|
import org.eclipse.ltk.core.refactoring.RefactoringStatus;
|
||||||
|
|
||||||
public class RenameFunctionTests extends RenameTests {
|
public class RenameFunctionTests extends RenameTestBase {
|
||||||
|
|
||||||
public RenameFunctionTests(String name) {
|
public RenameFunctionTests(String name) {
|
||||||
super(name);
|
super(name);
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* 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
|
* 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;
|
||||||
|
|
||||||
|
@ -17,7 +18,7 @@ import org.eclipse.core.resources.IFile;
|
||||||
import org.eclipse.ltk.core.refactoring.Change;
|
import org.eclipse.ltk.core.refactoring.Change;
|
||||||
import org.eclipse.ltk.core.refactoring.RefactoringStatus;
|
import org.eclipse.ltk.core.refactoring.RefactoringStatus;
|
||||||
|
|
||||||
public class RenameMacroTests extends RenameTests {
|
public class RenameMacroTests extends RenameTestBase {
|
||||||
|
|
||||||
public RenameMacroTests(String name) {
|
public RenameMacroTests(String name) {
|
||||||
super(name);
|
super(name);
|
||||||
|
@ -173,6 +174,23 @@ public class RenameMacroTests extends RenameTests {
|
||||||
assertTotalChanges(2, ch);
|
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 {
|
public void testIncludeGuard() throws Exception {
|
||||||
StringBuilder buf = new StringBuilder();
|
StringBuilder buf = new StringBuilder();
|
||||||
buf.append("#ifndef _guard \n"); //$NON-NLS-1$
|
buf.append("#ifndef _guard \n"); //$NON-NLS-1$
|
||||||
|
|
|
@ -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.dom.ast.IBinding;
|
||||||
import org.eclipse.cdt.core.tests.FailingTest;
|
import org.eclipse.cdt.core.tests.FailingTest;
|
||||||
|
|
||||||
public class RenameRegressionTests extends RenameTests {
|
public class RenameRegressionTests extends RenameTestBase {
|
||||||
public RenameRegressionTests() {
|
public RenameRegressionTests() {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,7 @@ import org.eclipse.ltk.core.refactoring.RefactoringStatus;
|
||||||
/**
|
/**
|
||||||
* @author markus.schorn@windriver.com
|
* @author markus.schorn@windriver.com
|
||||||
*/
|
*/
|
||||||
public class RenameTemplatesTests extends RenameTests {
|
public class RenameTemplatesTests extends RenameTestBase {
|
||||||
|
|
||||||
public RenameTemplatesTests(String name) {
|
public RenameTemplatesTests(String name) {
|
||||||
super(name);
|
super(name);
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* 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
|
* 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,19 +28,19 @@ import org.eclipse.cdt.internal.ui.refactoring.rename.TextSearchWrapper;
|
||||||
/**
|
/**
|
||||||
* @author markus.schorn@windriver.com
|
* @author markus.schorn@windriver.com
|
||||||
*/
|
*/
|
||||||
public class RenameTests extends RefactoringTests {
|
public class RenameTestBase extends RefactoringTests {
|
||||||
private static final IProgressMonitor NPM = new NullProgressMonitor();
|
private static final IProgressMonitor NPM = new NullProgressMonitor();
|
||||||
|
|
||||||
public RenameTests(String name) {
|
public RenameTestBase(String name) {
|
||||||
super(name);
|
super(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public RenameTests() {
|
public RenameTestBase() {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param element The CElement to rename
|
* @param element the CElement to rename
|
||||||
* @param newName The new name for the element
|
* @param newName the new name for the element
|
||||||
* @return
|
* @return
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
|
@ -54,11 +55,11 @@ public class RenameTests extends RefactoringTests {
|
||||||
return change;
|
return change;
|
||||||
}
|
}
|
||||||
|
|
||||||
fail ("Input check on " + newName + " failed. "+rs.getEntryMatchingSeverity(RefactoringStatus.ERROR)); //$NON-NLS-1$ //$NON-NLS-2$
|
fail("Input check on " + newName + " failed. " + rs.getEntryMatchingSeverity(RefactoringStatus.ERROR));
|
||||||
//rs.getFirstMessage(RefactoringStatus.ERROR) is not the message displayed in
|
// 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
|
// 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
|
// a warning is shown in the UI. If you click preview, then the error and the warning
|
||||||
//is shown.
|
// is shown.
|
||||||
return null;
|
return null;
|
||||||
} finally {
|
} finally {
|
||||||
((CRenameProcessor) proc.getProcessor()).unlockIndex();
|
((CRenameProcessor) proc.getProcessor()).unlockIndex();
|
||||||
|
@ -69,7 +70,7 @@ public class RenameTests extends RefactoringTests {
|
||||||
CRefactoringArgument arg= new CRefactoringArgument(file, offset, 0);
|
CRefactoringArgument arg= new CRefactoringArgument(file, offset, 0);
|
||||||
CRenameProcessor proc= new CRenameProcessor(CRefactory.getInstance(), arg);
|
CRenameProcessor proc= new CRenameProcessor(CRefactory.getInstance(), arg);
|
||||||
proc.setReplacementText(newName);
|
proc.setReplacementText(newName);
|
||||||
proc.setSelectedOptions(-1);
|
proc.setSelectedOptions(0xFFFF & ~CRefactory.OPTION_EXHAUSTIVE_FILE_SEARCH);
|
||||||
proc.setExhaustiveSearchScope(TextSearchWrapper.SCOPE_WORKSPACE);
|
proc.setExhaustiveSearchScope(TextSearchWrapper.SCOPE_WORKSPACE);
|
||||||
return new CRenameRefactoring(proc);
|
return new CRenameRefactoring(proc);
|
||||||
}
|
}
|
||||||
|
@ -81,7 +82,7 @@ public class RenameTests extends RefactoringTests {
|
||||||
try {
|
try {
|
||||||
RefactoringStatus rs = checkConditions(proc);
|
RefactoringStatus rs = checkConditions(proc);
|
||||||
if (!rs.hasWarning()) {
|
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;
|
return null;
|
||||||
}
|
}
|
||||||
RefactoringStatusEntry[] rse = rs.getEntries();
|
RefactoringStatusEntry[] rse = rs.getEntries();
|
||||||
|
@ -108,7 +109,7 @@ public class RenameTests extends RefactoringTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
private RefactoringStatus checkConditions(CRenameRefactoring proc) throws CoreException {
|
private RefactoringStatus checkConditions(CRenameRefactoring proc) throws CoreException {
|
||||||
RefactoringStatus rs =proc.checkInitialConditions(new NullProgressMonitor());
|
RefactoringStatus rs = proc.checkInitialConditions(new NullProgressMonitor());
|
||||||
if (!rs.hasError()) {
|
if (!rs.hasError()) {
|
||||||
rs= proc.checkFinalConditions(new NullProgressMonitor());
|
rs= proc.checkFinalConditions(new NullProgressMonitor());
|
||||||
}
|
}
|
||||||
|
@ -131,7 +132,7 @@ public class RenameTests extends RefactoringTests {
|
||||||
int count= 0;
|
int count= 0;
|
||||||
while (idx >= 0) {
|
while (idx >= 0) {
|
||||||
count++;
|
count++;
|
||||||
idx= contents.indexOf(lookup, idx+lookup.length());
|
idx= contents.indexOf(lookup, idx + lookup.length());
|
||||||
}
|
}
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
|
@ -23,7 +23,7 @@ import org.eclipse.ltk.core.refactoring.RefactoringStatus;
|
||||||
/**
|
/**
|
||||||
* @author markus.schorn@windriver.com
|
* @author markus.schorn@windriver.com
|
||||||
*/
|
*/
|
||||||
public class RenameTypeTests extends RenameTests {
|
public class RenameTypeTests extends RenameTestBase {
|
||||||
|
|
||||||
public RenameTypeTests(String name) {
|
public RenameTypeTests(String name) {
|
||||||
super(name);
|
super(name);
|
||||||
|
|
|
@ -22,7 +22,7 @@ import org.eclipse.ltk.core.refactoring.RefactoringStatus;
|
||||||
/**
|
/**
|
||||||
* @author markus.schorn@windriver.com
|
* @author markus.schorn@windriver.com
|
||||||
*/
|
*/
|
||||||
public class RenameVariableTests extends RenameTests {
|
public class RenameVariableTests extends RenameTestBase {
|
||||||
|
|
||||||
public RenameVariableTests(String name) {
|
public RenameVariableTests(String name) {
|
||||||
super(name);
|
super(name);
|
||||||
|
|
|
@ -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
|
* 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
|
||||||
|
@ -41,7 +41,11 @@ public class CRenameMacroProcessor extends CRenameGlobalProcessor {
|
||||||
protected void analyzeTextMatches(IBinding[] renameBindings, Collection<CRefactoringMatch> matches,
|
protected void analyzeTextMatches(IBinding[] renameBindings, Collection<CRefactoringMatch> matches,
|
||||||
IProgressMonitor monitor, RefactoringStatus status) {
|
IProgressMonitor monitor, RefactoringStatus status) {
|
||||||
for (CRefactoringMatch m : matches) {
|
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);
|
m.setASTInformation(CRefactoringMatch.AST_REFERENCE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue