KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > corext > refactoring > scripting > RenameMethodRefactoringContribution


1 /*******************************************************************************
2  * Copyright (c) 2005, 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.corext.refactoring.scripting;
12
13 import java.util.Map JavaDoc;
14
15 import org.eclipse.ltk.core.refactoring.Refactoring;
16 import org.eclipse.ltk.core.refactoring.RefactoringDescriptor;
17
18 import org.eclipse.jdt.core.IMethod;
19 import org.eclipse.jdt.core.JavaModelException;
20 import org.eclipse.jdt.core.refactoring.IJavaRefactorings;
21 import org.eclipse.jdt.core.refactoring.descriptors.RenameJavaElementDescriptor;
22
23 import org.eclipse.jdt.internal.corext.refactoring.JDTRefactoringContribution;
24 import org.eclipse.jdt.internal.corext.refactoring.JDTRefactoringDescriptor;
25 import org.eclipse.jdt.internal.corext.refactoring.rename.JavaRenameProcessor;
26 import org.eclipse.jdt.internal.corext.refactoring.rename.JavaRenameRefactoring;
27 import org.eclipse.jdt.internal.corext.refactoring.rename.MethodChecks;
28 import org.eclipse.jdt.internal.corext.refactoring.rename.RenameNonVirtualMethodProcessor;
29 import org.eclipse.jdt.internal.corext.refactoring.rename.RenameVirtualMethodProcessor;
30
31 /**
32  * Refactoring contribution for the rename method refactoring.
33  *
34  * @since 3.2
35  */

36 public final class RenameMethodRefactoringContribution extends JDTRefactoringContribution {
37
38     /**
39      * {@inheritDoc}
40      */

41     public Refactoring createRefactoring(final RefactoringDescriptor descriptor) throws JavaModelException {
42         String JavaDoc project= descriptor.getProject();
43         Map JavaDoc arguments= ((JDTRefactoringDescriptor) descriptor).getArguments();
44         String JavaDoc input= (String JavaDoc) arguments.get(JDTRefactoringDescriptor.ATTRIBUTE_INPUT);
45         IMethod method= (IMethod) JDTRefactoringDescriptor.handleToElement(project, input);
46         
47         JavaRenameProcessor processor;
48         if (MethodChecks.isVirtual(method)) {
49             processor= new RenameVirtualMethodProcessor(method);
50         } else {
51             processor= new RenameNonVirtualMethodProcessor(method);
52         }
53         return new JavaRenameRefactoring(processor);
54     }
55     
56     /**
57      * {@inheritDoc}
58      */

59     public RefactoringDescriptor createDescriptor() {
60         return new RenameJavaElementDescriptor(IJavaRefactorings.RENAME_METHOD);
61     }
62 }
63
Popular Tags