summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEugene Burmako <xeno.by@gmail.com>2012-01-31 11:30:41 +0100
committerEugene Burmako <xeno.by@gmail.com>2012-01-31 11:39:36 +0100
commit2e664079445549288789ad24a95ce7d583ae205c (patch)
tree166e7ff1e412a151f0d16f734e6c4e3c40f93ba3
parent263aa2ead1f599f48b218027eb9550745fef43f1 (diff)
downloadscala-2e664079445549288789ad24a95ce7d583ae205c.tar.gz
scala-2e664079445549288789ad24a95ce7d583ae205c.tar.bz2
scala-2e664079445549288789ad24a95ce7d583ae205c.zip
Introduce getAnnotations that triggers symbol completion
Default getter for annotations doesn't perform initialization, hence we've faced the following bug: https://issues.scala-lang.org/browse/SI-5423. One of the approaches to fixing it would be to auto-complete on getter, but according to Martin we'd better not do that because of cycles. That's why I'm just introducing a new, eager, variation of `annotations' and redirecting public API to it. Review by @odersky.
-rw-r--r--src/compiler/scala/reflect/internal/Symbols.scala10
-rwxr-xr-xsrc/library/scala/reflect/api/Symbols.scala2
-rw-r--r--test/files/run/t5423.check1
-rw-r--r--test/files/run/t5423.scala12
4 files changed, 24 insertions, 1 deletions
diff --git a/src/compiler/scala/reflect/internal/Symbols.scala b/src/compiler/scala/reflect/internal/Symbols.scala
index 94d764067f..e777491300 100644
--- a/src/compiler/scala/reflect/internal/Symbols.scala
+++ b/src/compiler/scala/reflect/internal/Symbols.scala
@@ -1272,6 +1272,16 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
* the annotations attached to member a definition (class, method, type, field).
*/
def annotations: List[AnnotationInfo] = _annotations
+
+ /** This getter is necessary for reflection, see https://issues.scala-lang.org/browse/SI-5423
+ * We could auto-inject completion into `annotations' and `setAnnotations', but I'm not sure about that
+ * @odersky writes: I fear we can't do the forcing for all compiler symbols as that could introduce cycles
+ */
+ def getAnnotations: List[AnnotationInfo] = {
+ initialize
+ _annotations
+ }
+
def setAnnotations(annots: List[AnnotationInfo]): this.type = {
_annotations = annots
this
diff --git a/src/library/scala/reflect/api/Symbols.scala b/src/library/scala/reflect/api/Symbols.scala
index 01c1a0f2ae..17d9b06324 100755
--- a/src/library/scala/reflect/api/Symbols.scala
+++ b/src/library/scala/reflect/api/Symbols.scala
@@ -79,7 +79,7 @@ trait Symbols { self: Universe =>
/** A list of annotations attached to this Symbol.
*/
- def annotations: List[self.AnnotationInfo]
+ def getAnnotations: List[self.AnnotationInfo]
/** For a class: the module or case class factory with the same name in the same package.
* For all others: NoSymbol
diff --git a/test/files/run/t5423.check b/test/files/run/t5423.check
new file mode 100644
index 0000000000..ae3d3fb82b
--- /dev/null
+++ b/test/files/run/t5423.check
@@ -0,0 +1 @@
+List(table) \ No newline at end of file
diff --git a/test/files/run/t5423.scala b/test/files/run/t5423.scala
new file mode 100644
index 0000000000..2139773ff1
--- /dev/null
+++ b/test/files/run/t5423.scala
@@ -0,0 +1,12 @@
+import java.lang.Class
+import scala.reflect.mirror._
+import scala.reflect.runtime.Mirror.ToolBox
+import scala.reflect.Code
+
+final class table extends StaticAnnotation
+@table class A
+
+object Test extends App{
+ val s = classToSymbol(classOf[A])
+ println(s.getAnnotations)
+}