Title: Handle type annotations · Issue #5 · google/google-java-format · GitHub
Open Graph Title: Handle type annotations · Issue #5 · google/google-java-format
X Title: Handle type annotations · Issue #5 · google/google-java-format
Description: We always want to format type annotations in-line: @Nullable Object foo() {} This is tricky in contexts where type annotations could be mixed together with declaration annotations, such as field, method, and variable declarations. There'...
Open Graph Description: We always want to format type annotations in-line: @Nullable Object foo() {} This is tricky in contexts where type annotations could be mixed together with declaration annotations, such as field, m...
X Description: We always want to format type annotations in-line: @Nullable Object foo() {} This is tricky in contexts where type annotations could be mixed together with declaration annotations, such as field, m...
Opengraph URL: https://github.com/google/google-java-format/issues/5
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Handle type annotations","articleBody":"We always want to format type annotations in-line:\n\n```\n@Nullable Object foo() {}\n```\n\nThis is tricky in contexts where type annotations could be mixed together with declaration annotations, such as field, method, and variable declarations. There's no syntactic information to we can use to distinguish between `@NullableType Object foo() {}` and `@Deprecated Object foo() {}`, but we want to output the first annotation in-line, and the second vertically.\n\nCurrently, we output ambiguous annotations as declaration annotations. This is fine for Java 7, and has the advantage of never incorrectly formatting a declaration annotation as a type annotation.\n\nHere are some possible heuristics we could use to support this case for Java 8:\n\n1) If the annotation occurs before a regular modifier, it's probably a declaration annotation:\n\n```\n@Deprecated\nstatic Object foo() {}\n```\n\n2) If the annotation occurs after regular modifiers, and it isn't on a void-returning method, it's probably a type annotation:\n\n```\nstatic @Nullable Object foo() {}\n```\n\n3) If the declaration isn't a void-returning method, and it has no regular modifiers, consider the existing formatting: type annotations are probably on the same line as the type, declaration annotations are probably vertical. (The risk here is that we'd preserve things like `@Override Object foo() {}`.)\n\n4) If the declaration is named `@Override`, it's probably a declaration annotation. This would offset the disadvantage of (3), but it could be confusing if `@Override` behaves differently than other annotations.\n\n5) An annotation with parameters is unlikely to be a type annotation, and should probably be formatted vertically.\n","author":{"url":"https://github.com/cushon","@type":"Person","name":"cushon"},"datePublished":"2015-05-16T03:20:28Z","url":"https://github.com/google/google-java-format/issues/5"}
| 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:474e5925-ec25-b8e6-74a3-757298e802b8 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | AB92:76282:2902D2:37AE2A:6AFBB12D |
| html-safe-nonce | 1a6f7791c344feba525a341e0149382bcfd5209ce66df075ae86a17259841751 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBQjkyOjc2MjgyOjI5MDJEMjozN0FFMkE6NkFGQkIxMkQiLCJ2aXNpdG9yX2lkIjoiNTE0OTMyMTE1MjkzMzExNDE1NyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | c1f251ce5130e70fb2aeaec84583a015eb359bf4c8570d530976521a1550f5bd |
| hovercard-subject-tag | issue:76931469 |
| 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/5/issue_layout |
| twitter:image | https://opengraph.githubassets.com/bc0113c2b1d6e01ff5d22c2de2ba95fdff53b0b1c380201d7566b1a4036ba2e8/google/google-java-format/issues/5 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/bc0113c2b1d6e01ff5d22c2de2ba95fdff53b0b1c380201d7566b1a4036ba2e8/google/google-java-format/issues/5 |
| og:image:alt | We always want to format type annotations in-line: @Nullable Object foo() {} This is tricky in contexts where type annotations could be mixed together with declaration annotations, such as field, m... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | cushon |
| 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