Skip to content

Commit 88b475b

Browse files
committed
Make mods an extension method
1 parent 5df723f commit 88b475b

File tree

10 files changed

+15
-19
lines changed

10 files changed

+15
-19
lines changed

compiler/src/dotty/tools/dotc/ast/Positioned.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import core.Contexts.Context
88
import core.Decorators._
99
import core.Flags.{JavaDefined, Extension}
1010
import core.StdNames.nme
11+
import ast.Trees.mods
1112
import annotation.constructorOnly
1213
import annotation.internal.sharable
1314
import reporting.Reporter

compiler/src/dotty/tools/dotc/ast/Trees.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,8 @@ object Trees {
333333
def namedType: NamedType = tpe.asInstanceOf[NamedType]
334334
}
335335

336+
def (mdef: untpd.DefTree).mods: untpd.Modifiers = mdef.rawMods
337+
336338
abstract class NamedDefTree[-T >: Untyped](implicit @constructorOnly src: SourceFile) extends NameTree[T] with DefTree[T] {
337339
type ThisTree[-T >: Untyped] <: NamedDefTree[T]
338340

compiler/src/dotty/tools/dotc/ast/untpd.scala

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -510,12 +510,6 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo {
510510

511511
// ----- Accessing modifiers ----------------------------------------------------
512512

513-
abstract class ModsDecorator { def mods: Modifiers }
514-
515-
implicit class modsDeco(val mdef: DefTree)(implicit ctx: Context) {
516-
def mods: Modifiers = mdef.rawMods
517-
}
518-
519513
// --------- Copier/Transformer/Accumulator classes for untyped trees -----
520514

521515
override val cpy: UntypedTreeCopier = UntypedTreeCopier()

compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
279279
}
280280

281281
protected def toTextCore[T >: Untyped](tree: Tree[T]): Text = {
282-
import untpd.{modsDeco => _, _}
282+
import untpd._
283283

284284
def isLocalThis(tree: Tree) = tree.typeOpt match {
285285
case tp: ThisType => tp.cls == ctx.owner.enclosingClass
@@ -647,7 +647,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
647647
}
648648

649649
override def toText[T >: Untyped](tree: Tree[T]): Text = controlled {
650-
import untpd.{modsDeco => _, _}
650+
import untpd._
651651

652652
var txt = toTextCore(tree)
653653

@@ -722,11 +722,9 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
722722
}
723723
}
724724

725-
/** Print modifiers from symbols if tree has type, overriding the untpd behavior. */
726-
private implicit def modsDeco(mdef: untpd.DefTree): untpd.ModsDecorator =
727-
new untpd.ModsDecorator {
728-
def mods = if (mdef.hasType) Modifiers(mdef.symbol) else mdef.rawMods
729-
}
725+
/** Print modifiers from symbols if tree has type, overriding the behavior in Trees. */
726+
def (mdef: untpd.DefTree).mods: untpd.Modifiers =
727+
if mdef.hasType then Modifiers(mdef.symbol) else mdef.rawMods
730728

731729
private def Modifiers(sym: Symbol): Modifiers = untpd.Modifiers(
732730
sym.flags & (if (sym.isType) ModifierFlags | VarianceFlags else ModifierFlags),
@@ -770,7 +768,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
770768
vparamss.foldLeft(leading)((txt, params) => txt ~ paramsText(params))
771769

772770
protected def valDefToText[T >: Untyped](tree: ValDef[T]): Text = {
773-
import untpd.{modsDeco => _}
771+
import untpd._
774772
dclTextOr(tree) {
775773
modText(tree.mods, tree.symbol, keywordStr(if (tree.mods.is(Mutable)) "var" else "val"), isType = false) ~~
776774
valDefText(nameIdText(tree)) ~ optAscription(tree.tpt) ~
@@ -784,7 +782,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
784782
~ toText(params, ", ") ~ ")"
785783

786784
protected def defDefToText[T >: Untyped](tree: DefDef[T]): Text = {
787-
import untpd.{modsDeco => _}
785+
import untpd._
788786
dclTextOr(tree) {
789787
val defKeyword = modText(tree.mods, tree.symbol, keywordStr("def"), isType = false)
790788
val isExtension = tree.hasType && tree.symbol.is(Extension)

compiler/src/dotty/tools/dotc/semanticdb/ExtractSemanticDB.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package semanticdb
55
import core._
66
import Phases._
77
import ast.tpd._
8+
import ast.Trees.mods
89
import Contexts._
910
import Symbols._
1011
import Flags._

compiler/src/dotty/tools/dotc/typer/Checking.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1095,7 +1095,6 @@ trait Checking {
10951095
* 2. Check that case class `enum` cases do not extend java.lang.Enum.
10961096
*/
10971097
def checkEnum(cdef: untpd.TypeDef, cls: Symbol, firstParent: Symbol)(using Context): Unit = {
1098-
import untpd.modsDeco
10991098
def isEnumAnonCls =
11001099
cls.isAnonymousClass &&
11011100
cls.owner.isTerm &&

compiler/src/dotty/tools/dotc/typer/Namer.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -854,7 +854,7 @@ class Namer { typer: Typer =>
854854
protected def addAnnotations(sym: Symbol): Unit = original match {
855855
case original: untpd.MemberDef =>
856856
lazy val annotCtx = annotContext(original, sym)
857-
for (annotTree <- untpd.modsDeco(original).mods.annotations) {
857+
for (annotTree <- original.mods.annotations) {
858858
val cls = typedAheadAnnotationClass(annotTree)(annotCtx)
859859
if (cls eq sym)
860860
ctx.error("An annotation class cannot be annotated with iself", annotTree.sourcePos)

compiler/src/dotty/tools/dotc/typer/Nullables.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import NullOpsDecorator._
1414
import collection.mutable
1515
import config.Printers.nullables
1616
import ast.{tpd, untpd}
17+
import ast.Trees.mods
1718

1819
/** Operations for implementing a flow analysis for nullability */
1920
object Nullables:

compiler/src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1811,7 +1811,7 @@ class Typer extends Namer
18111811
sym.annotations.foreach(_.ensureCompleted)
18121812
lazy val annotCtx = annotContext(mdef, sym)
18131813
// necessary in order to mark the typed ahead annotations as definitely typed:
1814-
for (annot <- untpd.modsDeco(mdef).mods.annotations)
1814+
for (annot <- mdef.mods.annotations)
18151815
checkAnnotApplicable(typedAnnotation(annot)(using annotCtx), sym)
18161816
}
18171817

compiler/test/dotty/tools/dotc/parsing/ModifiersParsingTest.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ package parsing
55
import org.junit.Test
66
import org.junit.Assert._
77

8-
import ast.untpd.modsDeco
8+
import ast.Trees.mods
99
import ast.untpd._
1010
import ast.{ Trees => d }
1111
import Parsers.Parser

0 commit comments

Comments
 (0)