2016-10-12 102 views
2

我正在運行一個ceylon項目的錫蘭typechecker,其中包含一個run.ceylon,它完全是typechecker/src/main/Main.java。從錫蘭運行錫蘭typechecker,就像typechecker/src/main/Main.java

這個項目應該是自我檢測。

它編譯沒有錯誤,但在運行時無法加載類型檢查的依賴關係。

文件:源極/ COM /示例/ 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"; 
} 

文件:源極/ COM /示例/ 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 

這是沒有意義的我,因爲編譯和類型檢查剛剛之前succeded。

這是一個新鮮的錫蘭1.3.0下載,未安裝,只需從解壓縮的.tar.gz運行即可。

typechecker需要什麼額外的信息,它沒有得到?

+0

Btw喲,我剛剛對即將發佈的1.3.1版本進行了一些更改,您可以通過更簡單的方式設置typechecker +模型加載器:https://gist.github .com/quintesse/004e33e84553abd75412ceb3d164bf4a – Quintesse

回答

2

所以這裏的問題是我們在測試運行器typechecker/src/main/Main.java中使用的typechecker只能夠理解在Ceylon源代碼中定義的東西。它是而不是能夠讀取已編譯的Java .jar存檔並根據該存檔中的類對您的Ceylon源代碼進行類型檢查。因此,爲了能夠檢測依賴於Java二進制文件的Ceylon代碼,您需要更多的基礎架構,包括我們所稱的「模型加載器」,它負責構建Java二進制文件的Ceylonic模型。 Ceylon生態系統中有多個不同的模型加載器— javac,一個用於Eclipse,一個用於IntelliJ,一個用於Java反射,一個用於Dart,一個用於打印腳本,一個用於JS —,它們都非常具體一個特定的編譯環境。

因此,不依賴於javac,IntelliJ,Eclipse等等的Ceylon typechecker的測試沒有任何Java interop功能。您的代碼可以成功查看Ceylon源代碼中定義的東西,包括Ceylon編譯器生成的依賴於Ceylon模塊的代碼,但是它不能查看Java .jar歸檔中定義的東西。

我希望有幫助。

+0

哦,我剛剛得知getTypeChecker(getter)被重寫爲typeChecker(屬性)。我沒有想到在這個領域有這麼多的行業。屬性並不總是很容易。 – Michael

+0

嗨,我們對此進行了一次快速討論,結果可能不是完全簡單的事情。您將不得不查看某個編譯器或IDE的源代碼,以瞭解涉及的內容。 –