1 11 package org.eclipse.jdt.internal.junit.refactoring; 12 13 import org.eclipse.core.runtime.CoreException; 14 15 import org.eclipse.core.resources.IProject; 16 17 import org.eclipse.jdt.core.IJavaElement; 18 import org.eclipse.jdt.core.IJavaProject; 19 import org.eclipse.jdt.core.IPackageFragment; 20 import org.eclipse.jdt.core.IPackageFragmentRoot; 21 import org.eclipse.jdt.core.JavaCore; 22 23 import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants; 24 25 import org.eclipse.jdt.internal.junit.launcher.JUnitLaunchConfigurationConstants; 26 27 public class ProjectRenameParticipant extends JUnitRenameParticipant { 28 29 private IJavaProject fProject; 30 31 private IJavaProject getNewJavaProject() { 32 IProject project= fProject.getProject().getWorkspace().getRoot().getProject(getNewName()); 33 return getJavaProject(project); 34 } 35 36 protected IJavaProject getJavaProject(IProject project) { 37 return JavaCore.create(project); 38 } 39 40 protected boolean initialize(Object element) { 41 fProject= (IJavaProject) element; 42 return true; 43 } 44 45 public void createChangeForConfig(JUnitRenameParticipant.ChangeList changeList, LaunchConfigurationContainer config) throws CoreException { 46 47 changeList.addAttributeChangeIfNeeded(config, IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME, fProject.getElementName(), getNewName()); 48 49 IJavaProject newJavaProject= getNewJavaProject(); 50 51 String container= config.getAttribute(JUnitLaunchConfigurationConstants.ATTR_TEST_CONTAINER, (String ) null); 52 IJavaElement javaElement= getJavaElement(container); 53 if (javaElement == null) 54 return; 55 IJavaElement potentialMatch= javaElement; 56 57 while (!potentialMatch.getHandleIdentifier().equals(fProject.getHandleIdentifier())) { 59 potentialMatch= potentialMatch.getParent(); 60 if (potentialMatch == null) 61 return; 62 } 63 64 String newHandle; 65 if (javaElement instanceof IPackageFragment) { 66 IPackageFragment fragment= (IPackageFragment) javaElement; 67 newHandle= newJavaProject.getPackageFragmentRoot(fragment.getParent().getElementName()).getPackageFragment(fragment.getElementName()).getHandleIdentifier(); 68 } else if (javaElement instanceof IPackageFragmentRoot) { 69 IPackageFragmentRoot root= (IPackageFragmentRoot) javaElement; 70 newHandle= newJavaProject.getPackageFragmentRoot(root.getElementName()).getHandleIdentifier(); 71 } else if (javaElement instanceof IJavaProject) { 72 newHandle= newJavaProject.getHandleIdentifier(); 73 } else { 74 return; 76 } 77 changeList.addAttributeChange(config, JUnitLaunchConfigurationConstants.ATTR_TEST_CONTAINER, newHandle); 78 79 changeList.addRenameChangeIfNeeded(config, fProject.getElementName()); 81 } 82 83 protected IJavaElement getJavaElement(String handle) { 84 return JavaCore.create(handle); 85 } 86 } 87 | Popular Tags |