KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > junit > refactoring > TypeRenameParticipant


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.jdt.internal.junit.refactoring;
12
13 import org.eclipse.core.runtime.CoreException;
14
15 import org.eclipse.jdt.core.IType;
16
17 import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
18
19 import org.eclipse.jdt.internal.junit.util.TestSearchEngine;
20
21 public class TypeRenameParticipant extends JUnitRenameParticipant {
22
23     private IType fType;
24
25     protected boolean initialize(Object JavaDoc element) {
26         fType= (IType) element;
27         return isTestOrTestSuite();
28     }
29
30     protected boolean isTestOrTestSuite() {
31         try {
32             return TestSearchEngine.isTestOrTestSuite(fType);
33         } catch (CoreException e) {
34             return false;
35         }
36     }
37
38     public void createChangeForConfig(ChangeList list, LaunchConfigurationContainer config) throws CoreException {
39         String JavaDoc typeName= fType.getFullyQualifiedName('.');
40         String JavaDoc mainType= config.getAttribute(IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME, (String JavaDoc) null);
41         if (typeName.equals(mainType)) {
42             int index= mainType.lastIndexOf('.');
43             String JavaDoc prefix;
44             if (index == -1)
45                 prefix= ""; //$NON-NLS-1$
46
prefix= mainType.substring(0, index + 1);
47             String JavaDoc newValue= prefix + getNewName();
48             list.addAttributeChange(config, IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME, newValue);
49
50             list.addRenameChangeIfNeeded(config, fType.getElementName());
51         }
52     }
53 }
54
Popular Tags