001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041: package org.netbeans.modules.refactoring.java.ui;
042:
043: import java.util.ArrayList;
044: import java.util.Collection;
045: import java.util.Collections;
046: import java.util.Set;
047: import javax.lang.model.element.Modifier;
048: import org.netbeans.api.java.source.TreePathHandle;
049: import org.netbeans.modules.refactoring.api.AbstractRefactoring;
050: import org.openide.util.lookup.Lookups;
051:
052: /** Encapsulate fields refactoring. This is a composed refactoring (uses instances of {@link org.netbeans.modules.refactoring.api.EncapsulateFieldRefactoring}
053: * to encapsulate several fields at once.
054: *
055: * @author Pavel Flaska
056: * @author Jan Becicka
057: * @author Jan Pokorsky
058: */
059: public final class EncapsulateFieldsRefactoring extends
060: AbstractRefactoring {
061:
062: private Collection<EncapsulateFieldInfo> refactorFields = Collections
063: .emptyList();
064: private Set<Modifier> methodModifiers = Collections.emptySet();
065: private Set<Modifier> fieldModifiers = Collections.emptySet();;
066: private boolean alwaysUseAccessors;
067:
068: /** Creates a new instance of EcapsulateFields.
069: * @param selectedObject field to encapsulate, whatever tree of class
070: * containing trees to encapsulate
071: */
072: public EncapsulateFieldsRefactoring(TreePathHandle selectedObject) {
073: super (Lookups.fixed(selectedObject));
074: }
075:
076: /**
077: * Getter for property refactorFields
078: * @return Value of refactorFields
079: */
080: public Collection<EncapsulateFieldInfo> getRefactorFields() {
081: return refactorFields;
082: }
083:
084: /**
085: * Getter for property methodModifier
086: * @return Value of methodModifier
087: */
088: public Set<Modifier> getMethodModifiers() {
089: return methodModifiers;
090: }
091:
092: /**
093: * Getter for property fieldModifier
094: * @return Value of fieldModifier
095: */
096: public Set<Modifier> getFieldModifiers() {
097: return fieldModifiers;
098: }
099:
100: /**
101: * Getter for property alwaysUseAccessors
102: * @return Value of alwaysUseAccessors
103: */
104: public boolean isAlwaysUseAccessors() {
105: return alwaysUseAccessors;
106: }
107:
108: /**
109: * Setter for property refactorFields
110: * @param refactorFields New value of property refactorFields
111: */
112: public void setRefactorFields(
113: Collection<EncapsulateFieldInfo> refactorFields) {
114: this .refactorFields = Collections
115: .unmodifiableCollection(new ArrayList<EncapsulateFieldInfo>(
116: refactorFields));
117: }
118:
119: /**
120: * Setter for property methodModifier
121: * @param methodModifier New value of property methodModifier
122: */
123: public void setMethodModifiers(Set<Modifier> methodModifier) {
124: this .methodModifiers = methodModifier;
125: }
126:
127: /**
128: * Setter for property fieldModifier
129: * @param fieldModifier New value of property fieldModifier
130: */
131: public void setFieldModifiers(Set<Modifier> fieldModifier) {
132: this .fieldModifiers = fieldModifier;
133: }
134:
135: /**
136: * Setter for property alwaysUseAccessors
137: * @param alwaysUseAccessors New value of property alwaysUseAccessors
138: */
139: public void setAlwaysUseAccessors(boolean alwaysUseAccessors) {
140: this .alwaysUseAccessors = alwaysUseAccessors;
141: }
142:
143: public TreePathHandle getSelectedObject() {
144: return getRefactoringSource().lookup(TreePathHandle.class);
145: }
146:
147: ////////////////////////////////////////////////////////////////////////////
148: // INNER CLASSES
149: ////////////////////////////////////////////////////////////////////////////
150: /**
151: * Represents data from the panel.
152: */
153: public static final class EncapsulateFieldInfo {
154: TreePathHandle field;
155: String getterName;
156: String setterName;
157:
158: /**
159: * Creates an instance of Encapsulate Field Info
160: * @param field
161: * @param getterName
162: * @param setterName
163: */
164: public EncapsulateFieldInfo(TreePathHandle field,
165: String getterName, String setterName) {
166: this .field = field;
167: this .getterName = getterName;
168: this .setterName = setterName;
169: }
170:
171: /**
172: * Getter for property getterName.
173: *
174: * @return Value of property getterName.
175: */
176: public String getGetterName() {
177: return getterName;
178: }
179:
180: /**
181: * Getter for property setterName.
182: *
183: * @return Value of property setterName.
184: */
185: public String getSetterName() {
186: return setterName;
187: }
188:
189: /**
190: * Getter for property field.
191: *
192: * @return Value of property field.
193: */
194: public TreePathHandle getField() {
195: return field;
196: }
197:
198: }
199: }
|