diff options
author | Tor Norbye <tnorbye@google.com> | 2011-03-03 16:30:16 -0800 |
---|---|---|
committer | Android Code Review <code-review@android.com> | 2011-03-03 16:30:16 -0800 |
commit | 9a90121133f55e3aadb542f554e2418a7ead22bb (patch) | |
tree | 33b1848114ee4326999e078dcd67531220185ffe /eclipse | |
parent | f4890a0b154aaeb3d2fea79663d90b0163659928 (diff) | |
parent | 87d9cd4aa2104f5365165150283276e5176cba5c (diff) | |
download | sdk-9a90121133f55e3aadb542f554e2418a7ead22bb.zip sdk-9a90121133f55e3aadb542f554e2418a7ead22bb.tar.gz sdk-9a90121133f55e3aadb542f554e2418a7ead22bb.tar.bz2 |
Merge "Make XML code completion case insensitive"
Diffstat (limited to 'eclipse')
2 files changed, 61 insertions, 3 deletions
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/AndroidContentAssist.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/AndroidContentAssist.java index e1d030f..ad4599d 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/AndroidContentAssist.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/AndroidContentAssist.java @@ -476,9 +476,9 @@ public abstract class AndroidContentAssist implements IContentAssistProcessor { String nsKeyword = nsPrefix == null ? keyword : (nsPrefix + keyword); - if (keyword.startsWith(wordPrefix) || - (nsPrefix != null && keyword.startsWith(nsPrefix)) || - (nsPrefix != null && nsKeyword.startsWith(wordPrefix))) { + if (startsWith(keyword, wordPrefix) || + (nsPrefix != null && startsWith(keyword, nsPrefix)) || + (nsPrefix != null && startsWith(nsKeyword, wordPrefix))) { if (nsPrefix != null) { keyword = nsPrefix + keyword; } @@ -535,6 +535,31 @@ public abstract class AndroidContentAssist implements IContentAssistProcessor { } /** + * Returns true if the given word starts with the given prefix. The comparison is not + * case sensitive. + * + * @param word the word to test + * @param prefix the prefix the word should start with + * @return true if the given word starts with the given prefix + */ + static boolean startsWith(String word, String prefix) { + int prefixLength = prefix.length(); + int wordLength = word.length(); + if (wordLength < prefixLength) { + return false; + } + + for (int i = 0; i < prefixLength; i++) { + if (Character.toLowerCase(prefix.charAt(i)) + != Character.toLowerCase(word.charAt(i))) { + return false; + } + } + + return true; + } + + /** * Indicates whether this descriptor describes an element that can potentially * have children (either sub-elements or text value). If an element can have children, * we want to explicitly write an opening and a separate closing tag. diff --git a/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/AndroidContentAssistTest.java b/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/AndroidContentAssistTest.java new file mode 100644 index 0000000..8151f3a --- /dev/null +++ b/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/AndroidContentAssistTest.java @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2011 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.editors; + +import junit.framework.TestCase; + +public class AndroidContentAssistTest extends TestCase { + public void testStartsWith() { + assertTrue(AndroidContentAssist.startsWith("", "")); + assertTrue(AndroidContentAssist.startsWith("a", "")); + assertTrue(AndroidContentAssist.startsWith("A", "")); + assertTrue(AndroidContentAssist.startsWith("A", "a")); + assertTrue(AndroidContentAssist.startsWith("A", "A")); + assertTrue(AndroidContentAssist.startsWith("Ab", "a")); + assertTrue(AndroidContentAssist.startsWith("ab", "A")); + assertTrue(AndroidContentAssist.startsWith("ab", "AB")); + assertFalse(AndroidContentAssist.startsWith("ab", "ABc")); + assertFalse(AndroidContentAssist.startsWith("", "ABc")); + } +} |