1 11 package org.eclipse.jdt.internal.junit.refactoring; 12 13 import java.util.ArrayList ; 14 import java.util.Iterator ; 15 import java.util.List ; 16 17 import org.eclipse.core.runtime.CoreException; 18 import org.eclipse.core.runtime.IProgressMonitor; 19 import org.eclipse.core.runtime.OperationCanceledException; 20 21 import org.eclipse.debug.core.DebugPlugin; 22 import org.eclipse.debug.core.ILaunchConfiguration; 23 import org.eclipse.debug.core.ILaunchConfigurationType; 24 import org.eclipse.debug.core.ILaunchManager; 25 26 import org.eclipse.ltk.core.refactoring.Change; 27 import org.eclipse.ltk.core.refactoring.CompositeChange; 28 import org.eclipse.ltk.core.refactoring.RefactoringStatus; 29 import org.eclipse.ltk.core.refactoring.participants.CheckConditionsContext; 30 import org.eclipse.ltk.core.refactoring.participants.RenameArguments; 31 import org.eclipse.ltk.core.refactoring.participants.RenameParticipant; 32 33 import org.eclipse.jdt.internal.junit.ui.JUnitMessages; 34 import org.eclipse.jdt.internal.junit.ui.JUnitPlugin; 35 36 public abstract class JUnitRenameParticipant extends RenameParticipant implements IChangeAdder { 37 38 static public class ChangeList { 39 40 private final RenameArguments fArguments; 41 42 private List fChanges; 43 44 private final ILaunchManager fLaunchManager; 45 46 private boolean fShouldFlagWarnings= true; 47 48 public ChangeList(RenameArguments arguments, ILaunchManager manager, List changes) { 49 fArguments= arguments; 50 fLaunchManager= manager; 51 fChanges= changes; 52 } 53 54 public void addChange(Change change) { 55 if (change != null) { 56 fChanges.add(change); 57 fShouldFlagWarnings= false; 58 } 59 } 60 61 public void createChangeForConfigs(ILaunchConfiguration[] configs, IChangeAdder changeCreator) throws CoreException { 62 for (int i= 0; i < configs.length; i++) { 63 fShouldFlagWarnings= true; 64 changeCreator.createChangeForConfig(this, new LaunchConfigurationContainer(configs[i])); 65 } 66 } 67 68 public boolean shouldFlagWarnings() { 69 return fShouldFlagWarnings; 70 } 71 72 public void addRenameChangeIfNeeded(LaunchConfigurationContainer config, String oldName) { 73 if (config.getName().equals(oldName)) { 74 LaunchConfigRenameChange renameChange= new LaunchConfigRenameChange(config, fArguments.getNewName(), fLaunchManager, shouldFlagWarnings()); 75 addChange(renameChange); 76 } 77 } 78 79 public void addAttributeChangeIfNeeded(LaunchConfigurationContainer config, String attributeName, String oldValue, String newValue) throws CoreException { 80 String currentValue= config.getAttribute(attributeName, (String ) null); 81 if (currentValue != null && oldValue.equals(currentValue)) { 82 addAttributeChange(config, attributeName, newValue); 83 } 84 } 85 86 public void addAttributeChange(LaunchConfigurationContainer config, String attributeName, String newValue) { 87 addChange(new LaunchConfigSetAttributeChange(config, attributeName, newValue, shouldFlagWarnings())); 88 } 89 } 90 91 public RefactoringStatus checkConditions(IProgressMonitor pm, CheckConditionsContext context) { 92 return new RefactoringStatus(); 93 } 94 95 public Change createChange(IProgressMonitor pm) throws CoreException { 96 if (!getArguments().getUpdateReferences()) 97 return null; 98 99 ILaunchManager manager= getLaunchManager(); 100 List launchConfigTypes= getLaunchConfigTypes(); 101 List changes= new ArrayList (); 102 for (Iterator types= launchConfigTypes.iterator(); types.hasNext();) { 103 String typeId= (String ) types.next(); 104 ILaunchConfigurationType type= manager.getLaunchConfigurationType(typeId); 105 ILaunchConfiguration configs[]= manager.getLaunchConfigurations(type); 106 new ChangeList(getArguments(), getLaunchManager(), changes).createChangeForConfigs(configs, this); 107 if (pm.isCanceled()) 108 throw new OperationCanceledException(); 109 } 110 if (changes.size() > 0) 111 return new CompositeChange(getChangeName(), (Change[]) changes.toArray(new Change[changes.size()])); 112 return null; 113 } 114 115 public abstract void createChangeForConfig(ChangeList list, LaunchConfigurationContainer config) throws CoreException; 119 120 protected String getChangeName() { 121 return JUnitMessages.TypeRenameParticipant_change_name; 122 } 123 124 protected List getLaunchConfigTypes() { 125 return JUnitPlugin.getDefault().getJUnitLaunchConfigTypeIDs(); 126 } 127 128 protected ILaunchManager getLaunchManager() { 129 return DebugPlugin.getDefault().getLaunchManager(); 130 } 131 132 protected String getNewName() { 133 return getArguments().getNewName(); 134 } 135 136 139 public String getName() { 140 return JUnitMessages.TypeRenameParticipant_name; 141 } 142 } 143 | Popular Tags |