KickJava   Java API By Example, From Geeks To Geeks.

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


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.IType;
20 import org.eclipse.jdt.core.refactoring.IJavaRefactorings;
21
22 import org.eclipse.jdt.internal.core.refactoring.descriptors.DescriptorMessages;
23
24 /**
25  * Refactoring descriptor for the use supertype refactoring.
26  * <p>
27  * An instance of this refactoring descriptor may be obtained by calling
28  * {@link RefactoringContribution#createDescriptor()} on a refactoring
29  * contribution requested by invoking
30  * {@link RefactoringCore#getRefactoringContribution(String)} with the
31  * appropriate refactoring id.
32  * </p>
33  * <p>
34  * Note: this class is not intended to be instantiated by clients.
35  * </p>
36  *
37  * @since 3.3
38  */

39 public final class UseSupertypeDescriptor extends JavaRefactoringDescriptor {
40
41     /** The instanceof attribute */
42     private static final String JavaDoc ATTRIBUTE_INSTANCEOF= "instanceof"; //$NON-NLS-1$
43

44     /** The instanceof attribute */
45     private boolean fInstanceof= false;
46
47     /** The subtype attribute */
48     private IType fSubType= null;
49
50     /** The supertype attribute */
51     private IType fSupertype= null;
52
53     /**
54      * Creates a new refactoring descriptor.
55      */

56     public UseSupertypeDescriptor() {
57         super(IJavaRefactorings.USE_SUPER_TYPE);
58     }
59
60     /**
61      * {@inheritDoc}
62      */

63     protected void populateArgumentMap() {
64         super.populateArgumentMap();
65         fArguments.put(ATTRIBUTE_INSTANCEOF, Boolean.valueOf(fInstanceof).toString());
66         fArguments.put(JavaRefactoringDescriptor.ATTRIBUTE_INPUT, elementToHandle(getProject(), fSubType));
67         fArguments.put(JavaRefactoringDescriptor.ATTRIBUTE_ELEMENT + 1, elementToHandle(getProject(), fSupertype));
68     }
69
70     /**
71      * Determines whether 'instanceof' statements are considered as candidates
72      * to replace the subtype occurrence by one of its supertypes.
73      * <p>
74      * The default is to not replace the subtype occurrence.
75      * </p>
76      *
77      * @param replace
78      * <code>true</code> to replace subtype occurrences in
79      * 'instanceof' statements, <code>false</code> otherwise
80      */

81     public void setReplaceInstanceof(final boolean replace) {
82         fInstanceof= replace;
83     }
84
85     /**
86      * Sets the subtype of the refactoring.
87      * <p>
88      * Occurrences of the subtype are replaced by the supertype set by
89      * {@link #setSupertype(IType)} where possible.
90      * </p>
91      *
92      * @param type
93      * the subtype to set
94      */

95     public void setSubtype(final IType type) {
96         Assert.isNotNull(type);
97         fSubType= type;
98     }
99
100     /**
101      * Sets the supertype of the refactoring.
102      * <p>
103      * Occurrences of the subtype set by {@link #setSubtype(IType)} are replaced
104      * by the supertype where possible.
105      * </p>
106      *
107      * @param type
108      * the supertype to set
109      */

110     public void setSupertype(final IType type) {
111         Assert.isNotNull(type);
112         fSupertype= type;
113     }
114
115     /**
116      * {@inheritDoc}
117      */

118     public RefactoringStatus validateDescriptor() {
119         RefactoringStatus status= super.validateDescriptor();
120         if (fSubType == null)
121             status.merge(RefactoringStatus.createFatalErrorStatus(DescriptorMessages.UseSupertypeDescriptor_no_subtype));
122         if (fSupertype == null)
123             status.merge(RefactoringStatus.createFatalErrorStatus(DescriptorMessages.UseSupertypeDescriptor_no_supertype));
124         return status;
125     }
126 }
Popular Tags