Feat:动态代码编译引擎成熟!
This commit is contained in:
parent
8798d4784d
commit
2f2ae4b6ef
@ -0,0 +1,6 @@
|
|||||||
|
package com.flyfish.framework.beans.enums;
|
||||||
|
|
||||||
|
public enum RestBeanCandidate {
|
||||||
|
|
||||||
|
REPOSITORY, SERVICE, CONTROLLER
|
||||||
|
}
|
@ -8,6 +8,7 @@ import com.flyfish.framework.compiler.DynamicJavaCompiler;
|
|||||||
import com.flyfish.framework.compiler.support.JavaSource;
|
import com.flyfish.framework.compiler.support.JavaSource;
|
||||||
import com.flyfish.framework.compiler.template.TemplateCompiler;
|
import com.flyfish.framework.compiler.template.TemplateCompiler;
|
||||||
import com.flyfish.framework.utils.Assert;
|
import com.flyfish.framework.utils.Assert;
|
||||||
|
import com.flyfish.framework.utils.StringFormats;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.lang3.ArrayUtils;
|
import org.apache.commons.lang3.ArrayUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
@ -41,7 +42,10 @@ public class RestBeanAutoConfigure implements ImportBeanDefinitionRegistrar, Res
|
|||||||
// 预编译模板
|
// 预编译模板
|
||||||
private final Map<String, Function<JavaSource, String>> templates = Stream.of("Repository", "Service", "Controller")
|
private final Map<String, Function<JavaSource, String>> templates = Stream.of("Repository", "Service", "Controller")
|
||||||
.collect(Collectors.toMap(key -> key, filename -> TemplateCompiler.compile("/templates/" + filename + ".tpl")));
|
.collect(Collectors.toMap(key -> key, filename -> TemplateCompiler.compile("/templates/" + filename + ".tpl")));
|
||||||
|
// 存放父类值的映射
|
||||||
private final Map<String, Function<RestBean, Class<?>>> superClasses;
|
private final Map<String, Function<RestBean, Class<?>>> superClasses;
|
||||||
|
// 编译器引用
|
||||||
|
private final DynamicJavaCompiler compiler = DynamicJavaCompiler.delegate();
|
||||||
|
|
||||||
// 资源加载器
|
// 资源加载器
|
||||||
private ResourceLoader resourceLoader;
|
private ResourceLoader resourceLoader;
|
||||||
@ -68,8 +72,6 @@ public class RestBeanAutoConfigure implements ImportBeanDefinitionRegistrar, Res
|
|||||||
Set<String> basePackages = getBasePackages(metadata);
|
Set<String> basePackages = getBasePackages(metadata);
|
||||||
// 扫描包路径,检测RestBean注解的bean
|
// 扫描包路径,检测RestBean注解的bean
|
||||||
Reflections reflections = new Reflections(basePackages);
|
Reflections reflections = new Reflections(basePackages);
|
||||||
// 编译器
|
|
||||||
DynamicJavaCompiler compiler = DynamicJavaCompiler.delegate();
|
|
||||||
// repo注册器
|
// repo注册器
|
||||||
CustomRepositoryRegistrar repositoryRegistrar = new CustomRepositoryRegistrar(metadata, resourceLoader,
|
CustomRepositoryRegistrar repositoryRegistrar = new CustomRepositoryRegistrar(metadata, resourceLoader,
|
||||||
environment, registry, beanNameGenerator);
|
environment, registry, beanNameGenerator);
|
||||||
@ -84,7 +86,7 @@ public class RestBeanAutoConfigure implements ImportBeanDefinitionRegistrar, Res
|
|||||||
.setBeanClass(clazz.getCanonicalName())
|
.setBeanClass(clazz.getCanonicalName())
|
||||||
.setQueryBeanClass(restBean.queryClass().getCanonicalName())
|
.setQueryBeanClass(restBean.queryClass().getCanonicalName())
|
||||||
.setPackageName(basePackages.stream().findFirst().orElse("com.flyfish.project"))
|
.setPackageName(basePackages.stream().findFirst().orElse("com.flyfish.project"))
|
||||||
.setUri(restBean.value());
|
.setUri(StringUtils.isBlank(restBean.value()) ? StringFormats.camel2Line(clazz.getSimpleName()) : restBean.value());
|
||||||
// 分别生成实现类,从repo到controller
|
// 分别生成实现类,从repo到controller
|
||||||
templates.forEach((key, template) -> {
|
templates.forEach((key, template) -> {
|
||||||
source.setSuperClass(superClasses.get(key).apply(restBean).getCanonicalName());
|
source.setSuperClass(superClasses.get(key).apply(restBean).getCanonicalName());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user