robolectric icon indicating copy to clipboard operation
robolectric copied to clipboard

[Warning] Eliminated AnnotateFormatMethod warnings

Open hellosagar opened this issue 2 years ago • 16 comments

Overview

Eliminated the AnnotateFormatMethod across the entire project.

Proposed Changes

Added the changes in the following files to fix the error-prone warning

hellosagar avatar Jun 04 '22 21:06 hellosagar

@hellosagar Look like new commit to applying google java format generates a reasonable change lines, instead of previous multi thousands lines.

utzcoz avatar Jun 11 '22 14:06 utzcoz

@hellosagar Look like new commit to applying google java format generates a reasonable change lines, instead of previous multi thousands lines.

Yes :)

hellosagar avatar Jun 11 '22 14:06 hellosagar

There are some formats don't look great, although it has passed checking. And I have wrote some comments for some wrong formats, I think.

utzcoz avatar Jun 11 '22 14:06 utzcoz

um.. lme check that locally on my system

hellosagar avatar Jun 11 '22 14:06 hellosagar

@utzcoz you are right, I little surprised how it passed in the CI but mainly AttributeResolution10.java contains a lot of weird indentation, Ive reformat it locally, pushing it again

hellosagar avatar Jun 11 '22 16:06 hellosagar

Why formatted change lines increase a lot again?

utzcoz avatar Jun 11 '22 16:06 utzcoz

Why formatted change lines increase a lot again?

because I open that file and pressed the cmd + ctrl + L which performed the google style format as I've their plugin installed.

TDLR: Used the plugin to reformat the file according to the standards

Screenshot 2022-06-11 at 10 00 10 PM

hellosagar avatar Jun 11 '22 16:06 hellosagar

It's not recommend to add not related formatted lines. Could you format with command in wiki? We just need add formatted lines that affected by this PR.

utzcoz avatar Jun 11 '22 16:06 utzcoz

Okay, lme undo this

hellosagar avatar Jun 11 '22 16:06 hellosagar

pushed again according to the wiki, but in that ALGOI method has a weird indentation

hellosagar avatar Jun 11 '22 16:06 hellosagar

Could you fix them manually one by one and check locally whether they can pass google format checking?

utzcoz avatar Jun 11 '22 16:06 utzcoz

Could you fix them manually one by one and check locally whether they can pass google format checking?

I tried it first before pushing 😅, but it shows a google format error.

hellosagar avatar Jun 11 '22 16:06 hellosagar

Okay, I will check and verify it tomorrow.

utzcoz avatar Jun 11 '22 16:06 utzcoz

After manually, changing the indentation for ALGOI, this log is generated

❯ /bin/zsh /Users/sagarkhurana/checkJavaFormat.sh
Please run google-java-format on the changes in this pull request
--- resources/src/main/java/org/robolectric/res/android/AttributeResolution10.java      (before formatting)
+++ resources/src/main/java/org/robolectric/res/android/AttributeResolution10.java      (after formatting)
@@ -94,9 +94,9 @@
             int src_values_length, int[] attrs,
             int attrs_length, int[] out_values, int[] out_indices) {
         if (kDebugStyles) {
-            ALOGI(
-                "APPLY STYLE: theme=0x%s defStyleAttr=0x%x defStyleRes=0x%x",
-                theme, def_style_attr, def_style_res);
+      ALOGI(
+          "APPLY STYLE: theme=0x%s defStyleAttr=0x%x defStyleRes=0x%x",
+          theme, def_style_attr, def_style_res);
         }
 
         CppAssetManager2 assetmanager = theme.GetAssetManager();
@@ -160,7 +160,7 @@
                     type_set_flags = def_style_flags.get();
                     value = entry.value;
                     if (kDebugStyles) {
-                        ALOGI("-> From def style: type=0x%x, data=0x%08x", value.dataType, value.data);
+            ALOGI("-> From def style: type=0x%x, data=0x%08x", value.dataType, value.data);
                     }
                 }
             }
@@ -193,7 +193,7 @@
                         cookie = new_cookie;
                     }
                     if (kDebugStyles) {
-                        ALOGI("-> Resolved theme: type=0x%x, data=0x%08x", value.dataType, value.data);
+            ALOGI("-> Resolved theme: type=0x%x, data=0x%08x", value.dataType, value.data);
                     }
                 }
             }
@@ -333,7 +333,7 @@
                 xml_parser.getAttributeValue(xml_attr_idx, value);
                 type_set_flags.set(style_flags.get());
                 if (kDebugStyles) {
-                    ALOGI("-> From XML: type=0x%x, data=0x%08x", value.get().dataType, value.get().data);
+          ALOGI("-> From XML: type=0x%x, data=0x%08x", value.get().dataType, value.get().data);
                 }
             }
 
