Base (only signature) generating repository from TreasureCaches
This commit is contained in:
parent
cf088e27cc
commit
69c4fc8015
6 changed files with 106 additions and 7 deletions
Binary file not shown.
|
@ -92,7 +92,11 @@ public class TreasureProcessor extends AbstractProcessor{
|
||||||
|
|
||||||
if(provider == null) return false;
|
if(provider == null) return false;
|
||||||
|
|
||||||
|
try {
|
||||||
provider.init(output);
|
provider.init(output);
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
|
||||||
for(Entry<File, JavaFile> classes : map.entrySet()){
|
for(Entry<File, JavaFile> classes : map.entrySet()){
|
||||||
Class treasure = classes.getValue().find((element) -> {
|
Class treasure = classes.getValue().find((element) -> {
|
||||||
|
@ -142,6 +146,7 @@ public class TreasureProcessor extends AbstractProcessor{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
provider.complete();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,11 +7,13 @@ import dev.peerat.parser.java.Function;
|
||||||
|
|
||||||
public interface Provider{
|
public interface Provider{
|
||||||
|
|
||||||
void init(File file);
|
void init(File file) throws Exception;
|
||||||
|
|
||||||
void mapTreasure(Class clazz);
|
void mapTreasure(Class clazz);
|
||||||
|
|
||||||
void mapBottle(Class clazz, Function function);
|
void mapBottle(Class clazz, Function function);
|
||||||
|
|
||||||
void mapUses(Class clazz, Function function);
|
void mapUses(Class clazz, Function function);
|
||||||
|
|
||||||
|
void complete();
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ package dev.peerat.mapping.providers.mysql;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import dev.peerat.parser.java.Function;
|
||||||
import dev.peerat.parser.java.Value;
|
import dev.peerat.parser.java.Value;
|
||||||
import dev.peerat.parser.java.Value.BiValue;
|
import dev.peerat.parser.java.Value.BiValue;
|
||||||
import dev.peerat.parser.java.Value.LambdaValue;
|
import dev.peerat.parser.java.Value.LambdaValue;
|
||||||
|
@ -10,14 +11,21 @@ import dev.peerat.parser.java.Value.MethodCallValue;
|
||||||
|
|
||||||
public class MySQLRequestBuilder{
|
public class MySQLRequestBuilder{
|
||||||
|
|
||||||
|
private Function function;
|
||||||
|
|
||||||
private List<MethodCallValue> calls;
|
private List<MethodCallValue> calls;
|
||||||
private String select;
|
private String select;
|
||||||
private String where;
|
private String where;
|
||||||
|
|
||||||
public MySQLRequestBuilder(List<MethodCallValue> calls){
|
public MySQLRequestBuilder(Function function, List<MethodCallValue> calls){
|
||||||
|
this.function = function;
|
||||||
this.calls = calls;
|
this.calls = calls;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Function getFunction(){
|
||||||
|
return this.function;
|
||||||
|
}
|
||||||
|
|
||||||
private String toStringOperation(MethodCallValue value){
|
private String toStringOperation(MethodCallValue value){
|
||||||
String method = value.getToken().getValue();
|
String method = value.getToken().getValue();
|
||||||
if(method.equals("selectAll()")){
|
if(method.equals("selectAll()")){
|
||||||
|
|
|
@ -1,12 +1,18 @@
|
||||||
package dev.peerat.mapping.providers.mysql;
|
package dev.peerat.mapping.providers.mysql;
|
||||||
|
|
||||||
|
import java.io.BufferedWriter;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.FileWriter;
|
||||||
|
import java.lang.reflect.Modifier;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import dev.peerat.mapping.providers.Provider;
|
import dev.peerat.mapping.providers.Provider;
|
||||||
import dev.peerat.mapping.providers.ProviderManager;
|
import dev.peerat.mapping.providers.ProviderManager;
|
||||||
|
import dev.peerat.parser.ElementBuilder.Builder;
|
||||||
|
import dev.peerat.parser.Token;
|
||||||
|
import dev.peerat.parser.java.BuildedJavaFile;
|
||||||
import dev.peerat.parser.java.Class;
|
import dev.peerat.parser.java.Class;
|
||||||
import dev.peerat.parser.java.Function;
|
import dev.peerat.parser.java.Function;
|
||||||
import dev.peerat.parser.java.Value;
|
import dev.peerat.parser.java.Value;
|
||||||
|
@ -20,14 +26,19 @@ public class MySQLProvider implements Provider{
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<String> treasures;
|
private List<String> treasures;
|
||||||
|
private File repo;
|
||||||
|
private List<MySQLRequestBuilder> requests;
|
||||||
|
|
||||||
public MySQLProvider(){
|
public MySQLProvider(){
|
||||||
this.treasures = new ArrayList<>();
|
this.treasures = new ArrayList<>();
|
||||||
|
this.requests = new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void init(File file){
|
public void init(File file) throws Exception{
|
||||||
|
repo = new File(file, "/dev/peerat/mapping/mysql/MySQlRepository.java");
|
||||||
|
repo.getParentFile().mkdirs();
|
||||||
|
repo.createNewFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -48,8 +59,8 @@ public class MySQLProvider implements Provider{
|
||||||
call = (MethodCallValue) call.base();
|
call = (MethodCallValue) call.base();
|
||||||
}
|
}
|
||||||
list.add(0, call);
|
list.add(0, call);
|
||||||
MySQLRequestBuilder builder = new MySQLRequestBuilder(list);
|
MySQLRequestBuilder builder = new MySQLRequestBuilder(function, list);
|
||||||
throw new RuntimeException(builder.build());
|
this.requests.add(builder);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,4 +69,39 @@ public class MySQLProvider implements Provider{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void complete(){
|
||||||
|
try{
|
||||||
|
BuildedJavaFile file = new BuildedJavaFile();
|
||||||
|
file.setPackage("dev.peerat.mapping.sql.MySQlRepository");
|
||||||
|
//
|
||||||
|
// file.addImport("");
|
||||||
|
//
|
||||||
|
Class clazz = new Class(null, new Token(0,0,"MySQlRepository",null));
|
||||||
|
|
||||||
|
for(MySQLRequestBuilder request : this.requests){
|
||||||
|
Function base = request.getFunction();
|
||||||
|
Function func = new Function(
|
||||||
|
null,
|
||||||
|
Modifier.PUBLIC,
|
||||||
|
null,
|
||||||
|
new Token(0,0,base.getReturnType().getValue(), null),
|
||||||
|
new Token(0,0,base.getName().getValue(),null),
|
||||||
|
base.getParameters());
|
||||||
|
clazz.addFunction(func);
|
||||||
|
}
|
||||||
|
|
||||||
|
file.setClass(clazz);
|
||||||
|
|
||||||
|
Builder builder = new Builder();
|
||||||
|
file.build().build(builder);
|
||||||
|
BufferedWriter writer = new BufferedWriter(new FileWriter(this.repo));
|
||||||
|
builder.build(writer);
|
||||||
|
writer.flush();
|
||||||
|
writer.close();
|
||||||
|
}catch(Exception ex){
|
||||||
|
throw new RuntimeException(ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
38
src/dev/peerat/parser/java/BuildedJavaFile.java
Normal file
38
src/dev/peerat/parser/java/BuildedJavaFile.java
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
package dev.peerat.parser.java;
|
||||||
|
|
||||||
|
import dev.peerat.parser.Bag;
|
||||||
|
import dev.peerat.parser.Token;
|
||||||
|
|
||||||
|
public class BuildedJavaFile{
|
||||||
|
|
||||||
|
private JavaFile file;
|
||||||
|
|
||||||
|
public BuildedJavaFile(){
|
||||||
|
this.file = new JavaFile();
|
||||||
|
}
|
||||||
|
|
||||||
|
public BuildedJavaFile setPackage(String value){
|
||||||
|
Bag bag = new Bag();
|
||||||
|
bag.set(new Token(0, 0, value, null));
|
||||||
|
this.file.setPackage(bag);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BuildedJavaFile addImport(String... values){
|
||||||
|
for(String value : values){
|
||||||
|
Import imp = new Import(false, new Token(0,0,value,null));
|
||||||
|
this.file.addImport(imp);
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BuildedJavaFile setClass(Class clazz){
|
||||||
|
this.file.addClass(clazz);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public JavaFile build(){
|
||||||
|
return this.file;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue