维护列表

master
Qin Dong Ming 2024-08-30 22:02:57 +08:00
parent 2d58f352e0
commit 0f5c517bb2
4 changed files with 12714 additions and 0 deletions

View File

@ -0,0 +1,79 @@
package com.muyu.calss;
import lombok.extern.log4j.Log4j2;
import org.springframework.stereotype.Component;
import javax.tools.*;
import java.io.IOException;
import java.io.Writer;
import java.util.Arrays;
/**
* @Authorqdm
* @Packagecom.muyu.calss
* @Projectcloud-etl-engine
* @nameClassSource
* @Date2024/8/30 21:44
*/
@Component
@Log4j2
public class ClassSource {
public static void main(String[] args) {
//定义类名和源代码
String className = "MyDynamicClass";
String sourceCode = "public class" + className + "{public String name}";
//编译代码
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
ClassLoader systemClassLoader = ClassLoader.getSystemClassLoader();
try {
Class<?> aClass = systemClassLoader.loadClass(className);
//使用反射创建实例
try {
Object o = aClass.newInstance();
} catch (InstantiationException e) {
throw new RuntimeException(e);
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
}
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
DiagnosticCollector<JavaFileObject> diagnostics = new DiagnosticCollector<>();
// 假设您已经有了一个JavaFileManager的实例这里使用默认的
StandardJavaFileManager fileManager = compiler.getStandardFileManager(diagnostics, null, null);
// 编译选项
Iterable<? extends String> options = Arrays.asList("-source", "8");
// 源代码文件这里需要JavaFileObject的实例这里只是示例您需要根据实际情况创建
Iterable<? extends JavaFileObject> sourceFiles = Arrays.asList(
);
// 创建编译任务
JavaCompiler.CompilationTask task1 = compiler.getTask((Writer) null, (JavaFileManager) fileManager, diagnostics, (Iterable<String>) options, null, sourceFiles);
// 执行编译任务
boolean success = task1.call();
log.info(success);
// 处理编译结果(例如,打印诊断信息)
for (Diagnostic<? extends JavaFileObject> diagnostic : diagnostics.getDiagnostics()) {
System.out.format("Error on line %d in %s%n",
diagnostic.getLineNumber(),
diagnostic.getSource().toUri());
}
// 关闭文件管理器
try {
fileManager.close();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}

View File

@ -0,0 +1,47 @@
package com.muyu.calss;
import lombok.Data;
/**
* @Authorqdm
* @Packagecom.muyu.calss
* @Projectcloud-etl-engine
* @nameMyDynamicClass
* @Date2024/8/30 22:01
*/
@Data
public class MyDynamicClass {
private String name;
private String description;
private String ruleContent;
private String versionClass;
private String versionCode;
private String versionName;
private String ruleClass;
private String ruleMethod;
private String ruleMethodDesc;
private String ruleMethodParam;
private String ruleMethodReturn;
private String ruleMethodType;
private String ruleMethodTypeDesc;
private String ruleMethodTypeParam;
private String ruleMethodTypeReturn;
private String ruleMethodTypeParamDesc;
private String ruleMethodTypeReturnDesc;
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff