1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-10 17:55:39 +02:00

Renaming a virtual method, bug 63290.

This commit is contained in:
Markus Schorn 2009-05-15 08:05:24 +00:00
parent 47e2c99bdb
commit 61f6529667
10 changed files with 152 additions and 66 deletions

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2005, 2008 IBM Corporation and others. * Copyright (c) 2005, 2009 IBM Corporation 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
@ -256,6 +256,7 @@ public class DOMAST extends ViewPart {
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor) * @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor)
*/ */
@Override
protected IStatus run(IProgressMonitor monitor) { protected IStatus run(IProgressMonitor monitor) {
job.schedule(); job.schedule();
@ -342,7 +343,8 @@ public class DOMAST extends ViewPart {
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.jface.operation.IRunnableWithProgress#run(org.eclipse.core.runtime.IProgressMonitor) * @see org.eclipse.jface.operation.IRunnableWithProgress#run(org.eclipse.core.runtime.IProgressMonitor)
*/ */
protected IStatus run(IProgressMonitor monitor) { @Override
protected IStatus run(IProgressMonitor monitor) {
long start=0; long start=0;
long overallStart=System.currentTimeMillis(); long overallStart=System.currentTimeMillis();
@ -463,6 +465,8 @@ public class DOMAST extends ViewPart {
*/ */
public void run() { public void run() {
if (view == null) return; if (view == null) return;
if (view.getTree().isDisposed())
return;
view.refresh(); view.refresh();
if (view.getTree().getItems().length > 0) { if (view.getTree().getItems().length > 0) {
@ -552,12 +556,14 @@ public class DOMAST extends ViewPart {
private static final String BLANK_STRING = ""; //$NON-NLS-1$ private static final String BLANK_STRING = ""; //$NON-NLS-1$
public String getText(Object obj) { @Override
public String getText(Object obj) {
if (obj == null) return BLANK_STRING; if (obj == null) return BLANK_STRING;
return obj.toString(); return obj.toString();
} }
public Image getImage(Object obj) { @Override
public Image getImage(Object obj) {
String imageKey = DOMASTPluginImages.IMG_DEFAULT; String imageKey = DOMASTPluginImages.IMG_DEFAULT;
IASTNode node = null; IASTNode node = null;
@ -630,7 +636,8 @@ public class DOMAST extends ViewPart {
* This is a callback that will allow us to create the viewer and initialize * This is a callback that will allow us to create the viewer and initialize
* it. * it.
*/ */
public void createPartControl(Composite parent) { @Override
public void createPartControl(Composite parent) {
if (part == null) { if (part == null) {
part = getActiveEditor(); part = getActiveEditor();
@ -804,7 +811,8 @@ public class DOMAST extends ViewPart {
private void makeActions() { private void makeActions() {
loadActiveEditorAction = new Action() { loadActiveEditorAction = new Action() {
public void run() { @Override
public void run() {
// first make sure there is an open editor // first make sure there is an open editor
IEditorPart editor = getActiveEditor(); IEditorPart editor = getActiveEditor();
if (editor != null) { if (editor != null) {
@ -817,7 +825,8 @@ public class DOMAST extends ViewPart {
loadActiveEditorAction.setImageDescriptor(DOMASTPluginImages.DESC_RELOAD_VIEW); loadActiveEditorAction.setImageDescriptor(DOMASTPluginImages.DESC_RELOAD_VIEW);
refreshAction = new Action() { refreshAction = new Action() {
public void run() { @Override
public void run() {
// take a snapshot of the tree expansion // take a snapshot of the tree expansion
Object[] expanded = viewer.getExpandedElements(); Object[] expanded = viewer.getExpandedElements();
@ -830,7 +839,8 @@ public class DOMAST extends ViewPart {
refreshAction.setImageDescriptor(DOMASTPluginImages.DESC_REFRESH_VIEW); refreshAction.setImageDescriptor(DOMASTPluginImages.DESC_REFRESH_VIEW);
expandAllAction = new Action() { expandAllAction = new Action() {
public void run() { @Override
public void run() {
viewer.expandAll(); viewer.expandAll();
} }
}; };
@ -839,7 +849,8 @@ public class DOMAST extends ViewPart {
expandAllAction.setImageDescriptor(DOMASTPluginImages.DESC_EXPAND_ALL); expandAllAction.setImageDescriptor(DOMASTPluginImages.DESC_EXPAND_ALL);
collapseAllAction = new Action() { collapseAllAction = new Action() {
public void run() { @Override
public void run() {
viewer.collapseAll(); viewer.collapseAll();
} }
}; };
@ -848,7 +859,8 @@ public class DOMAST extends ViewPart {
collapseAllAction.setImageDescriptor(DOMASTPluginImages.DESC_COLLAPSE_ALL); collapseAllAction.setImageDescriptor(DOMASTPluginImages.DESC_COLLAPSE_ALL);
clearAction = new Action() { clearAction = new Action() {
public void run() { @Override
public void run() {
viewer.setContentProvider(new ViewContentProvider(null)); viewer.setContentProvider(new ViewContentProvider(null));
viewer.refresh(); viewer.refresh();
} }
@ -867,7 +879,8 @@ public class DOMAST extends ViewPart {
dialog.open(); dialog.open();
} }
public void run() { @Override
public void run() {
performSearch(); performSearch();
} }
}; };
@ -876,7 +889,8 @@ public class DOMAST extends ViewPart {
searchNamesAction.setImageDescriptor(DOMASTPluginImages.DESC_SEARCH_NAMES); searchNamesAction.setImageDescriptor(DOMASTPluginImages.DESC_SEARCH_NAMES);
displayNodeTypeAction = new Action() { displayNodeTypeAction = new Action() {
public void run() { @Override
public void run() {
ISelection selection = viewer.getSelection(); ISelection selection = viewer.getSelection();
if (selection instanceof IStructuredSelection && if (selection instanceof IStructuredSelection &&
((IStructuredSelection)selection).getFirstElement() instanceof DOMASTNodeLeaf && ((IStructuredSelection)selection).getFirstElement() instanceof DOMASTNodeLeaf &&
@ -889,7 +903,8 @@ public class DOMAST extends ViewPart {
.getImageDescriptor(ISharedImages.IMG_OBJS_INFO_TSK)); .getImageDescriptor(ISharedImages.IMG_OBJS_INFO_TSK));
displayNodeSignatureAction = new Action() { displayNodeSignatureAction = new Action() {
public void run() { @Override
public void run() {
ISelection selection = viewer.getSelection(); ISelection selection = viewer.getSelection();
if (selection instanceof IStructuredSelection && if (selection instanceof IStructuredSelection &&
((IStructuredSelection)selection).getFirstElement() instanceof DOMASTNodeLeaf && ((IStructuredSelection)selection).getFirstElement() instanceof DOMASTNodeLeaf &&
@ -902,7 +917,8 @@ public class DOMAST extends ViewPart {
.getImageDescriptor(ISharedImages.IMG_OBJS_INFO_TSK)); .getImageDescriptor(ISharedImages.IMG_OBJS_INFO_TSK));
displayExpressionAction = new Action() { displayExpressionAction = new Action() {
public void run() { @Override
public void run() {
ISelection selection = viewer.getSelection(); ISelection selection = viewer.getSelection();
if (selection instanceof IStructuredSelection && if (selection instanceof IStructuredSelection &&
((IStructuredSelection)selection).getFirstElement() instanceof DOMASTNodeLeaf && ((IStructuredSelection)selection).getFirstElement() instanceof DOMASTNodeLeaf &&
@ -915,7 +931,8 @@ public class DOMAST extends ViewPart {
.getImageDescriptor(ISharedImages.IMG_OBJS_INFO_TSK)); .getImageDescriptor(ISharedImages.IMG_OBJS_INFO_TSK));
displayInitializerAction = new Action() { displayInitializerAction = new Action() {
public void run() { @Override
public void run() {
ISelection selection = viewer.getSelection(); ISelection selection = viewer.getSelection();
if (selection instanceof IStructuredSelection && if (selection instanceof IStructuredSelection &&
((IStructuredSelection)selection).getFirstElement() instanceof DOMASTNodeLeaf && ((IStructuredSelection)selection).getFirstElement() instanceof DOMASTNodeLeaf &&
@ -970,7 +987,8 @@ public class DOMAST extends ViewPart {
return true; return true;
} }
public void run() { @Override
public void run() {
ISelection selection = viewer.getSelection(); ISelection selection = viewer.getSelection();
Object obj = ((IStructuredSelection) selection).getFirstElement(); Object obj = ((IStructuredSelection) selection).getFirstElement();
if (obj instanceof DOMASTNodeLeaf) { if (obj instanceof DOMASTNodeLeaf) {
@ -1034,7 +1052,8 @@ public class DOMAST extends ViewPart {
/** /**
* Passing the focus request to the viewer's control. * Passing the focus request to the viewer's control.
*/ */
public void setFocus() { @Override
public void setFocus() {
if (viewer==null) return; if (viewer==null) return;
viewer.getControl().setFocus(); viewer.getControl().setFocus();
@ -1072,6 +1091,7 @@ public class DOMAST extends ViewPart {
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor) * @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor)
*/ */
@Override
protected IStatus run(IProgressMonitor monitor) { protected IStatus run(IProgressMonitor monitor) {
try { try {
initializeASTViewJob.join(); initializeASTViewJob.join();

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2006, 2008 Wind River Systems, Inc. and others. * Copyright (c) 2006, 2009 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
@ -72,6 +72,11 @@ public class BaseUITestCase extends BaseTestCase {
@Override @Override
protected void setUp() throws Exception { protected void setUp() throws Exception {
super.setUp(); super.setUp();
final IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
IViewPart view= activePage.findView("org.eclipse.cdt.ui.tests.DOMAST.DOMAST");
if (view != null) {
activePage.hideView(view);
}
} }
/* (non-Javadoc) /* (non-Javadoc)

View file

@ -1,14 +1,13 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2005, 2007 Wind River Systems, Inc. * Copyright (c) 2005, 2009 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
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* Markus Schorn - initial API and implementation * Markus Schorn - initial API and implementation
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.ui.tests.refactoring.rename; package org.eclipse.cdt.ui.tests.refactoring.rename;
import java.io.StringWriter; import java.io.StringWriter;
@ -20,9 +19,6 @@ 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;
/**
* @author markus.schorn@windriver.com
*/
public class RenameFunctionTests extends RenameTests { public class RenameFunctionTests extends RenameTests {
public RenameFunctionTests(String name) { public RenameFunctionTests(String name) {
@ -813,7 +809,7 @@ public class RenameFunctionTests extends RenameTests {
IFile cpp= importFile("test.cpp", contents ); //$NON-NLS-1$ IFile cpp= importFile("test.cpp", contents ); //$NON-NLS-1$
int offset = contents.indexOf("mthd") ; //$NON-NLS-1$ int offset = contents.indexOf("mthd") ; //$NON-NLS-1$
offset= contents.indexOf("mthd", offset+1) ; //$NON-NLS-1$ offset= contents.indexOf("mthd", offset+1) ; //$NON-NLS-1$
RefactoringStatus status= checkConditions(cpp, offset, "xxx"); //$NON-NLS-1$ Change changes = getRefactorChanges(cpp, offset, "z"); //$NON-NLS-1$
assertRefactoringWarning(status, "Renaming a virtual method. Consider renaming the base and derived class methods (if any)."); //$NON-NLS-1$ assertTotalChanges( 2, changes );
} }
} }

View file

@ -1,12 +1,12 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2004, 2008 IBM Corporation and others. * Copyright (c) 2004, 2009 IBM Corporation 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
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* IBM Corporation - initial API and implementation * Andrew Niefer (IBM Corporation) - initial API and implementation
* Wind River Systems Inc. - ported for new rename implementation * Wind River Systems Inc. - ported for new rename implementation
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.ui.tests.refactoring.rename; package org.eclipse.cdt.ui.tests.refactoring.rename;
@ -25,9 +25,6 @@ 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;
/**
* @author aniefer
*/
public class RenameRegressionTests extends RenameTests { public class RenameRegressionTests extends RenameTests {
public RenameRegressionTests() { public RenameRegressionTests() {
@ -607,10 +604,11 @@ public class RenameRegressionTests extends RenameTests {
IFile file = importFile( "t.cpp", contents ); //$NON-NLS-1$ IFile file = importFile( "t.cpp", contents ); //$NON-NLS-1$
//vp1 implicit virtual method //vp1 implicit virtual method
int offset = contents.indexOf( "v/*vp1*/" ) ; //$NON-NLS-1$ int offset = contents.indexOf( "v/*vp1*/" ) ; //$NON-NLS-1$
String[] messages= getRefactorMessages( file, offset, "v2" ); //$NON-NLS-1$ Change changes = getRefactorChanges(file, offset, "v1" ); //$NON-NLS-1$
assertEquals(1, messages.length); assertTotalChanges( 3, changes );
assertEquals("Renaming a virtual method. Consider renaming the base and derived class methods (if any).", messages[0] ); //$NON-NLS-1$ assertChange( changes, file, contents.indexOf("v()"), 1, "v1" ); //$NON-NLS-1$//$NON-NLS-2$
assertChange( changes, file, contents.indexOf("v/*vp1*/"), 1, "v1" ); //$NON-NLS-1$//$NON-NLS-2$
assertChange( changes, file, contents.indexOf("v(){"), 1, "v1" ); //$NON-NLS-1$//$NON-NLS-2$
} }
public void testMethod_45() throws Exception { public void testMethod_45() throws Exception {
StringWriter writer = new StringWriter(); StringWriter writer = new StringWriter();
@ -627,15 +625,18 @@ public class RenameRegressionTests extends RenameTests {
writer.write( "}; \n" ); //$NON-NLS-1$ writer.write( "}; \n" ); //$NON-NLS-1$
String contents = writer.toString(); String contents = writer.toString();
IFile file = importFile( "t.cpp", contents ); //$NON-NLS-1$ IFile file = importFile( "t.cpp", contents ); //$NON-NLS-1$
waitForIndexer();
//vp1 implicit virtual method //vp1 implicit virtual method
int offset = contents.indexOf( "v/*vp1*/" ) ; //$NON-NLS-1$ int offset = contents.indexOf( "v/*vp1*/" ) ; //$NON-NLS-1$
String[] messages= getRefactorMessages( file, offset, "v2" ); //$NON-NLS-1$ Change changes = getRefactorChanges(file, offset, "v1" ); //$NON-NLS-1$
assertEquals(1, messages.length); assertTotalChanges( 4, changes );
assertEquals("Renaming a virtual method. Consider renaming the base and derived class methods (if any).", messages[0] ); //$NON-NLS-1$ assertChange( changes, file, contents.indexOf("v()"), 1, "v1" ); //$NON-NLS-1$//$NON-NLS-2$
assertChange( changes, file, contents.indexOf("v(){}"), 1, "v1" ); //$NON-NLS-1$//$NON-NLS-2$
assertChange( changes, file, contents.indexOf("v/*vp1*/"), 1, "v1" ); //$NON-NLS-1$//$NON-NLS-2$
assertChange( changes, file, contents.indexOf("v(){i"), 1, "v1" ); //$NON-NLS-1$//$NON-NLS-2$
} }
public void testStruct_46() throws Exception {
public void testStruct_46() throws Exception {
StringWriter writer = new StringWriter(); StringWriter writer = new StringWriter();
writer.write( "struct st1/*vp1*/{}; \n" ); //$NON-NLS-1$ writer.write( "struct st1/*vp1*/{}; \n" ); //$NON-NLS-1$
writer.write( "class c1/*vp1*/{ \n" ); //$NON-NLS-1$ writer.write( "class c1/*vp1*/{ \n" ); //$NON-NLS-1$

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2004, 2008 Wind River Systems, Inc. and others. * Copyright (c) 2004, 2009 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
@ -43,6 +43,7 @@ public class CRefactory {
public static final int OPTION_IN_PREPROCESSOR_DIRECTIVE = 0x20; public static final int OPTION_IN_PREPROCESSOR_DIRECTIVE = 0x20;
public static final int OPTION_IN_INACTIVE_CODE = 0x40; public static final int OPTION_IN_INACTIVE_CODE = 0x40;
public static final int OPTION_IN_CODE = 0x80; public static final int OPTION_IN_CODE = 0x80;
public static final int OPTION_DO_VIRTUAL = 0x100;
public static final int ARGUMENT_UNKNOWN = 0; public static final int ARGUMENT_UNKNOWN = 0;
public static final int ARGUMENT_LOCAL_VAR = 1; public static final int ARGUMENT_LOCAL_VAR = 1;

View file

@ -1,15 +1,18 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2005, 2008 Wind River Systems, Inc. and others. * Copyright (c) 2005, 2009 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
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* Markus Schorn - initial API and implementation * Markus Schorn - initial API and implementation
******************************************************************************/ ******************************************************************************/
package org.eclipse.cdt.internal.ui.refactoring.rename; package org.eclipse.cdt.internal.ui.refactoring.rename;
import java.util.ArrayList;
import java.util.Arrays;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.OperationCanceledException; import org.eclipse.core.runtime.OperationCanceledException;
@ -23,17 +26,20 @@ import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor; import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
import org.eclipse.cdt.internal.core.dom.parser.ASTInternal; import org.eclipse.cdt.internal.core.dom.parser.ASTInternal;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ClassTypeHelper;
/** /**
* Rename processor for methods. * Rename processor for methods.
*/ */
public class CRenameMethodProcessor extends CRenameGlobalProcessor { public class CRenameMethodProcessor extends CRenameGlobalProcessor {
public CRenameMethodProcessor(CRenameProcessor processor, String kind, boolean isVirtual) {
public CRenameMethodProcessor(CRenameProcessor processor, String kind) {
super(processor, kind); super(processor, kind);
if (isVirtual)
setAvailableOptions(getAvailableOptions() | CRefactory.OPTION_DO_VIRTUAL);
} }
@Override @Override
@ -83,11 +89,39 @@ public class CRenameMethodProcessor extends CRenameGlobalProcessor {
} }
} }
} }
if (argument.getArgumentKind() == CRefactory.ARGUMENT_VIRTUAL_METHOD) { if (argument.getArgumentKind() == CRefactory.ARGUMENT_VIRTUAL_METHOD && (getSelectedOptions() & CRefactory.OPTION_DO_VIRTUAL) == 0) {
result.merge(RefactoringStatus.createWarningStatus(Messages.getString("CRenameMethodProcessor.warning.renameVirtual"))); //$NON-NLS-1$ result.merge(RefactoringStatus.createWarningStatus(Messages.getString("CRenameMethodProcessor.warning.renameVirtual"))); //$NON-NLS-1$
} }
result.merge(super.checkFinalConditions(monitor, context)); result.merge(super.checkFinalConditions(monitor, context));
return result; return result;
} }
@Override
protected IBinding[] getBindingsToBeRenamed(RefactoringStatus status) {
if ((getSelectedOptions() & CRefactory.OPTION_DO_VIRTUAL) == 0) {
return super.getBindingsToBeRenamed(status);
}
CRefactoringArgument argument= getArgument();
IBinding binding= argument.getBinding();
ArrayList<IBinding> bindings= new ArrayList<IBinding>();
if (binding != null) {
bindings.add(binding);
}
if (binding instanceof ICPPMethod) {
ICPPMethod m= (ICPPMethod) binding;
try {
IBinding[] bs= ClassTypeHelper.findOverridden(m);
bindings.addAll(Arrays.asList(bs));
bs= ClassTypeHelper.findOverriders(getIndex(), m);
bindings.addAll(Arrays.asList(bs));
} catch (DOMException e) {
getAstManager().handleDOMException(argument.getTranslationUnit(), e, status);
} catch (CoreException e) {
status.addError(e.getMessage());
}
}
return bindings.toArray(new IBinding[bindings.size()]);
}
} }

View file

@ -1,16 +1,15 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2004, 2008 Wind River Systems, Inc. and others. * Copyright (c) 2004, 2009 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
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* Markus Schorn - initial API and implementation * Markus Schorn - initial API and implementation
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.ui.refactoring.rename; package org.eclipse.cdt.internal.ui.refactoring.rename;
import com.ibm.icu.text.MessageFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
@ -31,8 +30,11 @@ import org.eclipse.ltk.core.refactoring.participants.RenameParticipant;
import org.eclipse.ltk.core.refactoring.participants.RenameProcessor; import org.eclipse.ltk.core.refactoring.participants.RenameProcessor;
import org.eclipse.ltk.core.refactoring.participants.SharableParticipants; import org.eclipse.ltk.core.refactoring.participants.SharableParticipants;
import com.ibm.icu.text.MessageFormat;
import org.eclipse.cdt.core.CCProjectNature; import org.eclipse.cdt.core.CCProjectNature;
import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.CProjectNature;
import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.index.IIndex; import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.model.CoreModel;
@ -159,9 +161,9 @@ public class CRenameProcessor extends RenameProcessor {
case CRefactory.ARGUMENT_GLOBAL_FUNCTION: case CRefactory.ARGUMENT_GLOBAL_FUNCTION:
return new CRenameGlobalProcessor(this, Messages.getString("CRenameTopProcessor.globalFunction")); //$NON-NLS-1$ return new CRenameGlobalProcessor(this, Messages.getString("CRenameTopProcessor.globalFunction")); //$NON-NLS-1$
case CRefactory.ARGUMENT_VIRTUAL_METHOD: case CRefactory.ARGUMENT_VIRTUAL_METHOD:
return new CRenameMethodProcessor(this, Messages.getString("CRenameTopProcessor.virtualMethod")); //$NON-NLS-1$ return new CRenameMethodProcessor(this, Messages.getString("CRenameTopProcessor.virtualMethod"), true); //$NON-NLS-1$
case CRefactory.ARGUMENT_NON_VIRTUAL_METHOD: case CRefactory.ARGUMENT_NON_VIRTUAL_METHOD:
return new CRenameMethodProcessor(this, Messages.getString("CRenameTopProcessor.method")); //$NON-NLS-1$ return new CRenameMethodProcessor(this, Messages.getString("CRenameTopProcessor.method"), false); //$NON-NLS-1$
case CRefactory.ARGUMENT_CLASS_TYPE: case CRefactory.ARGUMENT_CLASS_TYPE:
return new CRenameClassProcessor(this, Messages.getString("CRenameTopProcessor.type")); //$NON-NLS-1$ return new CRenameClassProcessor(this, Messages.getString("CRenameTopProcessor.type")); //$NON-NLS-1$
case CRefactory.ARGUMENT_NAMESPACE: case CRefactory.ARGUMENT_NAMESPACE:
@ -198,7 +200,7 @@ public class CRenameProcessor extends RenameProcessor {
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, CCProjectNature.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();
if (binding != null) { if (binding != null) {

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2004, 2008 Wind River Systems, Inc. and others. * Copyright (c) 2004, 2009 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
@ -11,7 +11,6 @@
******************************************************************************/ ******************************************************************************/
package org.eclipse.cdt.internal.ui.refactoring.rename; package org.eclipse.cdt.internal.ui.refactoring.rename;
import com.ibm.icu.text.MessageFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
@ -35,7 +34,10 @@ import org.eclipse.text.edits.MultiTextEdit;
import org.eclipse.text.edits.ReplaceEdit; import org.eclipse.text.edits.ReplaceEdit;
import org.eclipse.text.edits.TextEditGroup; import org.eclipse.text.edits.TextEditGroup;
import com.ibm.icu.text.MessageFormat;
import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.ui.refactoring.CTextFileChange; import org.eclipse.cdt.ui.refactoring.CTextFileChange;
@ -90,6 +92,9 @@ public abstract class CRenameProcessorDelegate {
final public ASTManager getAstManager() { final public ASTManager getAstManager() {
return fTopProcessor.getAstManager(); return fTopProcessor.getAstManager();
} }
final public IIndex getIndex() {
return fTopProcessor.getIndex();
}
final public String getProcessorName() { final public String getProcessorName() {
String identifier= getArgument().getName(); String identifier= getArgument().getName();
if (identifier != null) { if (identifier != null) {

View file

@ -1,13 +1,13 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2004, 2008 Wind River Systems, Inc. and others. * Copyright (c) 2004, 2009 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
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* Markus Schorn - initial API and implementation * Markus Schorn - initial API and implementation
* Emanuel Graf (Institute for Software, HSR Hochschule fuer Technik) * Emanuel Graf (Institute for Software, HSR Hochschule fuer Technik)
******************************************************************************/ ******************************************************************************/
package org.eclipse.cdt.internal.ui.refactoring.rename; package org.eclipse.cdt.internal.ui.refactoring.rename;
@ -44,6 +44,7 @@ public class CRenameRefactoringInputPage extends UserInputWizardPage {
public static final String PAGE_NAME = "RenameRefactoringPage"; //$NON-NLS-1$ public static final String PAGE_NAME = "RenameRefactoringPage"; //$NON-NLS-1$
private static final String KEY_IGNORE_VIRTUAL = "ignoreVirtual"; //$NON-NLS-1$
private static final String KEY_REFERENCES_INV = "references_inv"; //$NON-NLS-1$ private static final String KEY_REFERENCES_INV = "references_inv"; //$NON-NLS-1$
private static final String KEY_COMMENT = "comment"; //$NON-NLS-1$ private static final String KEY_COMMENT = "comment"; //$NON-NLS-1$
private static final String KEY_STRING = "string"; //$NON-NLS-1$ private static final String KEY_STRING = "string"; //$NON-NLS-1$
@ -62,6 +63,7 @@ public class CRenameRefactoringInputPage extends UserInputWizardPage {
private int fEnableScopeOptions; private int fEnableScopeOptions;
private Text fNewName; private Text fNewName;
private Button fDoVirtual;
private Button fWorkspace; private Button fWorkspace;
private Button fDependent; private Button fDependent;
private Button fInComment; private Button fInComment;
@ -106,7 +108,7 @@ public class CRenameRefactoringInputPage extends UserInputWizardPage {
// new name // new name
Composite group= top; Composite group= top;
GridData gd; GridData gd; GridLayout gl;
Label l= new Label(group, SWT.NONE); Label l= new Label(group, SWT.NONE);
l.setText(Messages.getString("CRenameRefactoringInputPage.newIdentifier.label")); //$NON-NLS-1$ l.setText(Messages.getString("CRenameRefactoringInputPage.newIdentifier.label")); //$NON-NLS-1$
@ -115,32 +117,41 @@ public class CRenameRefactoringInputPage extends UserInputWizardPage {
fNewName.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); fNewName.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
fNewName.selectAll(); fNewName.selectAll();
boolean skippedLine= false; if (hasOption(CRefactory.OPTION_DO_VIRTUAL)) {
fDoVirtual= new Button(group, SWT.CHECK);
fDoVirtual.setText(Messages.getString("CRenameRefactoringInputPage.renameBaseAndDerivedMethods")); //$NON-NLS-1$
fDoVirtual.setLayoutData(gd= new GridData());
gd.horizontalSpan= 2;
}
// specify the scope // specify the scope
if (hasOption(CRefactory.OPTION_ASK_SCOPE)) { if (hasOption(CRefactory.OPTION_ASK_SCOPE)) {
skipLine(top); skipLine(top);
new Label(top, SWT.NONE).setText(Messages.getString("CRenameRefactoringInputPage.label.scope")); //$NON-NLS-1$ new Label(top, SWT.NONE).setText(Messages.getString("CRenameRefactoringInputPage.label.scope")); //$NON-NLS-1$
skippedLine= true;
group= new Composite(top, SWT.NONE); group= new Composite(top, SWT.NONE);
group.setLayoutData(gd= new GridData(GridData.FILL_HORIZONTAL)); group.setLayoutData(gd= new GridData(GridData.FILL_HORIZONTAL));
gd.horizontalSpan= 2; gd.horizontalSpan= 2;
group.setLayout(new GridLayout(3, false)); group.setLayout(gl= new GridLayout(3, false));
gl.marginHeight= 0;
fWorkspace= new Button(group, SWT.RADIO); fWorkspace= new Button(group, SWT.RADIO);
fWorkspace.setText(Messages.getString("CRenameRefactoringInputPage.button.scope.workspace")); //$NON-NLS-1$ fWorkspace.setText(Messages.getString("CRenameRefactoringInputPage.button.scope.workspace")); //$NON-NLS-1$
fWorkspace.setLayoutData(gd= new GridData()); fWorkspace.setLayoutData(gd= new GridData());
gd.horizontalSpan= 3;
fDependent= new Button(group, SWT.RADIO); fDependent= new Button(group, SWT.RADIO);
fDependent.setText(Messages.getString("CRenameRefactoringInputPage.button.scope.releatedprojects")); //$NON-NLS-1$ fDependent.setText(Messages.getString("CRenameRefactoringInputPage.button.scope.releatedprojects")); //$NON-NLS-1$
fDependent.setLayoutData(gd= new GridData()); fDependent.setLayoutData(gd= new GridData());
gd.horizontalSpan= 3;
fSingle= new Button(group, SWT.RADIO); fSingle= new Button(group, SWT.RADIO);
fSingle.setText(Messages.getString("CRenameRefactoringInputPage.button.singleProject")); //$NON-NLS-1$ fSingle.setText(Messages.getString("CRenameRefactoringInputPage.button.singleProject")); //$NON-NLS-1$
fSingle.setLayoutData(gd= new GridData()); fSingle.setLayoutData(gd= new GridData());
gd.horizontalSpan= 3;
group= new Composite(top, SWT.NONE);
group.setLayoutData(gd= new GridData(GridData.FILL_HORIZONTAL));
gd.horizontalSpan= 2;
group.setLayout(gl= new GridLayout(3, false));
gl.marginHeight= 0;
fWorkingSet= new Button(group, SWT.RADIO); fWorkingSet= new Button(group, SWT.RADIO);
fWorkingSet.setText(Messages.getString("CRenameRefactoringInputPage.button.workingSet")); //$NON-NLS-1$ fWorkingSet.setText(Messages.getString("CRenameRefactoringInputPage.button.workingSet")); //$NON-NLS-1$
@ -152,6 +163,7 @@ public class CRenameRefactoringInputPage extends UserInputWizardPage {
setButtonLayoutData(fWorkingSetButton); setButtonLayoutData(fWorkingSetButton);
} }
boolean skippedLine= false;
group= null; group= null;
if (hasOption(CRefactory.OPTION_IN_CODE)) { if (hasOption(CRefactory.OPTION_IN_CODE)) {
group= createLabelAndGroup(group, skippedLine, top); group= createLabelAndGroup(group, skippedLine, top);
@ -245,6 +257,7 @@ public class CRenameRefactoringInputPage extends UserInputWizardPage {
onSelectOption(); onSelectOption();
} }
}; };
registerOptionListener(fDoVirtual, listenOption);
registerOptionListener(fReferences, listenOption); registerOptionListener(fReferences, listenOption);
registerOptionListener(fInComment, listenOption); registerOptionListener(fInComment, listenOption);
registerOptionListener(fInInactiveCode, listenOption); registerOptionListener(fInInactiveCode, listenOption);
@ -331,6 +344,10 @@ public class CRenameRefactoringInputPage extends UserInputWizardPage {
processor.setWorkingSet(workingSet); processor.setWorkingSet(workingSet);
} }
if (fDoVirtual != null) {
boolean val= !fDialogSettings.getBoolean(KEY_IGNORE_VIRTUAL);
fDoVirtual.setSelection(val);
}
if (fReferences != null) { if (fReferences != null) {
boolean val= !fDialogSettings.getBoolean(KEY_REFERENCES_INV); boolean val= !fDialogSettings.getBoolean(KEY_REFERENCES_INV);
fReferences.setSelection(val); fReferences.setSelection(val);
@ -345,6 +362,7 @@ public class CRenameRefactoringInputPage extends UserInputWizardPage {
private int computeSelectedOptions() { private int computeSelectedOptions() {
int options= 0; int options= 0;
options |= computeOption(fDoVirtual, CRefactory.OPTION_DO_VIRTUAL);
options |= computeOption(fReferences, CRefactory.OPTION_IN_CODE); options |= computeOption(fReferences, CRefactory.OPTION_IN_CODE);
options |= computeOption(fInComment, CRefactory.OPTION_IN_COMMENT); options |= computeOption(fInComment, CRefactory.OPTION_IN_COMMENT);
options |= computeOption(fInString, CRefactory.OPTION_IN_STRING_LITERAL); options |= computeOption(fInString, CRefactory.OPTION_IN_STRING_LITERAL);
@ -395,6 +413,9 @@ public class CRenameRefactoringInputPage extends UserInputWizardPage {
fDialogSettings.put(KEY_SCOPE, choice); fDialogSettings.put(KEY_SCOPE, choice);
fDialogSettings.put(KEY_WORKING_SET_NAME, fWorkingSetSpec.getText()); fDialogSettings.put(KEY_WORKING_SET_NAME, fWorkingSetSpec.getText());
} }
if (fDoVirtual != null) {
fDialogSettings.put(KEY_IGNORE_VIRTUAL, !fDoVirtual.getSelection());
}
if (fReferences != null) { if (fReferences != null) {
fDialogSettings.put(KEY_REFERENCES_INV, !fReferences.getSelection()); fDialogSettings.put(KEY_REFERENCES_INV, !fReferences.getSelection());
} }

View file

@ -1,5 +1,5 @@
############################################################################### ###############################################################################
# Copyright (c) 2005, 2008 IBM Corporation and others. # Copyright (c) 2005, 2009 IBM Corporation 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
@ -86,6 +86,7 @@ CRefactoringMatch.label.potentialOccurrence=Rename potential occurrence
CRenameMethodProcessor.warning.renameVirtual=Renaming a virtual method. Consider renaming the base and derived class methods (if any). CRenameMethodProcessor.warning.renameVirtual=Renaming a virtual method. Consider renaming the base and derived class methods (if any).
CRenameRefactoringInputPage.button.preprocessor=other preprocessor directives CRenameRefactoringInputPage.button.preprocessor=other preprocessor directives
CRenameRefactoringInputPage.label.updateWithin=Update within: CRenameRefactoringInputPage.label.updateWithin=Update within:
CRenameRefactoringInputPage.renameBaseAndDerivedMethods=Rename virtual methods in base and derived classes, also (if any).
ASTManager.task.analyze=Analyzing source code ASTManager.task.analyze=Analyzing source code
ASTManager.task.generateAst=Generating AST ASTManager.task.generateAst=Generating AST
ASTManager.subtask.analyzing=Analyzing {0} files ASTManager.subtask.analyzing=Analyzing {0} files