Skip to content

Commit

Permalink
Merge pull request #522 from retronym/topic/jdk-9-10-parser
Browse files Browse the repository at this point in the history
WIP Support new constants in JDK 9 and 10
  • Loading branch information
jvican authored Apr 9, 2018
2 parents 88480f8 + c71ab53 commit 37d1a77
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,15 @@ private[sbt] object Analyze {
readAPI: (File, Seq[Class[_]]) => Set[(String, String)]): Unit = {
val sourceMap = sources.toSet[File].groupBy(_.getName)

def load(tpe: String, errMsg: => Option[String]): Option[Class[_]] =
try { Some(Class.forName(tpe, false, loader)) } catch {
case e: Throwable => errMsg.foreach(msg => log.warn(msg + " : " + e.toString)); None
}
def load(tpe: String, errMsg: => Option[String]): Option[Class[_]] = {
if (tpe.endsWith("module-info")) None
else
try {
Some(Class.forName(tpe, false, loader))
} catch {
case e: Throwable => errMsg.foreach(msg => log.warn(msg + " : " + e.toString)); None
}
}

val classNames = mutable.Set.empty[String]
val sourceToClassFiles = mutable.HashMap[File, Buffer[ClassFile]](
Expand All @@ -48,7 +53,8 @@ private[sbt] object Analyze {
_ <- classFile.sourceFile orElse guessSourceName(newClass.getName);
source <- guessSourcePath(sourceMap, classFile, log);
binaryClassName = classFile.className;
loadedClass <- load(binaryClassName, Some("Error reading API from class file"))) {
loadedClass <- load(binaryClassName,
Some("Error reading API from class file: " + binaryClassName))) {
binaryClassNameToLoadedClass.update(binaryClassName, loadedClass)

def loadEnclosingClass(clazz: Class[_]): Option[String] = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,5 +106,8 @@ private[sbt] object Constants {
final val ConstantMethodHandle = 15
final val ConstantMethodType = 16
final val ConstantInvokeDynamic = 18
final val ConstantModule = 19
final val ConstantPackage = 20
final val ConstantDynamic = 17 // http://openjdk.java.net/jeps/309
final val ClassDescriptor = 'L'
}
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,16 @@ private[sbt] object Parser {
in.readUnsignedShort()
in.readUnsignedShort()
Constant(tag, -1, -1, None)
case ConstantModule =>
in.readUnsignedShort()
Constant(tag, -1, -1, None)
case ConstantPackage =>
in.readUnsignedShort()
Constant(tag, -1, -1, None)
case ConstantDynamic =>
in.readUnsignedShort()
in.readUnsignedShort()
Constant(tag, -1, -1, None)
case _ => sys.error("Unknown constant: " + tag)
}
}
Expand Down

0 comments on commit 37d1a77

Please sign in to comment.