Annotation location when mixed with modifiers
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 35/100
Research direction
Start by comparing the supplied mixed-annotation examples with sections 4.8.5 and 4.8.7 of the linked Google Java Style Guide. No source file or test is named, so first locate the formatter logic and existing coverage for modifiers and annotations; done means the intended placement is decided and the examples are formatted consistently.
Written by the indexing model from the issue text.
Description
When annotations are mixed with modifiers, formatter formats the code in following way:
$ cat TestingModifiers.java
/** some javadoc. */
public abstract class TestingModifiers {
abstract @MyAnnotation2 public void fooMet1();
final strictfp synchronized protected @MyAnnotation2 void fooMethod7() {}
synchronized final strictfp @MyAnnotation2 public void fooMethod5() {}
@MyAnnotation2 public static @MyAnnotation4 strictfp void someMethod5() {}
strictfp protected final @MyAnnotation2 static synchronized void fooMethod1() {}
native synchronized protected static @MyAnnotation2 void fooMethod3();
}
$ java -jar google-java-format-1.23.0-all-deps.jar TestingModifiers.java > TestingModifiersUpdated.java
$ cat TestingModifiersUpdated.java
/** some javadoc. */
public abstract class TestingModifiers {
abstract @MyAnnotation2 public void fooMet1();
protected final synchronized strictfp @MyAnnotation2 void fooMethod7() {}
final synchronized strictfp @MyAnnotation2 public void fooMethod5() {}
@MyAnnotation2
public static @MyAnnotation4 strictfp void someMethod5() {}
protected final strictfp @MyAnnotation2 static synchronized void fooMethod1() {}
protected static synchronized native @MyAnnotation2 void fooMethod3();
}
$ diff -u TestingModifiers.java TestingModifiersUpdated.java
--- TestingModifiers.java 2024-08-28 11:00:02.129632600 +0530
+++ TestingModifiersUpdated.java 2024-08-28 11:01:40.748988100 +0530
@@ -2,13 +2,14 @@
public abstract class TestingModifiers {
abstract @MyAnnotation2 public void fooMet1();
- final strictfp synchronized protected @MyAnnotation2 void fooMethod7() {}
+ protected final synchronized strictfp @MyAnnotation2 void fooMethod7() {}
- synchronized final strictfp @MyAnnotation2 public void fooMethod5() {}
+ final synchronized strictfp @MyAnnotation2 public void fooMethod5() {}
- @MyAnnotation2 public static @MyAnnotation4 strictfp void someMethod5() {}
+ @MyAnnotation2
+ public static @MyAnnotation4 strictfp void someMethod5() {}
- strictfp protected final @MyAnnotation2 static synchronized void fooMethod1() {}
+ protected final strictfp @MyAnnotation2 static synchronized void fooMethod1() {}
- native synchronized protected static @MyAnnotation2 void fooMethod3();
+ protected static synchronized native @MyAnnotation2 void fooMethod3();
}
From 4.8.7 Modifiers
Class and member modifiers, when present, appear in the order recommended by the Java Language Specification:
public protected private abstract default static final transient volatile synchronized native strictfp
There's not explicitly mentioned anything about position of annotations when mixed with modifiers or annotations should not be mixed with modifiers or something similar to that in above rule.
Also, in 4.8.5 Annotations, there's not explicitly mentioned that how annotations should be positioned when used with modifiers. But all sub-sections mostly refers to:
Annotations applying to a class appear immediately after the documentation block, and each annotation is listed on a line of its own (that is, one annotation per line).
Attention to:
immediately after the documentation block
This kind of implies that annotations should be placed before any modifiers. But formatter does not places annotations before modifiers as shown in above example. So if annotations should not be mixed with modifiers and placed at the beginning or in a separate line then formatter should be updated and format the code according to this.
- Dominant language
- Java
- Stars
- 6.2k
- Forks
- 936
- Avg merge
- 6m
- Merged PRs (30d)
- 3
Getting set up
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from google/google-java-format
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
google/google-java-format#1094 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 5/5 Over a week Newbie friendliness 15/100
google/google-java-format#1450 · 1 reaction ·
Maintainers usually reply within 1 day
-
Difficulty 4/5 3-5 days Newbie friendliness 55/100
google/google-java-format#1439 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 3/5 1-2 days Newbie friendliness 62/100
google/google-java-format#1436 · 2 comments ·
Maintainers usually reply within 1 day
-
Difficulty 3/5 1-2 days Newbie friendliness 48/100
google/google-java-format#1428 · 4 comments ·
Maintainers usually reply within 1 day
All issues in google/google-java-format
Similar issues
-
and-bugs and-ui gpx-track
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
Maintainers usually reply within 2 days
-
TerminalRow.mSpaceUsed (short) overflows on terminals wider than 1023 columns, crashing setCharOpen
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
termux/termux-app#5340 ·
Maintainers usually reply within 1 day
-
OpenAICompatibleToolDescriptorSchemaGenerator drops requiredProperties of nested object parametersOpen
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 7 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
apache/rocketmq-dashboard#5110 ·
Maintainers usually reply within 1 day
-
frontend
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
No-Country-simulation/S08-26-equipo04#210 ·
Maintainers usually reply within 1 day