Title: Eclipse-Formatter-Plugin fails due to wrong assumptions · Issue #1172 · google/google-java-format · GitHub
Open Graph Title: Eclipse-Formatter-Plugin fails due to wrong assumptions · Issue #1172 · google/google-java-format
X Title: Eclipse-Formatter-Plugin fails due to wrong assumptions · Issue #1172 · google/google-java-format
Description: The Eclipse-Plugin has sometimes a problem when I call the formatter programatically inside Eclipse. I am using the Snippet from https://help.eclipse.org/latest/topic/org.eclipse.jdt.doc.isv/guide/jdt_api_codeformatter.htm to format a co...
Open Graph Description: The Eclipse-Plugin has sometimes a problem when I call the formatter programatically inside Eclipse. I am using the Snippet from https://help.eclipse.org/latest/topic/org.eclipse.jdt.doc.isv/guide/...
X Description: The Eclipse-Plugin has sometimes a problem when I call the formatter programatically inside Eclipse. I am using the Snippet from https://help.eclipse.org/latest/topic/org.eclipse.jdt.doc.isv/guide/...
Opengraph URL: https://github.com/google/google-java-format/issues/1172
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Eclipse-Formatter-Plugin fails due to wrong assumptions","articleBody":"The Eclipse-Plugin has sometimes a problem when I call the formatter programatically inside Eclipse. I am using the Snippet from https://help.eclipse.org/latest/topic/org.eclipse.jdt.doc.isv/guide/jdt_api_codeformatter.htm to format a complete Java-File. I have created a minimal Test-Class:\r\n\r\n```\r\npackage test;\r\n\r\n/**\r\n * Test Class\r\n * \r\n * Generated\r\n * \r\n */\r\npublic class Test\r\n{\r\n}\r\n```\r\nThe standalone-Formatter-Jar adds a HTML-Tag \u003cp> before the \"Generated\". Unfortunately, when I call the plugin via the Eclipse-APIs:\r\n```java\r\n final TextEdit edit =\r\n codeFormatter.format(\r\n CodeFormatter.K_COMPILATION_UNIT, // format a compilation unit\r\n content, // source to format\r\n 0, // starting position\r\n content.length(), // length\r\n 0, // initial indentation\r\n \"\\r\\n\" // line separator\r\n );\r\n```\r\nthe method returns a null because it can not format the content. I have tracked the problem back to the class SnippetFormatter.java, Method toReplacements(). This method has the condition which checks the unformatted and the formatted source:\r\n```java\r\nif (!NOT_WHITESPACE.retainFrom(source).equals(NOT_WHITESPACE.retainFrom(replacement))) {\r\n throw new IllegalArgumentException(\r\n \"source = \\\"\" + source + \"\\\", replacement = \\\"\" + replacement + \"\\\"\");\r\n }\r\n```\r\nThis condition checks that there are only whitespace-changes in the new formatted source. The Javadoc says:\r\n```quote\r\nunder the assumption that they differ in whitespace alone.\r\n```\r\nUnfortunately, this assumption is not correct. The source has (as mentioned above) an additional non-whitespace change and the IllegalArgumentException is thrown. This Exception causes the Eclipse-Formatter-Class to fail and to return only null, thereby denying to format the source.","author":{"url":"https://github.com/contitleine","@type":"Person","name":"contitleine"},"datePublished":"2024-10-07T08:32:03Z","url":"https://github.com/google/google-java-format/issues/1172"}
| 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:5a62df8b-5157-eb70-1861-91a64f6395ae |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8C72:28910C:29DC87:372BA4:6AFBB69E |
| html-safe-nonce | d4d801187c3828022109c22ee0d4d4d8488140b0baa96d12616adb83c1f5f45b |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4QzcyOjI4OTEwQzoyOURDODc6MzcyQkE0OjZBRkJCNjlFIiwidmlzaXRvcl9pZCI6Ijc2MDc2MDkyNDYwMTk3MjkwNTQiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | da96b74c6071b2a171438f3630b1c79eb2a68cebdf7e44d8b4e5d1e380008fc4 |
| hovercard-subject-tag | issue:2569735141 |
| 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/1172/issue_layout |
| twitter:image | https://opengraph.githubassets.com/4432ad608a7aa3eea5d6cc829d6d0469c9a61e49b004c43a80ac1290c4ac52fc/google/google-java-format/issues/1172 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/4432ad608a7aa3eea5d6cc829d6d0469c9a61e49b004c43a80ac1290c4ac52fc/google/google-java-format/issues/1172 |
| og:image:alt | The Eclipse-Plugin has sometimes a problem when I call the formatter programatically inside Eclipse. I am using the Snippet from https://help.eclipse.org/latest/topic/org.eclipse.jdt.doc.isv/guide/... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | contitleine |
| hostname | github.com |
| expected-hostname | github.com |
| None | 2b2ef9c1578c18d8ed27027940544c958743213cf4461659f14d3ccdf51e162c |
| 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 | e4cce0e99cf61481a318ff12c2e8580153a6c7c6 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width