1
1
package org .scalafmt .internal
2
2
3
- import org .scalafmt .config .BinPack
4
- import org .scalafmt .config .IndentOperator
5
- import org .scalafmt .config .Indents
6
- import org .scalafmt .config .Newlines
7
- import org .scalafmt .config .ScalafmtConfig
8
- import org .scalafmt .config .ScalafmtOptimizer
9
- import org .scalafmt .config .TrailingCommas
10
- import org .scalafmt .internal .Policy .NoPolicy
3
+ import org .scalafmt .config ._
11
4
import org .scalafmt .rewrite .RedundantBraces
12
5
import org .scalafmt .util .InfixApp ._
13
6
import org .scalafmt .util ._
@@ -158,10 +151,6 @@ class FormatOps(
158
151
case _ => false
159
152
})
160
153
161
- val StartsStatementRight = new FT .ExtractFromMeta [Tree ](meta =>
162
- optimizationEntities.statementStarts.get(meta.idx + 1 ),
163
- )
164
-
165
154
def parensTuple (ft : FT ): TokenRanges = matchingOptLeft(ft)
166
155
.fold(TokenRanges .empty)(other => TokenRanges (TokenRange (ft, other)))
167
156
def parensTuple (tree : Tree ): TokenRanges = parensTuple(getLast(tree))
@@ -900,7 +889,7 @@ class FormatOps(
900
889
! isAttachedCommentThenBreak(ftd) =>
901
890
d.onlyNewlinesWithoutFallback
902
891
}
903
- case _ => NoPolicy
892
+ case _ => Policy . NoPolicy
904
893
}
905
894
findTemplateGroupOnRight { x =>
906
895
// this method is called on a `with` or comma; hence, it can
@@ -1232,18 +1221,6 @@ class FormatOps(
1232
1221
case _ => Space (spaceOk && style.spaces.inParentheses)
1233
1222
}
1234
1223
1235
- def getNoSplitBeforeClosing (
1236
- ft : FT ,
1237
- commentNL : Modification ,
1238
- spaceOk : Boolean = true ,
1239
- )(implicit style : ScalafmtConfig ): Modification = ft.left match {
1240
- case _ : T .Comment =>
1241
- val isDetachedSlc = ft.hasBreak && prev(ft).hasBreak
1242
- if (isDetachedSlc || ft.leftHasNewline) commentNL else Space
1243
- case _ : T .RightParen if ft.meta.rightOwner eq ft.meta.leftOwner => NoSplit
1244
- case _ => Space (spaceOk && style.spaces.inParentheses)
1245
- }
1246
-
1247
1224
// look for arrow before body, if any, else after params
1248
1225
def getFuncArrow (term : Term .FunctionTerm ): Option [FT ] = tokens
1249
1226
.tokenBeforeOpt(term.body)
@@ -1739,8 +1716,8 @@ class FormatOps(
1739
1716
val semi = nextNonCommentSameLineAfter(nft)
1740
1717
if (semi.noBreak || (semi.left eq x) && ! semi.right.is[T .Comment ])
1741
1718
decideNewlinesOnlyAfterToken(semi)
1742
- else NoPolicy
1743
- case _ => NoPolicy
1719
+ else Policy . NoPolicy
1720
+ case _ => Policy . NoPolicy
1744
1721
})
1745
1722
}
1746
1723
@@ -1768,8 +1745,6 @@ class FormatOps(
1768
1745
getClosingIfBodyEnclosedAsBlock(body).isDefined
1769
1746
1770
1747
object GetSelectLike {
1771
- val OnRight =
1772
- new FT .ExtractFromMeta (m => onRightOpt(m.rightOwner, tokens(m.idx)))
1773
1748
1774
1749
private def get (
1775
1750
ro : Tree ,
@@ -1779,16 +1754,10 @@ class FormatOps(
1779
1754
case _ => None
1780
1755
}
1781
1756
1782
- private [FormatOps ] def onRightOpt (ro : Tree , ft : => FT ): Option [SelectLike ] =
1783
- get(ro)(_ =>
1784
- nextNonCommentAfter(ft) match {
1785
- case xft @ FT (_, _ : T .KwMatch , _) => Some (next(xft))
1786
- case _ => None
1787
- },
1788
- )
1789
-
1790
- def onRightOpt (ft : FT ): Option [SelectLike ] =
1791
- onRightOpt(ft.meta.rightOwner, ft)
1757
+ def onRightOpt (ft : FT ): Option [SelectLike ] = get(ft.rightOwner) { _ =>
1758
+ val nft = nextNonCommentAfter(ft)
1759
+ if (nft.right.is[T .KwMatch ]) Some (next(nft)) else None
1760
+ }
1792
1761
1793
1762
def unapply (tree : Tree ): Option [SelectLike ] =
1794
1763
get(tree)(x => Some (tokenBefore(x.casesBlock)))
@@ -1843,9 +1812,6 @@ class FormatOps(
1843
1812
// Optional braces after any token that can start indentation:
1844
1813
// ) = => ?=> <- catch do else finally for
1845
1814
// if match return then throw try while yield
1846
- def unapply (ftMeta : FT .Meta )(implicit
1847
- style : ScalafmtConfig ,
1848
- ): Option [Seq [Split ]] = get(tokens(ftMeta.idx)).flatMap(_.splits)
1849
1815
1850
1816
def get (
1851
1817
ft : FT ,
@@ -2802,7 +2768,7 @@ class FormatOps(
2802
2768
case Newlines .fold
2803
2769
if shouldDangle && ! style.binPack.indentCallSiteOnce =>
2804
2770
decideNewlinesOnlyBeforeCloseOnBreak(close)
2805
- case _ => NoPolicy
2771
+ case _ => Policy . NoPolicy
2806
2772
}
2807
2773
}
2808
2774
@@ -2890,10 +2856,10 @@ class FormatOps(
2890
2856
exclude : TokenRanges ,
2891
2857
): (Option [FT ], Policy ) = {
2892
2858
val beforeDelims = getBeforeRightDelims(ft)
2893
- if (beforeDelims eq null ) return (None , NoPolicy )
2859
+ if (beforeDelims eq null ) return (None , Policy . NoPolicy )
2894
2860
2895
2861
val afterDelims = getAfterRightDelims(ft)
2896
- if (afterDelims eq null ) return (None , NoPolicy )
2862
+ if (afterDelims eq null ) return (None , Policy . NoPolicy )
2897
2863
2898
2864
def closeBreakPolicy () = {
2899
2865
@ tailrec
@@ -2926,7 +2892,7 @@ class FormatOps(
2926
2892
delayedBreakPolicy(Policy .End >= beforeDelims, exclude)(
2927
2893
Policy .RelayOnSplit { case (s, nextft) =>
2928
2894
s.isNL && nextft.idx > beforeDelims.idx // don't need anymore
2929
- }(policy)(NoPolicy ),
2895
+ }(policy)(Policy . NoPolicy ),
2930
2896
)
2931
2897
2932
2898
(afterDelims.right match {
@@ -2962,7 +2928,7 @@ class FormatOps(
2962
2928
}
2963
2929
case _ => null
2964
2930
}) match {
2965
- case null => (None , NoPolicy )
2931
+ case null => (None , Policy . NoPolicy )
2966
2932
case (nft, policyOrOkToBreak) =>
2967
2933
val policyOpt = policyOrOkToBreak match {
2968
2934
case Left (policy) => Some (policy)
@@ -2980,7 +2946,7 @@ class FormatOps(
2980
2946
if ! nextNonCommentAfter(afterArg).right.is[T .CloseDelim ] =>
2981
2947
(None , splitOneArgPerLineAfterCommaOnBreak(exclude)(next(afterArg)))
2982
2948
case _ : T .CloseDelim if isCallSite => policyOnRightDelim(afterArg, exclude)
2983
- case _ => (None , NoPolicy )
2949
+ case _ => (None , Policy . NoPolicy )
2984
2950
}
2985
2951
}
2986
2952
@@ -3041,21 +3007,6 @@ class FormatOps(
3041
3007
)(implicit style : ScalafmtConfig , ft : FT ): Modification =
3042
3008
getBracesToParensMod(rb, mod, isWithinBraces)._1
3043
3009
3044
- @ tailrec
3045
- private def getSingleFunctionArg (
3046
- values : List [Tree ],
3047
- ): Option [Term .FunctionTerm ] = values match {
3048
- case (t : Term .FunctionTerm ) :: Nil => Some (t)
3049
- case (t : Term .Block ) :: Nil if ! isEnclosedInBraces(t) =>
3050
- getSingleFunctionArg(t.stats)
3051
- case _ => None
3052
- }
3053
-
3054
- val LambdaAtSingleArgCallSite = new FT .ExtractFromMeta (_.leftOwner match {
3055
- case Term .ArgClause (v, None ) => getSingleFunctionArg(v)
3056
- case _ => None
3057
- })
3058
-
3059
3010
}
3060
3011
3061
3012
object FormatOps {
@@ -3149,24 +3100,6 @@ object FormatOps {
3149
3100
def alignOpenDelim (implicit clauseSiteFlags : ClauseSiteFlags ): Boolean =
3150
3101
clauseSiteFlags.alignOpenDelim
3151
3102
3152
- val ImplicitUsingOnLeft =
3153
- new FT .ExtractFromMeta (meta => TreeOps .getImplicitParamList(meta.leftOwner))
3154
-
3155
- val WithTemplateOnLeft = new FT .ExtractFromMeta (_.leftOwner match {
3156
- case lo : Stat .WithTemplate => Some (lo.templ)
3157
- case _ => None
3158
- })
3159
-
3160
- val TemplateOnRight = new FT .ExtractFromMeta (_.rightOwner match {
3161
- case ro : Template => Some (ro)
3162
- case _ => None
3163
- })
3164
-
3165
- val EnumeratorAssignRhsOnLeft = new FT .ExtractFromMeta (_.leftOwner match {
3166
- case x : Enumerator .Assign => Some (x.rhs)
3167
- case _ => None
3168
- })
3169
-
3170
3103
@ tailrec
3171
3104
private def getBlockWithNonSingleTermStat (t : Term .Block ): Option [Term .Block ] =
3172
3105
t.stats match {
0 commit comments