Skip to content

Commit

Permalink
Replaced various now-unnecessary casts with str...
Browse files Browse the repository at this point in the history
Replaced various now-unnecessary casts with straight getClass calls.
Closes SI-4780, no review.
  • Loading branch information
paulp committed Aug 27, 2011
1 parent 649b426 commit 2c548ea
Show file tree
Hide file tree
Showing 7 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/compiler/scala/reflect/internal/Types.scala
Expand Up @@ -6069,7 +6069,7 @@ A type's typeSymbol should never be inspected directly.

/** Perform operation `p` on arguments `tp1`, `arg2` and print trace of computation. */
private def explain[T](op: String, p: (Type, T) => Boolean, tp1: Type, arg2: T): Boolean = {
Console.println(indent + tp1 + " " + op + " " + arg2 + "?" /* + "("+tp1.getClass+","+arg2.asInstanceOf[AnyRef].getClass+")"*/)
Console.println(indent + tp1 + " " + op + " " + arg2 + "?" /* + "("+tp1.getClass+","+arg2.getClass+")"*/)
indent = indent + " "
val result = p(tp1, arg2)
indent = indent dropRight 2
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/scala/tools/nsc/interpreter/TypeStrings.scala
Expand Up @@ -56,7 +56,7 @@ trait TypeStrings {
)
}
def scalaName(m: ClassManifest[_]): String = scalaName(m.erasure)
def anyClass(x: Any): JClass = if (x == null) null else x.asInstanceOf[AnyRef].getClass
def anyClass(x: Any): JClass = if (x == null) null else x.getClass

private def brackets(tps: String*): String =
if (tps.isEmpty) ""
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/scala/tools/nsc/io/Pickler.scala
Expand Up @@ -246,7 +246,7 @@ object Pickler {
p.tryPickle(wr, x) || qq.tryPickle(wr, x)
def pickle(wr: Writer, x: T) =
require(tryPickle(wr, x),
"no pickler found for "+x+" of class "+x.asInstanceOf[AnyRef].getClass.getName)
"no pickler found for "+x+" of class "+x.getClass.getName)
def unpickle(rd: Lexer) = p.unpickle(rd) orElse qq.unpickle(rd)
}

Expand Down
2 changes: 1 addition & 1 deletion src/compiler/scala/tools/nsc/util/ScalaClassLoader.scala
Expand Up @@ -134,7 +134,7 @@ object ScalaClassLoader {
}

/** Finding what jar a clazz or instance came from */
def origin(x: Any): Option[URL] = originOfClass(x.asInstanceOf[AnyRef].getClass)
def origin(x: Any): Option[URL] = originOfClass(x.getClass)
def originOfClass(x: Class[_]): Option[URL] =
Option(x.getProtectionDomain.getCodeSource) flatMap (x => Option(x.getLocation))
}
2 changes: 1 addition & 1 deletion src/library/scala/MatchError.scala
Expand Up @@ -25,7 +25,7 @@ final class MatchError(obj: Any) extends RuntimeException {
*/
private lazy val objString =
if (obj == null) "null"
else obj.toString() + " (of class " + obj.asInstanceOf[AnyRef].getClass.getName + ")"
else obj.toString() + " (of class " + obj.getClass.getName + ")"

override def getMessage() = objString
}
2 changes: 1 addition & 1 deletion src/library/scala/collection/TraversableLike.scala
Expand Up @@ -627,7 +627,7 @@ trait TraversableLike[+A, +Repr] extends HasNewBuilder[A, Repr]
* simple name of the collection class $coll.
*/
def stringPrefix : String = {
var string = repr.asInstanceOf[AnyRef].getClass.getName
var string = repr.getClass.getName
val idx1 = string.lastIndexOf('.' : Int)
if (idx1 != -1) string = string.substring(idx1 + 1)
val idx2 = string.indexOf('$')
Expand Down
2 changes: 1 addition & 1 deletion src/library/scala/runtime/ScalaRunTime.scala
Expand Up @@ -25,7 +25,7 @@ import java.lang.reflect.{ Modifier, Method => JMethod }
object ScalaRunTime {
def isArray(x: AnyRef): Boolean = isArray(x, 1)
def isArray(x: Any, atLevel: Int): Boolean =
x != null && isArrayClass(x.asInstanceOf[AnyRef].getClass, atLevel)
x != null && isArrayClass(x.getClass, atLevel)

private def isArrayClass(clazz: Class[_], atLevel: Int): Boolean =
clazz.isArray && (atLevel == 1 || isArrayClass(clazz.getComponentType, atLevel - 1))
Expand Down

0 comments on commit 2c548ea

Please sign in to comment.