2

我正在从一个带有 run.ceylon 的锡兰项目运行锡兰类型检查器,它正是 typechecker/src/main/Main.java 的锡兰版本。

这个项目应该自己进行类型检查。

它编译没有错误,但在运行时无法加载依赖项以进行类型检查。

文件:source/com/example/withmodule/module.ceylon

native("jvm")
module com.example.withmodule "1.0" {
    import com.redhat.ceylon.typechecker "1.3.0" ;
    //import     com.redhat.ceylon.module-resolver "1.3.0";
}

文件:source/com/example/withmodule/run.ceylon

import java.io{File}
import com.redhat.ceylon.cmr.api{RepositoryManager}
import com.redhat.ceylon.cmr.ceylon{CeylonUtils}
import com.redhat.ceylon.compiler.typechecker{TypeCheckerBuilder}
import com.redhat.ceylon.compiler.typechecker.io.cmr.impl{LeakingLogger}

shared void run(){

   value args = ["/absolutepath/ceylon-1.3.0/source/"];


    RepositoryManager repositoryManager = 
            CeylonUtils.repoManager()
                .systemRepo("/absolutepath/ceylon-1.3.0/repo")
                .logger( LeakingLogger())
                .buildManager();

    TypeCheckerBuilder tcb = 
              TypeCheckerBuilder()
                .setRepositoryManager(repositoryManager)
                .verbose(true)
                .statistics(true);

    for (String path in args) {
        tcb.addSrcDirectory( File(path));
    }

    tcb.typeChecker.process();
}

它编译没有错误。

但是在运行时会产生错误:

error [package not found in imported modules: 'com.redhat.ceylon.cmr.api' (add module import to module descriptor of 'com.example.withmodule')] at 2:7-2:31 of com/example/withmodule/withmodule.ceylon
error [package not found in imported modules: 'com.redhat.ceylon.cmr.ceylon' (add module import to module descriptor of 'com.example.withmodule')] at 3:7-3:34 of com/example/withmodule/withmodule.ceylon
error [package not found in imported modules: 'com.redhat.ceylon.compiler.typechecker' (add module import to module descriptor of 'com.example.withmodule')] at 4:7-4:44 of com/example/withmodule/withmodule.ceylon
error [package not found in imported modules: 'com.redhat.ceylon.compiler.typechecker.io.cmr.impl' (add module import to module descriptor of 'com.example.withmodule')] at 5:7-5:56 of com/example/withmodule/withmodule.ceylon

这对我来说毫无意义,因为编译和类型检查之前已经成功。

这是一个全新的 ceylon 1.3.0 下载,未安装,只需从解压缩的 .tar.gz 运行即可。

类型检查器需要哪些它没有的额外信息?

4

1 回答 1

2

所以这里的问题是我们在测试运行typechecker/src/main/Main.java器中使用的类型检查器只能理解 Ceylon 源代码中定义的东西。它无法读取已编译的 Java.jar存档并针对该存档中的类对您的 Ceylon 源代码进行类型检查。

因此,为了能够对依赖于 Java 二进制文件的 Ceylon 代码进行类型检查,您将需要更多的基础设施,包括我们所谓的“模型加载器”,它负责构建 Java 二进制文件的 Ceylonic 模型.class。Ceylon 生态系统中有许多不同的模型加载器——一个用于 . javac,一个用于 Eclipse,一个用于 IntelliJ,一个使用 Java 反射,一个用于 Dart,一个用于 typescript,一个用于 JS——它们都非常特定于特定的编译环境。

因此,不依赖于javac、IntelliJ、Eclipse 等的 Ceylon 类型检查器的测试不具有任何类型的 Java 互操作性。您的代码可以成功地对 Ceylon 源代码中定义的内容进行类型检查,包括依赖于 Ceylon 模块以及.src由 Ceylon 编译器生成的存档的代码,但它无法对 Java.jar存档中定义的内容进行类型检查。

我希望这会有所帮助。

于 2016-10-13T08:15:59.137 回答