从IntelliJ

时间:2017-01-22 16:30:03

标签: ceylon

通过右键单击某个功能并选择“运行functionName'”,我设法在'Walkthrough' repository中编译并执行Cyelon代码。

我还尝试创建自己的Ceylon项目(名为POSTtoFile),看看我是否可以执行“Hello World'功能从那里。我不能。我想我必须为我的项目创建某种构建配置,但我不知道填写这些表单字段的内容:

enter image description here

Installing Ceylon IDE for IntelliJ指南对此问题完全保持沉默。如果它包含了一个名为'制作你的第一个锡兰项目的部分,那将是很好的。知道该文件的所有先前读者必须事先知道这些东西,这很令人尴尬。所以我来了!唯一的例外。

在“锡兰”模块中'下拉,有一个名为module default "unversioned"的选项。我尝试选择那个,然后点击'运行' - > '运行POSTtoFile'。我得到了这个输出:

"C:\Program Files\Java\jdk1.8.0_121\bin\java" -Dceylon.system.repo=C:\Users\Jon\.IdeaIC2016.3\config\plugins\CeylonIDEA\classes\embeddedDist\repo -Didea.launcher.port=7536 "-Didea.launcher.bin.path=C:\Program Files (x86)\JetBrains\IntelliJ IDEA Community Edition 2016.3.3\bin" -Dfile.encoding=windows-1252 -classpath "C:\Users\Jon\.IdeaIC2016.3\config\plugins\CeylonIDEA\classes\embeddedDist\lib\ceylon-bootstrap.jar;C:\Program Files (x86)\JetBrains\IntelliJ IDEA Community Edition 2016.3.3\lib\idea_rt.jar" com.intellij.rt.execution.application.AppMain com.redhat.ceylon.launcher.Bootstrap run --run "" default/unversioned
ceylon run: Module default/unversioned not found in the following repositories:
 C:\Users\Jon\.IdeaIC2016.3\config\plugins\CeylonIDEA\classes\embeddedDist\repo
 C:\Users\Jon\Auchitect\POSTtoFile\modules
 C:\Users\Jon\.ceylon\cache
 https://modules.ceylon-lang.org/repo/1
 [Maven] Aether
 [NPM] npm

Process finished with exit code 1

编辑:

从下面的屏幕截图中可以看出,我在IntelliJ窗口的底部没有工具栏,我看不到名为' Ceylon问题的工具窗口':

enter image description here

关于你的其他问题:

  • '模块'文件夹是空的
  • 当我点击Build>Rebuild Project时,IntelliJ似乎正常工作。这是输出:

enter image description here

  • 以下是我的版本号:

enter image description here

  • 当我将下面的代码放在我的main.ceylon文件中时:

    shared void hello(){     打印("你好,世界!"); }

(抱歉,堆栈溢出不会将其格式化为代码,即使每行前面有4个空格)

我在功能hello的左侧显示绿色箭头,但我无法点击它。它说'这里没什么'':

enter image description here

编辑2: 我尝试将源代码文件(main.ceilon)从根目录(POSTtoFile)移动到源目录(POSTtoFile/source)。 然后我点击了Run - > Run 'POSTtoFile'

这给了我以下新输出:

"C:\Program Files\Java\jdk1.8.0_121\bin\java" -Dceylon.system.repo=C:\Users\Jon\.IdeaIC2016.3\config\plugins\CeylonIDEA\classes\embeddedDist\repo -Didea.launcher.port=7532 "-Didea.launcher.bin.path=C:\Program Files (x86)\JetBrains\IntelliJ IDEA Community Edition 2016.3.3\bin" -Dfile.encoding=windows-1252 -classpath "C:\Users\Jon\.IdeaIC2016.3\config\plugins\CeylonIDEA\classes\embeddedDist\lib\ceylon-bootstrap.jar;C:\Program Files (x86)\JetBrains\IntelliJ IDEA Community Edition 2016.3.3\lib\idea_rt.jar" com.intellij.rt.execution.application.AppMain com.redhat.ceylon.launcher.Bootstrap run --run "" default/unversioned
ceylon run: String index out of range: 0
java.lang.StringIndexOutOfBoundsException: String index out of range: 0
 at java.lang.String.charAt(String.java:658)
 at ceylon.modules.api.runtime.AbstractRuntime.invokeRun(AbstractRuntime.java:53)
 at ceylon.modules.api.runtime.AbstractRuntime.execute(AbstractRuntime.java:105)
 at ceylon.modules.api.runtime.AbstractRuntime.execute(AbstractRuntime.java:101)
 at ceylon.modules.Main.execute(Main.java:69)
 at ceylon.modules.Main.main(Main.java:42)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
 at java.lang.reflect.Method.invoke(Method.java:498)
 at org.jboss.modules.Module.run(Module.java:308)
 at org.jboss.modules.Main.main(Main.java:487)
 at ceylon.modules.bootstrap.CeylonRunTool.run(CeylonRunTool.java:292)
 at com.redhat.ceylon.common.tools.CeylonTool.run(CeylonTool.java:547)
 at com.redhat.ceylon.common.tools.CeylonTool.execute(CeylonTool.java:423)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
 at java.lang.reflect.Method.invoke(Method.java:498)
 at com.redhat.ceylon.launcher.Launcher.runInJava7Checked(Launcher.java:108)
 at com.redhat.ceylon.launcher.Launcher.run(Launcher.java:38)
 at com.redhat.ceylon.launcher.Launcher.run(Launcher.java:31)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
 at java.lang.reflect.Method.invoke(Method.java:498)
 at com.redhat.ceylon.launcher.Bootstrap.runVersion(Bootstrap.java:162)
 at com.redhat.ceylon.launcher.Bootstrap.runInternal(Bootstrap.java:117)
 at com.redhat.ceylon.launcher.Bootstrap.run(Bootstrap.java:93)
 at com.redhat.ceylon.launcher.Bootstrap.main(Bootstrap.java:85)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
 at java.lang.reflect.Method.invoke(Method.java:498)
 at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)

