diff --git a/examples/HelloWorld.java b/examples/HelloWorld.java index 3b449d9e..ada42c6b 100644 --- a/examples/HelloWorld.java +++ b/examples/HelloWorld.java @@ -1,5 +1,6 @@ class HelloWorld { public static void main(String[] args) { System.out.println("Hello, World!"); + System.out.println("سلام"); } } diff --git a/lib/grammars/java.js b/lib/grammars/java.js index 09126d65..eac62878 100644 --- a/lib/grammars/java.js +++ b/lib/grammars/java.js @@ -1,32 +1,30 @@ "use babel" - -/* - * decaffeinate suggestions: - * DS102: Remove unnecessary code created because of implicit returns - * DS207: Consider shorter variations of null checks - * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md - */ import path from "path" import GrammarUtils from "../grammar-utils" const { command } = GrammarUtils -const windows = GrammarUtils.OperatingSystem.isWindows() +function JavaArgs(filepath, context) { + const sourcePath = GrammarUtils.Java.getProjectPath(context) + const className = GrammarUtils.Java.getClassName(context) + const classPackages = GrammarUtils.Java.getClassPackage(context) + const tempFolder = GrammarUtils.createTempFolder("jar-") + const cmd = `javac -encoding UTF-8 -sourcepath '${sourcePath}' -d '${tempFolder}' '${filepath}' && java -D'file.encoding'='UTF-8' -cp '${tempFolder}' ${classPackages}${className}` + return GrammarUtils.formatArgs(cmd) +} export const Java = { + "Selection Based": { + command, + args(context) { + const code = context.getCode() + const tmpFile = GrammarUtils.createTempFileWithCode(code, ".java") + return JavaArgs(tmpFile, context) + }, + }, "File Based": { command, args(context) { - const className = GrammarUtils.Java.getClassName(context) - const classPackages = GrammarUtils.Java.getClassPackage(context) - const sourcePath = GrammarUtils.Java.getProjectPath(context) - if (windows) { - return [`/c javac -Xlint ${context.filename} && java ${className}`] - } else { - return [ - "-c", - `javac -J-Dfile.encoding=UTF-8 -sourcepath '${sourcePath}' -d /tmp '${context.filepath}' && java -Dfile.encoding=UTF-8 -cp /tmp:%CLASSPATH ${classPackages}${className}`, - ] - } + return JavaArgs(context.filepath, context) }, }, }