| career | drupal | java | mac | mysql | perl | scala | uml | unix  

Scala example source code file (TypeToStrings.scala)

This example Scala source code file (TypeToStrings.scala) is included in my "Source Code Warehouse" project. The intent of this project is to help you more easily find Scala source code examples by using tags.

All credit for the original source code belongs to; I'm just trying to make examples easier to find. (For my Scala work, see my Scala examples and tutorials.)

Scala tags/keywords

collection, exceeded, hashset, int, mutable, string, symboltable, type, typetostrings

The TypeToStrings.scala Scala example source code

package scala
package reflect
package internal
package tpe

import scala.collection.mutable.HashSet

private[internal] trait TypeToStrings {
  self: SymbolTable =>

  /** The maximum number of recursions allowed in toString
  final val maxToStringRecursions = 50

  private var _toStringRecursions = 0
  def toStringRecursions = _toStringRecursions
  def toStringRecursions_=(value: Int) = _toStringRecursions = value

  private var _toStringSubjects = HashSet[Type]()
  def toStringSubjects = _toStringSubjects

  protected def typeToString(tpe: Type): String =
    // if (toStringSubjects contains tpe) {
    //   // handles self-referential anonymous classes and who knows what else
    //   "..."
    // }
    // else
    if (toStringRecursions >= maxToStringRecursions) {
      devWarning("Exceeded recursion depth attempting to print " + util.shortClassOfInstance(tpe))
      if (settings.debug)
        (new Throwable).printStackTrace

      try {
        toStringRecursions += 1
        // TODO: study performance impact of this cache
        // to quote Jason:
        //   I'm a little uneasy with the performance impact of the fail-safe. We end up calling Type#toString
        //   when we generate error messages, including, importantly, errors issued during silent mode that are never issued.
        // toStringSubjects += tpe
      } finally {
        // toStringSubjects -= tpe
        toStringRecursions -= 1

Other Scala source code examples

Here is a short list of links related to this Scala TypeToStrings.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,
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.