[weaver-pojo] Implement first prototype of POJO weaving
This commit is contained in:
@@ -5,4 +5,11 @@ public interface NamingFormat {
|
||||
String joinToName(String[] words);
|
||||
|
||||
String name();
|
||||
|
||||
static String convert(String name, NamingFormat from, NamingFormat to) {
|
||||
if (from == to) {
|
||||
return name;
|
||||
}
|
||||
return to.joinToName(from.splitIntoWords(name));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
package de.siphalor.tweed5.namingformat.api;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.ServiceLoader;
|
||||
|
||||
public class NamingFormatCollector {
|
||||
private final Map<String, NamingFormat> namingFormats = new HashMap<>();
|
||||
|
||||
public void setupFormats() {
|
||||
ServiceLoader<NamingFormatProvider> serviceLoader = ServiceLoader.load(NamingFormatProvider.class);
|
||||
Context context = new Context();
|
||||
for (NamingFormatProvider provider : serviceLoader) {
|
||||
provider.provideNamingFormats(context);
|
||||
}
|
||||
}
|
||||
|
||||
public Map<String, NamingFormat> namingFormats() {
|
||||
return Collections.unmodifiableMap(namingFormats);
|
||||
}
|
||||
|
||||
private class Context implements NamingFormatProvider.ProvidingContext {
|
||||
@Override
|
||||
public void registerNamingFormat(String id, NamingFormat namingFormat) {
|
||||
namingFormats.put(id, namingFormat);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package de.siphalor.tweed5.namingformat.api;
|
||||
|
||||
public interface NamingFormatProvider {
|
||||
void provideNamingFormats(ProvidingContext context);
|
||||
|
||||
interface ProvidingContext {
|
||||
void registerNamingFormat(String id, NamingFormat namingFormat);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package de.siphalor.tweed5.namingformat.impl;
|
||||
|
||||
import com.google.auto.service.AutoService;
|
||||
import de.siphalor.tweed5.namingformat.api.NamingFormatProvider;
|
||||
|
||||
import static de.siphalor.tweed5.namingformat.api.NamingFormats.*;
|
||||
|
||||
@AutoService(NamingFormatProvider.class)
|
||||
public class DefaultNamingFormatProvider implements NamingFormatProvider {
|
||||
@Override
|
||||
public void provideNamingFormats(ProvidingContext context) {
|
||||
context.registerNamingFormat("camel_case", camelCase());
|
||||
context.registerNamingFormat("pascal_case", pascalCase());
|
||||
context.registerNamingFormat("kebab_case", kebabCase());
|
||||
context.registerNamingFormat("upper_kebab_case", upperKebabCase());
|
||||
context.registerNamingFormat("snake_case", snakeCase());
|
||||
context.registerNamingFormat("upper_snake_case", upperKebabCase());
|
||||
context.registerNamingFormat("space_case", spaceCase());
|
||||
context.registerNamingFormat("upper_space_case", upperSpaceCase());
|
||||
context.registerNamingFormat("title_case", titleCase());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user