Annotation location when mixed with modifiers
Maintainer antworten meist innerhalb von 1 Tag
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Anfängerfreundlichkeit
- 35/100
Rechercherichtung
Beginne damit, die bereitgestellten Beispiele mit gemischten Annotationen mit den Abschnitten 4.8.5 und 4.8.7 des verlinkten Google Java Style Guide zu vergleichen. Es ist keine Quelldatei und kein Test angegeben, daher soll zunächst die Formatter-Logik und die bestehende Abdeckung für Modifier und Annotationen gefunden werden; fertig ist die Aufgabe, wenn die beabsichtigte Platzierung festgelegt ist und die Beispiele konsistent formatiert werden.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
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.
- Vorherrschende Sprache
- Java
- Sterne
- 6.2k
- Forks
- 940
- Ø Merge
- 5 Min.
- Gemergte PRs (30 T.)
- 8
Entwicklungsumgebung
- Kein Dockerfile und keine Docker-Compose-Datei
- Keine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus google/google-java-format
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
google/google-java-format#1094 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 35/100
google/google-java-format#1470 · 5 Reaktionen ·
Maintainer antworten meist innerhalb von 1 Tag
-
IndexOutOfBoundsException - Wrong formatted content when dealing with latex StringEvtl. wieder frei @Amlan2000 hat das vor 57 Tagen übernommen, und es ist kein Pull Request offen. Offen
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 55/100
google/google-java-format#1439 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
unused import removal leaves extra blank line between package declaration and class Javadoc / declarationEvtl. vergeben @arimu1 hat das vor 67 Tagen übernommen. Offen
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 62/100
google/google-java-format#1436 · 2 Kommentare ·
Maintainer antworten meist innerhalb von 1 Tag
-
Eclipse
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 48/100
google/google-java-format#1428 · 4 Kommentare ·
Maintainer antworten meist innerhalb von 1 Tag
Alle Issues in google/google-java-format
Ähnliche Issues
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
openhab/openhab-addons#21921 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
objectionary/eo-graphs#85 ·
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 84/100
objectionary/lints#1544 ·
Maintainer antworten meist innerhalb von 2 Tagen
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 76/100
objectionary/hone-maven-plugin#1309 ·
Maintainer antworten meist innerhalb von 1 Tag
-
chore s3
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 83/100
Maintainer antworten meist innerhalb von 1 Tag