aboutsummaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorTadashi G. Takaoka <takaoka@google.com>2014-11-02 22:20:26 +0900
committerTadashi G. Takaoka <takaoka@google.com>2014-11-02 22:31:42 +0900
commit519df535996427c87242f8dbdd5993c6ab5a87d0 (patch)
tree670cf700d03541760db368c06357afd5348dbdf4 /common
parent2cf5550749927a8f72766eb040adb7d8d15ba127 (diff)
downloadlatinime-519df535996427c87242f8dbdd5993c6ab5a87d0.tar.gz
latinime-519df535996427c87242f8dbdd5993c6ab5a87d0.tar.xz
latinime-519df535996427c87242f8dbdd5993c6ab5a87d0.zip
Add null analysis annotations to latinime-common
Change-Id: I06eedd9ab85e5a8890e6809bbf9e88e5b8c14e38
Diffstat (limited to 'common')
-rw-r--r--common/src/com/android/inputmethod/latin/common/CodePointUtils.java20
-rw-r--r--common/src/com/android/inputmethod/latin/common/ComposedData.java11
-rw-r--r--common/src/com/android/inputmethod/latin/common/Constants.java6
-rw-r--r--common/src/com/android/inputmethod/latin/common/InputPointers.java22
-rw-r--r--common/src/com/android/inputmethod/latin/common/ResizableIntArray.java10
5 files changed, 50 insertions, 19 deletions
diff --git a/common/src/com/android/inputmethod/latin/common/CodePointUtils.java b/common/src/com/android/inputmethod/latin/common/CodePointUtils.java
index 592da5c1f..ec59de850 100644
--- a/common/src/com/android/inputmethod/latin/common/CodePointUtils.java
+++ b/common/src/com/android/inputmethod/latin/common/CodePointUtils.java
@@ -20,6 +20,8 @@ import com.android.inputmethod.annotations.UsedForTesting;
import java.util.Random;
+import javax.annotation.Nonnull;
+
// Utility methods related with code points used for tests.
// TODO: Figure out where this class should be.
@UsedForTesting
@@ -65,17 +67,23 @@ public class CodePointUtils {
};
@UsedForTesting
- public static int[] generateCodePointSet(final int codePointSetSize, final Random random) {
+ @Nonnull
+ public static int[] generateCodePointSet(final int codePointSetSize,
+ @Nonnull final Random random) {
final int[] codePointSet = new int[codePointSetSize];
for (int i = codePointSet.length - 1; i >= 0; ) {
final int r = Math.abs(random.nextInt());
- if (r < 0) continue;
+ if (r < 0) {
+ continue;
+ }
// Don't insert 0~0x20, but insert any other code point.
// Code points are in the range 0~0x10FFFF.
final int candidateCodePoint = 0x20 + r % (Character.MAX_CODE_POINT - 0x20);
// Code points between MIN_ and MAX_SURROGATE are not valid on their own.
if (candidateCodePoint >= Character.MIN_SURROGATE
- && candidateCodePoint <= Character.MAX_SURROGATE) continue;
+ && candidateCodePoint <= Character.MAX_SURROGATE) {
+ continue;
+ }
codePointSet[i] = candidateCodePoint;
--i;
}
@@ -86,8 +94,10 @@ public class CodePointUtils {
* Generates a random word.
*/
@UsedForTesting
- public static String generateWord(final Random random, final int[] codePointSet) {
- StringBuilder builder = new StringBuilder();
+ @Nonnull
+ public static String generateWord(@Nonnull final Random random,
+ @Nonnull final int[] codePointSet) {
+ final StringBuilder builder = new StringBuilder();
// 8 * 4 = 32 chars max, but we do it the following way so as to bias the random toward
// longer words. This should be closer to natural language, and more importantly, it will
// exercise the algorithms in dicttool much more.
diff --git a/common/src/com/android/inputmethod/latin/common/ComposedData.java b/common/src/com/android/inputmethod/latin/common/ComposedData.java
index 0508d49cb..7f0966050 100644
--- a/common/src/com/android/inputmethod/latin/common/ComposedData.java
+++ b/common/src/com/android/inputmethod/latin/common/ComposedData.java
@@ -16,15 +16,20 @@
package com.android.inputmethod.latin.common;
+import javax.annotation.Nonnull;
+
/**
* An immutable class that encapsulates a snapshot of word composition data.
*/
public class ComposedData {
+ @Nonnull
public final InputPointers mInputPointers;
public final boolean mIsBatchMode;
+ @Nonnull
public final String mTypedWord;
- public ComposedData(final InputPointers inputPointers, final boolean isBatchMode,
- final String typedWord) {
+
+ public ComposedData(@Nonnull final InputPointers inputPointers, final boolean isBatchMode,
+ @Nonnull final String typedWord) {
mInputPointers = inputPointers;
mIsBatchMode = isBatchMode;
mTypedWord = typedWord;
@@ -40,7 +45,7 @@ public class ComposedData {
* @return the number of copied code points.
*/
public int copyCodePointsExceptTrailingSingleQuotesAndReturnCodePointCount(
- final int[] destination) {
+ @Nonnull final int[] destination) {
// lastIndex is exclusive
final int lastIndex = mTypedWord.length()
- StringUtils.getTrailingSingleQuotesCount(mTypedWord);
diff --git a/common/src/com/android/inputmethod/latin/common/Constants.java b/common/src/com/android/inputmethod/latin/common/Constants.java
index 8f4a1e50d..abc377a84 100644
--- a/common/src/com/android/inputmethod/latin/common/Constants.java
+++ b/common/src/com/android/inputmethod/latin/common/Constants.java
@@ -18,6 +18,8 @@ package com.android.inputmethod.latin.common;
import com.android.inputmethod.annotations.UsedForTesting;
+import javax.annotation.Nonnull;
+
public final class Constants {
public static final class Color {
/**
@@ -259,6 +261,7 @@ public final class Constants {
return code >= CODE_SPACE;
}
+ @Nonnull
public static String printableCode(final int code) {
switch (code) {
case CODE_SHIFT: return "shift";
@@ -286,7 +289,8 @@ public final class Constants {
}
}
- public static String printableCodes(final int[] codes) {
+ @Nonnull
+ public static String printableCodes(@Nonnull final int[] codes) {
final StringBuilder sb = new StringBuilder();
boolean addDelimiter = false;
for (final int code : codes) {
diff --git a/common/src/com/android/inputmethod/latin/common/InputPointers.java b/common/src/com/android/inputmethod/latin/common/InputPointers.java
index 40131aca4..7beee1536 100644
--- a/common/src/com/android/inputmethod/latin/common/InputPointers.java
+++ b/common/src/com/android/inputmethod/latin/common/InputPointers.java
@@ -18,6 +18,8 @@ package com.android.inputmethod.latin.common;
import com.android.inputmethod.annotations.UsedForTesting;
+import javax.annotation.Nonnull;
+
// TODO: This class is not thread-safe.
public final class InputPointers {
private static final boolean DEBUG_TIME = false;
@@ -28,7 +30,7 @@ public final class InputPointers {
private final ResizableIntArray mPointerIds;
private final ResizableIntArray mTimes;
- public InputPointers(int defaultCapacity) {
+ public InputPointers(final int defaultCapacity) {
mDefaultCapacity = defaultCapacity;
mXCoordinates = new ResizableIntArray(defaultCapacity);
mYCoordinates = new ResizableIntArray(defaultCapacity);
@@ -51,7 +53,8 @@ public final class InputPointers {
mTimes.fill(lastTime, fromIndex, fillLength);
}
- public void addPointerAt(int index, int x, int y, int pointerId, int time) {
+ public void addPointerAt(final int index, final int x, final int y, final int pointerId,
+ final int time) {
mXCoordinates.addAt(index, x);
mYCoordinates.addAt(index, y);
mPointerIds.addAt(index, pointerId);
@@ -62,21 +65,21 @@ public final class InputPointers {
}
@UsedForTesting
- public void addPointer(int x, int y, int pointerId, int time) {
+ public void addPointer(final int x, final int y, final int pointerId, final int time) {
mXCoordinates.add(x);
mYCoordinates.add(y);
mPointerIds.add(pointerId);
mTimes.add(time);
}
- public void set(InputPointers ip) {
+ public void set(@Nonnull final InputPointers ip) {
mXCoordinates.set(ip.mXCoordinates);
mYCoordinates.set(ip.mYCoordinates);
mPointerIds.set(ip.mPointerIds);
mTimes.set(ip.mTimes);
}
- public void copy(InputPointers ip) {
+ public void copy(@Nonnull final InputPointers ip) {
mXCoordinates.copy(ip.mXCoordinates);
mYCoordinates.copy(ip.mYCoordinates);
mPointerIds.copy(ip.mPointerIds);
@@ -93,8 +96,9 @@ public final class InputPointers {
* @param startPos the starting index of the data in {@code times} and etc.
* @param length the number of data to be appended.
*/
- public void append(int pointerId, ResizableIntArray times, ResizableIntArray xCoordinates,
- ResizableIntArray yCoordinates, int startPos, int length) {
+ public void append(final int pointerId, @Nonnull final ResizableIntArray times,
+ @Nonnull final ResizableIntArray xCoordinates,
+ @Nonnull final ResizableIntArray yCoordinates, final int startPos, final int length) {
if (length == 0) {
return;
}
@@ -127,14 +131,17 @@ public final class InputPointers {
return mXCoordinates.getLength();
}
+ @Nonnull
public int[] getXCoordinates() {
return mXCoordinates.getPrimitiveArray();
}
+ @Nonnull
public int[] getYCoordinates() {
return mYCoordinates.getPrimitiveArray();
}
+ @Nonnull
public int[] getPointerIds() {
return mPointerIds.getPrimitiveArray();
}
@@ -145,6 +152,7 @@ public final class InputPointers {
* @return The time each point was registered, in milliseconds, relative to the first event in
* the sequence.
*/
+ @Nonnull
public int[] getTimes() {
return mTimes.getPrimitiveArray();
}
diff --git a/common/src/com/android/inputmethod/latin/common/ResizableIntArray.java b/common/src/com/android/inputmethod/latin/common/ResizableIntArray.java
index ea23d8a33..340abb23e 100644
--- a/common/src/com/android/inputmethod/latin/common/ResizableIntArray.java
+++ b/common/src/com/android/inputmethod/latin/common/ResizableIntArray.java
@@ -18,8 +18,11 @@ package com.android.inputmethod.latin.common;
import java.util.Arrays;
+import javax.annotation.Nonnull;
+
// TODO: This class is not thread-safe.
public final class ResizableIntArray {
+ @Nonnull
private int[] mArray;
private int mLength;
@@ -89,17 +92,18 @@ public final class ResizableIntArray {
mLength = 0;
}
+ @Nonnull
public int[] getPrimitiveArray() {
return mArray;
}
- public void set(final ResizableIntArray ip) {
+ public void set(@Nonnull final ResizableIntArray ip) {
// TODO: Implement primitive array pool.
mArray = ip.mArray;
mLength = ip.mLength;
}
- public void copy(final ResizableIntArray ip) {
+ public void copy(@Nonnull final ResizableIntArray ip) {
final int newCapacity = calculateCapacity(ip.mLength);
if (newCapacity > 0) {
// TODO: Implement primitive array pool.
@@ -109,7 +113,7 @@ public final class ResizableIntArray {
mLength = ip.mLength;
}
- public void append(final ResizableIntArray src, final int startPos, final int length) {
+ public void append(@Nonnull final ResizableIntArray src, final int startPos, final int length) {
if (length == 0) {
return;
}