提交 dc7ff27d 编写于 作者: sq3536's avatar sq3536

函数

上级 5a97114a
......@@ -20,6 +20,7 @@ package cn.ibizlab.codegen;
import cn.ibizlab.codegen.config.GlobalSettings;
import cn.ibizlab.codegen.templating.TemplateDefinition;
import cn.ibizlab.codegen.templating.TemplatingEngineAdapter;
import cn.ibizlab.codegen.templating.mustache.*;
import cn.ibizlab.codegen.utils.StringAdvUtils;
import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;
......@@ -40,7 +41,6 @@ import java.util.regex.Pattern;
@Getter
@Setter
@NoArgsConstructor
@Accessors(chain = true)
public class CodegenConfig {
......@@ -108,6 +108,21 @@ public class CodegenConfig {
return templateDefinitions;
}
public CodegenConfig addLambda()
{
additionalProperties.put("lowercase", new LowercaseLambda().generator(this));
additionalProperties.put("uppercase", new UppercaseLambda());
additionalProperties.put("snakecase", new SnakecaseLambda());
additionalProperties.put("titlecase", new TitlecaseLambda());
additionalProperties.put("camelcase", new CamelCaseLambda(true).generator(this));
additionalProperties.put("pascalcase", new CamelCaseLambda(false).generator(this));
additionalProperties.put("indented", new IndentedLambda());
additionalProperties.put("indented_8", new IndentedLambda(8, " "));
additionalProperties.put("indented_12", new IndentedLambda(12, " "));
additionalProperties.put("indented_16", new IndentedLambda(16, " "));
return this;
}
private void scanTemplate(File file,List<TemplateDefinition> templateDefinitions)
{
if(file.isDirectory())
......@@ -121,6 +136,8 @@ public class CodegenConfig {
}
}
@SuppressWarnings("static-method")
public String sanitizeName(String name) {
return sanitizeName(name, "\\W");
......
......@@ -24,6 +24,7 @@ import cn.ibizlab.codegen.templating.*;
import cn.ibizlab.codegen.templating.TemplatePathLocator;
import cn.ibizlab.codegen.templating.TemplateProcessor;
import cn.ibizlab.codegen.templating.TemplatingEngineAdapter;
import cn.ibizlab.codegen.templating.mustache.*;
import lombok.extern.slf4j.Slf4j;
import java.io.*;
......@@ -50,6 +51,7 @@ public class DefaultGenerator implements Generator {
@Override
public Generator opts(CodegenConfig opts) {
this.config = opts;
this.config.addLambda();
modelStorage=ModelStorage.getInstance().config(config);
......@@ -70,7 +72,6 @@ public class DefaultGenerator implements Generator {
this.ignoreProcessor=CodegenIgnoreProcessor.getInstance(ignoreFileLocation,this.config.getOutputDir(),this.config.getTemplateDir());
return this;
}
......
......@@ -124,7 +124,7 @@ public class StringAdvUtils {
* @return camelized string
*/
public static String camelize(final String inputWord, boolean lowercaseFirstLetter) {
Pair<String, Boolean> key = new ImmutablePair<>(inputWord, lowercaseFirstLetter);
Pair<String, Boolean> key = new ImmutablePair<>(underscore(inputWord), lowercaseFirstLetter);
return camelizedWordsCache.get(key, pair -> {
String word = pair.getKey();
......
......@@ -3,5 +3,21 @@ package {{packageName}}.{{module}}.domain;
// {{entity.dataAccCtrlArch}}
public class {{entity.codeName}}
{
{{#pascalcase}}{{entity.codeName}}{{/pascalcase}}
{{#camelcase}}{{entity.codeName}}{{/camelcase}}
{{#snakecase}}{{entity.codeName}}{{/snakecase}}
{{#snakecase}}SNAKECASE{{/snakecase}}
{{#snakecase}}snakeCase{{/snakecase}}
{{#snakecase}}snake_case{{/snakecase}}
{{#camelcase}}camelCase{{/camelcase}}
{{#camelcase}}Camel_case{{/camelcase}}
{{#camelcase}}CAMELCase{{/camelcase}}
{{#camelcase}}CAMELCASE{{/camelcase}}
}
\ No newline at end of file
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册