@@ -347,9 +347,9 @@
                     value.set(entry.value);
                     source_style_resid = entry.style;
                     if (kDebugStyles) {
-                        ALOGI(
-                            "-> From style: type=0x%x, data=0x%08x, style=0x%08x",
-                            value.get().dataType, value.get().data, entry.style);
+            ALOGI(
+                "-> From style: type=0x%x, data=0x%08x, style=0x%08x",
+                value.get().dataType, value.get().data, entry.style);
                     }
                 }
             }
@@ -364,9 +364,9 @@
 
                     value.set(entry.value);
                     if (kDebugStyles) {
-                        ALOGI(
-                            "-> From def style: type=0x%x, data=0x%08x, style=0x%08x",
-                            value.get().dataType, value.get().data, entry.style);
+            ALOGI(
+                "-> From def style: type=0x%x, data=0x%08x, style=0x%08x",
+                value.get().dataType, value.get().data, entry.style);
                     }
                     source_style_resid = entry.style;
                 }
@@ -382,14 +382,14 @@
                 }
 
                 if (kDebugStyles) {
-                    ALOGI("-> Resolved attr: type=0x%x, data=0x%08x", value.get().dataType, value.get().data);
+          ALOGI("-> Resolved attr: type=0x%x, data=0x%08x", value.get().dataType, value.get().data);
                 }
             } else if (value.get().data != Res_value.DATA_NULL_EMPTY) {
                 // If we still don't have a value for this attribute, try to find it in the theme!
                 ApkAssetsCookie new_cookie = theme.GetAttribute(cur_ident, value, type_set_flags);
                 if (new_cookie.intValue() != kInvalidCookie) {
                     if (kDebugStyles) {
-                        ALOGI("-> From theme: type=0x%x, data=0x%08x", value.get().dataType, value.get().data);
+            ALOGI("-> From theme: type=0x%x, data=0x%08x", value.get().dataType, value.get().data);
                     }
                     new_cookie =
                             assetmanager.ResolveReference(new_cookie, value, config, type_set_flags, resid);
@@ -398,9 +398,9 @@
                     }
 
                     if (kDebugStyles) {
-                        ALOGI(
-                            "-> Resolved theme: type=0x%x, data=0x%08x",
-                            value.get().dataType, value.get().data);
+            ALOGI(
+                "-> Resolved theme: type=0x%x, data=0x%08x",
+                value.get().dataType, value.get().data);
                     }
                 }
             }
@@ -415,9 +415,9 @@
             }
 
             if (kDebugStyles) {
-                ALOGI(
-                    "Attribute 0x%08x: type=0x%x, data=0x%08x",
-                    cur_ident, value.get().dataType, value.get().data);
+        ALOGI(
+            "Attribute 0x%08x: type=0x%x, data=0x%08x",
+            cur_ident, value.get().dataType, value.get().data);
             }
 
             // Write the final value back to Java.

hellosagar avatar Jun 11 '22 16:06 hellosagar

@hellosagar could you rebase and squash commits for this PR? I think wrong formatting are generated by wrong HEAD when using google-java-format locally. We have analyzed this problem before. Maybe you can get correct code formatting after rebasing, squashing, and running google-java-format with correct command locally again.

utzcoz avatar Aug 06 '22 14:08 utzcoz

I've ran the formatting locally and pushed it again

hellosagar avatar Aug 09 '22 16:08 hellosagar

@utzcoz any update after I pushed the new commit?

hellosagar avatar Aug 30 '22 13:08 hellosagar

@hellosagar Please fix incorrect format problem and rebase it to latest master.

utzcoz avatar Aug 31 '22 02:08 utzcoz

:integration_tests:androidx_test:connectedDebugAndroidTest test is even failing in master as well

Below is the log generated from master branch

image

hellosagar avatar Aug 31 '22 19:08 hellosagar

@utzcoz I've added a separate commit for easy review, later I'll squash it. Please have a look at it

hellosagar avatar Sep 01 '22 16:09 hellosagar

@utzcoz I've added a separate commit for easy review, later I'll squash it. Please have a look at it

You can squash it. Hi @hoisie What about skipping format error for this special case?

utzcoz avatar Sep 02 '22 02:09 utzcoz

Squashed :)

hellosagar avatar Sep 03 '22 07:09 hellosagar

@hellosagar Could you enable kDebugStringPoolNoisy and build and run tests locally to check whether your changes can work without error? The default value of kDebugStringPoolNoisy is false, and I think current CI will not run into some code you modified.

utzcoz avatar Sep 13 '22 11:09 utzcoz

Locally all checks are passing, without enabling the kDebugStringPoolNoisy in ResTable and ResXMLParser

Screenshot from 2022-09-17 11-55-22

and this is the output after enabling the kDebugStringPoolNoisy in ResTable and ResXMLParser

Screenshot from 2022-09-17 12-08-35

hellosagar avatar Sep 17 '22 06:09 hellosagar

Hi @hoisie , because there are strange code formatting generated by google-java-format, so I leave format checking error here, and merge this PR firstly.

utzcoz avatar Sep 18 '22 07:09 utzcoz