diff options
author | Nico Weber <nicolasweber@gmx.de> | 2018-10-05 18:22:21 +0000 |
---|---|---|
committer | Nico Weber <nicolasweber@gmx.de> | 2018-10-05 18:22:21 +0000 |
commit | a42b1d8f647c28ed6050fc59ec2c4df1961c8143 (patch) | |
tree | a63e6eb2e5ffef6550481f911535abcf8d2e45fc /lib/Format | |
parent | 3f6d5060de9d76c441d4104cb11fe380e99887f8 (diff) |
clang-format: Don't insert spaces in front of :: for Java 8 Method References.
The existing code kept the space if it was there for identifiers, and it didn't
handle `this`. After this patch, for Java `this` is handled in addition to
identifiers, and existing space is always stripped between identifier and `::`.
Also accept `::` in addition to `.` in front of `<` in `foo::<T>bar` generic
calls.
Differential Revision: https://reviews.llvm.org/D52842
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@343872 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Format')
-rw-r--r-- | lib/Format/TokenAnnotator.cpp | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index 2cb4c0361b..d032fd7cb9 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/lib/Format/TokenAnnotator.cpp @@ -2555,8 +2555,11 @@ bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line, return false; if (Left.is(TT_TemplateCloser) && Left.MatchingParen && Left.MatchingParen->Previous && - Left.MatchingParen->Previous->is(tok::period)) + (Left.MatchingParen->Previous->is(tok::period) || + Left.MatchingParen->Previous->is(tok::coloncolon))) + // Java call to generic function with explicit type: // A.<B<C<...>>>DoSomething(); + // A::<B<C<...>>>DoSomething(); // With a Java 8 method reference. return false; if (Left.is(TT_TemplateCloser) && Right.is(tok::l_square)) return false; @@ -2776,6 +2779,9 @@ bool TokenAnnotator::spaceRequiredBefore(const AnnotatedLine &Line, if (!Style.SpaceBeforeAssignmentOperators && Right.getPrecedence() == prec::Assignment) return false; + if (Style.Language == FormatStyle::LK_Java && Right.is(tok::coloncolon) && + (Left.is(tok::identifier) || Left.is(tok::kw_this))) + return false; if (Right.is(tok::coloncolon) && Left.is(tok::identifier)) // Generally don't remove existing spaces between an identifier and "::". // The identifier might actually be a macro name such as ALWAYS_INLINE. If |