From 2804c6316e9ad822fa7de45009f0fe4aed67ab7d Mon Sep 17 00:00:00 2001 From: Adriaan Moors Date: Tue, 11 Apr 2017 10:57:27 -0700 Subject: Revert some of ade53a123. Use completer factory methods. Scalameta et al need to be able to customize the type completer behavior, so we must use factory methods to instantiate them, rather than instantiating the classes directly. --- .../tools/nsc/typechecker/MethodSynthesis.scala | 14 +++++------ .../scala/tools/nsc/typechecker/Namers.scala | 29 +++++++++++----------- 2 files changed, 22 insertions(+), 21 deletions(-) diff --git a/src/compiler/scala/tools/nsc/typechecker/MethodSynthesis.scala b/src/compiler/scala/tools/nsc/typechecker/MethodSynthesis.scala index 72d186b301..fea9debe7e 100644 --- a/src/compiler/scala/tools/nsc/typechecker/MethodSynthesis.scala +++ b/src/compiler/scala/tools/nsc/typechecker/MethodSynthesis.scala @@ -146,8 +146,8 @@ trait MethodSynthesis { // if there's no field symbol, the ValDef tree receives the getter symbol and thus is not a synthetic if (fieldSym != NoSymbol) { context.unit.synthetics(getterSym) = getter.derivedTree(getterSym) - getterSym setInfo new namer.AccessorTypeCompleter(tree, tree.tpt.isEmpty, isBean = false, isSetter = false) - } else getterSym setInfo new namer.ValTypeCompleter(tree) + getterSym setInfo namer.accessorTypeCompleter(tree, tree.tpt.isEmpty, isBean = false, isSetter = false) + } else getterSym setInfo namer.valTypeCompleter(tree) enterInScope(getterSym) @@ -155,17 +155,17 @@ trait MethodSynthesis { val setter = Setter(tree) val setterSym = setter.createSym context.unit.synthetics(setterSym) = setter.derivedTree(setterSym) - setterSym setInfo new namer.AccessorTypeCompleter(tree, tree.tpt.isEmpty, isBean = false, isSetter = true) + setterSym setInfo namer.accessorTypeCompleter(tree, tree.tpt.isEmpty, isBean = false, isSetter = true) enterInScope(setterSym) } // TODO: delay emitting the field to the fields phase (except for private[this] vals, which only get a field and no accessors) if (fieldSym != NoSymbol) { - fieldSym setInfo new namer.ValTypeCompleter(tree) + fieldSym setInfo namer.valTypeCompleter(tree) enterInScope(fieldSym) } } else { - getterSym setInfo new namer.ValTypeCompleter(tree) + getterSym setInfo namer.valTypeCompleter(tree) enterInScope(getterSym) } @@ -208,11 +208,11 @@ trait MethodSynthesis { sym } - val getterCompleter = new namer.AccessorTypeCompleter(tree, missingTpt, isBean = true, isSetter = false) + val getterCompleter = namer.accessorTypeCompleter(tree, missingTpt, isBean = true, isSetter = false) enterInScope(deriveBeanAccessor(if (hasBeanProperty) "get" else "is") setInfo getterCompleter) if (tree.mods.isMutable) { - val setterCompleter = new namer.AccessorTypeCompleter(tree, missingTpt, isBean = true, isSetter = true) + val setterCompleter = namer.accessorTypeCompleter(tree, missingTpt, isBean = true, isSetter = true) enterInScope(deriveBeanAccessor("set") setInfo setterCompleter) } } diff --git a/src/compiler/scala/tools/nsc/typechecker/Namers.scala b/src/compiler/scala/tools/nsc/typechecker/Namers.scala index fee56cfc13..bbb9d33140 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Namers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Namers.scala @@ -105,7 +105,7 @@ trait Namers extends MethodSynthesis { def enterValueParams(vparamss: List[List[ValDef]]): List[List[Symbol]] = mmap(vparamss) { param => - enterInScope(assignMemberSymbol(param, mask = ValueParameterFlags)) setInfo new MonoTypeCompleter(param) + enterInScope(assignMemberSymbol(param, mask = ValueParameterFlags)) setInfo monoTypeCompleter(param) } protected def owner = context.owner @@ -337,10 +337,8 @@ trait Namers extends MethodSynthesis { } } - def createImportSymbol(tree: Import) = { - val importNamer = namerOf(tree.symbol) - NoSymbol.newImport(tree.pos) setInfo new importNamer.ImportTypeCompleter(tree) - } + def createImportSymbol(tree: Import) = + NoSymbol.newImport(tree.pos) setInfo (namerOf(tree.symbol) importTypeCompleter tree) /** All PackageClassInfoTypes come from here. */ def createPackageSymbol(pos: Position, pid: RefTree): Symbol = { @@ -430,8 +428,7 @@ trait Namers extends MethodSynthesis { def enterModuleDef(tree: ModuleDef) = { val sym = enterModuleSymbol(tree) - val mcsNamer = namerOf(sym) - sym.moduleClass setInfo new mcsNamer.ModuleClassTypeCompleter(tree) + sym.moduleClass setInfo namerOf(sym).moduleClassTypeCompleter(tree) sym setInfo completerOf(tree) validateCompanionDefs(tree) sym @@ -684,8 +681,7 @@ trait Namers extends MethodSynthesis { } def completerOf(tree: MemberDef): TypeCompleter = { - val treeNamer = namerOf(tree.symbol) - val mono = new treeNamer.MonoTypeCompleter(tree) + val mono = namerOf(tree.symbol) monoTypeCompleter tree val tparams = treeInfo.typeParameters(tree) if (tparams.isEmpty) mono else { @@ -1081,7 +1077,7 @@ trait Namers extends MethodSynthesis { val sym = ( if (hasType || hasName) { - owner.typeOfThis = if (hasType) new SelfTypeCompleter(tpt) else owner.tpe_* + owner.typeOfThis = if (hasType) selfTypeCompleter(tpt) else owner.tpe_* val selfSym = owner.thisSym setPos self.pos if (hasName) selfSym setName name else selfSym } @@ -1175,7 +1171,7 @@ trait Namers extends MethodSynthesis { val res = GenPolyType(tparams0, resultType) val pluginsTp = pluginsTypeSig(res, typer, cdef, WildcardType) - // Already assign the type to the class symbol (MonoTypeCompleter will do it again). + // Already assign the type to the class symbol (monoTypeCompleter will do it again). // Allows isDerivedValueClass to look at the info. clazz setInfo pluginsTp if (clazz.isDerivedValueClass) { @@ -1189,7 +1185,7 @@ trait Namers extends MethodSynthesis { private def moduleSig(mdef: ModuleDef): Type = { val moduleSym = mdef.symbol - // The info of both the module and the moduleClass symbols need to be assigned. MonoTypeCompleter assigns + // The info of both the module and the moduleClass symbols need to be assigned. monoTypeCompleter assigns // the result of typeSig to the module symbol. The module class info is assigned here as a side-effect. val result = templateSig(mdef.impl) val pluginsTp = pluginsTypeSig(result, typer, mdef, WildcardType) @@ -1589,7 +1585,7 @@ trait Namers extends MethodSynthesis { // (a val's name ends in a " ", so can't compare to def) val overridingSym = if (isGetter) vdef.symbol else vdef.symbol.getterIn(valOwner) - // We're called from an AccessorTypeCompleter, which is completing the info for the accessor's symbol, + // We're called from an accessorTypeCompleter, which is completing the info for the accessor's symbol, // which may or may not be `vdef.symbol` (see isGetter above) val overridden = safeNextOverriddenSymbol(overridingSym) @@ -1732,7 +1728,7 @@ trait Namers extends MethodSynthesis { } /** - * TypeSig is invoked by MonoTypeCompleters. It returns the type of a definition which + * TypeSig is invoked by monoTypeCompleters. It returns the type of a definition which * is then assigned to the corresponding symbol (typeSig itself does not need to assign * the type to the symbol, but it can if necessary). */ @@ -1923,6 +1919,11 @@ trait Namers extends MethodSynthesis { } } + @deprecated("Instantiate TypeCompleterBase (for monomorphic, non-wrapping completer) or CompleterWrapper directly.", "2.12.2") + def mkTypeCompleter(t: Tree)(c: Symbol => Unit) = new TypeCompleterBase(t) { + def completeImpl(sym: Symbol) = c(sym) + } + // NOTE: only meant for monomorphic definitions, // do not use to wrap existing completers (see CompleterWrapper for that) abstract class TypeCompleterBase[T <: Tree](val tree: T) extends LockingTypeCompleter with FlagAgnosticCompleter -- cgit v1.2.3