Skip to content

Commit f5377a7

Browse files
jsharkeyAndroid (Google) Code Review
authored andcommitted
Merge "Useful annotations for code documentation." into jb-mr1.1-dev
2 parents 7420ab6 + 8b2c3a1 commit f5377a7

17 files changed

+158
-27
lines changed

core/java/android/content/SyncManager.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
import android.util.Slog;
5959

6060
import com.android.internal.R;
61+
import com.android.internal.annotations.GuardedBy;
6162
import com.android.internal.util.IndentingPrintWriter;
6263
import com.google.android.collect.Lists;
6364
import com.google.android.collect.Maps;
@@ -155,7 +156,7 @@ public class SyncManager {
155156

156157
private SyncStorageEngine mSyncStorageEngine;
157158

158-
// @GuardedBy("mSyncQueue")
159+
@GuardedBy("mSyncQueue")
159160
private final SyncQueue mSyncQueue;
160161

161162
protected final ArrayList<ActiveSyncContext> mActiveSyncContexts = Lists.newArrayList();

core/java/android/content/SyncStorageEngine.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package android.content;
1818

19+
import com.android.internal.annotations.VisibleForTesting;
1920
import com.android.internal.util.ArrayUtils;
2021
import com.android.internal.util.FastXmlSerializer;
2122

@@ -74,7 +75,7 @@ public class SyncStorageEngine extends Handler {
7475

7576
private static final long DEFAULT_POLL_FREQUENCY_SECONDS = 60 * 60 * 24; // One day
7677

77-
// @VisibleForTesting
78+
@VisibleForTesting
7879
static final long MILLIS_IN_4WEEKS = 1000L * 60 * 60 * 24 * 7 * 4;
7980

8081
/** Enum value for a sync start event. */

core/java/android/content/pm/RegisteredServicesCache.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import android.util.SparseArray;
3535
import android.util.Xml;
3636

37+
import com.android.internal.annotations.GuardedBy;
3738
import com.android.internal.util.FastXmlSerializer;
3839
import com.google.android.collect.Lists;
3940
import com.google.android.collect.Maps;
@@ -77,15 +78,15 @@ public abstract class RegisteredServicesCache<V> {
7778

7879
private final Object mServicesLock = new Object();
7980

80-
// @GuardedBy("mServicesLock")
81+
@GuardedBy("mServicesLock")
8182
private boolean mPersistentServicesFileDidNotExist;
82-
// @GuardedBy("mServicesLock")
83+
@GuardedBy("mServicesLock")
8384
private final SparseArray<UserServices<V>> mUserServices = new SparseArray<UserServices<V>>();
8485

8586
private static class UserServices<V> {
86-
// @GuardedBy("mServicesLock")
87+
@GuardedBy("mServicesLock")
8788
public final Map<V, Integer> persistentServices = Maps.newHashMap();
88-
// @GuardedBy("mServicesLock")
89+
@GuardedBy("mServicesLock")
8990
public Map<V, ServiceInfo<V>> services = null;
9091
}
9192

core/java/android/net/NetworkStats.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import android.os.SystemClock;
2222
import android.util.SparseBooleanArray;
2323

24+
import com.android.internal.annotations.VisibleForTesting;
2425
import com.android.internal.util.ArrayUtils;
2526
import com.android.internal.util.Objects;
2627

@@ -190,14 +191,14 @@ public NetworkStats clone() {
190191
return clone;
191192
}
192193

193-
// @VisibleForTesting
194+
@VisibleForTesting
194195
public NetworkStats addIfaceValues(
195196
String iface, long rxBytes, long rxPackets, long txBytes, long txPackets) {
196197
return addValues(
197198
iface, UID_ALL, SET_DEFAULT, TAG_NONE, rxBytes, rxPackets, txBytes, txPackets, 0L);
198199
}
199200

200-
// @VisibleForTesting
201+
@VisibleForTesting
201202
public NetworkStats addValues(String iface, int uid, int set, int tag, long rxBytes,
202203
long rxPackets, long txBytes, long txPackets, long operations) {
203204
return addValues(new Entry(
@@ -269,7 +270,7 @@ public int size() {
269270
return size;
270271
}
271272

272-
// @VisibleForTesting
273+
@VisibleForTesting
273274
public int internalSize() {
274275
return iface.length;
275276
}
@@ -335,7 +336,7 @@ public int findIndex(String iface, int uid, int set, int tag) {
335336
* Find first stats index that matches the requested parameters, starting
336337
* search around the hinted index as an optimization.
337338
*/
338-
// @VisibleForTesting
339+
@VisibleForTesting
339340
public int findIndexHinted(String iface, int uid, int set, int tag, int hintIndex) {
340341
for (int offset = 0; offset < size; offset++) {
341342
final int halfOffset = offset / 2;

core/java/android/net/NetworkTemplate.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import android.os.Parcel;
3434
import android.os.Parcelable;
3535

36+
import com.android.internal.annotations.VisibleForTesting;
3637
import com.android.internal.util.Objects;
3738

3839
/**
@@ -63,7 +64,7 @@ public class NetworkTemplate implements Parcelable {
6364

6465
private static boolean sForceAllNetworkTypes = false;
6566

66-
// @VisibleForTesting
67+
@VisibleForTesting
6768
public static void forceAllNetworkTypes() {
6869
sForceAllNetworkTypes = true;
6970
}

core/java/android/os/Environment.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
import android.text.TextUtils;
2323
import android.util.Log;
2424

25+
import com.android.internal.annotations.GuardedBy;
26+
2527
import java.io.File;
2628

2729
/**
@@ -47,7 +49,7 @@ public class Environment {
4749

4850
private static final Object sLock = new Object();
4951

50-
// @GuardedBy("sLock")
52+
@GuardedBy("sLock")
5153
private static volatile StorageVolume sPrimaryVolume;
5254

5355
private static StorageVolume getPrimaryVolume() {
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Copyright (C) 2012 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
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+
17+
package com.android.internal.annotations;
18+
19+
import java.lang.annotation.ElementType;
20+
import java.lang.annotation.Retention;
21+
import java.lang.annotation.RetentionPolicy;
22+
import java.lang.annotation.Target;
23+
24+
/**
25+
* Annotation type used to mark a method or field that can only be accessed when
26+
* holding the referenced lock.
27+
*/
28+
@Target({ ElementType.FIELD, ElementType.METHOD })
29+
@Retention(RetentionPolicy.CLASS)
30+
public @interface GuardedBy {
31+
String value();
32+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Copyright (C) 2012 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
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+
17+
package com.android.internal.annotations;
18+
19+
import java.lang.annotation.ElementType;
20+
import java.lang.annotation.Retention;
21+
import java.lang.annotation.RetentionPolicy;
22+
import java.lang.annotation.Target;
23+
24+
/**
25+
* Annotation type used to mark a class which is immutable.
26+
*/
27+
@Target(ElementType.TYPE)
28+
@Retention(RetentionPolicy.CLASS)
29+
public @interface Immutable {
30+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Copyright (C) 2012 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
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+
17+
package com.android.internal.annotations;
18+
19+
import java.lang.annotation.Retention;
20+
import java.lang.annotation.RetentionPolicy;
21+
22+
/**
23+
* Denotes that the class, method or field has its visibility relaxed so
24+
* that unit tests can access it.
25+
* <p/>
26+
* The <code>visibility</code> argument can be used to specific what the original
27+
* visibility should have been if it had not been made public or package-private for testing.
28+
* The default is to consider the element private.
29+
*/
30+
@Retention(RetentionPolicy.SOURCE)
31+
public @interface VisibleForTesting {
32+
/**
33+
* Intended visibility if the element had not been made public or package-private for
34+
* testing.
35+
*/
36+
enum Visibility {
37+
/** The element should be considered protected. */
38+
PROTECTED,
39+
/** The element should be considered package-private. */
40+
PACKAGE,
41+
/** The element should be considered private. */
42+
PRIVATE
43+
}
44+
45+
/**
46+
* Intended visibility if the element had not been made public or package-private for testing.
47+
* If not specified, one should assume the element originally intended to be private.
48+
*/
49+
Visibility visibility() default Visibility.PRIVATE;
50+
}

core/java/com/android/internal/net/NetworkStatsFactory.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import android.os.StrictMode;
2626
import android.os.SystemClock;
2727

28+
import com.android.internal.annotations.VisibleForTesting;
2829
import com.android.internal.util.ProcFileReader;
2930

3031
import java.io.File;
@@ -53,7 +54,7 @@ public NetworkStatsFactory() {
5354
this(new File("/proc/"));
5455
}
5556

56-
// @VisibleForTesting
57+
@VisibleForTesting
5758
public NetworkStatsFactory(File procRoot) {
5859
mStatsXtIfaceAll = new File(procRoot, "net/xt_qtaguid/iface_stat_all");
5960
mStatsXtIfaceFmt = new File(procRoot, "net/xt_qtaguid/iface_stat_fmt");

0 commit comments

Comments
 (0)