summaryrefslogtreecommitdiff
path: root/src/reflect
diff options
context:
space:
mode:
authorDen Shabalin <den.shabalin@gmail.com>2013-10-31 11:47:51 +0100
committerDen Shabalin <den.shabalin@gmail.com>2013-11-12 14:04:42 +0100
commitc6fe22f5479458a688a819f92f2af43c5867ea81 (patch)
treecf51804be7b997336d2b2e4f93a082500f1bbaa2 /src/reflect
parentee1e81aa39ccbb44a4176eaf0dde5bc2e2ad5ddd (diff)
downloadscala-c6fe22f5479458a688a819f92f2af43c5867ea81.tar.gz
scala-c6fe22f5479458a688a819f92f2af43c5867ea81.tar.bz2
scala-c6fe22f5479458a688a819f92f2af43c5867ea81.zip
add support for importable attachments
Previously attachments weren't imported by importTree. Now a new marker trait has been added that lets attachments to import themselves to the new universe together with all their innards. Additionally a simpler subtrait is defined to mark attachments that can be imported as-is.
Diffstat (limited to 'src/reflect')
-rw-r--r--src/reflect/scala/reflect/internal/Importers.scala14
-rw-r--r--src/reflect/scala/reflect/internal/StdAttachments.scala8
-rw-r--r--src/reflect/scala/reflect/runtime/JavaUniverseForce.scala2
3 files changed, 19 insertions, 5 deletions
diff --git a/src/reflect/scala/reflect/internal/Importers.scala b/src/reflect/scala/reflect/internal/Importers.scala
index 72c8ccfa62..cc6e55192f 100644
--- a/src/reflect/scala/reflect/internal/Importers.scala
+++ b/src/reflect/scala/reflect/internal/Importers.scala
@@ -8,6 +8,16 @@ import scala.ref.WeakReference
// SI-6241: move importers to a mirror
trait Importers extends api.Importers { to: SymbolTable =>
+ /** Attachment that knows how to import itself into another universe. */
+ trait ImportableAttachment {
+ def importAttachment(importer: Importer): this.type
+ }
+
+ /** Attachment that doesn't contain any reflection artificats and can be imported as-is. */
+ trait PlainAttachment extends ImportableAttachment {
+ def importAttachment(importer: Importer): this.type = this
+ }
+
def mkImporter(from0: api.Universe): Importer { val from: from0.type } = (
if (to eq from0) {
new Importer {
@@ -417,11 +427,15 @@ trait Importers extends api.Importers { to: SymbolTable =>
my.setPos(importPosition(their.pos))
}
}
+ importAttachments(their.attachments.all).foreach { my.updateAttachment(_) }
my
}
// ============== MISCELLANEOUS ==============
+ def importAttachments(attachments: Set[Any]): Set[Any] =
+ attachments.collect { case ia: ImportableAttachment => ia.importAttachment(this) }
+
def importAnnotationInfo(ann: from.AnnotationInfo): AnnotationInfo = {
val atp1 = importType(ann.atp)
val args1 = ann.args map importTree
diff --git a/src/reflect/scala/reflect/internal/StdAttachments.scala b/src/reflect/scala/reflect/internal/StdAttachments.scala
index 2e89ffca56..fe4438015d 100644
--- a/src/reflect/scala/reflect/internal/StdAttachments.scala
+++ b/src/reflect/scala/reflect/internal/StdAttachments.scala
@@ -22,13 +22,13 @@ trait StdAttachments {
def setPos(newpos: Position): this.type = { pos = newpos; this }
}
- /** When present, indicates that the host `Ident` has been created from a backquoted identifier.
- */
- case object BackquotedIdentifierAttachment
-
/** Stores the trees that give rise to a refined type to be used in reification.
* Unfortunately typed `CompoundTypeTree` is lacking essential info, and the reifier cannot use `CompoundTypeTree.tpe`.
* Therefore we need this hack (see `Reshape.toPreTyperTypeTree` for a detailed explanation).
*/
case class CompoundTypeTreeOriginalAttachment(parents: List[Tree], stats: List[Tree])
+
+ /** When present, indicates that the host `Ident` has been created from a backquoted identifier.
+ */
+ case object BackquotedIdentifierAttachment extends PlainAttachment
}
diff --git a/src/reflect/scala/reflect/runtime/JavaUniverseForce.scala b/src/reflect/scala/reflect/runtime/JavaUniverseForce.scala
index 4d69a6673c..26091b84a1 100644
--- a/src/reflect/scala/reflect/runtime/JavaUniverseForce.scala
+++ b/src/reflect/scala/reflect/runtime/JavaUniverseForce.scala
@@ -53,8 +53,8 @@ trait JavaUniverseForce { self: runtime.JavaUniverse =>
this.perRunCaches
this.FixedMirrorTreeCreator
this.FixedMirrorTypeCreator
- this.BackquotedIdentifierAttachment
this.CompoundTypeTreeOriginalAttachment
+ this.BackquotedIdentifierAttachment
this.noPrint
this.typeDebug
// inaccessible: this.maxFree