KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > core > refactoring > descriptors > MoveStaticMembersDescriptor


1 /*******************************************************************************
2  * Copyright (c) 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.core.refactoring.descriptors;
12
13 import org.eclipse.core.runtime.Assert;
14
15 import org.eclipse.ltk.core.refactoring.RefactoringContribution;
16 import org.eclipse.ltk.core.refactoring.RefactoringCore;
17 import org.eclipse.ltk.core.refactoring.RefactoringStatus;
18
19 import org.eclipse.jdt.core.IMember;
20 import org.eclipse.jdt.core.IType;
21 import org.eclipse.jdt.core.refactoring.IJavaRefactorings;
22
23 import org.eclipse.jdt.internal.core.refactoring.descriptors.DescriptorMessages;
24
25 /**
26  * Refactoring descriptor for the move static members refactoring.
27  * <p>
28  * An instance of this refactoring descriptor may be obtained by calling
29  * {@link RefactoringContribution#createDescriptor()} on a refactoring
30  * contribution requested by invoking
31  * {@link RefactoringCore#getRefactoringContribution(String)} with the
32  * appropriate refactoring id.
33  * </p>
34  * <p>
35  * Note: this class is not intended to be instantiated by clients.
36  * </p>
37  *
38  * @since 3.3
39  */

40 public final class MoveStaticMembersDescriptor extends JavaRefactoringDescriptor {
41
42     /** The delegate attribute */
43     private static final String JavaDoc ATTRIBUTE_DELEGATE= "delegate"; //$NON-NLS-1$
44

45     /** The deprecate attribute */
46     private static final String JavaDoc ATTRIBUTE_DEPRECATE= "deprecate"; //$NON-NLS-1$
47

48     /** The delegate attribute */
49     private boolean fDelegate= false;
50
51     /** The deprecate attribute */
52     private boolean fDeprecate= false;
53
54     /** The members attribute */
55     private IMember[] fMembers;
56
57     /** The type attribute */
58     private IType fType= null;
59
60     /**
61      * Creates a new refactoring descriptor.
62      */

63     public MoveStaticMembersDescriptor() {
64         super(IJavaRefactorings.MOVE_STATIC_MEMBERS);
65     }
66
67     /**
68      * {@inheritDoc}
69      */

70     protected void populateArgumentMap() {
71         super.populateArgumentMap();
72         fArguments.put(JavaRefactoringDescriptor.ATTRIBUTE_INPUT, elementToHandle(getProject(), fType));
73         fArguments.put(ATTRIBUTE_DELEGATE, Boolean.valueOf(fDelegate).toString());
74         fArguments.put(ATTRIBUTE_DEPRECATE, Boolean.valueOf(fDeprecate).toString());
75         for (int index= 0; index < fMembers.length; index++)
76             fArguments.put(JavaRefactoringDescriptor.ATTRIBUTE_ELEMENT + (index + 1), elementToHandle(getProject(), fMembers[index]));
77     }
78
79     /**
80      * Determines whether the delegate for a member should be declared as
81      * deprecated.
82      *
83      * @param deprecate
84      * <code>true</code> to deprecate the delegate,
85      * <code>false</code> otherwise
86      */

87     public void setDeprecateDelegate(final boolean deprecate) {
88         fDeprecate= deprecate;
89     }
90
91     /**
92      * Sets the destination type of the move operation.
93      *
94      * @param type
95      * the destination type
96      */

97     public void setDestinationType(final IType type) {
98         Assert.isNotNull(type);
99         fType= type;
100     }
101
102     /**
103      * Determines whether the the original members should be kept as delegates
104      * to the moved ones.
105      *
106      * @param delegate
107      * <code>true</code> to keep the originals, <code>false</code>
108      * otherwise
109      */

110     public void setKeepOriginal(final boolean delegate) {
111         fDelegate= delegate;
112     }
113
114     /**
115      * Sets the static members to move.
116      *
117      * @param members
118      * the members to move
119      */

120     public void setMembers(final IMember[] members) {
121         Assert.isNotNull(members);
122         fMembers= members;
123     }
124
125     /**
126      * {@inheritDoc}
127      */

128     public RefactoringStatus validateDescriptor() {
129         final RefactoringStatus status= super.validateDescriptor();
130         if (fType == null)
131             status.merge(RefactoringStatus.createFatalErrorStatus(DescriptorMessages.MoveStaticMembersDescriptor_no_type));
132         if (fMembers == null)
133             status.merge(RefactoringStatus.createFatalErrorStatus(DescriptorMessages.MoveStaticMembersDescriptor_no_members));
134         else {
135             for (int index= 0; index < fMembers.length; index++) {
136                 if (fMembers[index] == null) {
137                     status.merge(RefactoringStatus.createFatalErrorStatus(DescriptorMessages.MoveStaticMembersDescriptor_invalid_members));
138                     break;
139                 }
140             }
141         }
142         return status;
143     }
144 }
Popular Tags