mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-30 12:25:35 +02:00
Fixed a bug in renaming of virtual methods.
This commit is contained in:
parent
b937c5c50b
commit
57425dde44
6 changed files with 108 additions and 116 deletions
|
@ -115,8 +115,8 @@ import org.eclipse.cdt.internal.corext.util.CModelUtil;
|
||||||
import org.eclipse.cdt.internal.ui.editor.ASTProvider;
|
import org.eclipse.cdt.internal.ui.editor.ASTProvider;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Used per refactoring to cache the IASTTranslationUnits. Collects methods operating
|
* Used for refactoring to cache the IASTTranslationUnits.
|
||||||
* on ASTNodes.
|
* Contains a collection of methods operating on ASTNodes.
|
||||||
*/
|
*/
|
||||||
public class ASTManager {
|
public class ASTManager {
|
||||||
public final static int TRUE= 1;
|
public final static int TRUE= 1;
|
||||||
|
@ -331,8 +331,7 @@ public class ASTManager {
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (node1 instanceof IASTTranslationUnit &&
|
if (node1 instanceof IASTTranslationUnit && node2 instanceof IASTTranslationUnit) {
|
||||||
node2 instanceof IASTTranslationUnit) {
|
|
||||||
return hasSameLocation(node1, node2, fileStatic);
|
return hasSameLocation(node1, node2, fileStatic);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -425,8 +424,7 @@ public class ASTManager {
|
||||||
return isSameParameterList(b1.getParameterTypes(), b2.getParameterTypes());
|
return isSameParameterList(b1.getParameterTypes(), b2.getParameterTypes());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int isSameParameterList(IType[] p1,
|
private static int isSameParameterList(IType[] p1, IType[] p2) throws DOMException {
|
||||||
IType[] p2) throws DOMException {
|
|
||||||
if (p1 == p2) {
|
if (p1 == p2) {
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
@ -484,8 +482,7 @@ public class ASTManager {
|
||||||
if (t1 == t2) {
|
if (t1 == t2) {
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
if (t1 == null || t2 == null || t1 instanceof IProblemBinding ||
|
if (t1 == null || t2 == null || t1 instanceof IProblemBinding || t2 instanceof IProblemBinding) {
|
||||||
t2 instanceof IProblemBinding) {
|
|
||||||
return UNKNOWN;
|
return UNKNOWN;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -750,8 +747,8 @@ public class ASTManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IBinding[] findInScope(final IScope scope, String name,
|
public static IBinding[] findInScope(final IScope scope, String name, boolean removeGlobalsWhenClassScope)
|
||||||
boolean removeGlobalsWhenClassScope) throws DOMException {
|
throws DOMException {
|
||||||
IBinding[] result= null;
|
IBinding[] result= null;
|
||||||
result = scope.find(name);
|
result = scope.find(name);
|
||||||
if (result == null || result.length == 0) {
|
if (result == null || result.length == 0) {
|
||||||
|
@ -841,7 +838,8 @@ public class ASTManager {
|
||||||
node instanceof IASTPreprocessorIfStatement) {
|
node instanceof IASTPreprocessorIfStatement) {
|
||||||
final IASTFileLocation fileLocation = node.getFileLocation();
|
final IASTFileLocation fileLocation = node.getFileLocation();
|
||||||
if (fileLocation != null) {
|
if (fileLocation != null) {
|
||||||
final String ident= extractIdentifier(node.getRawSignature(), offset - fileLocation.getNodeOffset(), length);
|
final String ident= extractIdentifier(node.getRawSignature(),
|
||||||
|
offset - fileLocation.getNodeOffset(), length);
|
||||||
if (ident != null) {
|
if (ident != null) {
|
||||||
IASTPreprocessorMacroDefinition[] mdefs= tu.getMacroDefinitions();
|
IASTPreprocessorMacroDefinition[] mdefs= tu.getMacroDefinitions();
|
||||||
for (IASTPreprocessorMacroDefinition mdef : mdefs) {
|
for (IASTPreprocessorMacroDefinition mdef : mdefs) {
|
||||||
|
@ -898,22 +896,13 @@ public class ASTManager {
|
||||||
return rawSignature.substring(offset, end);
|
return rawSignature.substring(offset, end);
|
||||||
}
|
}
|
||||||
|
|
||||||
private IASTTranslationUnit getTranslationUnit(IIndex index, IFile sourceFile,
|
private IASTTranslationUnit getTranslationUnit(IIndex index, IFile sourceFile, boolean cacheit,
|
||||||
boolean cacheit, RefactoringStatus status) {
|
RefactoringStatus status) {
|
||||||
IASTTranslationUnit ast= fTranslationUnits.get(sourceFile);
|
IASTTranslationUnit ast= fTranslationUnits.get(sourceFile);
|
||||||
if (ast == null) {
|
if (ast == null) {
|
||||||
ICElement celem= CoreModel.getDefault().create(sourceFile);
|
ICElement celem= CoreModel.getDefault().create(sourceFile);
|
||||||
if (celem instanceof ITranslationUnit) {
|
if (celem instanceof ITranslationUnit) {
|
||||||
ITranslationUnit tu= CModelUtil.toWorkingCopy((ITranslationUnit) celem);
|
ITranslationUnit tu= CModelUtil.toWorkingCopy((ITranslationUnit) celem);
|
||||||
// if (tu instanceof IWorkingCopy) {
|
|
||||||
// synchronized (tu) {
|
|
||||||
// try {
|
|
||||||
// ast = ((IWorkingCopy) tu).reconcile(true, false, null);
|
|
||||||
// } catch (CModelException e) {
|
|
||||||
// CUIPlugin.log(e);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// Try to get a shared AST before creating our own.
|
// Try to get a shared AST before creating our own.
|
||||||
final IASTTranslationUnit[] ast_holder = new IASTTranslationUnit[1];
|
final IASTTranslationUnit[] ast_holder = new IASTTranslationUnit[1];
|
||||||
ASTProvider.getASTProvider().runOnAST(tu, ASTProvider.WAIT_IF_OPEN, null, new ASTRunnable() {
|
ASTProvider.getASTProvider().runOnAST(tu, ASTProvider.WAIT_IF_OPEN, null, new ASTRunnable() {
|
||||||
|
@ -942,8 +931,8 @@ public class ASTManager {
|
||||||
return ast;
|
return ast;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void analyzeTextMatches(IIndex index, ArrayList<CRefactoringMatch> matches, IProgressMonitor monitor,
|
public void analyzeTextMatches(IIndex index, Collection<CRefactoringMatch> matches,
|
||||||
RefactoringStatus status) {
|
IProgressMonitor monitor, RefactoringStatus status) {
|
||||||
CRefactoringMatchStore store= new CRefactoringMatchStore();
|
CRefactoringMatchStore store= new CRefactoringMatchStore();
|
||||||
for (CRefactoringMatch match : matches) {
|
for (CRefactoringMatch match : matches) {
|
||||||
store.addMatch(match);
|
store.addMatch(match);
|
||||||
|
@ -1030,9 +1019,8 @@ public class ASTManager {
|
||||||
fConflictingBinding= null;
|
fConflictingBinding= null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void analyzeLanguageMatches(IASTTranslationUnit tu,
|
private void analyzeLanguageMatches(IASTTranslationUnit tu, final CRefactoringMatchStore store,
|
||||||
final CRefactoringMatchStore store, final Set<IPath> paths,
|
final Set<IPath> paths, final RefactoringStatus status) {
|
||||||
final RefactoringStatus status) {
|
|
||||||
ASTNameVisitor nv = new ASTSpecificNameVisitor(fArgument.getName()) {
|
ASTNameVisitor nv = new ASTSpecificNameVisitor(fArgument.getName()) {
|
||||||
@Override
|
@Override
|
||||||
protected int visitName(IASTName name, boolean isDestructor) {
|
protected int visitName(IASTName name, boolean isDestructor) {
|
||||||
|
@ -1044,9 +1032,8 @@ public class ASTManager {
|
||||||
tu.accept(nv);
|
tu.accept(nv);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void analyzeMacroMatches(IASTTranslationUnit tu,
|
private void analyzeMacroMatches(IASTTranslationUnit tu, final CRefactoringMatchStore store,
|
||||||
final CRefactoringMatchStore store, final Set<IPath> pathsVisited,
|
final Set<IPath> pathsVisited, final RefactoringStatus status) {
|
||||||
final RefactoringStatus status) {
|
|
||||||
String lookfor= fArgument.getName();
|
String lookfor= fArgument.getName();
|
||||||
IASTPreprocessorMacroDefinition[] mdefs= tu.getMacroDefinitions();
|
IASTPreprocessorMacroDefinition[] mdefs= tu.getMacroDefinitions();
|
||||||
for (IASTPreprocessorMacroDefinition mdef : mdefs) {
|
for (IASTPreprocessorMacroDefinition mdef : mdefs) {
|
||||||
|
@ -1122,10 +1109,8 @@ public class ASTManager {
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
|
|
||||||
private void findConflictingBindingsWithNewName(IASTTranslationUnit tu,
|
private void findConflictingBindingsWithNewName(IASTTranslationUnit tu, CRefactoringMatchStore store,
|
||||||
CRefactoringMatchStore store, final Set<IPath> paths,
|
final Set<IPath> paths, final RefactoringStatus status) {
|
||||||
final RefactoringStatus status) {
|
|
||||||
|
|
||||||
ASTNameVisitor nv = new ASTSpecificNameVisitor(fRenameTo) {
|
ASTNameVisitor nv = new ASTSpecificNameVisitor(fRenameTo) {
|
||||||
@Override
|
@Override
|
||||||
protected int visitName(IASTName name, boolean isDestructor) {
|
protected int visitName(IASTName name, boolean isDestructor) {
|
||||||
|
@ -1156,8 +1141,8 @@ public class ASTManager {
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected IPath analyzeAstMatch(IASTName name, CRefactoringMatchStore store,
|
protected IPath analyzeAstMatch(IASTName name, CRefactoringMatchStore store, boolean isDestructor,
|
||||||
boolean isDestructor, RefactoringStatus status) {
|
RefactoringStatus status) {
|
||||||
IPath path= null;
|
IPath path= null;
|
||||||
CRefactoringMatch match= null;
|
CRefactoringMatch match= null;
|
||||||
|
|
||||||
|
@ -1250,7 +1235,8 @@ public class ASTManager {
|
||||||
handleProblemBinding(tu, e.getProblem(), status);
|
handleProblemBinding(tu, e.getProblem(), status);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void handleProblemBinding(IASTTranslationUnit tu, final IProblemBinding pb, RefactoringStatus status) {
|
public void handleProblemBinding(IASTTranslationUnit tu, final IProblemBinding pb,
|
||||||
|
RefactoringStatus status) {
|
||||||
if (tu != null) {
|
if (tu != null) {
|
||||||
String fpath= tu.getFilePath();
|
String fpath= tu.getFilePath();
|
||||||
if (fProblemUnits.add(fpath)) {
|
if (fProblemUnits.add(fpath)) {
|
||||||
|
@ -1316,11 +1302,11 @@ public class ASTManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
Collection<IBinding>[] cflc=
|
Collection<IBinding>[] cflc=
|
||||||
new Collection[] { new HashSet<IBinding>(), new ArrayList<IBinding>(), new ArrayList<IBinding>() };
|
new Collection[] { new HashSet<IBinding>(), new ArrayList<IBinding>(),
|
||||||
|
new ArrayList<IBinding>() };
|
||||||
String[] errs= null;
|
String[] errs= null;
|
||||||
if (isMacro) {
|
if (isMacro) {
|
||||||
errs= new String[] {
|
errs= new String[] { RenameMessages.CRenameLocalProcessor_error_conflict };
|
||||||
RenameMessages.CRenameLocalProcessor_error_conflict };
|
|
||||||
cflc[0]= fConflictingBinding;
|
cflc[0]= fConflictingBinding;
|
||||||
} else {
|
} else {
|
||||||
errs= new String[] {
|
errs= new String[] {
|
||||||
|
@ -1464,9 +1450,8 @@ public class ASTManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void classifyConflictingBindings(IASTTranslationUnit tu,
|
protected void classifyConflictingBindings(IASTTranslationUnit tu, Set<IBinding> shadows,
|
||||||
Set<IBinding> shadows, Collection<IBinding> redecl, Collection<IBinding> barriers,
|
Collection<IBinding> redecl, Collection<IBinding> barriers, RefactoringStatus status) {
|
||||||
RefactoringStatus status) {
|
|
||||||
// collect bindings on higher or equal level
|
// collect bindings on higher or equal level
|
||||||
String name= fArgument.getName();
|
String name= fArgument.getName();
|
||||||
IBinding[] newBindingsAboverOrEqual= null;
|
IBinding[] newBindingsAboverOrEqual= null;
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
package org.eclipse.cdt.internal.ui.refactoring.rename;
|
package org.eclipse.cdt.internal.ui.refactoring.rename;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.Collection;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
|
||||||
import org.eclipse.core.runtime.IProgressMonitor;
|
import org.eclipse.core.runtime.IProgressMonitor;
|
||||||
|
@ -19,6 +19,7 @@ import org.eclipse.ltk.core.refactoring.RefactoringStatus;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
|
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||||
import org.eclipse.cdt.core.dom.ast.IParameter;
|
import org.eclipse.cdt.core.dom.ast.IParameter;
|
||||||
import org.eclipse.cdt.core.dom.ast.IScope;
|
import org.eclipse.cdt.core.dom.ast.IScope;
|
||||||
|
|
||||||
|
@ -52,9 +53,9 @@ public class CRenameLocalProcessor extends CRenameProcessorDelegate {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void analyzeTextMatches(ArrayList<CRefactoringMatch> matches, IProgressMonitor monitor,
|
protected void analyzeTextMatches(IBinding[] renameBindings, Collection<CRefactoringMatch> matches,
|
||||||
RefactoringStatus status) {
|
IProgressMonitor monitor, RefactoringStatus status) {
|
||||||
super.analyzeTextMatches(matches, monitor, status);
|
super.analyzeTextMatches(renameBindings, matches, monitor, status);
|
||||||
if (fScope != null) {
|
if (fScope != null) {
|
||||||
CRefactoringArgument argument = getArgument();
|
CRefactoringArgument argument = getArgument();
|
||||||
int[] result= new int[] {0, Integer.MAX_VALUE};
|
int[] result= new int[] {0, Integer.MAX_VALUE};
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2005, 2008 Wind River Systems, Inc and others.
|
* Copyright (c) 2005, 2010 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
|
||||||
|
@ -7,14 +7,17 @@
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* Markus Schorn - initial API and implementation
|
* Markus Schorn - initial API and implementation
|
||||||
|
* Sergey Prigogin (Google)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.internal.ui.refactoring.rename;
|
package org.eclipse.cdt.internal.ui.refactoring.rename;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.Collection;
|
||||||
|
|
||||||
import org.eclipse.core.runtime.IProgressMonitor;
|
import org.eclipse.core.runtime.IProgressMonitor;
|
||||||
import org.eclipse.ltk.core.refactoring.RefactoringStatus;
|
import org.eclipse.ltk.core.refactoring.RefactoringStatus;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Rename processor that sets up the input page for renaming a global entity.
|
* Rename processor that sets up the input page for renaming a global entity.
|
||||||
|
@ -36,13 +39,13 @@ public class CRenameMacroProcessor extends CRenameGlobalProcessor {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void analyzeTextMatches(ArrayList<CRefactoringMatch> matches, IProgressMonitor monitor,
|
protected void analyzeTextMatches(IBinding[] renameBindings, Collection<CRefactoringMatch> matches,
|
||||||
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) {
|
||||||
m.setASTInformation(CRefactoringMatch.AST_REFERENCE);
|
m.setASTInformation(CRefactoringMatch.AST_REFERENCE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
super.analyzeTextMatches(matches, monitor, status);
|
super.analyzeTextMatches(renameBindings, matches, monitor, status);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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.internal.ui.refactoring.rename;
|
package org.eclipse.cdt.internal.ui.refactoring.rename;
|
||||||
|
|
||||||
|
@ -63,8 +64,8 @@ public class CRenameMethodProcessor extends CRenameGlobalProcessor {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public RefactoringStatus checkFinalConditions(IProgressMonitor monitor,
|
public RefactoringStatus checkFinalConditions(IProgressMonitor monitor, CheckConditionsContext context)
|
||||||
CheckConditionsContext context) throws OperationCanceledException, CoreException {
|
throws OperationCanceledException, CoreException {
|
||||||
CRefactoringArgument argument= getArgument();
|
CRefactoringArgument argument= getArgument();
|
||||||
RefactoringStatus result= new RefactoringStatus();
|
RefactoringStatus result= new RefactoringStatus();
|
||||||
IScope scope= argument.getScope();
|
IScope scope= argument.getScope();
|
||||||
|
@ -84,7 +85,8 @@ public class CRenameMethodProcessor extends CRenameGlobalProcessor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (argument.getArgumentKind() == CRefactory.ARGUMENT_VIRTUAL_METHOD && (getSelectedOptions() & CRefactory.OPTION_DO_VIRTUAL) == 0) {
|
if (argument.getArgumentKind() == CRefactory.ARGUMENT_VIRTUAL_METHOD &&
|
||||||
|
(getSelectedOptions() & CRefactory.OPTION_DO_VIRTUAL) == 0) {
|
||||||
result.merge(RefactoringStatus.createWarningStatus(RenameMessages.CRenameMethodProcessor_warning_renameVirtual));
|
result.merge(RefactoringStatus.createWarningStatus(RenameMessages.CRenameMethodProcessor_warning_renameVirtual));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2004, 2009 Wind River Systems, Inc. and others.
|
* Copyright (c) 2004, 2010 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
|
||||||
|
@ -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.internal.ui.refactoring.rename;
|
package org.eclipse.cdt.internal.ui.refactoring.rename;
|
||||||
|
|
||||||
|
@ -182,23 +183,20 @@ public class CRenameProcessor extends RenameProcessor {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public RefactoringStatus checkFinalConditions(IProgressMonitor pm,
|
public RefactoringStatus checkFinalConditions(IProgressMonitor pm, CheckConditionsContext context)
|
||||||
CheckConditionsContext context) throws CoreException,
|
throws CoreException, OperationCanceledException {
|
||||||
OperationCanceledException {
|
|
||||||
return fDelegate.checkFinalConditions(pm, context);
|
return fDelegate.checkFinalConditions(pm, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Change createChange(IProgressMonitor pm) throws CoreException,
|
public Change createChange(IProgressMonitor pm) throws CoreException, OperationCanceledException {
|
||||||
OperationCanceledException {
|
|
||||||
return fDelegate.createChange(pm);
|
return fDelegate.createChange(pm);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public RefactoringParticipant[] loadParticipants(RefactoringStatus status,
|
public RefactoringParticipant[] loadParticipants(RefactoringStatus status,
|
||||||
SharableParticipants sharedParticipants) throws CoreException {
|
SharableParticipants sharedParticipants) throws CoreException {
|
||||||
RenameArguments arguments= new RenameArguments(getReplacementText(),
|
RenameArguments arguments= new RenameArguments(getReplacementText(), true);
|
||||||
true);
|
|
||||||
final String[] natures= {CCProjectNature.CC_NATURE_ID, CProjectNature.C_NATURE_ID};
|
final String[] natures= {CCProjectNature.CC_NATURE_ID, CProjectNature.C_NATURE_ID};
|
||||||
List<RenameParticipant> result= new ArrayList<RenameParticipant>();
|
List<RenameParticipant> result= new ArrayList<RenameParticipant>();
|
||||||
IBinding binding= getArgument().getBinding();
|
IBinding binding= getArgument().getBinding();
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2004, 2009 Wind River Systems, Inc. and others.
|
* Copyright (c) 2004, 2010 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
|
||||||
|
@ -53,7 +53,7 @@ import org.eclipse.cdt.ui.refactoring.CTextFileChange;
|
||||||
*/
|
*/
|
||||||
public abstract class CRenameProcessorDelegate {
|
public abstract class CRenameProcessorDelegate {
|
||||||
private CRenameProcessor fTopProcessor;
|
private CRenameProcessor fTopProcessor;
|
||||||
private ArrayList<CRefactoringMatch> fMatches= null;
|
private ArrayList<CRefactoringMatch> fMatches;
|
||||||
protected String fProcessorBaseName;
|
protected String fProcessorBaseName;
|
||||||
private int fAvailableOptions=
|
private int fAvailableOptions=
|
||||||
CRefactory.OPTION_ASK_SCOPE |
|
CRefactory.OPTION_ASK_SCOPE |
|
||||||
|
@ -113,7 +113,8 @@ public abstract class CRenameProcessorDelegate {
|
||||||
final public String getProcessorName() {
|
final public String getProcessorName() {
|
||||||
String identifier= getArgument().getName();
|
String identifier= getArgument().getName();
|
||||||
if (identifier != null) {
|
if (identifier != null) {
|
||||||
return NLS.bind(RenameMessages.CRenameProcessorDelegate_wizard_title, fProcessorBaseName, identifier);
|
return NLS.bind(RenameMessages.CRenameProcessorDelegate_wizard_title, fProcessorBaseName,
|
||||||
|
identifier);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -158,29 +159,28 @@ public abstract class CRenameProcessorDelegate {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Builds an index-based file filter for the name search.
|
* Builds an index-based file filter for the name search.
|
||||||
* @return A set of files containing references to the name, or <code>null</code> if
|
* @param bindings bindings being renamed
|
||||||
|
* @return A set of files containing references to the bindings, or <code>null</code> if
|
||||||
* exhaustive file search is requested.
|
* exhaustive file search is requested.
|
||||||
*/
|
*/
|
||||||
private Collection<IResource> getFileFilter() {
|
private Collection<IResource> getFileFilter(IBinding[] bindings) {
|
||||||
if ((getSelectedOptions() & CRefactory.OPTION_EXHAUSTIVE_FILE_SEARCH) != 0) {
|
if ((getSelectedOptions() & CRefactory.OPTION_EXHAUSTIVE_FILE_SEARCH) != 0) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
IIndex index = getIndex();
|
IIndex index = getIndex();
|
||||||
if (index == null) {
|
if (index == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
|
||||||
IBinding binding = getArgument().getBinding();
|
|
||||||
if (binding == null) {
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
Set<IIndexFileLocation> locations = new HashSet<IIndexFileLocation>();
|
Set<IIndexFileLocation> locations = new HashSet<IIndexFileLocation>();
|
||||||
try {
|
try {
|
||||||
index.acquireReadLock();
|
index.acquireReadLock();
|
||||||
|
for (IBinding binding : bindings) {
|
||||||
IIndexName[] names = index.findNames(binding,
|
IIndexName[] names = index.findNames(binding,
|
||||||
IIndex.FIND_ALL_OCCURRENCES | IIndex.SEARCH_ACROSS_LANGUAGE_BOUNDARIES);
|
IIndex.FIND_ALL_OCCURRENCES | IIndex.SEARCH_ACROSS_LANGUAGE_BOUNDARIES);
|
||||||
for (IIndexName name : names) {
|
for (IIndexName name : names) {
|
||||||
locations.add(name.getFile().getLocation());
|
locations.add(name.getFile().getLocation());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
return null;
|
return null;
|
||||||
} catch (CoreException e) {
|
} catch (CoreException e) {
|
||||||
|
@ -208,16 +208,19 @@ public abstract class CRenameProcessorDelegate {
|
||||||
return new RefactoringStatus();
|
return new RefactoringStatus();
|
||||||
}
|
}
|
||||||
|
|
||||||
public RefactoringStatus checkFinalConditions(IProgressMonitor monitor, CheckConditionsContext context) throws CoreException, OperationCanceledException {
|
public RefactoringStatus checkFinalConditions(IProgressMonitor monitor, CheckConditionsContext context)
|
||||||
|
throws CoreException, OperationCanceledException {
|
||||||
RefactoringStatus result= new RefactoringStatus();
|
RefactoringStatus result= new RefactoringStatus();
|
||||||
monitor.beginTask(RenameMessages.CRenameProcessorDelegate_task_checkFinalCondition, 2);
|
monitor.beginTask(RenameMessages.CRenameProcessorDelegate_task_checkFinalCondition, 2);
|
||||||
IFile file= getArgument().getSourceFile();
|
IFile file= getArgument().getSourceFile();
|
||||||
//assert file!=null;
|
//assert file!=null;
|
||||||
|
|
||||||
|
IBinding[] renameBindings= getBindingsToBeRenamed(result);
|
||||||
|
|
||||||
// perform text-search
|
// perform text-search
|
||||||
fMatches= new ArrayList<CRefactoringMatch>();
|
fMatches= new ArrayList<CRefactoringMatch>();
|
||||||
TextSearchWrapper txtSearch= getManager().getTextSearch();
|
TextSearchWrapper txtSearch= getManager().getTextSearch();
|
||||||
Collection<IResource> fileFilter = getFileFilter();
|
Collection<IResource> fileFilter = getFileFilter(renameBindings);
|
||||||
if (fileFilter != null && !fileFilter.contains(file)) {
|
if (fileFilter != null && !fileFilter.contains(file)) {
|
||||||
fileFilter.add(file);
|
fileFilter.add(file);
|
||||||
}
|
}
|
||||||
|
@ -233,7 +236,7 @@ public abstract class CRenameProcessorDelegate {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
selectMatchesByLocation(fMatches);
|
selectMatchesByLocation(fMatches);
|
||||||
analyzeTextMatches(fMatches, new SubProgressMonitor(monitor, 1), result);
|
analyzeTextMatches(renameBindings, fMatches, new SubProgressMonitor(monitor, 1), result);
|
||||||
if (result.hasFatalError()) {
|
if (result.hasFatalError()) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -266,7 +269,8 @@ public abstract class CRenameProcessorDelegate {
|
||||||
if (potentialMatchCount == 1) {
|
if (potentialMatchCount == 1) {
|
||||||
msg= RenameMessages.CRenameProcessorDelegate_warning_potentialMatch_singular;
|
msg= RenameMessages.CRenameProcessorDelegate_warning_potentialMatch_singular;
|
||||||
} else {
|
} else {
|
||||||
msg= NLS.bind(RenameMessages.CRenameProcessorDelegate_warning_potentialMatch_plural, potentialMatchCount);
|
msg= NLS.bind(RenameMessages.CRenameProcessorDelegate_warning_potentialMatch_plural,
|
||||||
|
potentialMatchCount);
|
||||||
}
|
}
|
||||||
result.addWarning(msg);
|
result.addWarning(msg);
|
||||||
}
|
}
|
||||||
|
@ -275,7 +279,8 @@ public abstract class CRenameProcessorDelegate {
|
||||||
if (commentCount == 1) {
|
if (commentCount == 1) {
|
||||||
msg= RenameMessages.CRenameProcessorDelegate_warning_commentMatch_singular;
|
msg= RenameMessages.CRenameProcessorDelegate_warning_commentMatch_singular;
|
||||||
} else {
|
} else {
|
||||||
msg= NLS.bind(RenameMessages.CRenameProcessorDelegate_warning_commentMatch_plural, commentCount);
|
msg= NLS.bind(RenameMessages.CRenameProcessorDelegate_warning_commentMatch_plural,
|
||||||
|
commentCount);
|
||||||
}
|
}
|
||||||
result.addWarning(msg);
|
result.addWarning(msg);
|
||||||
}
|
}
|
||||||
|
@ -289,11 +294,9 @@ public abstract class CRenameProcessorDelegate {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void analyzeTextMatches(ArrayList<CRefactoringMatch> matches, IProgressMonitor monitor, RefactoringStatus status) {
|
protected void analyzeTextMatches(IBinding[] renameBindings, Collection<CRefactoringMatch> matches,
|
||||||
CRefactoringArgument argument= getArgument();
|
IProgressMonitor monitor, RefactoringStatus status) {
|
||||||
IBinding[] renameBindings= getBindingsToBeRenamed(status);
|
if (renameBindings.length > 0 && getArgument().getArgumentKind() != CRefactory.ARGUMENT_UNKNOWN) {
|
||||||
if (renameBindings != null && renameBindings.length > 0 &&
|
|
||||||
argument.getArgumentKind() != CRefactory.ARGUMENT_UNKNOWN) {
|
|
||||||
ASTManager mngr= getAstManager();
|
ASTManager mngr= getAstManager();
|
||||||
mngr.setValidBindings(renameBindings);
|
mngr.setValidBindings(renameBindings);
|
||||||
mngr.setRenameTo(getReplacementText());
|
mngr.setRenameTo(getReplacementText());
|
||||||
|
@ -301,7 +304,7 @@ public abstract class CRenameProcessorDelegate {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void selectMatchesByLocation(ArrayList<CRefactoringMatch> matches) {
|
private void selectMatchesByLocation(Collection<CRefactoringMatch> matches) {
|
||||||
int acceptTextLocation= getAcceptedLocations(getSelectedOptions());
|
int acceptTextLocation= getAcceptedLocations(getSelectedOptions());
|
||||||
for (Iterator<CRefactoringMatch> iter = matches.iterator(); iter.hasNext();) {
|
for (Iterator<CRefactoringMatch> iter = matches.iterator(); iter.hasNext();) {
|
||||||
CRefactoringMatch match = iter.next();
|
CRefactoringMatch match = iter.next();
|
||||||
|
@ -317,7 +320,7 @@ public abstract class CRenameProcessorDelegate {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Change createChange(IProgressMonitor pm) throws CoreException, OperationCanceledException {
|
public Change createChange(IProgressMonitor pm) throws CoreException, OperationCanceledException {
|
||||||
if (fMatches.size() == 0) {
|
if (fMatches.isEmpty()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
Collections.sort(fMatches, new Comparator<CRefactoringMatch>() {
|
Collections.sort(fMatches, new Comparator<CRefactoringMatch>() {
|
||||||
|
@ -371,7 +374,7 @@ public abstract class CRenameProcessorDelegate {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the array of bindings that must be renamed
|
* Returns the array of bindings that must be renamed.
|
||||||
*/
|
*/
|
||||||
protected IBinding[] getBindingsToBeRenamed(RefactoringStatus status) {
|
protected IBinding[] getBindingsToBeRenamed(RefactoringStatus status) {
|
||||||
return new IBinding[] { getArgument().getBinding() };
|
return new IBinding[] { getArgument().getBinding() };
|
||||||
|
|
Loading…
Add table
Reference in a new issue