Skip to content

Commit

Permalink
Fix unchecked casts
Browse files Browse the repository at this point in the history
  • Loading branch information
Mingun committed Nov 24, 2020
1 parent af69228 commit 1f5ff3c
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ object JavaScriptKSYParser {

def yamlJavascriptToScala(src: Any): Any = {
src match {
case array: js.Array[AnyRef] =>
case array: js.Array[_] =>
array.toList.map(yamlJavascriptToScala)
case _: String | _: Int | _: Double | _: Boolean =>
src
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ object JavaKSYParser {

def yamlJavaToScala(src: Any): Any = {
src match {
case jlist: JList[AnyRef] =>
case jlist: JList[_] =>
jlist.toList.map(yamlJavaToScala)
case jmap: JMap[String, AnyRef] =>
case jmap: JMap[_, _] =>
jmap.toMap.mapValues(yamlJavaToScala)
case _: String =>
src
Expand Down
6 changes: 3 additions & 3 deletions shared/src/main/scala/io/kaitai/struct/JSON.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ object JSON extends CommonLiterals {
case v: Int => v.toString
case v: String => stringToJson(v)
case v: List[_] => listToJson(v)
case v: Map[String, _] => mapToJson(v)
case v: Map[_, _] => mapToJson(v)
}
}

Expand All @@ -33,9 +33,9 @@ object JSON extends CommonLiterals {
def listToJson(obj: List[_]): String =
"[" + obj.map((x) => stringify(x)).mkString(",") + "]"

def mapToJson(obj: Map[String, _]): String = {
def mapToJson(obj: Map[_, _]): String = {
val kvs = obj.map { case (k, v) =>
stringToJson(k) + ": " + stringify(v)
stringToJson(k.toString) + ": " + stringify(v)
}
"{" + kvs.mkString(",") + "}"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ object Endianness {
case None => None
case Some("be") => Some(BigEndian)
case Some("le") => Some(LittleEndian)
case Some(srcMap: Map[Any, Any]) =>
case Some(srcMap: Map[_, _]) =>
val endianMap = ParseUtils.asMapStr(srcMap, path)
Some(fromMap(endianMap, path))
case _ =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ object AttrSpec {
DataType.fromYaml(
Some(simpleType), path, metaDef, yamlAttrArgs
)
case switchMap: Map[Any, Any] =>
case switchMap: Map[_, _] =>
val switchMapStr = ParseUtils.anyMapToStrMap(switchMap, path)
parseSwitch(switchMapStr, path, metaDef, yamlAttrArgs)
case unknown =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ object EnumValueSpec {
fromSimpleName(name, path)
case x: Boolean =>
fromSimpleName(x.toString, path)
case srcMap: Map[Any, Any] =>
case srcMap: Map[_, _] =>
fromMap(ParseUtils.anyMapToStrMap(srcMap, path), path)
case _ =>
throw YAMLParseException.badType("string or map", src, path)
Expand Down
14 changes: 7 additions & 7 deletions shared/src/main/scala/io/kaitai/struct/format/ParseUtils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,12 @@ object ParseUtils {
): List[T] = {
val pathField = path ++ List(field)
src.get(field) match {
case Some(srcList: List[Any]) =>
case Some(srcList: List[_]) =>
srcList.zipWithIndex.map { case (element, idx) =>
convertFunc(element, pathField ++ List(idx.toString))
}
case Some(singleObject: T) =>
List(singleObject)
case Some(singleObject) =>
List(convertFunc(singleObject, pathField))
case None =>
List()
case unknown =>
Expand Down Expand Up @@ -196,9 +196,9 @@ object ParseUtils {
}
}

def asMap(src: Any, path: List[String]): Map[Any, Any] = {
def asMap(src: Any, path: List[String]): Map[_, _] = {
src match {
case srcMap: Map[Any, Any] =>
case srcMap: Map[_, _] =>
srcMap
case unknown =>
throw YAMLParseException.badType("map", unknown, path)
Expand All @@ -211,14 +211,14 @@ object ParseUtils {
def asMapStrStr(src: Any, path: List[String]): Map[String, String] =
anyMapToStrStrMap(asMap(src, path), path)

def anyMapToStrMap(anyMap: Map[Any, Any], path: List[String]): Map[String, Any] = {
def anyMapToStrMap[V](anyMap: Map[_, V], path: List[String]): Map[String, V] = {
anyMap.map { case (key, value) =>
val keyStr = asStr(key, path)
keyStr -> value
}
}

def anyMapToStrStrMap(anyMap: Map[Any, Any], path: List[String]): Map[String, String] = {
def anyMapToStrStrMap(anyMap: Map[_, _], path: List[String]): Map[String, String] = {
anyMap.map { case (key, value) =>
val keyStr = asStr(key, path)
val valueStr = asStr(value, path ++ List(keyStr))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ object ValidationSpec {
fromString(x.toString, path)
case x: Long =>
fromString(x.toString, path)
case srcMap: Map[Any, Any] =>
case srcMap: Map[_, _] =>
fromMap(ParseUtils.anyMapToStrMap(srcMap, path), path)
case _ =>
throw YAMLParseException.badType("string or map", src, path)
Expand Down

0 comments on commit 1f5ff3c

Please sign in to comment.