2016-08-05 41 views
0

我试图从ceylon.interop.java(CeylonList)派生出一个锡兰类到java单元(用锡兰语来说,这将是称为模块,但java还没有),在包含这个衍生锡兰类的锡兰模块之外。Ceylon和Java之间的互操作性:如何共享从'ceylon.language'的导入

run.ceylon:

import java.util { 
    JList=List 
} 

import ceylon.interop.java { 
    CeylonList 
} 

// CL is deliberately annotated as 'shared' - this is the crucial point !! 
shared class CL(JList<out Integer> jil) extends CeylonList<Integer>(jil) {} 

为了使导入的模块在Java端可见我注释导入的模块在模块描述符作为“共享”。

module.ceylon:

native ("jvm") module com.example.simple "1.0.0" { 
    shared import "java.base" "8"; 
    shared import ceylon.collection "1.2.2"; 
    shared import ceylon.interop.java "1.2.2"; 
} 

但是编译器仍然会报错:

source/com/example/simple/run.ceylon:18: error: supertype of type 'CL' that is visible outside this module comes from an imported module that is not re-exported: 'Collection<Integer>' involves an unexported type declaration 
shared class CL(JList<out Integer> jil) extends CeylonList<Integer>(jil) {} 
       ^
source/com/example/simple/run.ceylon:18: error: supertype of type 'CL' that is visible outside this module comes from an imported module that is not re-exported: 'List<Integer>' involves an unexported type declaration 
shared class CL(JList<out Integer> jil) extends CeylonList<Integer>(jil) {} 
       ^
source/com/example/simple/run.ceylon:18: error: supertype of type 'CL' that is visible outside this module comes from an imported module that is not re-exported: 'Correspondence<Integer,Integer>' involves an unexported type declaration 
shared class CL(JList<out Integer> jil) extends CeylonList<Integer>(jil) {} 
       ^
source/com/example/simple/run.ceylon:18: error: supertype of type 'CL' that is visible outside this module comes from an imported module that is not re-exported: 'Ranged<Integer,Integer,List<Integer>>' involves an unexported type declaration 
shared class CL(JList<out Integer> jil) extends CeylonList<Integer>(jil) {} 

一个解决方案应该是再出口ceylon.language

... 
    shared import ceylon.language "1.2.2"; 
... 

但在一方面ceylon.language是不允许被导入的,所以它不能被注释,也不会被重新导出。

另一方面,我无法发现任何'...未重新导出的导入模块...',因为所有导入的模块都注释为共享。

除了:从run.ceylon类CL然后导入并在Use.java

使用Use.java:

package some.other.package 
// And thus some.other.module if there were 

import com.example.simple.*; 
import java.util.* ; 

public class Use{ 
    public static void main (String[] args) { 

    LinkedList ll = new LinkedList(); 
    ll.add(1); 
    ll.add(2); 

    CL c = new CL(ll); 

    } 
} 

现在的问题是(以上参照错误消息), 1.“CL”类型的超类型在此模块外部是否可见,并且来自未导出的导入模块,以及 2.如何重新导出它?

回答

2

在Ceylon 1.2.2中,您的示例将不起作用,因为Java代码无法在相同模块中使用Ceylon声明。

在尚未发布的Ceylon 1.2.3中,应该支持这个,但是我得到和你一样的错误,并且没有看到示例代码有什么问题。

+0

@ user3464741你会介意在https://github.com/ceylon/ceylon/issues上提供这方面的错误报告吗? –

+0

不好意思,我忘记提到我用锡兰1.2.3每晚编译(上周)编译它。如果我在run.ceylon中放弃'共享'注释,而不是'共享类CL',那么只有'class CL'),那么ceylon声明可以被同一模块中的Java代码使用。但不在模块之外。这需要在run.ceyon中将CL注释为“共享”。正是这导致了错误。 – Michael

+0

当然,我明白。我相信你提到的错误是特定于当前的1.2.3版本。 –