Process finished with exit code 2

这是main.ceilon

的内容
shared void hello() {
    print("Hello , World!");
}

编辑3:

main.ceilon的内容更改为此后:

void hello() {
    print("Hello, World!");
}

hello();

我在执行Run - >时获得此输出Run 'POSTtoFile'

enter image description here

现在我突然在底部工具栏中显示了Ceylon problems按钮!它说我有三个问题:

incorrect syntax: no viable alternative at token end of file.
missing declaration or argument name.
not an annotation constructor: hello

我不明白为什么会出现错误,因为我的代码直接来自Tour of Ceylon

1 个答案:

答案 0 :(得分:3)

同意,文档缺少“IntelliJ入门”部分,本周我将解决这个问题。

以下是在IntelliJ中运行简单项目所需的步骤。

通过File > New > Project创建一个新项目,然后选择Ceylon类别。

New Ceylon project

单击Next并选择是否要在JVM,JS或两者上编译/运行项目:

Ceylon project wizard: choose target platforms

点击Next两次,输入项目名称,然后点击Finish。您的项目现在已准备好托管新的Ceylon代码:

Project structure

在项目视图中,您可以看到一些现有文件和文件夹:

  • .ceylon包含可由CLI工具重用的内部配置,您不必在大多数时间直接修改它。
  • modules是将编译Ceylon模块的输出目录。
  • resource包含resources
  • source包含source modules

要将Ceylon代码添加到此项目,您可以将文件直接放在source文件夹下,以将其添加到default模块,或创建新模块并将源文件添加到此模块。在这两种情况下,.ceylon个文件必须位于source文件夹中,而不是直接位于项目文件夹中。

  • 要将文件添加到default模块,请右键单击source文件夹并选择New > Ceylon File/Declaration,输入名称(例如run),然后点击{ {1}}。
  • 要创建新模块,请右键单击OK文件夹,然后选择source,输入New > Ceylon Module之类的名称,如果不喜欢,请调整版本{{1将可运行的单位名称设置为my.ceylon.example,然后点击1.0.0。将创建新文件夹(run),以及模块描述符(OK),包描述符(my/ceylon/example)和可运行单元(module.ceylon)。

此时,底部工具栏中应该出现一个标题为package.ceylon的工具窗口,表明IDE现在知道该项目包含Ceylon代码并且已正确配置:

Ceylon Problems view

现在项目已经建立,是时候实际添加代码:)。打开run.ceylon并添加以下代码:

Ceylon Problems

左侧排水沟中会出现一个绿色箭头,点击该箭头即可运行或调试run.ceylon功能:

Run Ceylon function

单击shared void run() { print("hello"); } ,这将自动创建运行配置,构建项目并打印run

Running the file prints 'hello'

关于你的上一次错误:

  

语法不正确:文件的令牌末尾没有可行的替代方案。

就像Java及其Run 'run'方法一样,当您在Ceylon中声明一个可运行的函数时,您不必实际手动调用它。 Ceylon运行程序将为您执行此操作(使用CLI时,IDE或hello)。 Ceylon只接受toplevel 声明,而不接受语句,因此当在文件的根目录找到它时,此代码会触发解析错误:

main()

如果您已经尝试过web IDE,这有点误导,因为Web IDE会自动将您的代码包装在ceylon run函数中,因此上述语句永远不会是 toplevel 声明。