Title: Intellij Plugin breaks method inlining and variable extraction from inside if condition · Issue #1101 · google/google-java-format · GitHub
Open Graph Title: Intellij Plugin breaks method inlining and variable extraction from inside if condition · Issue #1101 · google/google-java-format
X Title: Intellij Plugin breaks method inlining and variable extraction from inside if condition · Issue #1101 · google/google-java-format
Description: Consider the following code and try inlining isEmpty2: import java.util.Collection; import java.util.List; public class InliningWithJavaFormat { static boolean isEmpty(Collection> c) { return c == null || c.isEmpty(); } static boolean ...
Open Graph Description: Consider the following code and try inlining isEmpty2: import java.util.Collection; import java.util.List; public class InliningWithJavaFormat { static boolean isEmpty(Collection> c) { return c =...
X Description: Consider the following code and try inlining isEmpty2: import java.util.Collection; import java.util.List; public class InliningWithJavaFormat { static boolean isEmpty(Collection<?> c) { retu...
Opengraph URL: https://github.com/google/google-java-format/issues/1101
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Intellij Plugin breaks method inlining and variable extraction from inside if condition","articleBody":"Consider the following code and try inlining `isEmpty2`:\r\n```java\r\nimport java.util.Collection;\r\nimport java.util.List;\r\n\r\npublic class InliningWithJavaFormat {\r\n static boolean isEmpty(Collection\u003c?> c) {\r\n return c == null || c.isEmpty();\r\n }\r\n\r\n static boolean isEmpty2(Collection\u003c?> c) {\r\n return isEmpty(c);\r\n }\r\n\r\n public static void main(String[] args){\r\n var pojo = new MyPojo();\r\n if (pojo != null && !isEmpty2(pojo.getCollection())) {\r\n System.out.println(\"empty\");\r\n }\r\n }\r\n\r\n static class MyPojo {\r\n Collection\u003cString> getCollection() {\r\n return List.of();\r\n }\r\n }\r\n}\r\n```\r\nNot only does it fail (without reporting it), but it adds an additional `if (true)`:\r\n```java\r\n public static void main(String[] args){\r\n var pojo = new MyPojo();\r\n if (pojo != null && !isEmpty2(pojo.getCollection())) {\r\n if (true) {\r\n System.out.println(\"empty\");\r\n }\r\n }\r\n }\r\n```\r\nwith the plugin disabled, it works:\r\n```java\r\n public static void main(String[] args){\r\n var pojo = new MyPojo();\r\n if (pojo != null) {\r\n Collection\u003c?> c = pojo.getCollection();\r\n if (!isEmpty(c)) {\r\n System.out.println(\"empty\");\r\n }\r\n }\r\n }\r\n```\r\n(not the ideal result but at least it does not fail)\r\n\r\nIn addition, when I do that on my actual project I get an error notification from the plugin and the formatting gets broken:\r\n\r\n(I did not try to reproduce this with an MRE, I guess it is a side effect of the first issue)","author":{"url":"https://github.com/DidierLoiseau","@type":"Person","name":"DidierLoiseau"},"datePublished":"2024-05-23T09:54:25Z","url":"https://github.com/google/google-java-format/issues/1101"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:cbf815fc-ed53-2266-f9d1-5646d65a50e5 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8D92:27AA32:1F459A:2A3CBB:6AFBAD09 |
| html-safe-nonce | e865d035212ccae85f0e44b38d7bde68d8ddf73ab8c0019e405303b97f584b3b |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4RDkyOjI3QUEzMjoxRjQ1OUE6MkEzQ0JCOjZBRkJBRDA5IiwidmlzaXRvcl9pZCI6IjMxNzAxNzcxOTMzMjE2NzE5NDUiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | fb71ccd9ede7aa354a57d6780b13ec3de6b9f936056ea82268d24d6a8462d4ea |
| hovercard-subject-tag | issue:2312473707 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/google/google-java-format/1101/issue_layout |
| twitter:image | https://opengraph.githubassets.com/e7eed0f6f12b4cc615d64c724473d800c12519f771bd8508617266f97db63a21/google/google-java-format/issues/1101 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/e7eed0f6f12b4cc615d64c724473d800c12519f771bd8508617266f97db63a21/google/google-java-format/issues/1101 |
| og:image:alt | Consider the following code and try inlining isEmpty2: import java.util.Collection; import java.util.List; public class InliningWithJavaFormat { static boolean isEmpty(Collection> c) { return c =... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | DidierLoiseau |
| hostname | github.com |
| expected-hostname | github.com |
| None | e25fbd830d3e6ad0e8935c105cf4fdc70c593dffcd27bb45b790ae4fece5ea55 |
| turbo-cache-control | no-preview |
| go-import | github.com/google/google-java-format git https://github.com/google/google-java-format.git |
| octolytics-dimension-user_id | 1342004 |
| octolytics-dimension-user_login | |
| octolytics-dimension-repository_id | 35448780 |
| octolytics-dimension-repository_nwo | google/google-java-format |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 35448780 |
| octolytics-dimension-repository_network_root_nwo | google/google-java-format |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 08c8f17f9d27054a108b8b6254e405de0151f660 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width