Skip to content

Commit 15dfcc3

Browse files
authored
Merge pull request #2470 from mhatano/mhatano-patch-1
2 parents 443bf81 + c7a78be commit 15dfcc3

File tree

2 files changed

+18
-19
lines changed

2 files changed

+18
-19
lines changed

examples/HelloWorld.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
class HelloWorld {
22
public static void main(String[] args) {
33
System.out.println("Hello, World!");
4+
System.out.println("سلام");
45
}
56
}

lib/grammars/java.js

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,30 @@
11
"use babel"
2-
3-
/*
4-
* decaffeinate suggestions:
5-
* DS102: Remove unnecessary code created because of implicit returns
6-
* DS207: Consider shorter variations of null checks
7-
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
8-
*/
92
import path from "path"
103
import GrammarUtils from "../grammar-utils"
114
const { command } = GrammarUtils
125

13-
const windows = GrammarUtils.OperatingSystem.isWindows()
6+
function JavaArgs(filepath, context) {
7+
const sourcePath = GrammarUtils.Java.getProjectPath(context)
8+
const className = GrammarUtils.Java.getClassName(context)
9+
const classPackages = GrammarUtils.Java.getClassPackage(context)
10+
const tempFolder = GrammarUtils.createTempFolder("jar-")
11+
const cmd = `javac -encoding UTF-8 -sourcepath '${sourcePath}' -d '${tempFolder}' '${filepath}' && java -D'file.encoding'='UTF-8' -cp '${tempFolder}' ${classPackages}${className}`
12+
return GrammarUtils.formatArgs(cmd)
13+
}
1414

1515
export const Java = {
16+
"Selection Based": {
17+
command,
18+
args(context) {
19+
const code = context.getCode()
20+
const tmpFile = GrammarUtils.createTempFileWithCode(code, ".java")
21+
return JavaArgs(tmpFile, context)
22+
},
23+
},
1624
"File Based": {
1725
command,
1826
args(context) {
19-
const className = GrammarUtils.Java.getClassName(context)
20-
const classPackages = GrammarUtils.Java.getClassPackage(context)
21-
const sourcePath = GrammarUtils.Java.getProjectPath(context)
22-
if (windows) {
23-
return [`/c javac -Xlint ${context.filename} && java ${className}`]
24-
} else {
25-
return [
26-
"-c",
27-
`javac -J-Dfile.encoding=UTF-8 -sourcepath '${sourcePath}' -d /tmp '${context.filepath}' && java -Dfile.encoding=UTF-8 -cp /tmp:%CLASSPATH ${classPackages}${className}`,
28-
]
29-
}
27+
return JavaArgs(context.filepath, context)
3028
},
3129
},
3230
}

0 commit comments

Comments
 (0)