Annotation location when mixed with modifiers
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 35/100
Hướng nghiên cứu
Bắt đầu bằng cách so sánh các ví dụ mixed-annotation được cung cấp với các mục 4.8.5 và 4.8.7 của Google Java Style Guide được liên kết. Không có tệp nguồn hoặc bài kiểm thử nào được nêu tên, vì vậy trước tiên hãy xác định logic của formatter và phần coverage hiện có cho các modifier và annotation; công việc được xem là hoàn tất khi vị trí dự kiến đã được quyết định và các ví dụ được format nhất quán.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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.
- Ngôn ngữ chính
- Java
- Star
- 6.2k
- Fork
- 936
- Merge trung bình
- 6 phút
- Pull request đã merge (30 ngày)
- 3
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của google/google-java-format
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
google/google-java-format#1094 · 1 bình luận ·
-
Complementary Teamups Đang mở
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 15/100
google/google-java-format#1450 · 1 reaction ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 55/100
google/google-java-format#1439 · 1 bình luận ·
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 62/100
google/google-java-format#1436 · 2 bình luận ·
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 48/100
google/google-java-format#1428 · 3 bình luận ·
Tất cả issue của google/google-java-format
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
elastic/gradle-plugins#157 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
cryptomator/hub#497 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
johanhaleby/occurrent#1120 ·