diff options
| author | Michael Williamson <mike@zwobble.org> | 2016-05-25 22:56:28 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2016-05-25 22:56:28 +0100 |
| commit | 6902fb4b752641f953b7701d67550f2de04912e9 (patch) | |
| tree | 6ecd877d92b89149d1b83b39ad9b6e58efc48510 | |
| parent | 9e8bf0001082d7836b7a672373e2800f26bbece4 (diff) | |
Add Hello world example for Java to C#
| -rw-r--r-- | README.md | 37 | ||||
| -rw-r--r-- | examples/hello-world/couscous.json | 11 | ||||
| -rw-r--r-- | examples/hello-world/src/main/java/com/example/Example.java | 7 |
3 files changed, 50 insertions, 5 deletions
@@ -2,15 +2,30 @@ Convert Java source code to other languages. C# and Python currently supported. -## Usage +## Hello world: Java to C# -1. Build the JAR: +1. Build the JAR: ``` mvn package -Dmaven.test.skip=true ``` -2. Create a file called `couscous.json`: +2. Create a Java source file: + + ```java + package com.example; + + public class Example { + public static void main() { + System.out.println("Hello world"); + } + } + ``` + + Assuming the normal Maven layout, + this file should be at `src/main/java/com/example/Example.java`. + +3. Create a file called `couscous.json`: ``` { @@ -21,16 +36,28 @@ Convert Java source code to other languages. C# and Python currently supported. "files": [ "src/main/java/com/example", ], - "output": "dotnet/Example/generated.cs", + "output": "dotnet/generated.cs", "namespace": "Example" } ``` -3. In the directory containing `couscous.json`: +4. In the directory containing `couscous.json`: ``` java -jar path/to/couscous.jar ``` + + This should generate the file `dotnet/generated.cs`, which looks something like: + + ```csharp + namespace Example.com.example { + internal class Example { + public static void main() { + (Example.java.lang.System._out).println("Hello world"); + } + } + } + ``` ## TODO diff --git a/examples/hello-world/couscous.json b/examples/hello-world/couscous.json new file mode 100644 index 0000000..e6f27a9 --- /dev/null +++ b/examples/hello-world/couscous.json @@ -0,0 +1,11 @@ +{ + "backend": "csharp", + "sourcepath": [ + "src/main/java" + ], + "files": [ + "src/main/java" + ], + "output": "dotnet/generated.cs", + "namespace": "Example" +} diff --git a/examples/hello-world/src/main/java/com/example/Example.java b/examples/hello-world/src/main/java/com/example/Example.java new file mode 100644 index 0000000..3fb932f --- /dev/null +++ b/examples/hello-world/src/main/java/com/example/Example.java @@ -0,0 +1,7 @@ +package com.example; + +public class Example { + public static void main() { + System.out.println("Hello world"); + } +} |
