KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.lang.reflect.Modifier JavaDoc;
22 import org.netbeans.api.java.source.TreePathHandle;
23 import org.netbeans.modules.refactoring.api.AbstractRefactoring;
24 import org.openide.util.lookup.Lookups;
25
26 /** Extract Interface Refactoring implementation class.
27  *
28  * @author Martin Matula, Jan Becicka
29  */

30 public final class ExtractInterfaceRefactoring extends AbstractRefactoring {
31     private static final TreePathHandle[] EMPTY_MEMBERS = new TreePathHandle[0];
32
33     // name of the new class to be created
34
private String JavaDoc ifcName;
35     private TreePathHandle[] members;
36     
37     /** Creates a new instance of ExtractInterfaceRefactoring
38      * @param sourceType Type the members of which should be extracted into an interface.
39      */

40     public ExtractInterfaceRefactoring(TreePathHandle sourceType) {
41         super(Lookups.fixed(sourceType));
42         // check if the sourceType is a ParameterizedType - if so, unwrap it
43
}
44     
45     /** Returns the type the members of which should be extracted into an interface
46      * by this refactoring.
47      * @return Source of the members to be extracted.
48      */

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

55     /** Returns name of the interface to be created.
56      * @return Name of the new interface or null if it is not set.
57      */

58     public String JavaDoc getInterfaceName() {
59         return ifcName;
60     }
61
62     /** Sets the name of the interface to be created.
63      * @param ifcName Name of the new interface.
64      */

65     public void setInterfaceName(String JavaDoc ifcName) {
66         this.ifcName = ifcName;
67     }
68
69     /** Returns members to extract.
70      * @return Array of members.
71      */

72     public TreePathHandle[] getMembers() {
73         // never return null
74
return members == null ? EMPTY_MEMBERS : members;
75     }
76
77     /** Sets members to extract.
78      * @param members Array of members to extract.
79      */

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

86 // public boolean acceptFeature(Feature feature) {
87
// int modifiers = feature.getModifiers();
88
// if (Modifier.isPublic(modifiers)) {
89
// if (feature instanceof JavaClass) {
90
// if (Modifier.isStatic(modifiers)) {
91
// return true;
92
// }
93
// } else if (feature instanceof Field) {
94
// if (Modifier.isStatic(modifiers) && Modifier.isFinal(modifiers) && ((Field) feature).getInitialValueText() != null) {
95
// return true;
96
// }
97
// } else if (feature instanceof Method) {
98
// if (!Modifier.isStatic(modifiers)) {
99
// return true;
100
// }
101
// }
102
// }
103
// return false;
104
// }
105
}
106
Popular Tags