diff options
author | 2014-10-20 14:48:56 +0900 | |
---|---|---|
committer | 2014-10-21 19:28:37 +0900 | |
commit | 5f00fe09e9a611b647592188316e5999465df4d3 (patch) | |
tree | 954a429256171897c7b9ed56a732e386eec76b2b /java/src/com/android/inputmethod/event | |
parent | fa1e65cb3a5dcce6299a6dd067cee95720107307 (diff) | |
download | latinime-5f00fe09e9a611b647592188316e5999465df4d3.tar.gz latinime-5f00fe09e9a611b647592188316e5999465df4d3.tar.xz latinime-5f00fe09e9a611b647592188316e5999465df4d3.zip |
Fix some compiler warnings
This CL fixes the following compiler warnings.
- Indirect access to static member
- Access to a non-accessible member of an enclosing type
- Parameter assignment
- Method can be static
- Local variable declaration hides another field or variable
- Value of local variable is not used
- Unused import
- Unused private member
- Unnecessary 'else' statement
- Unnecessary declaration of throw exception
- Redundant type arguments
- Missing '@Override' annotation
- Unused '@SuppressWarning' annotations
Bug: 18003991
Change-Id: Icfebe753e53a2cc621848f769d6a3d7ce501ebc7
Diffstat (limited to 'java/src/com/android/inputmethod/event')
4 files changed, 107 insertions, 97 deletions
diff --git a/java/src/com/android/inputmethod/event/DeadKeyCombiner.java b/java/src/com/android/inputmethod/event/DeadKeyCombiner.java index 88c70630d..2e65a08fa 100644 --- a/java/src/com/android/inputmethod/event/DeadKeyCombiner.java +++ b/java/src/com/android/inputmethod/event/DeadKeyCombiner.java @@ -18,7 +18,6 @@ package com.android.inputmethod.event; import android.text.TextUtils; import android.util.SparseIntArray; -import android.view.KeyCharacterMap; import com.android.inputmethod.latin.Constants; @@ -70,8 +69,8 @@ public class DeadKeyCombiner implements Combiner { /** * Maps Unicode combining diacritical to display-form dead key. */ - private static final SparseIntArray sCombiningToAccent = new SparseIntArray(); - private static final SparseIntArray sAccentToCombining = new SparseIntArray(); + static final SparseIntArray sCombiningToAccent = new SparseIntArray(); + static final SparseIntArray sAccentToCombining = new SparseIntArray(); static { // U+0300: COMBINING GRAVE ACCENT addCombining('\u0300', ACCENT_GRAVE); @@ -217,21 +216,20 @@ public class DeadKeyCombiner implements Combiner { final StringBuilder mDeadSequence = new StringBuilder(); @Nonnull - private Event createEventChainFromSequence(final @Nonnull CharSequence text, + private static Event createEventChainFromSequence(final @Nonnull CharSequence text, final Event originalEvent) { if (text.length() <= 0) { return originalEvent; - } else { - Event lastEvent = null; - int codePoint = 0; - for (int i = text.length(); i > 0; i -= Character.charCount(codePoint)) { - codePoint = Character.codePointBefore(text, i); - final Event thisEvent = Event.createHardwareKeypressEvent(codePoint, - originalEvent.mKeyCode, lastEvent, false /* isKeyRepeat */); - lastEvent = thisEvent; - } - return lastEvent; } + Event lastEvent = null; + int codePoint = 0; + for (int i = text.length(); i > 0; i -= Character.charCount(codePoint)) { + codePoint = Character.codePointBefore(text, i); + final Event thisEvent = Event.createHardwareKeypressEvent(codePoint, + originalEvent.mKeyCode, lastEvent, false /* isKeyRepeat */); + lastEvent = thisEvent; + } + return lastEvent; } @Override @@ -248,51 +246,49 @@ public class DeadKeyCombiner implements Combiner { // no dead keys at all in the current input, so this combiner has nothing to do and // simply returns the event as is. The majority of events will go through this path. return event; - } else { - if (Character.isWhitespace(event.mCodePoint) - || event.mCodePoint == mDeadSequence.codePointBefore(mDeadSequence.length())) { - // When whitespace or twice the same dead key, we should output the dead sequence - // as is. - final Event resultEvent = createEventChainFromSequence(mDeadSequence.toString(), - event); - mDeadSequence.setLength(0); - return resultEvent; - } else if (event.isFunctionalKeyEvent()) { - if (Constants.CODE_DELETE == event.mKeyCode) { - // Remove the last code point - final int trimIndex = mDeadSequence.length() - Character.charCount( - mDeadSequence.codePointBefore(mDeadSequence.length())); - mDeadSequence.setLength(trimIndex); - return Event.createConsumedEvent(event); - } else { - return event; - } - } else if (event.isDead()) { - mDeadSequence.appendCodePoint(event.mCodePoint); + } + if (Character.isWhitespace(event.mCodePoint) + || event.mCodePoint == mDeadSequence.codePointBefore(mDeadSequence.length())) { + // When whitespace or twice the same dead key, we should output the dead sequence as is. + final Event resultEvent = createEventChainFromSequence(mDeadSequence.toString(), + event); + mDeadSequence.setLength(0); + return resultEvent; + } + if (event.isFunctionalKeyEvent()) { + if (Constants.CODE_DELETE == event.mKeyCode) { + // Remove the last code point + final int trimIndex = mDeadSequence.length() - Character.charCount( + mDeadSequence.codePointBefore(mDeadSequence.length())); + mDeadSequence.setLength(trimIndex); return Event.createConsumedEvent(event); + } + return event; + } + if (event.isDead()) { + mDeadSequence.appendCodePoint(event.mCodePoint); + return Event.createConsumedEvent(event); + } + // Combine normally. + final StringBuilder sb = new StringBuilder(); + sb.appendCodePoint(event.mCodePoint); + int codePointIndex = 0; + while (codePointIndex < mDeadSequence.length()) { + final int deadCodePoint = mDeadSequence.codePointAt(codePointIndex); + final char replacementSpacingChar = + Data.getNonstandardCombination(deadCodePoint, event.mCodePoint); + if (Data.NOT_A_CHAR != replacementSpacingChar) { + sb.setCharAt(0, replacementSpacingChar); } else { - // Combine normally. - final StringBuilder sb = new StringBuilder(); - sb.appendCodePoint(event.mCodePoint); - int codePointIndex = 0; - while (codePointIndex < mDeadSequence.length()) { - final int deadCodePoint = mDeadSequence.codePointAt(codePointIndex); - final char replacementSpacingChar = - Data.getNonstandardCombination(deadCodePoint, event.mCodePoint); - if (Data.NOT_A_CHAR != replacementSpacingChar) { - sb.setCharAt(0, replacementSpacingChar); - } else { - final int combining = Data.sAccentToCombining.get(deadCodePoint); - sb.appendCodePoint(0 == combining ? deadCodePoint : combining); - } - codePointIndex += Character.isSupplementaryCodePoint(deadCodePoint) ? 2 : 1; - } - final String normalizedString = Normalizer.normalize(sb, Normalizer.Form.NFC); - final Event resultEvent = createEventChainFromSequence(normalizedString, event); - mDeadSequence.setLength(0); - return resultEvent; + final int combining = Data.sAccentToCombining.get(deadCodePoint); + sb.appendCodePoint(0 == combining ? deadCodePoint : combining); } + codePointIndex += Character.isSupplementaryCodePoint(deadCodePoint) ? 2 : 1; } + final String normalizedString = Normalizer.normalize(sb, Normalizer.Form.NFC); + final Event resultEvent = createEventChainFromSequence(normalizedString, event); + mDeadSequence.setLength(0); + return resultEvent; } @Override diff --git a/java/src/com/android/inputmethod/event/Event.java b/java/src/com/android/inputmethod/event/Event.java index ff6f88066..3e3ff771c 100644 --- a/java/src/com/android/inputmethod/event/Event.java +++ b/java/src/com/android/inputmethod/event/Event.java @@ -21,6 +21,8 @@ import com.android.inputmethod.latin.Constants; import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo; import com.android.inputmethod.latin.utils.StringUtils; +import javax.annotation.Nonnull; + /** * Class representing a generic input event as handled by Latin IME. * @@ -134,12 +136,14 @@ public class Event { } } + @Nonnull public static Event createSoftwareKeypressEvent(final int codePoint, final int keyCode, final int x, final int y, final boolean isKeyRepeat) { return new Event(EVENT_TYPE_INPUT_KEYPRESS, null /* text */, codePoint, keyCode, x, y, null /* suggestedWordInfo */, isKeyRepeat ? FLAG_REPEAT : FLAG_NONE, null); } + @Nonnull public static Event createHardwareKeypressEvent(final int codePoint, final int keyCode, final Event next, final boolean isKeyRepeat) { return new Event(EVENT_TYPE_INPUT_KEYPRESS, null /* text */, codePoint, keyCode, @@ -149,6 +153,7 @@ public class Event { // This creates an input event for a dead character. @see {@link #FLAG_DEAD} @ExternallyReferenced + @Nonnull public static Event createDeadEvent(final int codePoint, final int keyCode, final Event next) { // TODO: add an argument or something if we ever create a software layout with dead keys. return new Event(EVENT_TYPE_INPUT_KEYPRESS, null /* text */, codePoint, keyCode, @@ -163,6 +168,7 @@ public class Event { * @param codePoint the code point. * @return an event for this code point. */ + @Nonnull public static Event createEventForCodePointFromUnknownSource(final int codePoint) { // TODO: should we have a different type of event for this? After all, it's not a key press. return new Event(EVENT_TYPE_INPUT_KEYPRESS, null /* text */, codePoint, NOT_A_KEY_CODE, @@ -178,6 +184,7 @@ public class Event { * @param y the Y coordinate. * @return an event for this code point and coordinates. */ + @Nonnull public static Event createEventForCodePointFromAlreadyTypedText(final int codePoint, final int x, final int y) { // TODO: should we have a different type of event for this? After all, it's not a key press. @@ -189,6 +196,7 @@ public class Event { * Creates an input event representing the manual pick of a suggestion. * @return an event for this suggestion pick. */ + @Nonnull public static Event createSuggestionPickedEvent(final SuggestedWordInfo suggestedWordInfo) { return new Event(EVENT_TYPE_SUGGESTION_PICKED, suggestedWordInfo.mWord, NOT_A_CODE_POINT, NOT_A_KEY_CODE, @@ -204,6 +212,7 @@ public class Event { * @param keyCode the key code, or NOT_A_KEYCODE if not applicable. * @return an event for this text. */ + @Nonnull public static Event createSoftwareTextEvent(final CharSequence text, final int keyCode) { return new Event(EVENT_TYPE_SOFTWARE_GENERATED_STRING, text, NOT_A_CODE_POINT, keyCode, Constants.NOT_A_COORDINATE, Constants.NOT_A_COORDINATE, @@ -228,6 +237,7 @@ public class Event { * @param source the event to copy the properties of. * @return an identical event marked as consumed. */ + @Nonnull public static Event createConsumedEvent(final Event source) { // A consumed event should not input any text at all, so we pass the empty string as text. return new Event(source.mEventType, source.mText, source.mCodePoint, source.mKeyCode, @@ -235,6 +245,7 @@ public class Event { source.mNextEvent); } + @Nonnull public static Event createNotHandledEvent() { return new Event(EVENT_TYPE_NOT_HANDLED, null /* text */, NOT_A_CODE_POINT, NOT_A_KEY_CODE, Constants.NOT_A_COORDINATE, Constants.NOT_A_COORDINATE, diff --git a/java/src/com/android/inputmethod/event/HardwareKeyboardEventDecoder.java b/java/src/com/android/inputmethod/event/HardwareKeyboardEventDecoder.java index c61f45efa..6aa60439f 100644 --- a/java/src/com/android/inputmethod/event/HardwareKeyboardEventDecoder.java +++ b/java/src/com/android/inputmethod/event/HardwareKeyboardEventDecoder.java @@ -67,10 +67,9 @@ public class HardwareKeyboardEventDecoder implements HardwareEventDecoder { if (keyEvent.isShiftPressed()) { return Event.createHardwareKeypressEvent(Event.NOT_A_CODE_POINT, Constants.CODE_SHIFT_ENTER, null /* next */, isKeyRepeat); - } else { - return Event.createHardwareKeypressEvent(Constants.CODE_ENTER, keyCode, - null /* next */, isKeyRepeat); } + return Event.createHardwareKeypressEvent(Constants.CODE_ENTER, keyCode, + null /* next */, isKeyRepeat); } // If not Enter, then this is just a regular keypress event for a normal character // that can be committed right away, taking into account the current state. diff --git a/java/src/com/android/inputmethod/event/MyanmarReordering.java b/java/src/com/android/inputmethod/event/MyanmarReordering.java index dcd06c899..40b543949 100644 --- a/java/src/com/android/inputmethod/event/MyanmarReordering.java +++ b/java/src/com/android/inputmethod/event/MyanmarReordering.java @@ -115,6 +115,7 @@ public class MyanmarReordering implements Combiner { * @param newEvent the new event to add to the stream. null if none. * @return the resulting software text event. Never null. */ + @Nonnull private Event clearAndGetResultingEvent(final Event newEvent) { final CharSequence combinedText; if (mCurrentEvents.size() > 0) { @@ -139,7 +140,8 @@ public class MyanmarReordering implements Combiner { if (null == lastEvent) { mCurrentEvents.add(newEvent); return Event.createConsumedEvent(newEvent); - } else if (isConsonantOrMedial(lastEvent.mCodePoint)) { + } + if (isConsonantOrMedial(lastEvent.mCodePoint)) { final Event resultingEvent = clearAndGetResultingEvent(null); mCurrentEvents.add(Event.createSoftwareKeypressEvent(ZERO_WIDTH_NON_JOINER, Event.NOT_A_KEY_CODE, @@ -147,15 +149,17 @@ public class MyanmarReordering implements Combiner { false /* isKeyRepeat */)); mCurrentEvents.add(newEvent); return resultingEvent; - } else { // VOWEL_E == lastCodePoint. But if that was anything else this is correct too. - return clearAndGetResultingEvent(newEvent); } - } if (isConsonant(codePoint)) { + // VOWEL_E == lastCodePoint. But if that was anything else this is correct too. + return clearAndGetResultingEvent(newEvent); + } + if (isConsonant(codePoint)) { final Event lastEvent = getLastEvent(); if (null == lastEvent) { mCurrentEvents.add(newEvent); return Event.createConsumedEvent(newEvent); - } else if (VOWEL_E == lastEvent.mCodePoint) { + } + if (VOWEL_E == lastEvent.mCodePoint) { final int eventSize = mCurrentEvents.size(); if (eventSize >= 2 && mCurrentEvents.get(eventSize - 2).mCodePoint == ZERO_WIDTH_NON_JOINER) { @@ -178,15 +182,17 @@ public class MyanmarReordering implements Combiner { mCurrentEvents.add(newEvent); mCurrentEvents.add(lastEvent); return Event.createConsumedEvent(newEvent); - } else { // lastCodePoint is a consonant/medial. But if it's something else it's fine - return clearAndGetResultingEvent(newEvent); } - } else if (isMedial(codePoint)) { + // lastCodePoint is a consonant/medial. But if it's something else it's fine + return clearAndGetResultingEvent(newEvent); + } + if (isMedial(codePoint)) { final Event lastEvent = getLastEvent(); if (null == lastEvent) { mCurrentEvents.add(newEvent); return Event.createConsumedEvent(newEvent); - } else if (VOWEL_E == lastEvent.mCodePoint) { + } + if (VOWEL_E == lastEvent.mCodePoint) { final int eventSize = mCurrentEvents.size(); // If there is already a consonant, then we are in the middle of a syllable, and we // need to reorder. @@ -205,37 +211,36 @@ public class MyanmarReordering implements Combiner { } // Otherwise, we just commit everything. return clearAndGetResultingEvent(null); - } else { // lastCodePoint is a consonant/medial. But if it's something else it's fine - return clearAndGetResultingEvent(newEvent); } - } else if (Constants.CODE_DELETE == newEvent.mKeyCode) { - final Event lastEvent = getLastEvent(); + // lastCodePoint is a consonant/medial. But if it's something else it's fine + return clearAndGetResultingEvent(newEvent); + } + final Event lastEvent = getLastEvent(); + if (Constants.CODE_DELETE == newEvent.mKeyCode && null != lastEvent) { final int eventSize = mCurrentEvents.size(); - if (null != lastEvent) { - if (VOWEL_E == lastEvent.mCodePoint) { - // We have a VOWEL_E at the end. There are four cases. - // - The vowel is the only code point in the buffer. Remove it. - // - The vowel is preceded by a ZWNJ. Remove both vowel E and ZWNJ. - // - The vowel is preceded by a consonant/medial, remove the consonant/medial. - // - In all other cases, it's strange, so just remove the last code point. - if (eventSize <= 1) { - mCurrentEvents.clear(); - } else { // eventSize >= 2 - final int previousCodePoint = mCurrentEvents.get(eventSize - 2).mCodePoint; - if (previousCodePoint == ZERO_WIDTH_NON_JOINER) { - mCurrentEvents.remove(eventSize - 1); - mCurrentEvents.remove(eventSize - 2); - } else if (isConsonantOrMedial(previousCodePoint)) { - mCurrentEvents.remove(eventSize - 2); - } else { - mCurrentEvents.remove(eventSize - 1); - } + if (VOWEL_E == lastEvent.mCodePoint) { + // We have a VOWEL_E at the end. There are four cases. + // - The vowel is the only code point in the buffer. Remove it. + // - The vowel is preceded by a ZWNJ. Remove both vowel E and ZWNJ. + // - The vowel is preceded by a consonant/medial, remove the consonant/medial. + // - In all other cases, it's strange, so just remove the last code point. + if (eventSize <= 1) { + mCurrentEvents.clear(); + } else { // eventSize >= 2 + final int previousCodePoint = mCurrentEvents.get(eventSize - 2).mCodePoint; + if (previousCodePoint == ZERO_WIDTH_NON_JOINER) { + mCurrentEvents.remove(eventSize - 1); + mCurrentEvents.remove(eventSize - 2); + } else if (isConsonantOrMedial(previousCodePoint)) { + mCurrentEvents.remove(eventSize - 2); + } else { + mCurrentEvents.remove(eventSize - 1); } - return Event.createConsumedEvent(newEvent); - } else if (eventSize > 0) { - mCurrentEvents.remove(eventSize - 1); - return Event.createConsumedEvent(newEvent); } + return Event.createConsumedEvent(newEvent); + } else if (eventSize > 0) { + mCurrentEvents.remove(eventSize - 1); + return Event.createConsumedEvent(newEvent); } } // This character is not part of the combining scheme, so we should reset everything. @@ -243,10 +248,9 @@ public class MyanmarReordering implements Combiner { // If we have events in flight, then add the new event and return the resulting event. mCurrentEvents.add(newEvent); return clearAndGetResultingEvent(null); - } else { - // If we don't have any events in flight, then just pass this one through. - return newEvent; } + // If we don't have any events in flight, then just pass this one through. + return newEvent; } @Override |