<commit_before>/*                     __                                               *\
**     ________ ___   / /  ___     Scala API                            **
**    / __/ __// _ | / /  / _ |    (c) 2002-2004, LAMP/EPFL             **
**  __\ \/ /__/ __ |/ /__/ __ |                                         **
** /____/\___/_/ |_/____/_/ | |                                         **
**                          |/                                          **
** $Id$
\*                                                                      */

package scala.mobile;

import java.net._;

import scala.collection.mutable._;


/** The class <code>Location</code> provides a <code>create</code>
 *  method to instanciate objects from a network location by
 *  specifying its URL address.
 *
 *  Example:<pre>
 *    val url = new URL("http://scala.epfl.ch/classes/examples.jar");
 *    val obj = new Location(url) create "examples.sort";</pre>
 *
 *  @author  <NAME>
 *  @version 1.0, 04/05/2004
 */
class Location(url: URL) {

  /** A cache containing all class loaders of this location.
   */
  private var lcache: Map[URL, ClassLoader] = new HashMap;

  /** The class loader associated with this location.
   */
  private val loader = if (url == null)
    ClassLoader.getSystemClassLoader()
  else
    lcache.get(url) match {
    case Some(cl) =>
      cl
    case _ =>
      val cl = new URLClassLoader(Predef.Array(url));
      lcache(url) = cl;
      cl
  };

  /** A cache containing all classes of this location.
   */
  private var ccache: Map[String, java.lang.Class] = new HashMap;

  def create(className: String): Code = {
    val clazz = ccache.get(className) match {
      case Some(x) =>
        x
      case _ =>
        val clazz = if (loader.loadClass(className).isInterface()) {
          // Scala source: class A { ... };
          // Java bytecode: interface A.class + class A$class.class
          loader.loadClass(className + "$class");
        }
        else {
          // Scala source: object A { ... };
          // Java bytecode: interface A.class + class A$.class
          loader.loadClass(className + "$");
        }
        ccache(className) = clazz;
        clazz
    };
    new Code(clazz)
  }

}

object Location extends Location(null);
<commit_msg>- updated Scala comment for class 'Location'.<commit_after>/*                     __                                               *\
**     ________ ___   / /  ___     Scala API                            **
**    / __/ __// _ | / /  / _ |    (c) 2002-2004, LAMP/EPFL             **
**  __\ \/ /__/ __ |/ /__/ __ |                                         **
** /____/\___/_/ |_/____/_/ | |                                         **
**                          |/                                          **
** $Id$
\*                                                                      */

package scala.mobile;

import java.net._;

import scala.collection.mutable._;


/** The class <code>Location</code> provides a <code>create</code>
 *  method to instantiate objects from a network location by
 *  specifying the URL address of the jar/class file.<p/>
 *
 *  An update of the jar/class file should not break your code as far
 *  as the used class names and method signatures are the same.<p/>
 *
 *  Example:<pre>
 *    <b>val</b> url = <b>new</b> URL("http://scala.epfl.ch/classes/examples.jar");
 *    <b>val</b> obj = <b>new</b> Location(url) create "examples.sort";</pre>
 *
 *  @see class <a href="Code-class.html">Code</a>
 *
 *  @author  <NAME>
 *  @version 1.0, 04/05/2004
 */
class Location(url: URL) {

  /** A cache containing all class loaders of this location.
   */
  private var lcache: Map[URL, ClassLoader] = new HashMap;

  /** The class loader associated with this location.
   */
  private val loader = if (url == null)
    ClassLoader.getSystemClassLoader()
  else
    lcache.get(url) match {
    case Some(cl) =>
      cl
    case _ =>
      val cl = new URLClassLoader(Predef.Array(url));
      lcache(url) = cl;
      cl
  };

  /** A cache containing all classes of this location.
   */
  private var ccache: Map[String, java.lang.Class] = new HashMap;

  /** Return the code description for the string <code>className</code>
   *  at this location.
   *
   * @param the name of the class
   * @return the code description corresponding to <code>className</code>
   */
  def create(className: String) = new Code(
    ccache.get(className) match {
      case Some(clazz) =>
        clazz
      case _ =>
        val clazz = if (loader.loadClass(className).isInterface()) {
          // Scala source: class A { ... };
          // Java bytecode: interface A.class + class A$class.class
          loader.loadClass(className + "$class");
        }
        else {
          // Scala source: object A { ... };
          // Java bytecode: interface A.class + class A$.class
          loader.loadClass(className + "$");
        }
        ccache(className) = clazz;
        clazz
    }
  );

}

/** The object <code>Location</code> can be used to instantiate
 *  objects on the same Java VM. It is just provided to illustrate
 *  the special case where resources are available locally.<p/>
 *
 *  Example:<pre>
 *    <b>val</b> obj = Location.create("xcode.Math");
 *    <b>val</b> x = obj[Int, Int]("square")(5));</pre>
 *
 *  @author  <NAME>
 *  @version 1.0, 04/05/2004
 */
object Location extends Location(null);

{'fraction_non_alphanumeric': 0.13585253456221197, 'fraction_numerical': 0.008663594470046084, 'mean_word_length': 1.6162005785920925, 'pattern_counts': {'":': 0, '<': 43, '<?xml version=': 0, '>': 51, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 26, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5198573', 'n_tokens_mistral': 1620, 'n_tokens_neox': 1557, 'n_words': 418}