Load provider & receive Treasuers, SeaBottle & Uses
This commit is contained in:
parent
f0f22dae94
commit
fbdfd71f00
4 changed files with 34 additions and 13 deletions
|
@ -42,6 +42,13 @@ public class TreasureProcessor extends AbstractProcessor{
|
|||
@Override
|
||||
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv){
|
||||
|
||||
try {
|
||||
String[] providers = processingEnv.getOptions().get("treasure.providers").split(";");
|
||||
for(String provider : providers) java.lang.Class.forName(provider);
|
||||
}catch(Exception ex){
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
|
||||
String[] sources = processingEnv.getOptions().get("treasure.source").split(";");
|
||||
|
||||
List<File> workingDir = new ArrayList<>();
|
||||
|
@ -80,12 +87,14 @@ public class TreasureProcessor extends AbstractProcessor{
|
|||
}, values);
|
||||
if(values.size() < 1) continue;
|
||||
InstanceValue ship = (InstanceValue)values.get(0);
|
||||
String providerType = ship.getParameters().get(0).getToken().getValue();
|
||||
String providerType = ship.getParameters().get(0).getToken().getValue().replace("\"", "");
|
||||
provider = ProviderManager.getInstance().getProvider(providerType);
|
||||
}
|
||||
|
||||
if(provider == null) return false;
|
||||
|
||||
provider.init(output);
|
||||
|
||||
for(Entry<File, JavaFile> classes : map.entrySet()){
|
||||
Class treasure = classes.getValue().find((element) -> {
|
||||
if(element instanceof Class){
|
||||
|
@ -96,6 +105,7 @@ public class TreasureProcessor extends AbstractProcessor{
|
|||
});
|
||||
if(treasure != null){
|
||||
provider.mapTreasure(treasure);
|
||||
annotations.forEach((a) -> roundEnv.getElementsAnnotatedWith(a).forEach((e) -> processingEnv.getMessager().printMessage(Kind.ERROR, classes.getKey().getName(), e)));
|
||||
List<Function> seaBottles = new ArrayList<>();
|
||||
treasure.findAll((element) -> {
|
||||
if(element instanceof Function){
|
||||
|
@ -103,7 +113,7 @@ public class TreasureProcessor extends AbstractProcessor{
|
|||
return function.hasAnnotation((annotation) -> annotation.getName().getValue().equals("SeaBottle")); //can also be dev.peerat.mapping.SeaBottle
|
||||
}
|
||||
return false;
|
||||
}, null);
|
||||
}, seaBottles);
|
||||
for(Function function : seaBottles){
|
||||
provider.mapBottle(treasure, function);
|
||||
}
|
||||
|
@ -115,7 +125,7 @@ public class TreasureProcessor extends AbstractProcessor{
|
|||
classes.getValue().findAll((element) -> {
|
||||
if(element instanceof Class){
|
||||
Class c = (Class)element;
|
||||
return c.hasAnnotation((annotation) -> annotation.getName().getValue().equals("Treasure")); //can also be dev.peerat.mapping.Treasure
|
||||
return !c.hasAnnotation((annotation) -> annotation.getName().getValue().equals("Treasure")); //can also be dev.peerat.mapping.Treasure
|
||||
}
|
||||
return false;
|
||||
}, noTreasures);
|
||||
|
@ -124,7 +134,7 @@ public class TreasureProcessor extends AbstractProcessor{
|
|||
clazz.findAll((element) -> {
|
||||
if(element instanceof Function){
|
||||
Function function = (Function)element;
|
||||
return function.hasAnnotation((annotation) -> annotation.getName().getValue().equals("SeaBottle")); //can also be dev.peerat.mapping.SeaBottle
|
||||
return !function.hasAnnotation((annotation) -> annotation.getName().getValue().equals("SeaBottle")); //can also be dev.peerat.mapping.SeaBottle
|
||||
}
|
||||
return false;
|
||||
}, functions);
|
||||
|
|
|
@ -1,10 +1,14 @@
|
|||
package dev.peerat.mapping.providers;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import dev.peerat.parser.java.Class;
|
||||
import dev.peerat.parser.java.Function;
|
||||
|
||||
public interface Provider{
|
||||
|
||||
void init(File file);
|
||||
|
||||
void mapTreasure(Class clazz);
|
||||
|
||||
void mapBottle(Class clazz, Function function);
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package dev.peerat.mapping.providers.mysql;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -10,18 +11,24 @@ import dev.peerat.parser.java.Function;
|
|||
import dev.peerat.parser.java.Value;
|
||||
import dev.peerat.parser.java.operation.ReturnOperation;
|
||||
|
||||
public class MySQlProvider implements Provider{
|
||||
public class MySQLProvider implements Provider{
|
||||
|
||||
static{
|
||||
ProviderManager.getInstance().register("mysql", new MySQlProvider());
|
||||
ProviderManager.getInstance().register("mysql", new MySQLProvider());
|
||||
}
|
||||
|
||||
private List<String> treasures;
|
||||
|
||||
private MySQlProvider(){
|
||||
public MySQLProvider(){
|
||||
this.treasures = new ArrayList<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(File file){
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void mapTreasure(Class clazz){
|
||||
treasures.add(clazz.getName().getValue());
|
||||
|
@ -31,7 +38,7 @@ public class MySQlProvider implements Provider{
|
|||
public void mapBottle(Class clazz, Function function){
|
||||
ReturnOperation operation = (ReturnOperation) function.getElements().get(0);
|
||||
Value value = operation.getValue();
|
||||
|
||||
throw new IllegalArgumentException(value.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -2,19 +2,19 @@ package dev.peerat.mapping.providers.mysql;
|
|||
|
||||
import dev.peerat.mapping.providers.Map;
|
||||
|
||||
public class MySqlMap implements Map{
|
||||
public class MySQLMap implements Map{
|
||||
|
||||
public MySqlMap(){}
|
||||
public MySQLMap(){}
|
||||
|
||||
public MySqlMap link(Class<?> clazz, String table){
|
||||
public MySQLMap link(Class<?> clazz, String table){
|
||||
return this;
|
||||
}
|
||||
|
||||
public MySqlMap ref(String table_from, String column_from, String table_to, String column_to){
|
||||
public MySQLMap ref(String table_from, String column_from, String table_to, String column_to){
|
||||
return this;
|
||||
}
|
||||
|
||||
public MySqlMap bind(Class<?> clazz, String jfield, String sfield){
|
||||
public MySQLMap bind(Class<?> clazz, String jfield, String sfield){
|
||||
return this;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue