mirror of
https://github.com/alibaba/arthas.git
synced 2024-04-21 10:21:39 +00:00
clean code in MemoryCompiler
This commit is contained in:
+1
-18
@@ -1,8 +1,6 @@
|
||||
package com.taobao.arthas.core.command.klass100;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.Writer;
|
||||
import java.lang.instrument.Instrumentation;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.List;
|
||||
@@ -89,22 +87,7 @@ public class MemoryCompilerCommand extends AnnotatedCommand {
|
||||
}
|
||||
}
|
||||
|
||||
DynamicCompiler dynamicCompiler = new DynamicCompiler(classloader, new Writer() {
|
||||
@Override
|
||||
public void write(char[] cbuf, int off, int len) throws IOException {
|
||||
process.write(new String(cbuf, off, len));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void flush() throws IOException {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
DynamicCompiler dynamicCompiler = new DynamicCompiler(classloader);
|
||||
|
||||
Charset charset = Charset.defaultCharset();
|
||||
if (encoding != null) {
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.taobao.arthas.compiler;
|
||||
|
||||
import java.io.Writer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
@@ -25,18 +24,11 @@ public class DynamicCompiler {
|
||||
private final List<Diagnostic<? extends JavaFileObject>> errors = new ArrayList<Diagnostic<? extends JavaFileObject>>();
|
||||
private final List<Diagnostic<? extends JavaFileObject>> warnings = new ArrayList<Diagnostic<? extends JavaFileObject>>();
|
||||
|
||||
private Writer writer;
|
||||
|
||||
public DynamicCompiler(ClassLoader classLoader) {
|
||||
this(classLoader, null);
|
||||
}
|
||||
|
||||
public DynamicCompiler(ClassLoader classLoader, Writer writer) {
|
||||
standardFileManager = javaCompiler.getStandardFileManager(null, null, null);
|
||||
|
||||
options.add("-Xlint:unchecked");
|
||||
dynamicClassLoader = new DynamicClassLoader(classLoader);
|
||||
this.writer = writer;
|
||||
}
|
||||
|
||||
public void addSource(String className, String source) {
|
||||
@@ -89,7 +81,7 @@ public class DynamicCompiler {
|
||||
|
||||
return dynamicClassLoader.getClasses();
|
||||
} catch (Throwable e) {
|
||||
throw new DynamicCompilerException(e);
|
||||
throw new DynamicCompilerException(e, errors);
|
||||
} finally {
|
||||
compilationUnits.clear();
|
||||
|
||||
@@ -139,7 +131,7 @@ public class DynamicCompiler {
|
||||
|
||||
return dynamicClassLoader.getByteCodes();
|
||||
} catch (ClassFormatError e) {
|
||||
throw new DynamicCompilerException(e);
|
||||
throw new DynamicCompilerException(e, errors);
|
||||
} finally {
|
||||
compilationUnits.clear();
|
||||
|
||||
|
||||
+2
-1
@@ -33,8 +33,9 @@ public class DynamicCompilerException extends RuntimeException {
|
||||
this.diagnostics = diagnostics;
|
||||
}
|
||||
|
||||
public DynamicCompilerException(Throwable cause) {
|
||||
public DynamicCompilerException(Throwable cause, List<Diagnostic<? extends JavaFileObject>> diagnostics) {
|
||||
super(cause);
|
||||
this.diagnostics = diagnostics;
|
||||
}
|
||||
|
||||
private List<Map<String, Object>> getErrorList() {
|
||||
|
||||
Reference in New Issue
Block a user