================
@@ -3767,12 +3767,26 @@ tooling::Replacements sortJavaImports(const FormatStyle
&Style, StringRef Code,
Code.substr(Prev, (Pos != StringRef::npos ? Pos : Code.size()) - Prev);
StringRef Trimmed = Line.trim();
- if (isClangFormatOff(Trimmed))
+ if (Trimmed.empty()) {
+ // Skip empty lines.
+ } else if (isClangFormatOff(Trimmed)) {
FormattingOff = true;
- else if (isClangFormatOn(Trimmed))
+ } else if (isClangFormatOn(Trimmed)) {
FormattingOff = false;
-
- if (ImportRegex.match(Line, &Matches)) {
+ } else if (Trimmed.starts_with("//")) {
+ if (!ImportsInBlock.empty())
+ AssociatedCommentLines.push_back(Line);
+ } else if (Trimmed.starts_with("/*")) {
+ auto EndPos = Code.find("*/", SearchFrom + 2);
+ if (EndPos != StringRef::npos) {
+ Line = Code.substr(Prev, EndPos + 2 - Prev);
+ Pos = EndPos + 1;
+ }
+ if (!ImportsInBlock.empty())
+ AssociatedCommentLines.push_back(Line);
+ } else if (PackageRegex.match(Trimmed)) {
+ // Skip package declarations.
----------------
owenca wrote:
```suggestion
Pos = Code.find("*/", Pos + 2);
if (Pos != StringRef::npos)
Pos = Code.find('\n', Pos + 2);
if (HasImport) {
Line = GetLine();
AssociatedCommentLines.push_back(Line);
}
```
https://github.com/llvm/llvm-project/pull/177326
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits