KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > refactoring > java > api > PullUpRefactoring


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 package org.netbeans.modules.refactoring.java.api;
20
21 import org.netbeans.api.java.source.TreePathHandle;
22 import org.netbeans.modules.refactoring.api.AbstractRefactoring;
23 import org.openide.util.Lookup;
24
25 /** Pull Up Refactoring implementation class.
26  *
27  * @author Jan Becicka, Martin Matula
28  */

29 public final class PullUpRefactoring extends AbstractRefactoring {
30     private static final MemberInfo[] EMPTY_MEMBERS = new MemberInfo[0];
31
32     // parameters of the refactoring
33
private TreePathHandle targetType;
34     private MemberInfo[] members;
35     
36     /** Creates a new instance of PullUpRefactoring
37      * @param sourceType Type the members of which should be pulled up.
38      */

39     public PullUpRefactoring(Lookup sourceType) {
40         super(sourceType);
41     }
42     
43
44     /** Returns the type the members of which should be pulled up
45      * by this refactoring.
46      * @return Source of the members to be pulled up.
47      */

48     public TreePathHandle getSourceType() {
49         return getRefactoringSource().lookup(TreePathHandle.class);
50     }
51
52     // --- PARAMETERS ----------------------------------------------------------
53

54     /** Returns target supertype to pull members up to.
55      * @return Target supertype or null if no target supertype is set.
56      */

57     public TreePathHandle getTargetType() {
58         return targetType;
59     }
60
61     /** Sets target supertype to pull members up to.
62      * @param targetType Target supertype.
63      */

64     public void setTargetType(TreePathHandle targetType) {
65         this.targetType = targetType;
66     }
67
68     /** Returns descriptors of the members to pull up.
69      * @return Member descriptors.
70      */

71     public MemberInfo[] getMembers() {
72         // never return null
73
return members == null ? EMPTY_MEMBERS : members;
74     }
75
76     /** Sets members (using their descriptors) to pull up.
77      * @param members Descriptors of members to be pulled up.
78      */

79     public void setMembers(MemberInfo[] members) {
80         this.members = members;
81     }
82     
83     // --- HELPER METHODS ------------------------------------------------------
84

85 // /** Returns supertypes of the source type that the members could
86
// * be pull up to.
87
// * @return Supertypes available for pulling up members to.
88
// */
89
// public TreePathHandle[] collectSupertypes() {
90
// if (supertypes == null) {
91
// if (sourceType != null) {
92
// List list = new ArrayList();
93
// // collect all supertypes recursivelly using a helper method
94
// collectSupertypes(sourceType, list, new HashSet());
95
// supertypes = (JavaClass[]) list.toArray(new JavaClass[list.size()]);
96
// } else {
97
// supertypes = new JavaClass[0];
98
// }
99
// }
100
// return supertypes;
101
// }
102
//
103
// // helper method for collecting supertypes
104
// private static void collectSupertypes(JavaClass type, List result, Set visited) {
105
// JavaClass superClass = Utilities.getRealClass(type.getSuperClass());
106
// ArrayList supertypes = new ArrayList();
107
//
108
// // get superclass (if not visited already)
109
// if (superClass != null && visited.add(superClass)) {
110
// supertypes.add(superClass);
111
// // add it to the result set if its source is available
112
// if (Utilities.isFromSource(superClass) && !CheckUtils.isFromLibrary(superClass.getResource())) {
113
// result.add(superClass);
114
// }
115
// }
116
//
117
// // get all implemented super interfaces (if not visited already)
118
// for (Iterator it = type.getInterfaces().iterator(); it.hasNext();) {
119
// JavaClass ifc = Utilities.getRealClass((JavaClass) it.next());
120
// if (visited.add(ifc)) {
121
// supertypes.add(ifc);
122
// // add it to the result set if its source is available
123
// if (Utilities.isFromSource(ifc)) {
124
// result.add(ifc);
125
// }
126
// }
127
// }
128
//
129
// // iterate through the collected direct supertypes
130
// // and collect their supertypes recursivelly
131
// // (this is done in a separate loop to preserve logical ordering
132
// // of the supertypes)
133
// for (Iterator it = supertypes.iterator(); it.hasNext();) {
134
// collectSupertypes((JavaClass) it.next(), result, visited);
135
// }
136
// }
137
//
138

139     // --- HELPER CLASSES ------------------------------------------------------
140

141     /** Class describing a member to be pulled up.
142      */

143     public static final class MemberInfo {
144         public final TreePathHandle member;
145         public final boolean makeAbstract;
146         
147         /** Creates a new instance of MemberInfo describing a method.
148          * @param method Method to be pulled up.
149          * @param makeAbstract Indicates whether the method should be made abstract
150          * in the supertype.
151          */

152         private MemberInfo(TreePathHandle member, boolean makeAbstract) {
153             this.member = member;
154             this.makeAbstract = makeAbstract;
155         }
156
157         /** Creates a new instance of MemberInfo describing an inner class
158          * to be pulled up.
159          * @param field Inner class to be pulled up.
160          */

161         public MemberInfo(TreePathHandle innerClass) {
162             this(innerClass, false);
163         }
164         
165 // /** Creates a new instance of MemberInfo describing a field
166
// * to be pulled up.
167
// * @param field Field to be pulled up.
168
// */
169
// public MemberInfo(TreePathHandle field) {
170
// this(field, false);
171
// }
172
//
173
// /** Creates a new instance of MemberInfo describing an interface name
174
// * from the implements clause that should be pulled up.
175
// * @param interfaceName Interface name to be pulled up.
176
// */
177
// public MemberInfo(TreePathHandle interfaceName) {
178
// this(interfaceName, false);
179
// }
180
}
181 }
182
Popular Tags