aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSiva Velusamy <vsiva@google.com>2012-09-20 09:35:33 -0700
committerSiva Velusamy <vsiva@google.com>2012-09-20 17:30:45 -0700
commit1fb460987f7d832adf12290f41448d0c16a95972 (patch)
tree198f5d711522b77926125f4fbddb50a633cb23c5
parent1d96433fc413046aeecc8bd9388fecad511ecefb (diff)
downloadsdk-1fb460987f7d832adf12290f41448d0c16a95972.zip
sdk-1fb460987f7d832adf12290f41448d0c16a95972.tar.gz
sdk-1fb460987f7d832adf12290f41448d0c16a95972.tar.bz2
Move some utility functions from AdtUtils to common
Change-Id: Ia6f5c55e07c7f60712472c8e850b7c4595c46671
-rw-r--r--common/src/com/android/utils/SdkUtils.java136
-rw-r--r--common/tests/src/com/android/utils/SdkUtilsTest.java84
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/AdtUtils.java116
-rwxr-xr-xeclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/actions/DexDumpAction.java4
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/formatting/XmlPrettyPrinter.java8
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/ImageUtils.java2
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/properties/ResourceValueCompleter.java4
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/properties/ValueCompleter.java8
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/manifest/pages/ApplicationToggle.java4
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/uimodel/UiElementNode.java4
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/lint/EclipseLintClient.java7
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/lint/LintFixGenerator.java3
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/lint/LintJob.java3
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/ui/ResourcePreviewHelper.java2
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/newproject/ProjectNamePage.java2
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/newxmlfile/NewXmlFileCreationPage.java3
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/templates/TemplateHandler.java3
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/AdtUtilsTest.java67
18 files changed, 253 insertions, 207 deletions
diff --git a/common/src/com/android/utils/SdkUtils.java b/common/src/com/android/utils/SdkUtils.java
new file mode 100644
index 0000000..b49c120
--- /dev/null
+++ b/common/src/com/android/utils/SdkUtils.java
@@ -0,0 +1,136 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.utils;
+
+import com.android.annotations.NonNull;
+
+public class SdkUtils {
+ /**
+ * Returns true if the given string ends with the given suffix, using a
+ * case-insensitive comparison.
+ *
+ * @param string the full string to be checked
+ * @param suffix the suffix to be checked for
+ * @return true if the string case-insensitively ends with the given suffix
+ */
+ public static boolean endsWithIgnoreCase(String string, String suffix) {
+ return string.regionMatches(true /* ignoreCase */, string.length() - suffix.length(),
+ suffix, 0, suffix.length());
+ }
+
+ /**
+ * Returns true if the given sequence ends with the given suffix (case
+ * sensitive).
+ *
+ * @param sequence the character sequence to be checked
+ * @param suffix the suffix to look for
+ * @return true if the given sequence ends with the given suffix
+ */
+ public static boolean endsWith(CharSequence sequence, CharSequence suffix) {
+ return endsWith(sequence, sequence.length(), suffix);
+ }
+
+ /**
+ * Returns true if the given sequence ends at the given offset with the given suffix (case
+ * sensitive)
+ *
+ * @param sequence the character sequence to be checked
+ * @param endOffset the offset at which the sequence is considered to end
+ * @param suffix the suffix to look for
+ * @return true if the given sequence ends with the given suffix
+ */
+ public static boolean endsWith(CharSequence sequence, int endOffset, CharSequence suffix) {
+ if (endOffset < suffix.length()) {
+ return false;
+ }
+
+ for (int i = endOffset - 1, j = suffix.length() - 1; j >= 0; i--, j--) {
+ if (sequence.charAt(i) != suffix.charAt(j)) {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ /**
+ * Returns true if the given string starts with the given prefix, using a
+ * case-insensitive comparison.
+ *
+ * @param string the full string to be checked
+ * @param prefix the prefix to be checked for
+ * @return true if the string case-insensitively starts with the given prefix
+ */
+ public static boolean startsWithIgnoreCase(String string, String prefix) {
+ return string.regionMatches(true /* ignoreCase */, 0, prefix, 0, prefix.length());
+ }
+
+ /**
+ * Returns true if the given string starts at the given offset with the
+ * given prefix, case insensitively.
+ *
+ * @param string the full string to be checked
+ * @param offset the offset in the string to start looking
+ * @param prefix the prefix to be checked for
+ * @return true if the string case-insensitively starts at the given offset
+ * with the given prefix
+ */
+ public static boolean startsWith(String string, int offset, String prefix) {
+ return string.regionMatches(true /* ignoreCase */, offset, prefix, 0, prefix.length());
+ }
+
+ /**
+ * Strips the whitespace from the given string
+ *
+ * @param string the string to be cleaned up
+ * @return the string, without whitespace
+ */
+ public static String stripWhitespace(String string) {
+ StringBuilder sb = new StringBuilder(string.length());
+ for (int i = 0, n = string.length(); i < n; i++) {
+ char c = string.charAt(i);
+ if (!Character.isWhitespace(c)) {
+ sb.append(c);
+ }
+ }
+
+ return sb.toString();
+ }
+
+ /** For use by {@link #getLineSeparator()} */
+ private static String sLineSeparator;
+
+ /**
+ * Returns the default line separator to use.
+ * <p>
+ * NOTE: If you have an associated {@link IDocument}, it is better to call
+ * {@link TextUtilities#getDefaultLineDelimiter(IDocument)} since that will
+ * allow (for example) editing a \r\n-delimited document on a \n-delimited
+ * platform and keep a consistent usage of delimiters in the file.
+ *
+ * @return the delimiter string to use
+ */
+ @NonNull
+ public static String getLineSeparator() {
+ if (sLineSeparator == null) {
+ // This is guaranteed to exist:
+ sLineSeparator = System.getProperty("line.separator"); //$NON-NLS-1$
+ }
+
+ return sLineSeparator;
+ }
+}
diff --git a/common/tests/src/com/android/utils/SdkUtilsTest.java b/common/tests/src/com/android/utils/SdkUtilsTest.java
new file mode 100644
index 0000000..29a4d51
--- /dev/null
+++ b/common/tests/src/com/android/utils/SdkUtilsTest.java
@@ -0,0 +1,84 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.utils;
+
+import junit.framework.TestCase;
+
+public class SdkUtilsTest extends TestCase {
+ public void testEndsWithIgnoreCase() {
+ assertTrue(SdkUtils.endsWithIgnoreCase("foo", "foo"));
+ assertTrue(SdkUtils.endsWithIgnoreCase("foo", "Foo"));
+ assertTrue(SdkUtils.endsWithIgnoreCase("foo", "foo"));
+ assertTrue(SdkUtils.endsWithIgnoreCase("Barfoo", "foo"));
+ assertTrue(SdkUtils.endsWithIgnoreCase("BarFoo", "foo"));
+ assertTrue(SdkUtils.endsWithIgnoreCase("BarFoo", "foO"));
+
+ assertFalse(SdkUtils.endsWithIgnoreCase("foob", "foo"));
+ assertFalse(SdkUtils.endsWithIgnoreCase("foo", "fo"));
+ }
+
+ public void testStartsWithIgnoreCase() {
+ assertTrue(SdkUtils.startsWithIgnoreCase("foo", "foo"));
+ assertTrue(SdkUtils.startsWithIgnoreCase("foo", "Foo"));
+ assertTrue(SdkUtils.startsWithIgnoreCase("foo", "foo"));
+ assertTrue(SdkUtils.startsWithIgnoreCase("barfoo", "bar"));
+ assertTrue(SdkUtils.startsWithIgnoreCase("BarFoo", "bar"));
+ assertTrue(SdkUtils.startsWithIgnoreCase("BarFoo", "bAr"));
+
+ assertFalse(SdkUtils.startsWithIgnoreCase("bfoo", "foo"));
+ assertFalse(SdkUtils.startsWithIgnoreCase("fo", "foo"));
+ }
+
+ public void testStartsWith() {
+ assertTrue(SdkUtils.startsWith("foo", 0, "foo"));
+ assertTrue(SdkUtils.startsWith("foo", 0, "Foo"));
+ assertTrue(SdkUtils.startsWith("Foo", 0, "foo"));
+ assertTrue(SdkUtils.startsWith("aFoo", 1, "foo"));
+
+ assertFalse(SdkUtils.startsWith("aFoo", 0, "foo"));
+ assertFalse(SdkUtils.startsWith("aFoo", 2, "foo"));
+ }
+
+ public void testEndsWith() {
+ assertTrue(SdkUtils.endsWith("foo", "foo"));
+ assertTrue(SdkUtils.endsWith("foobar", "obar"));
+ assertTrue(SdkUtils.endsWith("foobar", "bar"));
+ assertTrue(SdkUtils.endsWith("foobar", "ar"));
+ assertTrue(SdkUtils.endsWith("foobar", "r"));
+ assertTrue(SdkUtils.endsWith("foobar", ""));
+
+ assertTrue(SdkUtils.endsWith(new StringBuilder("foobar"), "bar"));
+ assertTrue(SdkUtils.endsWith(new StringBuilder("foobar"), new StringBuffer("obar")));
+ assertTrue(SdkUtils.endsWith("foobar", new StringBuffer("obar")));
+
+ assertFalse(SdkUtils.endsWith("foo", "fo"));
+ assertFalse(SdkUtils.endsWith("foobar", "Bar"));
+ assertFalse(SdkUtils.endsWith("foobar", "longfoobar"));
+ }
+
+ public void testEndsWith2() {
+ assertTrue(SdkUtils.endsWith("foo", "foo".length(), "foo"));
+ assertTrue(SdkUtils.endsWith("foo", "fo".length(), "fo"));
+ assertTrue(SdkUtils.endsWith("foo", "f".length(), "f"));
+ }
+
+ public void testStripWhitespace() {
+ assertEquals("foo", SdkUtils.stripWhitespace("foo"));
+ assertEquals("foobar", SdkUtils.stripWhitespace("foo bar"));
+ assertEquals("foobar", SdkUtils.stripWhitespace(" foo bar \n\t"));
+ }
+}
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/AdtUtils.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/AdtUtils.java
index cf79c90..d5fa567 100644
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/AdtUtils.java
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/AdtUtils.java
@@ -53,7 +53,6 @@ import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IRegion;
-import org.eclipse.jface.text.TextUtilities;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.swt.widgets.Display;
@@ -90,98 +89,6 @@ import java.util.Locale;
@SuppressWarnings("restriction") // WST API
public class AdtUtils {
/**
- * Returns true if the given string ends with the given suffix, using a
- * case-insensitive comparison.
- *
- * @param string the full string to be checked
- * @param suffix the suffix to be checked for
- * @return true if the string case-insensitively ends with the given suffix
- */
- public static boolean endsWithIgnoreCase(String string, String suffix) {
- return string.regionMatches(true /* ignoreCase */, string.length() - suffix.length(),
- suffix, 0, suffix.length());
- }
-
- /**
- * Returns true if the given sequence ends with the given suffix (case
- * sensitive).
- *
- * @param sequence the character sequence to be checked
- * @param suffix the suffix to look for
- * @return true if the given sequence ends with the given suffix
- */
- public static boolean endsWith(CharSequence sequence, CharSequence suffix) {
- return endsWith(sequence, sequence.length(), suffix);
- }
-
- /**
- * Returns true if the given sequence ends at the given offset with the given suffix (case
- * sensitive)
- *
- * @param sequence the character sequence to be checked
- * @param endOffset the offset at which the sequence is considered to end
- * @param suffix the suffix to look for
- * @return true if the given sequence ends with the given suffix
- */
- public static boolean endsWith(CharSequence sequence, int endOffset, CharSequence suffix) {
- if (endOffset < suffix.length()) {
- return false;
- }
-
- for (int i = endOffset - 1, j = suffix.length() - 1; j >= 0; i--, j--) {
- if (sequence.charAt(i) != suffix.charAt(j)) {
- return false;
- }
- }
-
- return true;
- }
-
- /**
- * Returns true if the given string starts with the given prefix, using a
- * case-insensitive comparison.
- *
- * @param string the full string to be checked
- * @param prefix the prefix to be checked for
- * @return true if the string case-insensitively starts with the given prefix
- */
- public static boolean startsWithIgnoreCase(String string, String prefix) {
- return string.regionMatches(true /* ignoreCase */, 0, prefix, 0, prefix.length());
- }
-
- /**
- * Returns true if the given string starts at the given offset with the
- * given prefix, case insensitively.
- *
- * @param string the full string to be checked
- * @param offset the offset in the string to start looking
- * @param prefix the prefix to be checked for
- * @return true if the string case-insensitively starts at the given offset
- * with the given prefix
- */
- public static boolean startsWith(String string, int offset, String prefix) {
- return string.regionMatches(true /* ignoreCase */, offset, prefix, 0, prefix.length());
- }
-
- /**
- * Strips the whitespace from the given string
- *
- * @param string the string to be cleaned up
- * @return the string, without whitespace
- */
- public static String stripWhitespace(String string) {
- StringBuilder sb = new StringBuilder(string.length());
- for (int i = 0, n = string.length(); i < n; i++) {
- char c = string.charAt(i);
- if (!Character.isWhitespace(c)) {
- sb.append(c);
- }
- }
-
- return sb.toString();
- }
-
- /**
* Creates a Java class name out of the given string, if possible. For
* example, "My Project" becomes "MyProject", "hello" becomes "Hello",
* "Java's" becomes "Java", and so on.
@@ -344,29 +251,6 @@ public class AdtUtils {
return sb.toString();
}
- /** For use by {@link #getLineSeparator()} */
- private static String sLineSeparator;
-
- /**
- * Returns the default line separator to use.
- * <p>
- * NOTE: If you have an associated {@link IDocument}, it is better to call
- * {@link TextUtilities#getDefaultLineDelimiter(IDocument)} since that will
- * allow (for example) editing a \r\n-delimited document on a \n-delimited
- * platform and keep a consistent usage of delimiters in the file.
- *
- * @return the delimiter string to use
- */
- @NonNull
- public static String getLineSeparator() {
- if (sLineSeparator == null) {
- // This is guaranteed to exist:
- sLineSeparator = System.getProperty("line.separator"); //$NON-NLS-1$
- }
-
- return sLineSeparator;
- }
-
/**
* Returns the current editor (the currently visible and active editor), or null if
* not found
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/actions/DexDumpAction.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/actions/DexDumpAction.java
index 98d931f..a483e9b 100755
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/actions/DexDumpAction.java
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/actions/DexDumpAction.java
@@ -19,12 +19,12 @@ package com.android.ide.eclipse.adt.internal.actions;
import com.android.SdkConstants;
import com.android.annotations.Nullable;
import com.android.ide.eclipse.adt.AdtPlugin;
-import com.android.ide.eclipse.adt.AdtUtils;
import com.android.ide.eclipse.adt.internal.preferences.AdtPrefs.BuildVerbosity;
import com.android.ide.eclipse.adt.internal.sdk.Sdk;
import com.android.sdklib.util.GrabProcessOutput;
import com.android.sdklib.util.GrabProcessOutput.IProcessOutput;
import com.android.sdklib.util.GrabProcessOutput.Wait;
+import com.android.utils.SdkUtils;
import org.eclipse.core.filesystem.EFS;
import org.eclipse.core.filesystem.IFileStore;
@@ -166,7 +166,7 @@ public class DexDumpAction implements IObjectActionDelegate {
final BufferedWriter writer = new BufferedWriter(new FileWriter(dstFile));
try {
- final String lineSep = AdtUtils.getLineSeparator();
+ final String lineSep = SdkUtils.getLineSeparator();
int err = GrabProcessOutput.grabProcessOutput(
process,
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/formatting/XmlPrettyPrinter.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/formatting/XmlPrettyPrinter.java
index 6f15d83..1dd32c7 100644
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/formatting/XmlPrettyPrinter.java
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/formatting/XmlPrettyPrinter.java
@@ -24,8 +24,8 @@ import static com.android.SdkConstants.XMLNS;
import com.android.annotations.NonNull;
import com.android.annotations.Nullable;
-import com.android.ide.eclipse.adt.AdtUtils;
import com.android.ide.eclipse.adt.internal.editors.layout.gle2.DomUtilities;
+import com.android.utils.SdkUtils;
import com.android.utils.XmlUtils;
import org.eclipse.wst.xml.core.internal.document.DocumentTypeImpl;
@@ -86,7 +86,7 @@ public class XmlPrettyPrinter {
mPrefs = prefs;
mStyle = style;
if (lineSeparator == null) {
- lineSeparator = AdtUtils.getLineSeparator();
+ lineSeparator = SdkUtils.getLineSeparator();
}
mLineSeparator = lineSeparator;
}
@@ -877,8 +877,8 @@ public class XmlPrettyPrinter {
return false;
}
- return AdtUtils.endsWith(mOut, mLineSeparator) &&
- AdtUtils.endsWith(mOut, mOut.length() - mLineSeparator.length(), mLineSeparator);
+ return SdkUtils.endsWith(mOut, mLineSeparator) &&
+ SdkUtils.endsWith(mOut, mOut.length() - mLineSeparator.length(), mLineSeparator);
}
private boolean newlineAfterElementClose(Element element, int depth) {
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/ImageUtils.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/ImageUtils.java
index 0178173..c55d0d8 100644
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/ImageUtils.java
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/ImageUtils.java
@@ -20,7 +20,7 @@ import static com.android.SdkConstants.DOT_BMP;
import static com.android.SdkConstants.DOT_GIF;
import static com.android.SdkConstants.DOT_JPG;
import static com.android.SdkConstants.DOT_PNG;
-import static com.android.ide.eclipse.adt.AdtUtils.endsWithIgnoreCase;
+import static com.android.utils.SdkUtils.endsWithIgnoreCase;
import com.android.annotations.NonNull;
import com.android.annotations.Nullable;
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/properties/ResourceValueCompleter.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/properties/ResourceValueCompleter.java
index f6b80d7..081ec80 100644
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/properties/ResourceValueCompleter.java
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/properties/ResourceValueCompleter.java
@@ -24,7 +24,6 @@ import static com.android.SdkConstants.PREFIX_THEME_REF;
import com.android.ide.common.resources.ResourceItem;
import com.android.ide.common.resources.ResourceRepository;
-import com.android.ide.eclipse.adt.AdtUtils;
import com.android.ide.eclipse.adt.internal.editors.AndroidXmlEditor;
import com.android.ide.eclipse.adt.internal.editors.common.CommonXmlEditor;
import com.android.ide.eclipse.adt.internal.editors.descriptors.AttributeDescriptor;
@@ -32,6 +31,7 @@ import com.android.ide.eclipse.adt.internal.editors.uimodel.UiResourceAttributeN
import com.android.ide.eclipse.adt.internal.resources.manager.ResourceManager;
import com.android.ide.eclipse.adt.internal.sdk.AndroidTargetData;
import com.android.resources.ResourceType;
+import com.android.utils.SdkUtils;
import org.eclipse.core.resources.IProject;
import org.eclipse.jface.fieldassist.ContentProposal;
@@ -172,7 +172,7 @@ class ResourceValueCompleter implements IContentProposalProvider {
prefix.length() <= nameStart ? "" : prefix.substring(nameStart);
for (ResourceItem item : repository.getResourceItemsOfType(type)) {
String name = item.getName();
- if (AdtUtils.startsWithIgnoreCase(name, namePrefix)) {
+ if (SdkUtils.startsWithIgnoreCase(name, namePrefix)) {
results.add(base + name);
}
}
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/properties/ValueCompleter.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/properties/ValueCompleter.java
index 132855d..5559349 100644
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/properties/ValueCompleter.java
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/properties/ValueCompleter.java
@@ -35,9 +35,9 @@ import com.android.annotations.NonNull;
import com.android.annotations.Nullable;
import com.android.ide.common.api.IAttributeInfo;
import com.android.ide.common.api.IAttributeInfo.Format;
-import com.android.ide.eclipse.adt.AdtUtils;
import com.android.ide.eclipse.adt.internal.editors.common.CommonXmlEditor;
import com.android.ide.eclipse.adt.internal.editors.descriptors.AttributeDescriptor;
+import com.android.utils.SdkUtils;
import org.eclipse.jface.fieldassist.ContentProposal;
import org.eclipse.jface.fieldassist.IContentProposal;
@@ -147,7 +147,7 @@ abstract class ValueCompleter implements IContentProposalProvider {
}
for (String value : values) {
- if (AdtUtils.startsWithIgnoreCase(value, prefix)) {
+ if (SdkUtils.startsWithIgnoreCase(value, prefix)) {
if (prepend != null && prepend.contains(value)) {
continue;
}
@@ -165,13 +165,13 @@ abstract class ValueCompleter implements IContentProposalProvider {
String[] values = info.getEnumValues();
if (values != null) {
for (String value : values) {
- if (AdtUtils.startsWithIgnoreCase(value, prefix)) {
+ if (SdkUtils.startsWithIgnoreCase(value, prefix)) {
proposals.add(new ContentProposal(value));
}
}
for (String value : values) {
- if (!AdtUtils.startsWithIgnoreCase(value, prefix)) {
+ if (!SdkUtils.startsWithIgnoreCase(value, prefix)) {
proposals.add(new ContentProposal(value));
}
}
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/manifest/pages/ApplicationToggle.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/manifest/pages/ApplicationToggle.java
index 16519fe..159f089 100644
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/manifest/pages/ApplicationToggle.java
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/manifest/pages/ApplicationToggle.java
@@ -17,7 +17,6 @@
package com.android.ide.eclipse.adt.internal.editors.manifest.pages;
import com.android.ide.eclipse.adt.AdtPlugin;
-import com.android.ide.eclipse.adt.AdtUtils;
import com.android.ide.eclipse.adt.internal.editors.descriptors.DescriptorsUtils;
import com.android.ide.eclipse.adt.internal.editors.manifest.ManifestEditor;
import com.android.ide.eclipse.adt.internal.editors.ui.UiElementPart;
@@ -25,6 +24,7 @@ import com.android.ide.eclipse.adt.internal.editors.uimodel.IUiUpdateListener;
import com.android.ide.eclipse.adt.internal.editors.uimodel.IUiUpdateListener.UiUpdateState;
import com.android.ide.eclipse.adt.internal.editors.uimodel.UiElementNode;
import com.android.ide.eclipse.adt.internal.sdk.Sdk;
+import com.android.utils.SdkUtils;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
@@ -220,7 +220,7 @@ final class ApplicationToggle extends UiElementPart {
}
mUndoXmlParent.insertBefore(mUndoXmlNode, next);
if (next == null) {
- Text sep = mUndoXmlDocument.createTextNode(AdtUtils.getLineSeparator());
+ Text sep = mUndoXmlDocument.createTextNode(SdkUtils.getLineSeparator());
mUndoXmlParent.insertBefore(sep, null); // insert separator before end tag
}
success = true;
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/uimodel/UiElementNode.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/uimodel/UiElementNode.java
index b521d78..f905c73 100644
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/uimodel/UiElementNode.java
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/uimodel/UiElementNode.java
@@ -27,7 +27,6 @@ import com.android.annotations.VisibleForTesting;
import com.android.ide.common.api.IAttributeInfo.Format;
import com.android.ide.common.resources.platform.AttributeInfo;
import com.android.ide.eclipse.adt.AdtPlugin;
-import com.android.ide.eclipse.adt.AdtUtils;
import com.android.ide.eclipse.adt.internal.editors.AndroidXmlEditor;
import com.android.ide.eclipse.adt.internal.editors.descriptors.AttributeDescriptor;
import com.android.ide.eclipse.adt.internal.editors.descriptors.ElementDescriptor;
@@ -42,6 +41,7 @@ import com.android.ide.eclipse.adt.internal.editors.otherxml.descriptors.OtherXm
import com.android.ide.eclipse.adt.internal.editors.uimodel.IUiUpdateListener.UiUpdateState;
import com.android.ide.eclipse.adt.internal.preferences.AdtPrefs;
import com.android.ide.eclipse.adt.internal.sdk.AndroidTargetData;
+import com.android.utils.SdkUtils;
import com.android.utils.XmlUtils;
import org.eclipse.jface.text.TextUtilities;
@@ -1035,7 +1035,7 @@ public class UiElementNode implements IPropertySource {
if (document != null) {
newLine = TextUtilities.getDefaultLineDelimiter(document);
} else {
- newLine = AdtUtils.getLineSeparator();
+ newLine = SdkUtils.getLineSeparator();
}
Text indentNode = doc.createTextNode(newLine + indent);
parentXmlNode.insertBefore(indentNode, xmlNextSibling);
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/lint/EclipseLintClient.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/lint/EclipseLintClient.java
index 1937a94..b3303b3 100644
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/lint/EclipseLintClient.java
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/lint/EclipseLintClient.java
@@ -15,9 +15,9 @@
*/
package com.android.ide.eclipse.adt.internal.lint;
-import static com.android.SdkConstants.FD_NATIVE_LIBS;
import static com.android.SdkConstants.DOT_JAR;
import static com.android.SdkConstants.DOT_XML;
+import static com.android.SdkConstants.FD_NATIVE_LIBS;
import static com.android.ide.eclipse.adt.AdtConstants.MARKER_LINT;
import static com.android.ide.eclipse.adt.AdtUtils.workspacePathToFile;
@@ -50,6 +50,7 @@ import com.android.tools.lint.detector.api.Project;
import com.android.tools.lint.detector.api.Severity;
import com.android.tools.lint.detector.api.XmlContext;
import com.android.utils.Pair;
+import com.android.utils.SdkUtils;
import com.google.common.collect.Maps;
import org.eclipse.core.resources.IFile;
@@ -673,7 +674,7 @@ public class EclipseLintClient extends LintClient implements IDomParser {
return readPlainFile(f);
}
- if (AdtUtils.endsWithIgnoreCase(file.getName(), DOT_XML)) {
+ if (SdkUtils.endsWithIgnoreCase(file.getName(), DOT_XML)) {
IStructuredModel model = null;
try {
IModelManager modelManager = StructuredModelManager.getModelManager();
@@ -813,7 +814,7 @@ public class EclipseLintClient extends LintClient implements IDomParser {
File[] jars = libs.listFiles();
if (jars != null) {
for (File jar : jars) {
- if (AdtUtils.endsWith(jar.getPath(), DOT_JAR)) {
+ if (SdkUtils.endsWith(jar.getPath(), DOT_JAR)) {
libraries.add(jar);
}
}
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/lint/LintFixGenerator.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/lint/LintFixGenerator.java
index 47aac0c..5d2a2bb 100644
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/lint/LintFixGenerator.java
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/lint/LintFixGenerator.java
@@ -29,6 +29,7 @@ import com.android.tools.lint.client.api.IssueRegistry;
import com.android.tools.lint.detector.api.Issue;
import com.android.tools.lint.detector.api.Project;
import com.android.tools.lint.detector.api.Severity;
+import com.android.utils.SdkUtils;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IMarker;
@@ -258,7 +259,7 @@ public class LintFixGenerator implements IMarkerResolutionGenerator2, IQuickAssi
}
IFile file = (IFile) resource;
boolean isJava = file.getName().endsWith(DOT_JAVA);
- boolean isXml = AdtUtils.endsWith(file.getName(), DOT_XML);
+ boolean isXml = SdkUtils.endsWith(file.getName(), DOT_XML);
if (!isJava && !isXml) {
return;
}
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/lint/LintJob.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/lint/LintJob.java
index 0442f18..2851c47 100644
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/lint/LintJob.java
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/lint/LintJob.java
@@ -28,6 +28,7 @@ import com.android.tools.lint.client.api.IssueRegistry;
import com.android.tools.lint.client.api.LintDriver;
import com.android.tools.lint.detector.api.Issue;
import com.android.tools.lint.detector.api.Scope;
+import com.android.utils.SdkUtils;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IMarker;
@@ -93,7 +94,7 @@ final class LintJob extends Job {
scope = Scope.ALL;
} else {
String name = resource.getName();
- if (AdtUtils.endsWithIgnoreCase(name, DOT_XML)) {
+ if (SdkUtils.endsWithIgnoreCase(name, DOT_XML)) {
if (name.equals(SdkConstants.FN_ANDROID_MANIFEST_XML)) {
scope = EnumSet.of(Scope.MANIFEST);
} else {
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/ui/ResourcePreviewHelper.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/ui/ResourcePreviewHelper.java
index d97d176..eeaca0c 100644
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/ui/ResourcePreviewHelper.java
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/ui/ResourcePreviewHelper.java
@@ -16,7 +16,7 @@
package com.android.ide.eclipse.adt.internal.ui;
import static com.android.SdkConstants.DOT_9PNG;
-import static com.android.ide.eclipse.adt.AdtUtils.endsWithIgnoreCase;
+import static com.android.utils.SdkUtils.endsWithIgnoreCase;
import com.android.ide.common.rendering.api.ResourceValue;
import com.android.ide.common.resources.ResourceResolver;
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/newproject/ProjectNamePage.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/newproject/ProjectNamePage.java
index 31c7225..6bf5e28 100644
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/newproject/ProjectNamePage.java
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/newproject/ProjectNamePage.java
@@ -18,8 +18,8 @@ package com.android.ide.eclipse.adt.internal.wizards.newproject;
import static com.android.SdkConstants.FN_PROJECT_PROGUARD_FILE;
import static com.android.SdkConstants.OS_SDK_TOOLS_LIB_FOLDER;
import static com.android.ide.eclipse.adt.AdtUtils.capitalize;
-import static com.android.ide.eclipse.adt.AdtUtils.stripWhitespace;
import static com.android.ide.eclipse.adt.internal.wizards.newproject.ApplicationInfoPage.ACTIVITY_NAME_SUFFIX;
+import static com.android.utils.SdkUtils.stripWhitespace;
import com.android.SdkConstants;
import com.android.ide.common.xml.ManifestData;
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/newxmlfile/NewXmlFileCreationPage.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/newxmlfile/NewXmlFileCreationPage.java
index e2d061b..68c7f4c 100644
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/newxmlfile/NewXmlFileCreationPage.java
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/newxmlfile/NewXmlFileCreationPage.java
@@ -46,6 +46,7 @@ import com.android.ide.eclipse.adt.internal.sdk.Sdk.TargetChangeListener;
import com.android.resources.ResourceFolderType;
import com.android.sdklib.IAndroidTarget;
import com.android.utils.Pair;
+import com.android.utils.SdkUtils;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
@@ -648,7 +649,7 @@ class NewXmlFileCreationPage extends WizardPage {
if (res.getType() == IResource.FOLDER) {
wsFolderPath = res.getProjectRelativePath();
} else if (res.getType() == IResource.FILE) {
- if (AdtUtils.endsWithIgnoreCase(res.getName(), DOT_XML)) {
+ if (SdkUtils.endsWithIgnoreCase(res.getName(), DOT_XML)) {
fileName = res.getName();
}
wsFolderPath = res.getParent().getProjectRelativePath();
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/templates/TemplateHandler.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/templates/TemplateHandler.java
index cb45522..f1bd840 100644
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/templates/TemplateHandler.java
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/templates/TemplateHandler.java
@@ -42,6 +42,7 @@ import com.android.ide.eclipse.adt.internal.sdk.AdtManifestMergeCallback;
import com.android.manifmerger.ManifestMerger;
import com.android.manifmerger.MergerLog;
import com.android.resources.ResourceFolderType;
+import com.android.utils.SdkUtils;
import com.google.common.base.Charsets;
import com.google.common.collect.Lists;
import com.google.common.io.Files;
@@ -688,7 +689,7 @@ class TemplateHandler {
} else {
// Just insert into file along with comment, using the "standard" conflict
// syntax that many tools and editors recognize.
- String sep = AdtUtils.getLineSeparator();
+ String sep = SdkUtils.getLineSeparator();
contents =
"<<<<<<< Original" + sep
+ currentXml + sep
diff --git a/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/AdtUtilsTest.java b/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/AdtUtilsTest.java
index 0d4e02e..c1e94ac 100644
--- a/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/AdtUtilsTest.java
+++ b/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/AdtUtilsTest.java
@@ -15,75 +15,12 @@
*/
package com.android.ide.eclipse.adt;
-import java.util.Locale;
-
import junit.framework.TestCase;
+import java.util.Locale;
+
@SuppressWarnings("javadoc")
public class AdtUtilsTest extends TestCase {
- public void testEndsWithIgnoreCase() {
- assertTrue(AdtUtils.endsWithIgnoreCase("foo", "foo"));
- assertTrue(AdtUtils.endsWithIgnoreCase("foo", "Foo"));
- assertTrue(AdtUtils.endsWithIgnoreCase("foo", "foo"));
- assertTrue(AdtUtils.endsWithIgnoreCase("Barfoo", "foo"));
- assertTrue(AdtUtils.endsWithIgnoreCase("BarFoo", "foo"));
- assertTrue(AdtUtils.endsWithIgnoreCase("BarFoo", "foO"));
-
- assertFalse(AdtUtils.endsWithIgnoreCase("foob", "foo"));
- assertFalse(AdtUtils.endsWithIgnoreCase("foo", "fo"));
- }
-
- public void testStartsWithIgnoreCase() {
- assertTrue(AdtUtils.startsWithIgnoreCase("foo", "foo"));
- assertTrue(AdtUtils.startsWithIgnoreCase("foo", "Foo"));
- assertTrue(AdtUtils.startsWithIgnoreCase("foo", "foo"));
- assertTrue(AdtUtils.startsWithIgnoreCase("barfoo", "bar"));
- assertTrue(AdtUtils.startsWithIgnoreCase("BarFoo", "bar"));
- assertTrue(AdtUtils.startsWithIgnoreCase("BarFoo", "bAr"));
-
- assertFalse(AdtUtils.startsWithIgnoreCase("bfoo", "foo"));
- assertFalse(AdtUtils.startsWithIgnoreCase("fo", "foo"));
- }
-
- public void testStartsWith() {
- assertTrue(AdtUtils.startsWith("foo", 0, "foo"));
- assertTrue(AdtUtils.startsWith("foo", 0, "Foo"));
- assertTrue(AdtUtils.startsWith("Foo", 0, "foo"));
- assertTrue(AdtUtils.startsWith("aFoo", 1, "foo"));
-
- assertFalse(AdtUtils.startsWith("aFoo", 0, "foo"));
- assertFalse(AdtUtils.startsWith("aFoo", 2, "foo"));
- }
-
- public void testEndsWith() {
- assertTrue(AdtUtils.endsWith("foo", "foo"));
- assertTrue(AdtUtils.endsWith("foobar", "obar"));
- assertTrue(AdtUtils.endsWith("foobar", "bar"));
- assertTrue(AdtUtils.endsWith("foobar", "ar"));
- assertTrue(AdtUtils.endsWith("foobar", "r"));
- assertTrue(AdtUtils.endsWith("foobar", ""));
-
- assertTrue(AdtUtils.endsWith(new StringBuilder("foobar"), "bar"));
- assertTrue(AdtUtils.endsWith(new StringBuilder("foobar"), new StringBuffer("obar")));
- assertTrue(AdtUtils.endsWith("foobar", new StringBuffer("obar")));
-
- assertFalse(AdtUtils.endsWith("foo", "fo"));
- assertFalse(AdtUtils.endsWith("foobar", "Bar"));
- assertFalse(AdtUtils.endsWith("foobar", "longfoobar"));
- }
-
- public void testEndsWith2() {
- assertTrue(AdtUtils.endsWith("foo", "foo".length(), "foo"));
- assertTrue(AdtUtils.endsWith("foo", "fo".length(), "fo"));
- assertTrue(AdtUtils.endsWith("foo", "f".length(), "f"));
- }
-
- public void testStripWhitespace() {
- assertEquals("foo", AdtUtils.stripWhitespace("foo"));
- assertEquals("foobar", AdtUtils.stripWhitespace("foo bar"));
- assertEquals("foobar", AdtUtils.stripWhitespace(" foo bar \n\t"));
- }
-
public void testExtractClassName() {
assertEquals("Foo", AdtUtils.extractClassName("foo"));
assertEquals("Foobar", AdtUtils.extractClassName("foo bar"));