summaryrefslogtreecommitdiff
path: root/src/reflect/scala
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2012-09-02 10:08:08 -0700
committerPaul Phillips <paulp@improving.org>2012-09-02 10:08:08 -0700
commite556abb524c9ca64f9b241fa07f40aa902594c66 (patch)
tree9f745c6662903683bf645da0e68ad3bbfea4287f /src/reflect/scala
parent2b707ee99bbb44447315874d360c498aac4c3089 (diff)
parent23cf705ba64641a3ba45e84984702cf97cdd0ccf (diff)
downloadscala-e556abb524c9ca64f9b241fa07f40aa902594c66.tar.gz
scala-e556abb524c9ca64f9b241fa07f40aa902594c66.tar.bz2
scala-e556abb524c9ca64f9b241fa07f40aa902594c66.zip
Merge pull request #1202 from scalamacros/topic/reflection
further polishing of reflection
Diffstat (limited to 'src/reflect/scala')
-rw-r--r--src/reflect/scala/reflect/api/Symbols.scala36
-rw-r--r--src/reflect/scala/reflect/internal/AbstractFileApi.scala7
-rw-r--r--src/reflect/scala/reflect/internal/Required.scala2
-rw-r--r--src/reflect/scala/reflect/internal/Symbols.scala31
-rw-r--r--src/reflect/scala/reflect/macros/Universe.scala6
-rw-r--r--src/reflect/scala/reflect/runtime/AbstractFile.scala7
-rw-r--r--src/reflect/scala/reflect/runtime/JavaUniverse.scala2
-rw-r--r--src/reflect/scala/reflect/runtime/ReflectionUtils.scala2
-rw-r--r--src/reflect/scala/reflect/runtime/SynchronizedSymbols.scala4
-rw-r--r--src/reflect/scala/tools/nsc/io/AbstractFile.scala2
10 files changed, 59 insertions, 40 deletions
diff --git a/src/reflect/scala/reflect/api/Symbols.scala b/src/reflect/scala/reflect/api/Symbols.scala
index b17377795b..d167099979 100644
--- a/src/reflect/scala/reflect/api/Symbols.scala
+++ b/src/reflect/scala/reflect/api/Symbols.scala
@@ -15,9 +15,10 @@ trait Symbols extends base.Symbols { self: Universe =>
/** The API of symbols */
trait SymbolApi extends SymbolBase { this: Symbol =>
- /** The position of this symbol
+ /** Source file if this symbol is created during this compilation run,
+ * or a class file if this symbol is loaded from a *.class or *.jar.
*/
- def pos: Position
+ def associatedFile: scala.tools.nsc.io.AbstractFile
/** A list of annotations attached to this Symbol.
*/
@@ -182,6 +183,10 @@ trait Symbols extends base.Symbols { self: Universe =>
*/
def isSpecialized: Boolean
+ /** Is this symbol defined by Java?
+ */
+ def isJava: Boolean
+
/******************* helpers *******************/
/** ...
@@ -204,16 +209,16 @@ trait Symbols extends base.Symbols { self: Universe =>
/** The API of term symbols */
trait TermSymbolApi extends SymbolApi with TermSymbolBase { this: TermSymbol =>
- /** Does this symbol represent a value, i.e. not a module and not a method?
+ /** Is this symbol introduced as `val`?
*/
- def isValue: Boolean
+ def isVal: Boolean
/** Does this symbol denote a stable value? */
def isStable: Boolean
- /** Does this symbol represent a mutable value?
+ /** Is this symbol introduced as `var`?
*/
- def isVariable: Boolean
+ def isVar: Boolean
/** Does this symbol represent a getter or a setter?
*/
@@ -320,6 +325,9 @@ trait Symbols extends base.Symbols { self: Universe =>
*/
def isConstructor: Boolean
+ /** Does this symbol denote the primary constructor of its enclosing class? */
+ def isPrimaryConstructor: Boolean
+
/** For a polymorphic method, its type parameters, the empty list for all other methods */
def typeParams: List[Symbol]
@@ -378,6 +386,22 @@ trait Symbols extends base.Symbols { self: Universe =>
*/
def isSealed: Boolean
+ /** If this is a sealed class, its known direct subclasses.
+ * Otherwise, the empty set.
+ */
+ def knownDirectSubclasses: Set[Symbol]
+
+ /** The list of all base classes of this type (including its own typeSymbol)
+ * in reverse linearization order, starting with the class itself and ending
+ * in class Any.
+ */
+ def baseClasses: List[Symbol]
+
+ /** The module corresponding to this module class,
+ * or NoSymbol if this symbol is not a module class.
+ */
+ def module: Symbol
+
/** If this symbol is a class or trait, its self type, otherwise the type
* of the symbol itself.
*/
diff --git a/src/reflect/scala/reflect/internal/AbstractFileApi.scala b/src/reflect/scala/reflect/internal/AbstractFileApi.scala
deleted file mode 100644
index 9f37f4536f..0000000000
--- a/src/reflect/scala/reflect/internal/AbstractFileApi.scala
+++ /dev/null
@@ -1,7 +0,0 @@
-package scala.reflect
-package internal
-
-trait AbstractFileApi {
- def path: String
- def canonicalPath: String
-}
diff --git a/src/reflect/scala/reflect/internal/Required.scala b/src/reflect/scala/reflect/internal/Required.scala
index abbe8fbfb7..842491d56d 100644
--- a/src/reflect/scala/reflect/internal/Required.scala
+++ b/src/reflect/scala/reflect/internal/Required.scala
@@ -5,8 +5,6 @@ import settings.MutableSettings
trait Required { self: SymbolTable =>
- type AbstractFileType >: Null <: AbstractFileApi
-
def picklerPhase: Phase
def settings: MutableSettings
diff --git a/src/reflect/scala/reflect/internal/Symbols.scala b/src/reflect/scala/reflect/internal/Symbols.scala
index 2e045b08b9..3548657c04 100644
--- a/src/reflect/scala/reflect/internal/Symbols.scala
+++ b/src/reflect/scala/reflect/internal/Symbols.scala
@@ -12,6 +12,7 @@ import util.Statistics
import Flags._
import base.Attachments
import scala.annotation.tailrec
+import scala.tools.nsc.io.AbstractFile
trait Symbols extends api.Symbols { self: SymbolTable =>
import definitions._
@@ -67,12 +68,18 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
def isParamWithDefault: Boolean = this.hasDefault
def isByNameParam: Boolean = this.isValueParameter && (this hasFlag BYNAMEPARAM)
def isImplementationArtifact: Boolean = (this hasFlag BRIDGE) || (this hasFlag VBRIDGE) || (this hasFlag ARTIFACT)
+ def isJava: Boolean = this hasFlag JAVA
+ def isVal: Boolean = isTerm && !isModule && !isMethod && !isMutable
+ def isVar: Boolean = isTerm && !isModule && !isMethod && isMutable
def newNestedSymbol(name: Name, pos: Position, newFlags: Long, isClass: Boolean): Symbol = name match {
case n: TermName => newTermSymbol(n, pos, newFlags)
case n: TypeName => if (isClass) newClassSymbol(n, pos, newFlags) else newNonClassSymbol(n, pos, newFlags)
}
+ def knownDirectSubclasses = children
+ def baseClasses = info.baseClasses
+ def module = sourceModule
def thisPrefix: Type = thisType
def selfType: Type = typeOfThis
def typeSignature: Type = info
@@ -2058,21 +2065,21 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
* of sourceFile (which is expected at least in the IDE only to
* return actual source code.) So sourceFile has classfiles filtered out.
*/
- private def sourceFileOnly(file: AbstractFileType): AbstractFileType =
+ private def sourceFileOnly(file: AbstractFile): AbstractFile =
if ((file eq null) || (file.path endsWith ".class")) null else file
- private def binaryFileOnly(file: AbstractFileType): AbstractFileType =
+ private def binaryFileOnly(file: AbstractFile): AbstractFile =
if ((file eq null) || !(file.path endsWith ".class")) null else file
- final def binaryFile: AbstractFileType = binaryFileOnly(associatedFile)
- final def sourceFile: AbstractFileType = sourceFileOnly(associatedFile)
+ final def binaryFile: AbstractFile = binaryFileOnly(associatedFile)
+ final def sourceFile: AbstractFile = sourceFileOnly(associatedFile)
/** Overridden in ModuleSymbols to delegate to the module class. */
- def associatedFile: AbstractFileType = enclosingTopLevelClass.associatedFile
- def associatedFile_=(f: AbstractFileType) { abort("associatedFile_= inapplicable for " + this) }
+ def associatedFile: AbstractFile = enclosingTopLevelClass.associatedFile
+ def associatedFile_=(f: AbstractFile) { abort("associatedFile_= inapplicable for " + this) }
@deprecated("Use associatedFile_= instead", "2.10.0")
- def sourceFile_=(f: AbstractFileType): Unit = associatedFile_=(f)
+ def sourceFile_=(f: AbstractFile): Unit = associatedFile_=(f)
/** If this is a sealed class, its known direct subclasses.
* Otherwise, the empty set.
@@ -2456,7 +2463,7 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
private var flatname: TermName = null
override def associatedFile = moduleClass.associatedFile
- override def associatedFile_=(f: AbstractFileType) { moduleClass.associatedFile = f }
+ override def associatedFile_=(f: AbstractFile) { moduleClass.associatedFile = f }
override def moduleClass = referenced
override def companionClass =
@@ -2760,9 +2767,9 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
extends TypeSymbol(initOwner, initPos, initName) with ClassSymbolApi {
type TypeOfClonedSymbol = ClassSymbol
- private[this] var flatname: TypeName = _
- private[this] var _associatedFile: AbstractFileType = _
- private[this] var thissym: Symbol = this
+ private[this] var flatname: TypeName = _
+ private[this] var _associatedFile: AbstractFile = _
+ private[this] var thissym: Symbol = this
private[this] var thisTypeCache: Type = _
private[this] var thisTypePeriod = NoPeriod
@@ -2860,7 +2867,7 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
}
override def associatedFile = if (owner.isPackageClass) _associatedFile else super.associatedFile
- override def associatedFile_=(f: AbstractFileType) { _associatedFile = f }
+ override def associatedFile_=(f: AbstractFile) { _associatedFile = f }
override def reset(completer: Type): this.type = {
super.reset(completer)
diff --git a/src/reflect/scala/reflect/macros/Universe.scala b/src/reflect/scala/reflect/macros/Universe.scala
index 8d9711dedd..06428ee3fc 100644
--- a/src/reflect/scala/reflect/macros/Universe.scala
+++ b/src/reflect/scala/reflect/macros/Universe.scala
@@ -24,6 +24,12 @@ abstract class Universe extends scala.reflect.api.Universe {
*/
trait SymbolContextApi extends SymbolApi with AttachableApi { self: Symbol =>
+ def deSkolemize: Symbol
+
+ /** The position of this symbol
+ */
+ def pos: Position
+
def setTypeSignature(tpe: Type): Symbol
def setAnnotations(annots: AnnotationInfo*): Symbol
diff --git a/src/reflect/scala/reflect/runtime/AbstractFile.scala b/src/reflect/scala/reflect/runtime/AbstractFile.scala
deleted file mode 100644
index 0f88af1b0a..0000000000
--- a/src/reflect/scala/reflect/runtime/AbstractFile.scala
+++ /dev/null
@@ -1,7 +0,0 @@
-package scala.reflect
-package runtime
-
-class AbstractFile(val jfile: java.io.File) extends internal.AbstractFileApi {
- def path: String = jfile.getPath()
- def canonicalPath: String = jfile.getCanonicalPath()
-}
diff --git a/src/reflect/scala/reflect/runtime/JavaUniverse.scala b/src/reflect/scala/reflect/runtime/JavaUniverse.scala
index 629df76178..77d65a7db2 100644
--- a/src/reflect/scala/reflect/runtime/JavaUniverse.scala
+++ b/src/reflect/scala/reflect/runtime/JavaUniverse.scala
@@ -8,8 +8,6 @@ import internal.{SomePhase, NoPhase, Phase, TreeGen}
*/
class JavaUniverse extends internal.SymbolTable with ReflectSetup with runtime.SymbolTable { self =>
- type AbstractFileType = AbstractFile
-
def picklerPhase = SomePhase
lazy val settings = new Settings
diff --git a/src/reflect/scala/reflect/runtime/ReflectionUtils.scala b/src/reflect/scala/reflect/runtime/ReflectionUtils.scala
index e87c6b339b..0125fa2c53 100644
--- a/src/reflect/scala/reflect/runtime/ReflectionUtils.scala
+++ b/src/reflect/scala/reflect/runtime/ReflectionUtils.scala
@@ -49,7 +49,7 @@ object ReflectionUtils {
case cl: java.net.URLClassLoader =>
(cl.getURLs mkString ",")
case cl if cl != null && isAbstractFileClassLoader(cl.getClass) =>
- cl.asInstanceOf[{val root: scala.reflect.internal.AbstractFileApi}].root.canonicalPath
+ cl.asInstanceOf[{val root: scala.tools.nsc.io.AbstractFile}].root.canonicalPath
case null =>
inferBootClasspath
case _ =>
diff --git a/src/reflect/scala/reflect/runtime/SynchronizedSymbols.scala b/src/reflect/scala/reflect/runtime/SynchronizedSymbols.scala
index 12db7a7bf9..40346cad79 100644
--- a/src/reflect/scala/reflect/runtime/SynchronizedSymbols.scala
+++ b/src/reflect/scala/reflect/runtime/SynchronizedSymbols.scala
@@ -1,7 +1,7 @@
package scala.reflect
package runtime
-import internal.Flags.DEFERRED
+import scala.tools.nsc.io.AbstractFile
trait SynchronizedSymbols extends internal.Symbols { self: SymbolTable =>
@@ -123,7 +123,7 @@ trait SynchronizedSymbols extends internal.Symbols { self: SymbolTable =>
trait SynchronizedClassSymbol extends ClassSymbol with SynchronizedTypeSymbol {
override def associatedFile = synchronized { super.associatedFile }
- override def associatedFile_=(f: AbstractFileType) = synchronized { super.associatedFile_=(f) }
+ override def associatedFile_=(f: AbstractFile) = synchronized { super.associatedFile_=(f) }
override def thisSym: Symbol = synchronized { super.thisSym }
override def thisType: Type = synchronized { super.thisType }
override def typeOfThis: Type = synchronized { super.typeOfThis }
diff --git a/src/reflect/scala/tools/nsc/io/AbstractFile.scala b/src/reflect/scala/tools/nsc/io/AbstractFile.scala
index 8d55b708b1..018a017c6d 100644
--- a/src/reflect/scala/tools/nsc/io/AbstractFile.scala
+++ b/src/reflect/scala/tools/nsc/io/AbstractFile.scala
@@ -82,7 +82,7 @@ object AbstractFile {
* <code>global.settings.encoding.value</code>.
* </p>
*/
-abstract class AbstractFile extends reflect.internal.AbstractFileApi with Iterable[AbstractFile] {
+abstract class AbstractFile extends Iterable[AbstractFile] {
/** Returns the name of this abstract file. */
def name: String