From 9a654c3e45ec87e29d0644ab6fb3c830fa73e5ba Mon Sep 17 00:00:00 2001 From: Tor Norbye Date: Tue, 6 Mar 2012 17:50:42 -0800 Subject: Misc Lint Fixes This changeset contains fixes for several unrelated reported lint bugs: 26505: Default disabled rules that are explicitly enabled do not activate 26467: Lint says ByteBuffer.array is API 9+ but it's really API 1+ 26501: Warning "This tag and its children can be replaced by one and a compound drawable" is not always correct (Partially fixed) It also fixes the following bugs: - The quickfix for the typography detector did not work for the fraction warning (replacing 1/2 with the half unicode symbol etc) - A couple of XML detectors did not check for SuppressLint on the associated root node - Add a --exitcode flag, and only set the exit code to non-zero if that flag is specified. Also fix the code such that non-fatal errors also contribute to the exit code. - Make the HTML reporter classes public to help Maven integration. Change-Id: I60f5fdcb2a465d51fa58bb918a195b373096d54b --- .../refactoring/UseCompoundDrawableRefactoring.java | 12 ++++++++++++ .../UseCompoundDrawableRefactoringTest.java | 5 +++++ .../refactoring/usecompound/compound5-expected-7.xml | 9 +++++++++ .../testdata/refactoring/usecompound/compound5.info | 3 +++ .../testdata/refactoring/usecompound/compound5.xml | 18 ++++++++++++++++++ 5 files changed, 47 insertions(+) create mode 100644 eclipse/plugins/com.android.ide.eclipse.tests/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/testdata/refactoring/usecompound/compound5-expected-7.xml create mode 100644 eclipse/plugins/com.android.ide.eclipse.tests/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/testdata/refactoring/usecompound/compound5.info create mode 100644 eclipse/plugins/com.android.ide.eclipse.tests/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/testdata/refactoring/usecompound/compound5.xml (limited to 'eclipse') diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/UseCompoundDrawableRefactoring.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/UseCompoundDrawableRefactoring.java index 0480cda..53b8f49 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/UseCompoundDrawableRefactoring.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/UseCompoundDrawableRefactoring.java @@ -56,6 +56,7 @@ import org.eclipse.text.edits.MultiTextEdit; import org.eclipse.text.edits.ReplaceEdit; import org.eclipse.text.edits.TextEdit; import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel; +import org.eclipse.wst.sse.core.internal.provisional.IndexedRegion; import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument; import org.w3c.dom.Attr; import org.w3c.dom.Document; @@ -283,6 +284,17 @@ public class UseCompoundDrawableRefactoring extends VisualRefactoring { setAndroidAttribute(newTextElement, androidNsPrefix, drawableAttribute, src); + // If the removed LinearLayout is the root container, transfer its namespace + // declaration to the TextView + if (layout.getParentNode() instanceof Document) { + List declarations = findNamespaceAttributes(layout); + for (Attr attribute : declarations) { + if (attribute instanceof IndexedRegion) { + newTextElement.setAttribute(attribute.getName(), attribute.getValue()); + } + } + } + // Update any layout references to the layout to point to the text view String layoutId = getId(layout); if (layoutId.length() > 0) { diff --git a/eclipse/plugins/com.android.ide.eclipse.tests/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/UseCompoundDrawableRefactoringTest.java b/eclipse/plugins/com.android.ide.eclipse.tests/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/UseCompoundDrawableRefactoringTest.java index 04b9b1a..c1a5ca4 100644 --- a/eclipse/plugins/com.android.ide.eclipse.tests/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/UseCompoundDrawableRefactoringTest.java +++ b/eclipse/plugins/com.android.ide.eclipse.tests/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/UseCompoundDrawableRefactoringTest.java @@ -57,6 +57,11 @@ public class UseCompoundDrawableRefactoringTest extends RefactoringTest { checkRefactoring("refactoring/usecompound/compound_all.xml", "@+id/layout3"); } + public void test7() throws Exception { + // Test converting where a namespace needs to be migrated + checkRefactoring("refactoring/usecompound/compound5.xml", "@+id/layout"); + } + private void checkRefactoring(String basename, String id) throws Exception { IFile file = getLayoutFile(getProject(), basename); TestContext info = setupTestContext(file, basename); diff --git a/eclipse/plugins/com.android.ide.eclipse.tests/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/testdata/refactoring/usecompound/compound5-expected-7.xml b/eclipse/plugins/com.android.ide.eclipse.tests/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/testdata/refactoring/usecompound/compound5-expected-7.xml new file mode 100644 index 0000000..e909811 --- /dev/null +++ b/eclipse/plugins/com.android.ide.eclipse.tests/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/testdata/refactoring/usecompound/compound5-expected-7.xml @@ -0,0 +1,9 @@ + + + + \ No newline at end of file diff --git a/eclipse/plugins/com.android.ide.eclipse.tests/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/testdata/refactoring/usecompound/compound5.info b/eclipse/plugins/com.android.ide.eclipse.tests/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/testdata/refactoring/usecompound/compound5.info new file mode 100644 index 0000000..8eb5c4b --- /dev/null +++ b/eclipse/plugins/com.android.ide.eclipse.tests/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/testdata/refactoring/usecompound/compound5.info @@ -0,0 +1,3 @@ +android.widget.LinearLayout [0,74,480,800] + android.widget.TextView [0,0,107,26] + android.widget.ImageView [0,26,72,98] diff --git a/eclipse/plugins/com.android.ide.eclipse.tests/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/testdata/refactoring/usecompound/compound5.xml b/eclipse/plugins/com.android.ide.eclipse.tests/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/testdata/refactoring/usecompound/compound5.xml new file mode 100644 index 0000000..49c0594 --- /dev/null +++ b/eclipse/plugins/com.android.ide.eclipse.tests/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/testdata/refactoring/usecompound/compound5.xml @@ -0,0 +1,18 @@ + + + + + + + + -- cgit v1.1