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

Refactoring bug fixes

This commit is contained in:
Hoda Amer 2004-05-04 15:58:18 +00:00
parent ecd1e968f2
commit b3577f221d
8 changed files with 152 additions and 72 deletions

View file

@ -1,3 +1,7 @@
2004-05-04 Hoda Amer
Fix for bug#60331 : [Refactoring] All namespace declarations not renamed
Fix for bug#59270 : [Refactoring] missing warning/error icons
2004-05-03 Alain Magloire
Refactor the indexer block to be in the same

View file

@ -93,8 +93,29 @@ public class Checks {
//fix for: 1GF5Z0Z: ITPJUI:WINNT - assertion failed after renameType refactoring
if (name.indexOf(".") != -1) //$NON-NLS-1$
return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.getString("Checks.no_dot"));//$NON-NLS-1$
else
return checkName(name, CConventions.validateClassName(name));
else {
RefactoringStatus status = checkName(name, CConventions.validateClassName(name));
if (status.hasFatalError()){
String msg = RefactoringCoreMessages.getFormattedString(
"Checks.error.InvalidClassName",//$NON-NLS-1$
status.getFirstMessage(RefactoringStatus.FATAL));
return RefactoringStatus.createFatalErrorStatus(msg);
}
else if (status.hasError()){
String msg = RefactoringCoreMessages.getFormattedString(
"Checks.error.InvalidClassName",//$NON-NLS-1$
status.getFirstMessage(RefactoringStatus.ERROR));
return RefactoringStatus.createErrorStatus(msg);
}
else if (status.hasWarning()){
String msg = RefactoringCoreMessages.getFormattedString(
"Checks.warning.ClassNameDiscouraged",//$NON-NLS-1$
status.getFirstMessage(RefactoringStatus.INFO));
return RefactoringStatus.createWarningStatus(msg);
}else{
return status;
}
}
}

View file

@ -22,7 +22,7 @@ Checks.cannot_be_parsed=''{0}'' has syntax errors. Content of that file will not
Checks.cu_not_created=Translation unit could not be created for this element.
Checks.cu_not_parsed=This refactoring cannot be performed correctly due to syntax errors in the translation unit. To perform this operation you will need to fix the errors.
Checks.cu_has_compile_errors=Code modification may not be accurate as affected resource ''{0}'' has compile errors.
Checks.no_dot=Type name cannot contain a dot (.)
Checks.no_dot=Class name cannot contain a dot (.)
Checks.cu_name_used=translation unit ''{0}.java'' already exists
Checks.method_native=Method {0}::{1} is native. Running the modified program will cause {2}.
Checks.methodName.constructor=New method name has constructor name
@ -32,6 +32,8 @@ Checks.methodName.returnTypeClash=New method ''{0}'' overrides a method declared
Checks.has_main=Type {0} contains a main method - some applications (such as scripts) may not work after refactoring
Checks.constructor_name= If you proceed, the method {0} in ''{1}'' will have a constructor name.
Checks.method_names_lowercase=This name is discouraged. According to convention, names of methods should start with lowercase letters
Checks.error.InvalidClassName=Class name is not valid. {0}
Checks.warning.ClassNameDiscouraged=Class name is discouraged. {0}
#######################################
# org.eclipse.jdt.internal.core.refactoring.base

View file

