Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TreeOps: statements don't start on a comment #4286

Merged
merged 2 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,13 @@ object TreeOps {
val ret = Map.newBuilder[Int, Tree]
ret.sizeHint(tree.tokens.length)

def addFT(ft: FormatToken, tree: Tree): Unit = ret += ft.meta.idx -> tree
def addTok(token: Token, tree: Tree) = addFT(ftoks.after(token), tree)
def addTree(t: Tree, o: Tree) = ftoks.getHeadOpt(t).foreach(addFT(_, o))
def addFT(stmt: Tree)(ft: FormatToken): Unit = {
val isComment = ft.left.is[Token.Comment]
val nft = if (isComment) ftoks.nextAfterNonComment(ft) else ft
ret += nft.meta.idx -> stmt
}
def addTok(stmt: Tree)(token: Token) = addFT(stmt)(ftoks.after(token))
def addTree(t: Tree, stmt: Tree) = ftoks.getHeadOpt(t).foreach(addFT(stmt))
def addOne(t: Tree) = addTree(t, t)
def addAll(trees: Seq[Tree]) = trees.foreach(addOne)

Expand All @@ -142,10 +146,8 @@ object TreeOps {
case Some(x) => addTree(x, tree)
case _ =>
// No non-annotation modifier exists, fallback to keyword like `object`
tree.tokens.find(isMatch) match {
case Some(x) => addTok(x, tree)
case None => throw Error.CantFindDefnToken(what, tree)
}
tree.tokens.find(isMatch)
.fold(throw Error.CantFindDefnToken(what, tree))(addTok(tree))
}
}
def addDefn[T](mods: Seq[Mod], tree: Tree)(implicit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,3 +253,58 @@ object a {
object a {
childContext.onDone { type a = Int }
}
<<< #4133 lambda body with a comment
rewrite.redundantBraces.maxLines = 100
===
object a {
lowClass.isJavaDefined && highClass.isJavaDefined && { // skip if both are java-defined, and
lowClass.isNonBottomSubClass(highClass) || { // - low <:< high, which means they are overrides in Java and javac is doing the check; or
base.info.parents.tail.forall(p => { // - every mixin parent is unrelated to (not a subclass of) low and high, i.e.,
val psym = p.typeSymbol // we're not mixing in high or low, both are coming from the superclass
!psym.isNonBottomSubClass(lowClass) && !psym.isNonBottomSubClass(highClass)
})
}
}
}
>>>
object a {
lowClass.isJavaDefined && highClass.isJavaDefined && { // skip if both are java-defined, and
lowClass
.isNonBottomSubClass(highClass) || { // - low <:< high, which means they are overrides in Java and javac is doing the check; or
base.info.parents.tail.forall {
p => // - every mixin parent is unrelated to (not a subclass of) low and high, i.e.,
val psym =
p.typeSymbol // we're not mixing in high or low, both are coming from the superclass
!psym.isNonBottomSubClass(lowClass) && !psym.isNonBottomSubClass(
highClass
)
}
}
}
}
<<< #4133 lambda body without a comment
rewrite.redundantBraces.maxLines = 100
===
object a {
lowClass.isJavaDefined && highClass.isJavaDefined && {
lowClass.isNonBottomSubClass(highClass) || {
base.info.parents.tail.forall(p => {
val psym = p.typeSymbol
!psym.isNonBottomSubClass(lowClass) && !psym.isNonBottomSubClass(highClass)
})
}
}
}
>>>
object a {
lowClass.isJavaDefined && highClass.isJavaDefined && {
lowClass.isNonBottomSubClass(highClass) || {
base.info.parents.tail.forall { p =>
val psym = p.typeSymbol
!psym.isNonBottomSubClass(lowClass) && !psym.isNonBottomSubClass(
highClass
)
}
}
}
}
Loading