Skip to content

Commit

Permalink
FormatOps: move ExtractFromMeta to companion obj
Browse files Browse the repository at this point in the history
  • Loading branch information
kitbellew committed Jun 18, 2024
1 parent 3a44a87 commit 79bd6e2
Showing 1 changed file with 17 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,6 @@ class FormatOps(
(arguments.toMap, optional.result())
}

class ExtractFromMeta[A](f: FormatToken.Meta => Option[A]) {
def unapply(meta: FormatToken.Meta): Option[A] = f(meta)
}

@inline
final def findFirst(start: FormatToken, end: T)(
f: FormatToken => Boolean,
Expand Down Expand Up @@ -319,16 +315,6 @@ class FormatOps(
if (r.is[T.LeftBrace]) SplitTag.OneArgPerLine.activateOnly(s)
else Decision.onlyNewlineSplits(s)

val WithTemplateOnLeft = new ExtractFromMeta(_.leftOwner match {
case lo: Stat.WithTemplate => Some(lo.templ)
case _ => None
})

val TemplateOnRight = new ExtractFromMeta(_.rightOwner match {
case ro: Template => Some(ro)
case _ => None
})

def templateCurlyFt(template: Template): Option[FormatToken] =
getStartOfTemplateBody(template).map(tokenBefore)

Expand Down Expand Up @@ -862,9 +848,6 @@ class FormatOps(
style.newlines.notBeforeImplicitParamListModifier &&
hasImplicitParamList(formatToken.meta.rightOwner)

val ImplicitUsingOnLeft =
new ExtractFromMeta(meta => getImplicitParamList(meta.leftOwner))

def isSingleIdentifierAnnotation(tok: FormatToken): Boolean = {
val toMatch =
if (tok.right.is[T.RightParen])
Expand Down Expand Up @@ -2876,4 +2859,21 @@ object FormatOps {
)
}

class ExtractFromMeta[A](f: FormatToken.Meta => Option[A]) {
def unapply(meta: FormatToken.Meta): Option[A] = f(meta)
}

val ImplicitUsingOnLeft =
new ExtractFromMeta(meta => TreeOps.getImplicitParamList(meta.leftOwner))

val WithTemplateOnLeft = new ExtractFromMeta(_.leftOwner match {
case lo: Stat.WithTemplate => Some(lo.templ)
case _ => None
})

val TemplateOnRight = new ExtractFromMeta(_.rightOwner match {
case ro: Template => Some(ro)
case _ => None
})

}

0 comments on commit 79bd6e2

Please sign in to comment.