Eclipse-Formatter-Plugin fails due to wrong assumptions
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
- 45/100
Hướng nghiên cứu
Bắt đầu bằng cách tái hiện lớp Test tối thiểu với đoạn mã API Eclipse, sau đó đọc SnippetFormatter.java và phương thức toReplacements() của nó. Theo dõi cách phép so sánh không có khoảng trắng dẫn đến việc Eclipse formatter trả về null. Được xem là hoàn tất khi mã nguồn mẫu có thể được định dạng thông qua plugin mà không gặp lỗi này, với hành vi được xác minh bằng một regression test.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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:
package test;
/**
* Test Class
*
* Generated
*
*/
public class Test
{
}
The standalone-Formatter-Jar adds a HTML-Tag
before the "Generated". Unfortunately, when I call the plugin via the Eclipse-APIs:
final TextEdit edit =
codeFormatter.format(
CodeFormatter.K_COMPILATION_UNIT, // format a compilation unit
content, // source to format
0, // starting position
content.length(), // length
0, // initial indentation
"\r\n" // line separator
);
the 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:
if (!NOT_WHITESPACE.retainFrom(source).equals(NOT_WHITESPACE.retainFrom(replacement))) {
throw new IllegalArgumentException(
"source = \"" + source + "\", replacement = \"" + replacement + "\"");
}
This condition checks that there are only whitespace-changes in the new formatted source. The Javadoc says:
under the assumption that they differ in whitespace alone.
Unfortunately, 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.
- 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 75/100
elastic/gradle-plugins#157 ·
-
enhancement Tools
Độ khó 1/5 Dưới một 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 70/100
apache/rocketmq-dashboard#5008 ·
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
-
DETECT_PARAMETER_NAMES=false silently disables @ConstructorProperties-based Creator detection too Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
FasterXML/jackson-databind#6229 ·