• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2012 The Android Open Source Project
3  *
4  * Licensed under the Eclipse Public License, Version 1.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.eclipse.org/org/documents/epl-v10.php
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package com.android.ide.eclipse.adt.internal.refactorings.core;
17 
18 import com.android.annotations.NonNull;
19 import com.android.annotations.Nullable;
20 
21 /**
22  * A result from a renaming operation
23  */
24 public class RenameResult {
25     private boolean mCanceled;
26     private boolean mUnavailable;
27     private @Nullable String mName;
28     private boolean mClear;
29 
30     /**
31      * Constructs a new rename result
32      */
RenameResult()33     private RenameResult() {
34     }
35 
36     /**
37      * Creates a new blank {@linkplain RenameResult}
38      * @return a new result
39      */
40     @NonNull
create()41     public static RenameResult create() {
42         return new RenameResult();
43     }
44 
45     /**
46      * Creates a new {@linkplain RenameResult} for a user canceled renaming operation
47      * @return a canceled operation
48      */
49     @NonNull
canceled()50     public static RenameResult canceled() {
51         return new RenameResult().setCanceled(true);
52     }
53 
54     /**
55      * Creates a {@linkplain RenameResult} for a renaming operation that was
56      * not available (for example because the field attempted to be renamed
57      * does not yet exist (or does not exist any more)
58      *
59      * @return a new result
60      */
61     @NonNull
unavailable()62     public static RenameResult unavailable() {
63         return new RenameResult().setUnavailable(true);
64     }
65 
66     /**
67      * Creates a new {@linkplain RenameResult} for a successful renaming
68      * operation to the given name
69      *
70      * @param name the new name
71      * @return a new result
72      */
73     @NonNull
name(@ullable String name)74     public static RenameResult name(@Nullable String name) {
75         return new RenameResult().setName(name);
76     }
77 
78     /**
79      * Marks this result as canceled
80      *
81      * @param canceled whether the result was canceled
82      * @return this, for constructor chaining
83      */
84     @NonNull
setCanceled(boolean canceled)85     public RenameResult setCanceled(boolean canceled) {
86         mCanceled = canceled;
87         return this;
88     }
89 
90     /**
91      * Marks this result as unavailable
92      *
93      * @param unavailable whether this result was unavailable
94      * @return this, for constructor chaining
95      */
96     @NonNull
setUnavailable(boolean unavailable)97     public RenameResult setUnavailable(boolean unavailable) {
98         mUnavailable = unavailable;
99         return this;
100     }
101 
102     /**
103      * Sets the new name of the renaming operation
104      *
105      * @param name the new name
106      * @return this, for constructor chaining
107      */
108     @NonNull
setName(@ullable String name)109     public RenameResult setName(@Nullable String name) {
110         mName = name;
111         return this;
112     }
113 
114     /**
115      * Marks this result as clearing the name (reverting it back to the default)
116      *
117      * @param clear whether the name was cleared
118      * @return this, for constructor chaining
119      */
120     @NonNull
setCleared(boolean clear)121     public RenameResult setCleared(boolean clear) {
122         mClear = clear;
123         return this;
124     }
125 
126     /**
127      * Returns whether this result represents a canceled renaming operation
128      *
129      * @return true if the operation was canceled
130      */
isCanceled()131     public boolean isCanceled() {
132         return mCanceled;
133     }
134 
135     /**
136      * Returns whether this result represents an unavailable renaming operation
137      *
138      * @return true if the operation was not available
139      */
isUnavailable()140     public boolean isUnavailable() {
141         return mUnavailable;
142     }
143 
144     /**
145      * Returns whether this result represents a renaming back to the default (possibly
146      * clear) name. In this case, {@link #getName()} will return {@code null}.
147      *
148      * @return true if the name should be reset
149      */
isCleared()150     public boolean isCleared() {
151         return mClear;
152     }
153 
154     /**
155      * Returns the new name.
156      *
157      * @return the new name
158      */
159     @Nullable
getName()160     public String getName() {
161         return mName;
162     }
163 }