aboutsummaryrefslogtreecommitdiff
path: root/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/refactorings/core/RenameResult.java
blob: ade346fa904a5d77e8c52c7087e446d012031d31 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
/*
 * Copyright (C) 2012 The Android Open Source Project
 *
 * Licensed under the Eclipse Public License, Version 1.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.eclipse.org/org/documents/epl-v10.php
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.android.ide.eclipse.adt.internal.refactorings.core;

import com.android.annotations.NonNull;
import com.android.annotations.Nullable;

/**
 * A result from a renaming operation
 */
public class RenameResult {
    private boolean mCanceled;
    private boolean mUnavailable;
    private @Nullable String mName;
    private boolean mClear;

    /**
     * Constructs a new rename result
     */
    private RenameResult() {
    }

    /**
     * Creates a new blank {@linkplain RenameResult}
     * @return a new result
     */
    @NonNull
    public static RenameResult create() {
        return new RenameResult();
    }

    /**
     * Creates a new {@linkplain RenameResult} for a user canceled renaming operation
     * @return a canceled operation
     */
    @NonNull
    public static RenameResult canceled() {
        return new RenameResult().setCanceled(true);
    }

    /**
     * Creates a {@linkplain RenameResult} for a renaming operation that was
     * not available (for example because the field attempted to be renamed
     * does not yet exist (or does not exist any more)
     *
     * @return a new result
     */
    @NonNull
    public static RenameResult unavailable() {
        return new RenameResult().setUnavailable(true);
    }

    /**
     * Creates a new {@linkplain RenameResult} for a successful renaming
     * operation to the given name
     *
     * @param name the new name
     * @return a new result
     */
    @NonNull
    public static RenameResult name(@Nullable String name) {
        return new RenameResult().setName(name);
    }

    /**
     * Marks this result as canceled
     *
     * @param canceled whether the result was canceled
     * @return this, for constructor chaining
     */
    @NonNull
    public RenameResult setCanceled(boolean canceled) {
        mCanceled = canceled;
        return this;
    }

    /**
     * Marks this result as unavailable
     *
     * @param unavailable whether this result was unavailable
     * @return this, for constructor chaining
     */
    @NonNull
    public RenameResult setUnavailable(boolean unavailable) {
        mUnavailable = unavailable;
        return this;
    }

    /**
     * Sets the new name of the renaming operation
     *
     * @param name the new name
     * @return this, for constructor chaining
     */
    @NonNull
    public RenameResult setName(@Nullable String name) {
        mName = name;
        return this;
    }

    /**
     * Marks this result as clearing the name (reverting it back to the default)
     *
     * @param clear whether the name was cleared
     * @return this, for constructor chaining
     */
    @NonNull
    public RenameResult setCleared(boolean clear) {
        mClear = clear;
        return this;
    }

    /**
     * Returns whether this result represents a canceled renaming operation
     *
     * @return true if the operation was canceled
     */
    public boolean isCanceled() {
        return mCanceled;
    }

    /**
     * Returns whether this result represents an unavailable renaming operation
     *
     * @return true if the operation was not available
     */
    public boolean isUnavailable() {
        return mUnavailable;
    }

    /**
     * Returns whether this result represents a renaming back to the default (possibly
     * clear) name. In this case, {@link #getName()} will return {@code null}.
     *
     * @return true if the name should be reset
     */
    public boolean isCleared() {
        return mClear;
    }

    /**
     * Returns the new name.
     *
     * @return the new name
     */
    @Nullable
    public String getName() {
        return mName;
    }
}