@ -295,14 +295,11 @@ public class RenameElementProcessor extends RenameProcessor implements IReferenc
return result;
fReferences= null;
if (fUpdateReferences){
pm.setTaskName(RefactoringCoreMessages.getString("RenameTypeRefactoring.searching")); //$NON-NLS-1$
fReferences= getReferences(getElementQualifiedName(fCElement), new SubProgressMonitor(pm, 35));
}
pm.setTaskName(RefactoringCoreMessages.getString("RenameTypeRefactoring.searching")); //$NON-NLS-1$
fReferences= getReferences(getElementQualifiedName(fCElement), new SubProgressMonitor(pm, 35), fUpdateReferences);
pm.worked(6);
if (fUpdateReferences)
result.merge(analyzeAffectedTranslationUnits());
result.merge(analyzeAffectedTranslationUnits());
pm.setTaskName(RefactoringCoreMessages.getString("RenameTypeRefactoring.checking")); //$NON-NLS-1$
if (pm.isCanceled())
@ -343,12 +340,12 @@ public class RenameElementProcessor extends RenameProcessor implements IReferenc
pm.beginTask("", 7); //$NON-NLS-1$
TextChangeManager manager= new TextChangeManager();
if (fUpdateReferences)
addReferenceUpdates(manager, new SubProgressMonitor(pm, 3));
addReferenceUpdates(manager, new SubProgressMonitor(pm, 3));
pm.worked(1);
addTypeDeclarationUpdate(manager);
// now both declarations and references are searched for in references
//addTypeDeclarationUpdate(manager);
pm.worked(1);
return manager;
@ -394,8 +391,8 @@ public class RenameElementProcessor extends RenameProcessor implements IReferenc
}
}
private SearchResultGroup[] getReferences(String searchPrefix, IProgressMonitor pm) throws CoreException {
return RefactoringSearchEngine.search(pm, createRefactoringScope(), createSearchPattern(searchPrefix));
private SearchResultGroup[] getReferences(String searchPrefix, IProgressMonitor pm, boolean updateReferences) throws CoreException {
return RefactoringSearchEngine.search(pm, createRefactoringScope(), createSearchPattern(searchPrefix, updateReferences));
}
private ICSearchScope createRefactoringScope() throws CoreException {
@ -405,11 +402,16 @@ public class RenameElementProcessor extends RenameProcessor implements IReferenc
return scope;
}
private OrPattern createSearchPattern(String searchPrefix) throws CoreException {
private OrPattern createSearchPattern(String searchPrefix, boolean updateReferences) throws CoreException {
OrPattern orPattern = new OrPattern();
if(fCElement instanceof IStructure){
orPattern.addPattern(SearchEngine.createSearchPattern( searchPrefix,
ICSearchConstants.TYPE, ICSearchConstants.REFERENCES, false ));
if(updateReferences){
orPattern.addPattern(SearchEngine.createSearchPattern( searchPrefix,
ICSearchConstants.TYPE, ICSearchConstants.ALL_OCCURRENCES, false ));
}else {
orPattern.addPattern(SearchEngine.createSearchPattern( searchPrefix,
ICSearchConstants.TYPE, ICSearchConstants.DECLARATIONS, false ));
}
IStructure structure = (IStructure) fCElement;
if(structure.getElementType() == ICElement.C_CLASS){
orPattern.addPattern(SearchEngine.createSearchPattern( searchPrefix + QUALIFIER + structure.getElementName(),
@ -419,57 +421,100 @@ public class RenameElementProcessor extends RenameProcessor implements IReferenc
}
}
else if(fCElement instanceof IMethod){
// The inline declaration is the same as the definition
// we don't need to search for the declaration if it is inline
ICElement parent = fCElement.getParent();
if(updateReferences){
orPattern.addPattern(SearchEngine.createSearchPattern( searchPrefix,
ICSearchConstants.METHOD, ICSearchConstants.ALL_OCCURRENCES, false ));
}else {
orPattern.addPattern(SearchEngine.createSearchPattern( searchPrefix,
ICSearchConstants.METHOD, ICSearchConstants.DEFINITIONS, false ));
// The inline declaration is the same as the definition
// we don't need to search for the definition if it is inline
/* ICElement parent = fCElement.getParent();
if( (!(((IMethod)fCElement).isInline())) && (!(parent instanceof IStructure )) ) {
orPattern.addPattern(SearchEngine.createSearchPattern( searchPrefix,
ICSearchConstants.METHOD, ICSearchConstants.DECLARATIONS, false ));
}
orPattern.addPattern(SearchEngine.createSearchPattern( searchPrefix,
ICSearchConstants.METHOD, ICSearchConstants.REFERENCES, false ));
*/ }
}
else if(fCElement instanceof IMethodDeclaration){
orPattern.addPattern(SearchEngine.createSearchPattern( searchPrefix,
ICSearchConstants.METHOD, ICSearchConstants.DEFINITIONS, false ));
orPattern.addPattern(SearchEngine.createSearchPattern( searchPrefix,
ICSearchConstants.METHOD, ICSearchConstants.REFERENCES, false ));
if(updateReferences){
orPattern.addPattern(SearchEngine.createSearchPattern( searchPrefix,
ICSearchConstants.METHOD, ICSearchConstants.ALL_OCCURRENCES, false ));
}else {
orPattern.addPattern(SearchEngine.createSearchPattern( searchPrefix,
ICSearchConstants.METHOD, ICSearchConstants.DECLARATIONS, false ));
}
}
else if(fCElement instanceof IFunction){
orPattern.addPattern(SearchEngine.createSearchPattern( searchPrefix,
ICSearchConstants.FUNCTION, ICSearchConstants.DECLARATIONS, false ));
orPattern.addPattern(SearchEngine.createSearchPattern( searchPrefix,
ICSearchConstants.FUNCTION, ICSearchConstants.REFERENCES, false ));
orPattern.addPattern(SearchEngine.createSearchPattern( searchPrefix,
ICSearchConstants.METHOD, ICSearchConstants.DECLARATIONS, false ));
orPattern.addPattern(SearchEngine.createSearchPattern( searchPrefix,
ICSearchConstants.METHOD, ICSearchConstants.REFERENCES, false ));
if(updateReferences){
orPattern.addPattern(SearchEngine.createSearchPattern( searchPrefix,
ICSearchConstants.FUNCTION, ICSearchConstants.ALL_OCCURRENCES, false ));
orPattern.addPattern(SearchEngine.createSearchPattern( searchPrefix,
ICSearchConstants.METHOD, ICSearchConstants.ALL_OCCURRENCES, false ));
}else {
orPattern.addPattern(SearchEngine.createSearchPattern( searchPrefix,
ICSearchConstants.FUNCTION, ICSearchConstants.DEFINITIONS, false ));
orPattern.addPattern(SearchEngine.createSearchPattern( searchPrefix,
ICSearchConstants.METHOD, ICSearchConstants.DEFINITIONS, false ));
}
}
else if(fCElement instanceof IFunctionDeclaration){
orPattern.addPattern(SearchEngine.createSearchPattern( searchPrefix,
ICSearchConstants.FUNCTION, ICSearchConstants.DEFINITIONS, false ));
orPattern.addPattern(SearchEngine.createSearchPattern( searchPrefix,
ICSearchConstants.FUNCTION, ICSearchConstants.REFERENCES, false ));
if(updateReferences){
orPattern.addPattern(SearchEngine.createSearchPattern( searchPrefix,
ICSearchConstants.FUNCTION, ICSearchConstants.ALL_OCCURRENCES, false ));
}else {
orPattern.addPattern(SearchEngine.createSearchPattern( searchPrefix,
ICSearchConstants.FUNCTION, ICSearchConstants.DECLARATIONS, false ));
}
}
else if(fCElement instanceof IEnumeration){
orPattern.addPattern(SearchEngine.createSearchPattern( searchPrefix,
ICSearchConstants.ENUM, ICSearchConstants.REFERENCES, false ));
if(updateReferences){
orPattern.addPattern(SearchEngine.createSearchPattern( searchPrefix,
ICSearchConstants.ENUM, ICSearchConstants.ALL_OCCURRENCES, false ));
}else {
orPattern.addPattern(SearchEngine.createSearchPattern( searchPrefix,
ICSearchConstants.ENUM, ICSearchConstants.DECLARATIONS, false ));
}
}
else if(fCElement instanceof IField){
orPattern.addPattern(SearchEngine.createSearchPattern( searchPrefix,
ICSearchConstants.FIELD, ICSearchConstants.REFERENCES, false ));
if(updateReferences){
orPattern.addPattern(SearchEngine.createSearchPattern( searchPrefix,
ICSearchConstants.FIELD, ICSearchConstants.ALL_OCCURRENCES, false ));
}else {
orPattern.addPattern(SearchEngine.createSearchPattern( searchPrefix,
ICSearchConstants.FIELD, ICSearchConstants.DECLARATIONS, false ));
}
}
else if(fCElement instanceof IVariable){
orPattern.addPattern(SearchEngine.createSearchPattern( searchPrefix,
ICSearchConstants.VAR, ICSearchConstants.REFERENCES, false ));
if(updateReferences){
orPattern.addPattern(SearchEngine.createSearchPattern( searchPrefix,
ICSearchConstants.VAR, ICSearchConstants.ALL_OCCURRENCES, false ));
}else {
orPattern.addPattern(SearchEngine.createSearchPattern( searchPrefix,
ICSearchConstants.VAR, ICSearchConstants.DECLARATIONS, false ));
}
}
else if(fCElement instanceof INamespace){
orPattern.addPattern(SearchEngine.createSearchPattern( searchPrefix,
ICSearchConstants.NAMESPACE, ICSearchConstants.REFERENCES, false ));
if(updateReferences){
orPattern.addPattern(SearchEngine.createSearchPattern( searchPrefix,
ICSearchConstants.NAMESPACE, ICSearchConstants.ALL_OCCURRENCES, false ));
}else {
orPattern.addPattern(SearchEngine.createSearchPattern( searchPrefix,
ICSearchConstants.NAMESPACE, ICSearchConstants.DECLARATIONS, false ));
}
}
else {
orPattern.addPattern(SearchEngine.createSearchPattern( searchPrefix,
ICSearchConstants.UNKNOWN_SEARCH_FOR, ICSearchConstants.REFERENCES, false ));
if(updateReferences){
orPattern.addPattern(SearchEngine.createSearchPattern( searchPrefix,
ICSearchConstants.UNKNOWN_SEARCH_FOR, ICSearchConstants.ALL_OCCURRENCES, false ));
}else {
orPattern.addPattern(SearchEngine.createSearchPattern( searchPrefix,
ICSearchConstants.UNKNOWN_SEARCH_FOR, ICSearchConstants.DECLARATIONS, false ));
}
}
return orPattern;
}

View file

@ -50,10 +50,12 @@ public class RefactoringStarter {
} else {
wizard.setActivationStatus(activationStatus);
Dialog dialog;
if (wizard.hasMultiPageUserInput())
if (wizard.hasMultiPageUserInput()){
dialog= new RefactoringWizardDialog(parent, wizard);
else
}
else {
dialog= new RefactoringWizardDialog2(parent, wizard);
}
if (dialog.open() == Window.CANCEL)
fSaveHelper.triggerBuild();
return null;

View file

@ -14,6 +14,22 @@ import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.cdt.internal.ui.CPluginImages;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.jface.dialogs.ControlEnableState;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.DialogSettings;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.IDialogSettings;
import org.eclipse.jface.dialogs.IMessageProvider;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.operation.ModalContext;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.util.Assert;
import org.eclipse.jface.wizard.IWizardContainer;
import org.eclipse.jface.wizard.IWizardPage;
import org.eclipse.jface.wizard.ProgressMonitorPart;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.StackLayout;
import org.eclipse.swt.events.SelectionAdapter;
@ -31,24 +47,6 @@ import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.jface.dialogs.ControlEnableState;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.DialogSettings;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.IDialogSettings;
import org.eclipse.jface.dialogs.IMessageProvider;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.operation.ModalContext;
import org.eclipse.jface.util.Assert;
import org.eclipse.jface.wizard.IWizardContainer;
import org.eclipse.jface.wizard.IWizardPage;
import org.eclipse.jface.wizard.ProgressMonitorPart;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.internal.ui.CPluginImages;
public class RefactoringWizardDialog2 extends Dialog implements IWizardContainer {
private RefactoringWizard fWizard;

View file

@ -11,12 +11,11 @@
package org.eclipse.cdt.internal.ui.refactoring;
import org.eclipse.jface.wizard.IWizardPage;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.cdt.internal.corext.refactoring.base.Refactoring;
import org.eclipse.cdt.internal.corext.refactoring.base.RefactoringStatus;
import org.eclipse.cdt.internal.ui.CPluginImages;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.jface.wizard.IWizardPage;
/**
* An abstract wizard page that can be used to implement user input pages for
@ -52,14 +51,17 @@ public abstract class UserInputWizardPage extends RefactoringWizardPage {
if (severity == RefactoringStatus.FATAL){
setPageComplete(false);
setErrorMessage(status.getFirstMessage(severity));
setImageDescriptor(CPluginImages.DESC_OBJS_DEFAULT_CHANGE);
} else {
setPageComplete(true);
setErrorMessage(null);
//setErrorMessage(RefactoringMessages.getString("RenameInputWizardPage.no_undo")); //$NON-NLS-1$
if (severity == RefactoringStatus.OK)
setMessage(null, NONE);
else
setMessage(status.getFirstMessage(severity), getCorrespondingIStatusSeverity(severity));
else {
setMessage(status.getFirstMessage(severity), getCorrespondingIStatusSeverity(severity));
setImageDescriptor(CPluginImages.DESC_OBJS_DEFAULT_CHANGE);
}
}
}

View file

@ -198,6 +198,12 @@ public class CPluginImages {
public static final String IMG_OBJS_REFACTORING_ERROR= NAME_PREFIX + "error_obj.gif"; //$NON-NLS-1$
public static final String IMG_OBJS_REFACTORING_WARNING= NAME_PREFIX + "warning_obj.gif"; //$NON-NLS-1$
public static final String IMG_OBJS_REFACTORING_INFO= NAME_PREFIX + "info_obj.gif"; //$NON-NLS-1$
public static final ImageDescriptor DESC_REFACTORING_FATAL= createManaged( T_OBJ, IMG_OBJS_REFACTORING_FATAL); //$NON-NLS-1$
public static final ImageDescriptor DESC_REFACTORING_ERROR= createManaged( T_OBJ, IMG_OBJS_REFACTORING_ERROR); //$NON-NLS-1$
public static final ImageDescriptor DESC_REFACTORING_WARNING= createManaged( T_OBJ, IMG_OBJS_REFACTORING_WARNING); //$NON-NLS-1$
public static final ImageDescriptor DESC_REFACTORING_INFO= createManaged ( T_OBJ, IMG_OBJS_REFACTORING_INFO); //$NON-NLS-1$
public static final ImageDescriptor DESC_WIZBAN_REFACTOR_FIELD= create(T_WIZBAN, "fieldrefact_wiz.gif"); //$NON-NLS-1$
public static final ImageDescriptor DESC_WIZBAN_REFACTOR_METHOD= create(T_WIZBAN, "methrefact_wiz.gif"); //$NON-NLS-1$
public static final ImageDescriptor DESC_WIZBAN_REFACTOR_TYPE= create(T_WIZBAN, "typerefact_wiz.gif"); //$NON-NLS-1$