alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Scala example source code file (Dossiers.scala)

This example Scala source code file (Dossiers.scala) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Scala tags/keywords

anyref, dossier, dossier, imain, jclass, namedparamclass, namedparamclass, symbol, symbol, termdossier, type, type, typedossier, typesymbol

The Scala Dossiers.scala source code

/* NSC -- new Scala compiler
 * Copyright 2005-2011 LAMP/EPFL
 * @author  Paul Phillips
 */

package scala.tools.nsc
package interpreter

// Coming soon
trait Dossiers {
  val intp: IMain

  import intp._
  import intp.global._
  
  trait Dossier {
    def symbol: Symbol
    def staticType: Type
    
    def id               = name.toString
    def name             = symbol.name
    def normalizedType   = staticType.typeSymbolDirect.tpe.normalize
    def simpleNameOfType = staticType.typeSymbol.simpleName
    def staticTypeString = staticType.toString
    
    override def toString = "Dossier on %s:\n  static type %s (normalized %s)".format(
      symbol, staticType, normalizedType
    )
  }
  
  class TypeDossier(val symbol: TypeSymbol, val staticType: Type) extends Dossier {
    override def toString = super.toString
  }
  
  class TermDossier(val symbol: TermSymbol, val staticType: Type, val value: AnyRef) extends Dossier {
    def runtimeClass: JClass = value.getClass
    def runtimeSymbol: Symbol  = safeClass(runtimeClass.getName) getOrElse NoSymbol
    def runtimeType: Type      = runtimeSymbol.tpe
    def runtimeTypeString      = TypeStrings.fromClazz(runtimeClass)
    
    def runtimeTypedParam = NamedParamClass(id, runtimeTypeString, value)
    def staticTypedParam  = NamedParamClass(id, staticTypeString, value)

    def isRuntimeTypeTighter = runtimeSymbol.ancestors contains normalizedType.typeSymbol
    
    override def toString = super.toString + (
      "\n  runtime type %s/%s\n  value %s".format(
        runtimeType, runtimeTypeString, value
      )
    )
  }
}

Other Scala examples (source code examples)

Here is a short list of links related to this Scala Dossiers.scala source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.