运行 来自锡兰的锡兰类型检查器,如 typechecker/src/main/Main。java

Running the ceylon typechecker from ceylon, like in typechecker/src/main/Main.java

我正在 运行从锡兰项目中使用 run.ceylon 来安装锡兰类型检查器,它正是 typechecker/src/main/Main.java 的锡兰版本。

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

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

文件:source/com/example/withmodule/module.锡兰

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.锡兰

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();
}

编译没有错误。

但是当 运行ning 时它会产生错误:

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.

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

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

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

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

希望对您有所帮助。