Skip to content

Commit e755486

Browse files
ZhiFengJiajiazhifeng
authored andcommitted
feat:支持编译package语句
1 parent bdf981e commit e755486

File tree

5 files changed

+36
-23
lines changed

5 files changed

+36
-23
lines changed

remote-core/src/main/java/com/jzf/remote/core/HotSwapClassLoader.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,6 @@ protected Class<?> findClass(String name) {
3434
} catch (IOException e) {
3535
System.out.println(e.getMessage());
3636
}
37-
return super.defineClass(name, modiBytes, 0, modiBytes.length);
37+
return super.defineClass(name.replaceAll("/","."), modiBytes, 0, modiBytes.length);
3838
}
3939
}

remote-web/src/main/java/com/jzf/remote/web/controller/RemoteDebugController.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ public class RemoteDebugController {
3232
*/
3333
@PostMapping("/executeJavaSourceCode")
3434
public String executeJavaSourceCode(String className, String sourceCode) throws Exception {
35-
className = className.substring(className.lastIndexOf("\\") + 1, className.lastIndexOf("."));
3635
return JavaFileExecuter.execute(className, sourceCode);
3736
}
3837
}

remote-web/src/main/java/com/jzf/remote/web/controller/projectController.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,12 @@ public class projectController {
2323

2424
@PostMapping("/getFile")
2525
public String getFile(String filePath) throws IOException {
26-
return FileUtils.readFileToString(new File(TreeUtils.fileDirectory + filePath), Charset.forName("UTF-8"));
26+
File file = new File(TreeUtils.fileDirectory + filePath);
27+
if (file.isFile()){
28+
return FileUtils.readFileToString(file, Charset.forName("UTF-8"));
29+
}else{
30+
return "";
31+
}
2732
}
2833

2934
@GetMapping("/tree")

remote-web/src/main/resources/static/RemoteDebug.html

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -124,25 +124,34 @@
124124
editor.setSize('auto', '620');
125125

126126
function getFileByPath(filePath) {
127-
console.log(filePath);
128-
if( /^.*\.java$/.test(filePath)){
129-
console.log("正在从服务器获取文件内容");
130-
var form = new FormData();
131-
form.append("filePath", filePath);
132-
var settings = {
133-
"url": "/project/getFile",
134-
"method": "POST",
135-
"timeout": 0,
136-
"processData": false,
137-
"mimeType": "multipart/form-data",
138-
"contentType": false,
139-
"data": form
140-
};
141-
$.ajax(settings).done(function (response) {
142-
$('#SourceCodeFileName').text(filePath);
143-
editor.setValue(response);
144-
});
145-
}
127+
console.log("当前选择的节点:" + filePath);
128+
var form = new FormData();
129+
form.append("filePath", filePath[0]);
130+
var settings = {
131+
"url": "/project/getFile",
132+
"method": "POST",
133+
"timeout": 0,
134+
"processData": false,
135+
"mimeType": "multipart/form-data",
136+
"contentType": false,
137+
"data": form
138+
};
139+
$.ajax(settings).done(function (response) {
140+
if(response.valueOf() == ""){
141+
console.log("当前选择的节点是文件夹");
142+
return;
143+
}
144+
editor.setValue(response);
145+
146+
var packageStr = editor.getLine(0);
147+
var className = filePath[0].substring(filePath[0].lastIndexOf("\\") + 1,filePath[0].lastIndexOf("."));
148+
if(/^package.*$/.test(packageStr)){
149+
className = packageStr.substring(8,packageStr.indexOf(";")) + "/" + className;
150+
className = className.replace(/\./g,"/");
151+
}
152+
console.log("className:" + className);
153+
$('#SourceCodeFileName').text(className);
154+
});
146155
}
147156

148157
$('#execute').click(function () {

remote-web/src/test/java/com/jzf/remote/web/model/dto/TreeDTOTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public void test2() {
5454
public void test3() {
5555
String className = "\\DemoProject\\RemoteClassLoader.java";
5656
System.out.println(className);
57-
className = className.substring(className.lastIndexOf("\\"), className.lastIndexOf("."));
57+
className = className.substring(className.lastIndexOf("\\") + 1, className.lastIndexOf("."));
5858
System.out.println(className);
5959
}
6060
}

0 commit comments

Comments
 (0)