diff options
author | Eugene Burmako <xeno.by@gmail.com> | 2014-02-15 12:41:23 +0100 |
---|---|---|
committer | Eugene Burmako <xeno.by@gmail.com> | 2014-02-15 12:41:23 +0100 |
commit | 2fb6a1e240f7892e73979150fb323cd03de637e0 (patch) | |
tree | bb6ce4a577c0d548960fdbcd52b31d49e4e8b5c1 /src/reflect | |
parent | 8801d2937c45681bd58252ce3390a80754da6d6b (diff) | |
download | scala-2fb6a1e240f7892e73979150fb323cd03de637e0.tar.gz scala-2fb6a1e240f7892e73979150fb323cd03de637e0.tar.bz2 scala-2fb6a1e240f7892e73979150fb323cd03de637e0.zip |
fixes compat for tree and type extractors
When I removed XXXDef(...) and XXXType(...) methods from the public API,
I put compatibility stubs in compat via implicit classes enriching
XXXExtractor traits with apply methods.
Unfortunately, this doesn't work, because if XXXDef or XXXType have
any kind of an apply method left in the public API, then implicit classes
won't even be considered when resolving calls to XXXDef(...) or XXXType(...).
Therefore I had to put those removed methods back and adorn them with an
implicit parameter that can only be resolved when "import compat._"
is in place. Quite extravagant, yes, but goes along the lines with the
design goals of the refactoring, which are:
1) Break source compatibility for users who are using methods that are
now moved to internal in order to attract attention.
2) Provide an easy way to fix the breakage by importing compat._, which
will pimp back all the missing APIs with deprecation warnings that are
going to guide migration.
Diffstat (limited to 'src/reflect')
-rw-r--r-- | src/reflect/scala/reflect/api/Internals.scala | 174 | ||||
-rw-r--r-- | src/reflect/scala/reflect/api/Trees.scala | 48 | ||||
-rw-r--r-- | src/reflect/scala/reflect/api/Types.scala | 56 | ||||
-rw-r--r-- | src/reflect/scala/reflect/internal/Trees.scala | 110 |
4 files changed, 169 insertions, 219 deletions
diff --git a/src/reflect/scala/reflect/api/Internals.scala b/src/reflect/scala/reflect/api/Internals.scala index 41ded97487..c2f7f411b9 100644 --- a/src/reflect/scala/reflect/api/Internals.scala +++ b/src/reflect/scala/reflect/api/Internals.scala @@ -995,10 +995,20 @@ trait Internals { self: Universe => */ type Compat <: CompatApi + /** Presence of an implicit value of this type in scope + * indicates that source compatibility with Scala 2.10 has been enabled. + * @group Internal + */ + @scala.annotation.implicitNotFound("This method has been removed from the public API. Import compat._ or migrate away.") + class CompatToken + /** @see [[compat]] * @group Internal */ trait CompatApi { + /** @see [[CompatToken]] */ + implicit val token = new CompatToken + /** @see [[InternalApi.typeTagToManifest]] */ @deprecated("Use `internal.typeTagToManifest` instead", "2.11.0") def typeTagToManifest[T: ClassTag](mirror: Any, tag: Universe#TypeTag[T]): Manifest[T] = @@ -1037,72 +1047,6 @@ trait Internals { self: Universe => def substituteThis(clazz: Symbol, to: Tree): Tree = internal.substituteThis(tree, clazz, to) } - /** Scala 2.10 compatibility enrichments for ClassDef. */ - implicit class CompatibleClassDefExtractor(dex: ClassDefExtractor) { - /** @see [[InternalApi.classDef]] */ - @deprecated("Use `internal.classDef` instead", "2.11.0") - def apply(sym: Symbol, impl: Template): ClassDef = internal.classDef(sym, impl) - } - - /** Scala 2.10 compatibility enrichments for ModuleDef. */ - implicit class CompatibleModuleDefExtractor(dex: ModuleDefExtractor) { - /** @see [[InternalApi.moduleDef]] */ - @deprecated("Use `internal.moduleDef` instead", "2.11.0") - def apply(sym: Symbol, impl: Template): ModuleDef = internal.moduleDef(sym, impl) - } - - /** Scala 2.10 compatibility enrichments for ValDef. */ - implicit class CompatibleValDefExtractor(dex: ValDefExtractor) { - /** @see [[InternalApi.valDef]] */ - @deprecated("Use `internal.valDef` instead", "2.11.0") - def apply(sym: Symbol, rhs: Tree): ValDef = internal.valDef(sym, rhs) - - /** @see [[InternalApi.valDef]] */ - @deprecated("Use `internal.valDef` instead", "2.11.0") - def apply(sym: Symbol): ValDef = internal.valDef(sym) - } - - /** Scala 2.10 compatibility enrichments for ValDef. */ - implicit class CompatibleDefDefExtractor(dex: DefDefExtractor) { - /** @see [[InternalApi.defDef]] */ - @deprecated("Use `internal.defDef` instead", "2.11.0") - def apply(sym: Symbol, mods: Modifiers, vparamss: List[List[ValDef]], rhs: Tree): DefDef = internal.defDef(sym, mods, vparamss, rhs) - - /** @see [[InternalApi.defDef]] */ - @deprecated("Use `internal.defDef` instead", "2.11.0") - def apply(sym: Symbol, vparamss: List[List[ValDef]], rhs: Tree): DefDef = internal.defDef(sym, vparamss, rhs) - - /** @see [[InternalApi.defDef]] */ - @deprecated("Use `internal.defDef` instead", "2.11.0") - def apply(sym: Symbol, mods: Modifiers, rhs: Tree): DefDef = internal.defDef(sym, mods, rhs) - - /** @see [[InternalApi.defDef]] */ - @deprecated("Use `internal.defDef` instead", "2.11.0") - def apply(sym: Symbol, rhs: Tree): DefDef = internal.defDef(sym, rhs) - - /** @see [[InternalApi.defDef]] */ - @deprecated("Use `internal.defDef` instead", "2.11.0") - def apply(sym: Symbol, rhs: List[List[Symbol]] => Tree): DefDef = internal.defDef(sym, rhs) - } - - /** Scala 2.10 compatibility enrichments for TypeDef. */ - implicit class CompatibleTypeDefExtractor(dex: TypeDefExtractor) { - /** @see [[InternalApi.typeDef]] */ - @deprecated("Use `internal.typeDef` instead", "2.11.0") - def apply(sym: Symbol, rhs: Tree): TypeDef = internal.typeDef(sym, rhs) - - /** @see [[InternalApi.typeDef]] */ - @deprecated("Use `internal.typeDef` instead", "2.11.0") - def apply(sym: Symbol): TypeDef = internal.typeDef(sym) - } - - /** Scala 2.10 compatibility enrichments for LabelDef. */ - implicit class CompatibleLabelDefExtractor(dex: LabelDefExtractor) { - /** @see [[InternalApi.labelDef]] */ - @deprecated("Use `internal.labelDef` instead", "2.11.0") - def apply(sym: Symbol, params: List[Symbol], rhs: Tree): LabelDef = internal.labelDef(sym, params, rhs) - } - /** Scala 2.10 compatibility enrichments for Tree. */ implicit class CompatibleSymbol(symbol: Symbol) { @deprecated("This API is unreliable. Use `isPrivateThis` or `isProtectedThis` instead", "2.11.0") @@ -1159,103 +1103,5 @@ trait Internals { self: Universe => @deprecated("Use `internal.deSkolemize` instead", "2.11.0") def deSkolemize: Symbol = internal.deSkolemize(symbol) } - - /** Scala 2.10 compatibility enrichments for ThisType. */ - implicit class CompatibleThisType(tex: ThisTypeExtractor) { - /** @see [[InternalApi.thisType]] */ - @deprecated("Use `internal.thisType` instead") - def apply(sym: Symbol): Type = internal.thisType(sym) - } - - /** Scala 2.10 compatibility enrichments for SingleType. */ - implicit class CompatibleSingleType(tex: SingleTypeExtractor) { - /** @see [[InternalApi.singleType]] */ - @deprecated("Use `ClassSymbol.thisPrefix` or `internal.singleType` instead") - def apply(pre: Type, sym: Symbol): Type = internal.singleType(pre, sym) - } - - /** Scala 2.10 compatibility enrichments for SuperType. */ - implicit class CompatibleSuperType(tex: SuperTypeExtractor) { - /** @see [[InternalApi.superType]] */ - @deprecated("Use `ClassSymbol.superPrefix` or `internal.superType` instead") - def apply(thistpe: Type, supertpe: Type): Type = internal.superType(thistpe, supertpe) - } - - /** Scala 2.10 compatibility enrichments for ConstantType. */ - implicit class CompatibleConstantType(tex: ConstantTypeExtractor) { - /** @see [[InternalApi.constantType]] */ - @deprecated("Use `value.tpe` or `internal.constantType` instead") - def apply(value: Constant): ConstantType = internal.constantType(value) - } - - /** Scala 2.10 compatibility enrichments for TypeRef. */ - implicit class CompatibleTypeRef(tex: TypeRefExtractor) { - /** @see [[InternalApi.typeRef]] */ - @deprecated("Use `internal.typeRef` instead") - def apply(pre: Type, sym: Symbol, args: List[Type]): Type = internal.typeRef(pre, sym, args) - } - - /** Scala 2.10 compatibility enrichments for RefinedType. */ - implicit class CompatibleRefinedType(tex: RefinedTypeExtractor) { - /** @see [[InternalApi.refinedType]] */ - @deprecated("Use `internal.refinedType` instead") - def apply(parents: List[Type], decls: Scope): RefinedType = internal.refinedType(parents, decls) - } - - /** Scala 2.10 compatibility enrichments for ClassInfoType. */ - implicit class CompatibleClassInfoType(tex: ClassInfoTypeExtractor) { - /** @see [[InternalApi.classInfoType]] */ - @deprecated("Use `internal.classInfoType` instead") - def apply(parents: List[Type], decls: Scope, typeSymbol: Symbol): ClassInfoType = internal.classInfoType(parents, decls, typeSymbol) - } - - /** Scala 2.10 compatibility enrichments for MethodType. */ - implicit class CompatibleMethodType(tex: MethodTypeExtractor) { - /** @see [[InternalApi.methodType]] */ - @deprecated("Use `internal.methodType` instead") - def apply(params: List[Symbol], resultType: Type): MethodType = internal.methodType(params, resultType) - } - - /** Scala 2.10 compatibility enrichments for NullaryMethodType. */ - implicit class CompatibleNullaryMethodType(tex: NullaryMethodTypeExtractor) { - /** @see [[InternalApi.nullaryMethodType]] */ - @deprecated("Use `internal.nullaryMethodType` instead") - def apply(resultType: Type): NullaryMethodType = internal.nullaryMethodType(resultType) - } - - /** Scala 2.10 compatibility enrichments for PolyType. */ - implicit class CompatiblePolyType(tex: PolyTypeExtractor) { - /** @see [[InternalApi.polyType]] */ - @deprecated("Use `internal.polyType` instead") - def apply(typeParams: List[Symbol], resultType: Type): PolyType = internal.polyType(typeParams, resultType) - } - - /** Scala 2.10 compatibility enrichments for ExistentialType. */ - implicit class CompatibleExistentialType(tex: ExistentialTypeExtractor) { - /** @see [[InternalApi.existentialType]] */ - @deprecated("Use `internal.existentialType` instead") - def apply(quantified: List[Symbol], underlying: Type): ExistentialType = internal.existentialType(quantified, underlying) - } - - /** Scala 2.10 compatibility enrichments for AnnotatedType. */ - implicit class CompatibleAnnotatedType(tex: AnnotatedTypeExtractor) { - /** @see [[InternalApi.annotatedType]] */ - @deprecated("Use `internal.annotatedType` instead") - def apply(annotations: List[Annotation], underlying: Type): AnnotatedType = internal.annotatedType(annotations, underlying) - } - - /** Scala 2.10 compatibility enrichments for TypeBounds. */ - implicit class CompatibleTypeBounds(tex: TypeBoundsExtractor) { - /** @see [[InternalApi.typeBounds]] */ - @deprecated("Use `internal.typeBounds` instead") - def apply(lo: Type, hi: Type): TypeBounds = internal.typeBounds(lo, hi) - } - - /** Scala 2.10 compatibility enrichments for BoundedWildcardType. */ - implicit class CompatibleBoundedWildcardType(tex: BoundedWildcardTypeExtractor) { - /** @see [[InternalApi.boundedWildcardType]] */ - @deprecated("Use `internal.boundedWildcardType` instead") - def apply(bounds: TypeBounds): BoundedWildcardType = internal.boundedWildcardType(bounds) - } } } diff --git a/src/reflect/scala/reflect/api/Trees.scala b/src/reflect/scala/reflect/api/Trees.scala index a42f6ab728..ff8926651b 100644 --- a/src/reflect/scala/reflect/api/Trees.scala +++ b/src/reflect/scala/reflect/api/Trees.scala @@ -386,6 +386,10 @@ trait Trees { self: Universe => abstract class ClassDefExtractor { def apply(mods: Modifiers, name: TypeName, tparams: List[TypeDef], impl: Template): ClassDef def unapply(classDef: ClassDef): Option[(Modifiers, TypeName, List[TypeDef], Template)] + + /** @see [[InternalApi.classDef]] */ + @deprecated("Use `internal.classDef` instead", "2.11.0") + def apply(sym: Symbol, impl: Template)(implicit token: CompatToken): ClassDef = internal.classDef(sym, impl) } /** The API that all class defs support @@ -431,6 +435,10 @@ trait Trees { self: Universe => abstract class ModuleDefExtractor { def apply(mods: Modifiers, name: TermName, impl: Template): ModuleDef def unapply(moduleDef: ModuleDef): Option[(Modifiers, TermName, Template)] + + /** @see [[InternalApi.moduleDef]] */ + @deprecated("Use `internal.moduleDef` instead", "2.11.0") + def apply(sym: Symbol, impl: Template)(implicit token: CompatToken): ModuleDef = internal.moduleDef(sym, impl) } /** The API that all module defs support @@ -507,6 +515,14 @@ trait Trees { self: Universe => abstract class ValDefExtractor { def apply(mods: Modifiers, name: TermName, tpt: Tree, rhs: Tree): ValDef def unapply(valDef: ValDef): Option[(Modifiers, TermName, Tree, Tree)] + + /** @see [[InternalApi.valDef]] */ + @deprecated("Use `internal.valDef` instead", "2.11.0") + def apply(sym: Symbol, rhs: Tree)(implicit token: CompatToken): ValDef = internal.valDef(sym, rhs) + + /** @see [[InternalApi.valDef]] */ + @deprecated("Use `internal.valDef` instead", "2.11.0") + def apply(sym: Symbol)(implicit token: CompatToken): ValDef = internal.valDef(sym) } /** The API that all val defs support @@ -550,6 +566,26 @@ trait Trees { self: Universe => abstract class DefDefExtractor { def apply(mods: Modifiers, name: TermName, tparams: List[TypeDef], vparamss: List[List[ValDef]], tpt: Tree, rhs: Tree): DefDef def unapply(defDef: DefDef): Option[(Modifiers, TermName, List[TypeDef], List[List[ValDef]], Tree, Tree)] + + /** @see [[InternalApi.defDef]] */ + @deprecated("Use `internal.defDef` instead", "2.11.0") + def apply(sym: Symbol, mods: Modifiers, vparamss: List[List[ValDef]], rhs: Tree)(implicit token: CompatToken): DefDef = internal.defDef(sym, mods, vparamss, rhs) + + /** @see [[InternalApi.defDef]] */ + @deprecated("Use `internal.defDef` instead", "2.11.0") + def apply(sym: Symbol, vparamss: List[List[ValDef]], rhs: Tree)(implicit token: CompatToken): DefDef = internal.defDef(sym, vparamss, rhs) + + /** @see [[InternalApi.defDef]] */ + @deprecated("Use `internal.defDef` instead", "2.11.0") + def apply(sym: Symbol, mods: Modifiers, rhs: Tree)(implicit token: CompatToken): DefDef = internal.defDef(sym, mods, rhs) + + /** @see [[InternalApi.defDef]] */ + @deprecated("Use `internal.defDef` instead", "2.11.0") + def apply(sym: Symbol, rhs: Tree)(implicit token: CompatToken): DefDef = internal.defDef(sym, rhs) + + /** @see [[InternalApi.defDef]] */ + @deprecated("Use `internal.defDef` instead", "2.11.0") + def apply(sym: Symbol, rhs: List[List[Symbol]] => Tree)(implicit token: CompatToken): DefDef = internal.defDef(sym, rhs) } /** The API that all def defs support @@ -602,6 +638,14 @@ trait Trees { self: Universe => abstract class TypeDefExtractor { def apply(mods: Modifiers, name: TypeName, tparams: List[TypeDef], rhs: Tree): TypeDef def unapply(typeDef: TypeDef): Option[(Modifiers, TypeName, List[TypeDef], Tree)] + + /** @see [[InternalApi.typeDef]] */ + @deprecated("Use `internal.typeDef` instead", "2.11.0") + def apply(sym: Symbol, rhs: Tree)(implicit token: CompatToken): TypeDef = internal.typeDef(sym, rhs) + + /** @see [[InternalApi.typeDef]] */ + @deprecated("Use `internal.typeDef` instead", "2.11.0") + def apply(sym: Symbol)(implicit token: CompatToken): TypeDef = internal.typeDef(sym) } /** The API that all type defs support @@ -662,6 +706,10 @@ trait Trees { self: Universe => abstract class LabelDefExtractor { def apply(name: TermName, params: List[Ident], rhs: Tree): LabelDef def unapply(labelDef: LabelDef): Option[(TermName, List[Ident], Tree)] + + /** @see [[InternalApi.labelDef]] */ + @deprecated("Use `internal.labelDef` instead", "2.11.0") + def apply(sym: Symbol, params: List[Symbol], rhs: Tree)(implicit token: CompatToken): LabelDef = internal.labelDef(sym, params, rhs) } /** The API that all label defs support diff --git a/src/reflect/scala/reflect/api/Types.scala b/src/reflect/scala/reflect/api/Types.scala index d41b6724e6..cb83b73f3d 100644 --- a/src/reflect/scala/reflect/api/Types.scala +++ b/src/reflect/scala/reflect/api/Types.scala @@ -428,6 +428,10 @@ trait Types { */ abstract class ThisTypeExtractor { def unapply(tpe: ThisType): Option[Symbol] + + /** @see [[InternalApi.thisType]] */ + @deprecated("Use `internal.thisType` instead", "2.11.0") + def apply(sym: Symbol)(implicit token: CompatToken): Type = internal.thisType(sym) } /** The API that all this types support. @@ -463,6 +467,10 @@ trait Types { */ abstract class SingleTypeExtractor { def unapply(tpe: SingleType): Option[(Type, Symbol)] + + /** @see [[InternalApi.singleType]] */ + @deprecated("Use `ClassSymbol.thisPrefix` or `internal.singleType` instead") + def apply(pre: Type, sym: Symbol)(implicit token: CompatToken): Type = internal.singleType(pre, sym) } /** The API that all single types support. @@ -499,6 +507,10 @@ trait Types { */ abstract class SuperTypeExtractor { def unapply(tpe: SuperType): Option[(Type, Type)] + + /** @see [[InternalApi.superType]] */ + @deprecated("Use `ClassSymbol.superPrefix` or `internal.superType` instead", "2.11.0") + def apply(thistpe: Type, supertpe: Type)(implicit token: CompatToken): Type = internal.superType(thistpe, supertpe) } /** The API that all super types support. @@ -538,6 +550,10 @@ trait Types { */ abstract class ConstantTypeExtractor { def unapply(tpe: ConstantType): Option[Constant] + + /** @see [[InternalApi.constantType]] */ + @deprecated("Use `value.tpe` or `internal.constantType` instead", "2.11.0") + def apply(value: Constant)(implicit token: CompatToken): ConstantType = internal.constantType(value) } /** The API that all constant types support. @@ -577,6 +593,10 @@ trait Types { */ abstract class TypeRefExtractor { def unapply(tpe: TypeRef): Option[(Type, Symbol, List[Type])] + + /** @see [[InternalApi.typeRef]] */ + @deprecated("Use `internal.typeRef` instead", "2.11.0") + def apply(pre: Type, sym: Symbol, args: List[Type])(implicit token: CompatToken): Type = internal.typeRef(pre, sym, args) } /** The API that all type refs support. @@ -633,6 +653,10 @@ trait Types { */ abstract class RefinedTypeExtractor { def unapply(tpe: RefinedType): Option[(List[Type], Scope)] + + /** @see [[InternalApi.refinedType]] */ + @deprecated("Use `internal.refinedType` instead", "2.11.0") + def apply(parents: List[Type], decls: Scope)(implicit token: CompatToken): RefinedType = internal.refinedType(parents, decls) } /** The API that all refined types support. @@ -674,6 +698,10 @@ trait Types { */ abstract class ClassInfoTypeExtractor { def unapply(tpe: ClassInfoType): Option[(List[Type], Scope, Symbol)] + + /** @see [[InternalApi.classInfoType]] */ + @deprecated("Use `internal.classInfoType` instead", "2.11.0") + def apply(parents: List[Type], decls: Scope, typeSymbol: Symbol)(implicit token: CompatToken): ClassInfoType = internal.classInfoType(parents, decls, typeSymbol) } /** The API that all class info types support. @@ -719,6 +747,10 @@ trait Types { */ abstract class MethodTypeExtractor { def unapply(tpe: MethodType): Option[(List[Symbol], Type)] + + /** @see [[InternalApi.methodType]] */ + @deprecated("Use `internal.methodType` instead", "2.11.0") + def apply(params: List[Symbol], resultType: Type)(implicit token: CompatToken): MethodType = internal.methodType(params, resultType) } /** The API that all method types support. @@ -751,6 +783,10 @@ trait Types { */ abstract class NullaryMethodTypeExtractor { def unapply(tpe: NullaryMethodType): Option[(Type)] + + /** @see [[InternalApi.nullaryMethodType]] */ + @deprecated("Use `internal.nullaryMethodType` instead", "2.11.0") + def apply(resultType: Type)(implicit token: CompatToken): NullaryMethodType = internal.nullaryMethodType(resultType) } /** The API that all nullary method types support. @@ -781,6 +817,10 @@ trait Types { */ abstract class PolyTypeExtractor { def unapply(tpe: PolyType): Option[(List[Symbol], Type)] + + /** @see [[InternalApi.polyType]] */ + @deprecated("Use `internal.polyType` instead", "2.11.0") + def apply(typeParams: List[Symbol], resultType: Type)(implicit token: CompatToken): PolyType = internal.polyType(typeParams, resultType) } /** The API that all polymorphic types support. @@ -815,6 +855,10 @@ trait Types { */ abstract class ExistentialTypeExtractor { def unapply(tpe: ExistentialType): Option[(List[Symbol], Type)] + + /** @see [[InternalApi.existentialType]] */ + @deprecated("Use `internal.existentialType` instead", "2.11.0") + def apply(quantified: List[Symbol], underlying: Type)(implicit token: CompatToken): ExistentialType = internal.existentialType(quantified, underlying) } /** The API that all existential types support. @@ -849,6 +893,10 @@ trait Types { */ abstract class AnnotatedTypeExtractor { def unapply(tpe: AnnotatedType): Option[(List[Annotation], Type)] + + /** @see [[InternalApi.annotatedType]] */ + @deprecated("Use `internal.annotatedType` instead", "2.11.0") + def apply(annotations: List[Annotation], underlying: Type)(implicit token: CompatToken): AnnotatedType = internal.annotatedType(annotations, underlying) } /** The API that all annotated types support. @@ -889,6 +937,10 @@ trait Types { */ abstract class TypeBoundsExtractor { def unapply(tpe: TypeBounds): Option[(Type, Type)] + + /** @see [[InternalApi.typeBounds]] */ + @deprecated("Use `internal.typeBounds` instead", "2.11.0") + def apply(lo: Type, hi: Type)(implicit token: CompatToken): TypeBounds = internal.typeBounds(lo, hi) } /** The API that all type bounds support. @@ -938,6 +990,10 @@ trait Types { */ abstract class BoundedWildcardTypeExtractor { def unapply(tpe: BoundedWildcardType): Option[TypeBounds] + + /** @see [[InternalApi.boundedWildcardType]] */ + @deprecated("Use `internal.boundedWildcardType` instead", "2.11.0") + def apply(bounds: TypeBounds)(implicit token: CompatToken): BoundedWildcardType = internal.boundedWildcardType(bounds) } /** The API that all this types support. diff --git a/src/reflect/scala/reflect/internal/Trees.scala b/src/reflect/scala/reflect/internal/Trees.scala index 42952e5d80..5b4b7fd2a4 100644 --- a/src/reflect/scala/reflect/internal/Trees.scala +++ b/src/reflect/scala/reflect/internal/Trees.scala @@ -296,11 +296,39 @@ trait Trees extends api.Trees { case class ClassDef(mods: Modifiers, name: TypeName, tparams: List[TypeDef], impl: Template) extends ImplDef with ClassDefApi - object ClassDef extends ClassDefExtractor + object ClassDef extends ClassDefExtractor { + /** @param sym the class symbol + * @param impl the implementation template + * @return the class definition + */ + def apply(sym: Symbol, impl: Template): ClassDef = + atPos(sym.pos) { + ClassDef(Modifiers(sym.flags), + sym.name.toTypeName, + sym.typeParams map TypeDef.apply, + impl) setSymbol sym + } + + /** @param sym the class symbol + * @param body trees that constitute the body of the class + * @return the class definition + */ + def apply(sym: Symbol, body: List[Tree]): ClassDef = + ClassDef(sym, Template(sym, body)) + } case class ModuleDef(mods: Modifiers, name: TermName, impl: Template) extends ImplDef with ModuleDefApi - object ModuleDef extends ModuleDefExtractor + object ModuleDef extends ModuleDefExtractor { + /** + * @param sym the class symbol + * @param impl the implementation template + */ + def apply(sym: Symbol, impl: Template): ModuleDef = + atPos(sym.pos) { + ModuleDef(Modifiers(sym.flags), sym.name.toTermName, impl) setSymbol sym + } + } abstract class ValOrDefDef extends MemberDef with ValOrDefDefApi { def name: TermName @@ -317,19 +345,37 @@ trait Trees extends api.Trees { } case class ValDef(mods: Modifiers, name: TermName, tpt: Tree, rhs: Tree) extends ValOrDefDef with ValDefApi - object ValDef extends ValDefExtractor + object ValDef extends ValDefExtractor { + def apply(sym: Symbol): ValDef = newValDef(sym, EmptyTree)() + def apply(sym: Symbol, rhs: Tree): ValDef = newValDef(sym, rhs)() + } case class DefDef(mods: Modifiers, name: TermName, tparams: List[TypeDef], vparamss: List[List[ValDef]], tpt: Tree, rhs: Tree) extends ValOrDefDef with DefDefApi - object DefDef extends DefDefExtractor + object DefDef extends DefDefExtractor { + def apply(sym: Symbol, rhs: Tree): DefDef = newDefDef(sym, rhs)() + def apply(sym: Symbol, vparamss: List[List[ValDef]], rhs: Tree): DefDef = newDefDef(sym, rhs)(vparamss = vparamss) + def apply(sym: Symbol, mods: Modifiers, rhs: Tree): DefDef = newDefDef(sym, rhs)(mods = mods) + def apply(sym: Symbol, mods: Modifiers, vparamss: List[List[ValDef]], rhs: Tree): DefDef = newDefDef(sym, rhs)(mods = mods, vparamss = vparamss) + def apply(sym: Symbol, rhs: List[List[Symbol]] => Tree): DefDef = newDefDef(sym, rhs(sym.info.paramss))() + } case class TypeDef(mods: Modifiers, name: TypeName, tparams: List[TypeDef], rhs: Tree) extends MemberDef with TypeDefApi - object TypeDef extends TypeDefExtractor + object TypeDef extends TypeDefExtractor { + /** A TypeDef node which defines abstract type or type parameter for given `sym` */ + def apply(sym: Symbol): TypeDef = newTypeDef(sym, TypeBoundsTree(sym))() + def apply(sym: Symbol, rhs: Tree): TypeDef = newTypeDef(sym, rhs)() + } case class LabelDef(name: TermName, params: List[Ident], rhs: Tree) extends DefTree with TermTree with LabelDefApi - object LabelDef extends LabelDefExtractor + object LabelDef extends LabelDefExtractor { + def apply(sym: Symbol, params: List[Symbol], rhs: Tree): LabelDef = + atPos(sym.pos) { + LabelDef(sym.name.toTermName, params map Ident, rhs) setSymbol sym + } + } case class ImportSelector(name: Name, namePos: Int, rename: Name, renamePos: Int) extends ImportSelectorApi object ImportSelector extends ImportSelectorExtractor { @@ -1007,25 +1053,6 @@ trait Trees extends api.Trees { // ---- values and creators --------------------------------------- - /** @param sym the class symbol - * @param impl the implementation template - * @return the class definition - */ - def ClassDef(sym: Symbol, impl: Template): ClassDef = - atPos(sym.pos) { - ClassDef(Modifiers(sym.flags), - sym.name.toTypeName, - sym.typeParams map TypeDef, - impl) setSymbol sym - } - - /** @param sym the class symbol - * @param body trees that constitute the body of the class - * @return the class definition - */ - def ClassDef(sym: Symbol, body: List[Tree]): ClassDef = - ClassDef(sym, Template(sym, body)) - /** @param sym the template's symbol * @param body trees that constitute the body of the template * @return the template @@ -1038,15 +1065,6 @@ trait Trees extends api.Trees { } } - /** - * @param sym the class symbol - * @param impl the implementation template - */ - def ModuleDef(sym: Symbol, impl: Template): ModuleDef = - atPos(sym.pos) { - ModuleDef(Modifiers(sym.flags), sym.name.toTermName, impl) setSymbol sym - } - trait CannotHaveAttrs extends Tree { super.setPos(NoPosition) super.setType(NoType) @@ -1083,8 +1101,8 @@ trait Trees extends api.Trees { def newDefDef(sym: Symbol, rhs: Tree)( mods: Modifiers = Modifiers(sym.flags), name: TermName = sym.name.toTermName, - tparams: List[TypeDef] = sym.typeParams map TypeDef, - vparamss: List[List[ValDef]] = mapParamss(sym)(ValDef), + tparams: List[TypeDef] = sym.typeParams map TypeDef.apply, + vparamss: List[List[ValDef]] = mapParamss(sym)(ValDef.apply), tpt: Tree = TypeTreeMemberType(sym) ): DefDef = ( atPos(sym.pos)(DefDef(mods, name, tparams, vparamss, tpt, rhs)) setSymbol sym @@ -1093,29 +1111,11 @@ trait Trees extends api.Trees { def newTypeDef(sym: Symbol, rhs: Tree)( mods: Modifiers = Modifiers(sym.flags), name: TypeName = sym.name.toTypeName, - tparams: List[TypeDef] = sym.typeParams map TypeDef + tparams: List[TypeDef] = sym.typeParams map TypeDef.apply ): TypeDef = ( atPos(sym.pos)(TypeDef(mods, name, tparams, rhs)) setSymbol sym ) - def DefDef(sym: Symbol, rhs: Tree): DefDef = newDefDef(sym, rhs)() - def DefDef(sym: Symbol, vparamss: List[List[ValDef]], rhs: Tree): DefDef = newDefDef(sym, rhs)(vparamss = vparamss) - def DefDef(sym: Symbol, mods: Modifiers, rhs: Tree): DefDef = newDefDef(sym, rhs)(mods = mods) - def DefDef(sym: Symbol, mods: Modifiers, vparamss: List[List[ValDef]], rhs: Tree): DefDef = newDefDef(sym, rhs)(mods = mods, vparamss = vparamss) - def DefDef(sym: Symbol, rhs: List[List[Symbol]] => Tree): DefDef = newDefDef(sym, rhs(sym.info.paramss))() - - def ValDef(sym: Symbol): ValDef = newValDef(sym, EmptyTree)() - def ValDef(sym: Symbol, rhs: Tree): ValDef = newValDef(sym, rhs)() - - /** A TypeDef node which defines abstract type or type parameter for given `sym` */ - def TypeDef(sym: Symbol): TypeDef = newTypeDef(sym, TypeBoundsTree(sym))() - def TypeDef(sym: Symbol, rhs: Tree): TypeDef = newTypeDef(sym, rhs)() - - def LabelDef(sym: Symbol, params: List[Symbol], rhs: Tree): LabelDef = - atPos(sym.pos) { - LabelDef(sym.name.toTermName, params map Ident, rhs) setSymbol sym - } - /** casedef shorthand */ def CaseDef(pat: Tree, body: Tree): CaseDef = CaseDef(pat, EmptyTree, body) |