diff options
author | Jan Christopher Vogt <oss.nsp@cvogt.org> | 2016-09-28 21:29:26 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-09-28 21:29:26 -0400 |
commit | 9d3c9e9087a6dc0a4445f9428e02f6e7612470c6 (patch) | |
tree | ab1aef0726e71ff1ad760b6574489dc20b2d1950 /stage1/Stage1Lib.scala | |
parent | ab5ebf2577146b6d8e7c54db4d6bf9ba6230ab57 (diff) | |
parent | 9b4b9e0c7a747972229fe9dbabe4b6e546c29f4d (diff) | |
download | cbt-9d3c9e9087a6dc0a4445f9428e02f6e7612470c6.tar.gz cbt-9d3c9e9087a6dc0a4445f9428e02f6e7612470c6.tar.bz2 cbt-9d3c9e9087a6dc0a4445f9428e02f6e7612470c6.zip |
Merge pull request #235 from cvogt/dotty
Dotty plugin and example project.
Diffstat (limited to 'stage1/Stage1Lib.scala')
-rw-r--r-- | stage1/Stage1Lib.scala | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/stage1/Stage1Lib.scala b/stage1/Stage1Lib.scala index bbb6f7b..c427b77 100644 --- a/stage1/Stage1Lib.scala +++ b/stage1/Stage1Lib.scala @@ -101,13 +101,19 @@ class Stage1Lib( val logger: Logger ) extends BaseLib{ } else ExitCode.Success } - def runMain(cls: String, args: Seq[String], classLoader: ClassLoader ): ExitCode = { + def runMain( cls: String, args: Seq[String], classLoader: ClassLoader, fakeInstance: Boolean = false ): ExitCode = { + import java.lang.reflect.Modifier logger.lib(s"Running $cls.main($args) with classLoader: " ++ classLoader.toString) trapExitCode{ - classLoader - .loadClass(cls) - .getMethod( "main", classOf[Array[String]] ) - .invoke( null, args.toArray.asInstanceOf[AnyRef] ) + val c = classLoader.loadClass(cls) + val m = c.getMethod( "main", classOf[Array[String]] ) + val instance = + if(!fakeInstance) null else c.newInstance + assert( + fakeInstance || (m.getModifiers & java.lang.reflect.Modifier.STATIC) > 0, + "Cannot run non-static method " ++ cls+".main" + ) + m.invoke( instance, args.toArray.asInstanceOf[AnyRef] ) ExitCode.Success } } |