summaryrefslogtreecommitdiffstats
path: root/clang/lib/Format
diff options
context:
space:
mode:
Diffstat (limited to 'clang/lib/Format')
-rw-r--r--clang/lib/Format/ContinuationIndenter.cpp7
-rw-r--r--clang/lib/Format/TokenAnnotator.cpp15
-rw-r--r--clang/lib/Format/UnwrappedLineParser.cpp8
3 files changed, 23 insertions, 7 deletions
diff --git a/clang/lib/Format/ContinuationIndenter.cpp b/clang/lib/Format/ContinuationIndenter.cpp
index b6dd9bdcf8b..707153242b8 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -503,6 +503,13 @@ unsigned ContinuationIndenter::getNewLineColumn(const LineState &State) {
const FormatToken *NextNonComment = Previous.getNextNonComment();
if (!NextNonComment)
NextNonComment = &Current;
+
+ // Java specific bits.
+ if (Style.Language == FormatStyle::LK_Java && Current.is(tok::identifier) &&
+ (Current.TokenText == "implements" || Current.TokenText == "extends"))
+ return std::max(State.Stack.back().LastSpace,
+ State.Stack.back().Indent + Style.ContinuationIndentWidth);
+
if (NextNonComment->is(tok::l_brace) && NextNonComment->BlockKind == BK_Block)
return Current.NestingLevel == 0 ? State.FirstIndent
: State.Stack.back().Indent;
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index c54b04138b4..ebcad05d863 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -1064,7 +1064,8 @@ static int PrecedenceArrowAndPeriod = prec::PointerToMember + 2;
/// operator precedence.
class ExpressionParser {
public:
- ExpressionParser(AnnotatedLine &Line) : Current(Line.First) {}
+ ExpressionParser(const FormatStyle &Style, AnnotatedLine &Line)
+ : Style(Style), Current(Line.First) {}
/// \brief Parse expressions with the given operatore precedence.
void parse(int Precedence = 0) {
@@ -1167,6 +1168,11 @@ private:
return Current->getPrecedence();
else if (Current->isOneOf(tok::period, tok::arrow))
return PrecedenceArrowAndPeriod;
+ else if (Style.Language == FormatStyle::LK_Java &&
+ Current->is(tok::identifier) &&
+ (Current->TokenText == "extends" ||
+ Current->TokenText == "implements"))
+ return 0;
}
return -1;
}
@@ -1224,6 +1230,7 @@ private:
Current = Current->Next;
}
+ const FormatStyle &Style;
FormatToken *Current;
};
@@ -1256,7 +1263,7 @@ void TokenAnnotator::annotate(AnnotatedLine &Line) {
if (Line.Type == LT_Invalid)
return;
- ExpressionParser ExprParser(Line);
+ ExpressionParser ExprParser(Style, Line);
ExprParser.parse();
if (Line.First->Type == TT_ObjCMethodSpecifier)
@@ -1837,7 +1844,9 @@ bool TokenAnnotator::canBreakBefore(const AnnotatedLine &Line,
const FormatToken &Left = *Right.Previous;
if (Style.Language == FormatStyle::LK_Java) {
- if (Left.is(tok::identifier) && Left.TokenText == "throws")
+ if (Left.is(tok::identifier) &&
+ (Left.TokenText == "throws" || Left.TokenText == "extends" ||
+ Left.TokenText == "implements"))
return false;
}
diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp
index 6d2b67c29c0..256fc28720f 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -1375,10 +1375,10 @@ void UnwrappedLineParser::parseRecord() {
}
// The actual identifier can be a nested name specifier, and in macros
// it is often token-pasted.
- while (
- FormatTok->is(tok::identifier) || FormatTok->is(tok::coloncolon) ||
- FormatTok->is(tok::hashhash) ||
- (Style.Language == FormatStyle::LK_Java && FormatTok->is(tok::period)))
+ while (FormatTok->is(tok::identifier) || FormatTok->is(tok::coloncolon) ||
+ FormatTok->is(tok::hashhash) ||
+ (Style.Language == FormatStyle::LK_Java &&
+ FormatTok->isOneOf(tok::period, tok::comma)))
nextToken();
// Note that parsing away template declarations here leads to incorrectly
OpenPOWER on IntegriCloud