summaryrefslogtreecommitdiff
path: root/src/library
diff options
context:
space:
mode:
authorEugene Burmako <xeno.by@gmail.com>2012-07-30 13:17:17 +0200
committerEugene Burmako <xeno.by@gmail.com>2012-08-02 15:36:55 +0200
commita727c6fc198d33842ff85d8a16d48143a6757d51 (patch)
tree3b995ade8066488c3ac42d7b65e0bb02b976cabc /src/library
parent937da62be2834a646a31dbfb01527a82672f111e (diff)
downloadscala-a727c6fc198d33842ff85d8a16d48143a6757d51.tar.gz
scala-a727c6fc198d33842ff85d8a16d48143a6757d51.tar.bz2
scala-a727c6fc198d33842ff85d8a16d48143a6757d51.zip
SI-5732 members and derivatives now return Scope
Firstly this unifies the reflection API - now both decls and members return Scope (not Scope and List[Symbol] as it were before). Secondly this fixes SI-5732 without having to sort the result of members. Type.members now returns Scope, a distinguished type, which has the `sorted` method, which does the required sorting if necessary. Also removes nonPrivateMembers and nonPrivateDeclarations to keep the API minimalistic (as can be seen from their implementation in internal.Types they are just members and decls with bridges and private members removed).
Diffstat (limited to 'src/library')
-rw-r--r--src/library/scala/reflect/base/Base.scala13
-rw-r--r--src/library/scala/reflect/base/Scopes.scala22
2 files changed, 30 insertions, 5 deletions
diff --git a/src/library/scala/reflect/base/Base.scala b/src/library/scala/reflect/base/Base.scala
index 53854f160d..ddb502fd44 100644
--- a/src/library/scala/reflect/base/Base.scala
+++ b/src/library/scala/reflect/base/Base.scala
@@ -170,12 +170,17 @@ class Base extends Universe { self =>
object BoundedWildcardType extends BoundedWildcardTypeExtractor
implicit val BoundedWildcardTypeTag = ClassTag[BoundedWildcardType](classOf[BoundedWildcardType])
- type Scope = Iterable[Symbol]
+ class Scope(elems: Iterable[Symbol]) extends ScopeBase with MemberScopeBase {
+ def iterator = elems.iterator
+ def sorted = elems.toList
+ }
+ type MemberScope = Scope
implicit val ScopeTag = ClassTag[Scope](classOf[Scope])
+ implicit val MemberScopeTag = ClassTag[MemberScope](classOf[MemberScope])
- def newScope = newScopeWith()
- def newNestedScope(outer: Iterable[Symbol]) = newScope
- def newScopeWith(elems: Symbol*): Scope = elems
+ def newScope: Scope = newScopeWith()
+ def newNestedScope(outer: Scope): Scope = newScope
+ def newScopeWith(elems: Symbol*): Scope = new Scope(elems)
abstract class Name(str: String) extends NameBase {
override def toString = str
diff --git a/src/library/scala/reflect/base/Scopes.scala b/src/library/scala/reflect/base/Scopes.scala
index a5db01c0ce..a388fdc392 100644
--- a/src/library/scala/reflect/base/Scopes.scala
+++ b/src/library/scala/reflect/base/Scopes.scala
@@ -3,13 +3,33 @@ package base
trait Scopes { self: Universe =>
- type Scope >: Null <: Iterable[Symbol]
+ type Scope >: Null <: ScopeBase
+
+ /** The base API that all scopes support */
+ trait ScopeBase extends Iterable[Symbol]
/** A tag that preserves the identity of the `Scope` abstract type from erasure.
* Can be used for pattern matching, instance tests, serialization and likes.
*/
implicit val ScopeTag: ClassTag[Scope]
+ type MemberScope >: Null <: Scope with MemberScopeBase
+
+ /** The base API that all member scopes support */
+ trait MemberScopeBase extends ScopeBase {
+ /** Sorts the symbols included in this scope so that:
+ * 1) Symbols appear the linearization order of their owners.
+ * 2) Symbols with the same owner appear in reverse order of their declarations.
+ * 3) Synthetic members (e.g. getters/setters for vals/vars) might appear in arbitrary order.
+ */
+ def sorted: List[Symbol]
+ }
+
+ /** A tag that preserves the identity of the `MemberScope` abstract type from erasure.
+ * Can be used for pattern matching, instance tests, serialization and likes.
+ */
+ implicit val MemberScopeTag: ClassTag[MemberScope]
+
/** Create a new scope */
def newScope: Scope