From f2d406081c254c35958883622e98b7e81cc4443d Mon Sep 17 00:00:00 2001 From: TangBean <984354469@qq.com> Date: Sat, 16 Feb 2019 20:58:06 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E7=AB=AF=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/org/olexec/compile/StringSourceCompiler.java | 4 +++- src/main/java/org/olexec/execute/ClassModifier.java | 6 ++++++ src/main/resources/application.properties | 3 +-- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/olexec/compile/StringSourceCompiler.java b/src/main/java/org/olexec/compile/StringSourceCompiler.java index 9bcc3ad..4b65bb5 100644 --- a/src/main/java/org/olexec/compile/StringSourceCompiler.java +++ b/src/main/java/org/olexec/compile/StringSourceCompiler.java @@ -13,8 +13,10 @@ public class StringSourceCompiler { private static Map fileObjectMap = new ConcurrentHashMap<>(); - // 使用 Pattern 预编译功能 + + /** 使用 Pattern 预编译功能 */ private static Pattern CLASS_PATTERN = Pattern.compile("class\\s+([$_a-zA-Z][$_a-zA-Z0-9]*)\\s*"); + public static byte[] compile(String source, DiagnosticCollector compileCollector) { JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); JavaFileManager javaFileManager = diff --git a/src/main/java/org/olexec/execute/ClassModifier.java b/src/main/java/org/olexec/execute/ClassModifier.java index 9c9ed0c..9bf91ad 100644 --- a/src/main/java/org/olexec/execute/ClassModifier.java +++ b/src/main/java/org/olexec/execute/ClassModifier.java @@ -41,6 +41,12 @@ public int getConstantPoolCount() { return ByteUtils.byte2Int(classByte, CONSTANT_POOL_COUNT_INDEX, u2); } + /** + * 字节码修改器,替换字节码常量池中 oldStr 为 newStr + * @param oldStr + * @param newStr + * @return 修改后的字节码字节数组 + */ public byte[] modifyUTF8Constant(String oldStr, String newStr) { int cpc = getConstantPoolCount(); int offset = CONSTANT_POOL_COUNT_INDEX + u2; // 真实的常量起始位置 diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 9e3bcad..4b1cbf3 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,2 +1 @@ -spring.freemarker.suffix=.html -server.port=9090 \ No newline at end of file +spring.freemarker.suffix=.html \ No newline at end of file