Skip to content

Commit fe7cb56

Browse files
committed
[NFC] IDE: Refactor for recursive MemberTypeRepr representation
1 parent de499d1 commit fe7cb56

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

lib/IDE/Formatting.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -692,10 +692,11 @@ class RangeWalker: protected ASTWalker {
692692
} else if (isa<ArrayTypeRepr>(T) || isa<DictionaryTypeRepr>(T)) {
693693
if (!handleSquares(T->getStartLoc(), T->getEndLoc(), T->getStartLoc()))
694694
return Action::Stop();
695-
} else if (auto *GI = dyn_cast<GenericIdentTypeRepr>(T)) {
696-
SourceLoc ContextLoc = GI->getNameLoc().getBaseNameLoc();
697-
SourceRange Brackets = GI->getAngleBrackets();
698-
if (!handleAngles(Brackets.Start, Brackets.End, ContextLoc))
695+
} else if (auto *DRTR = dyn_cast<DeclRefTypeRepr>(T)) {
696+
SourceLoc ContextLoc = DRTR->getNameLoc().getBaseNameLoc();
697+
auto Brackets = DRTR->getAngleBrackets();
698+
if (Brackets.isValid() &&
699+
!handleAngles(Brackets.Start, Brackets.End, ContextLoc))
699700
return Action::Stop();
700701
}
701702
return Action::Continue();
@@ -2784,17 +2785,17 @@ class FormatWalker : public ASTWalker {
27842785
if (TrailingTarget)
27852786
return llvm::None;
27862787

2787-
if (auto *GIT = dyn_cast<GenericIdentTypeRepr>(T)) {
2788-
SourceLoc ContextLoc = GIT->getNameLoc().getBaseNameLoc();
2789-
SourceRange Brackets = GIT->getAngleBrackets();
2788+
if (auto *DRTR = dyn_cast<DeclRefTypeRepr>(T)) {
2789+
SourceLoc ContextLoc = DRTR->getNameLoc().getBaseNameLoc();
2790+
SourceRange Brackets = DRTR->getAngleBrackets();
27902791
if (Brackets.isInvalid())
27912792
return llvm::None;
27922793

27932794
SourceLoc L = Brackets.Start;
27942795
SourceLoc R = getLocIfTokenTextMatches(SM, Brackets.End, ">");
27952796
ListAligner Aligner(SM, TargetLocation, ContextLoc, L, R);
2796-
for (auto *Arg: GIT->getGenericArgs())
2797-
Aligner.updateAlignment(Arg->getSourceRange(), GIT);
2797+
for (auto *Arg: DRTR->getGenericArgs())
2798+
Aligner.updateAlignment(Arg->getSourceRange(), DRTR);
27982799

27992800
return Aligner.getContextAndSetAlignment(CtxOverride);
28002801
}

0 commit comments

Comments
 (0)