Include Ship in running programs (before was only for compilation)
This commit is contained in:
parent
69c4fc8015
commit
53f8c3d2eb
6 changed files with 123 additions and 53 deletions
Binary file not shown.
|
@ -2,6 +2,7 @@ package dev.peerat.mapping;
|
||||||
|
|
||||||
import dev.peerat.mapping.providers.Compass;
|
import dev.peerat.mapping.providers.Compass;
|
||||||
import dev.peerat.mapping.providers.Map;
|
import dev.peerat.mapping.providers.Map;
|
||||||
|
import dev.peerat.mapping.providers.ProviderManager;
|
||||||
|
|
||||||
public class Ship{
|
public class Ship{
|
||||||
|
|
||||||
|
@ -14,6 +15,20 @@ public class Ship{
|
||||||
this.compass = compass;
|
this.compass = compass;
|
||||||
this.map = map;
|
this.map = map;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSails() throws Exception{}
|
public String getType(){
|
||||||
|
return this.type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Compass getCompass(){
|
||||||
|
return this.compass;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map getMap(){
|
||||||
|
return this.map;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSails() throws Exception{
|
||||||
|
ProviderManager.getInstance().register(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -94,60 +94,61 @@ public class TreasureProcessor extends AbstractProcessor{
|
||||||
|
|
||||||
try {
|
try {
|
||||||
provider.init(output);
|
provider.init(output);
|
||||||
|
throw new Exception(output.getAbsolutePath());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RuntimeException(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) -> {
|
||||||
if(element instanceof Class){
|
// if(element instanceof Class){
|
||||||
Class c = (Class)element;
|
// 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;
|
// return false;
|
||||||
});
|
// });
|
||||||
if(treasure != null){
|
// if(treasure != null){
|
||||||
provider.mapTreasure(treasure);
|
// provider.mapTreasure(treasure);
|
||||||
// annotations.forEach((a) -> roundEnv.getElementsAnnotatedWith(a).forEach((e) -> processingEnv.getMessager().printMessage(Kind.ERROR, classes.getKey().getName(), e)));
|
//// annotations.forEach((a) -> roundEnv.getElementsAnnotatedWith(a).forEach((e) -> processingEnv.getMessager().printMessage(Kind.ERROR, classes.getKey().getName(), e)));
|
||||||
List<Function> seaBottles = new ArrayList<>();
|
// List<Function> seaBottles = new ArrayList<>();
|
||||||
treasure.findAll((element) -> {
|
// treasure.findAll((element) -> {
|
||||||
if(element instanceof Function){
|
// if(element instanceof Function){
|
||||||
Function function = (Function)element;
|
// 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;
|
// return false;
|
||||||
}, seaBottles);
|
// }, seaBottles);
|
||||||
for(Function function : seaBottles){
|
// for(Function function : seaBottles){
|
||||||
provider.mapBottle(treasure, function);
|
// provider.mapBottle(treasure, function);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
for(Entry<File, JavaFile> classes : map.entrySet()){
|
// for(Entry<File, JavaFile> classes : map.entrySet()){
|
||||||
List<Class> noTreasures = new ArrayList<>();
|
// List<Class> noTreasures = new ArrayList<>();
|
||||||
classes.getValue().findAll((element) -> {
|
// classes.getValue().findAll((element) -> {
|
||||||
if(element instanceof Class){
|
// if(element instanceof Class){
|
||||||
Class c = (Class)element;
|
// 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;
|
// return false;
|
||||||
}, noTreasures);
|
// }, noTreasures);
|
||||||
for(Class clazz : noTreasures){
|
// for(Class clazz : noTreasures){
|
||||||
List<Function> functions = new ArrayList<>();
|
// List<Function> functions = new ArrayList<>();
|
||||||
clazz.findAll((element) -> {
|
// clazz.findAll((element) -> {
|
||||||
if(element instanceof Function){
|
// if(element instanceof Function){
|
||||||
Function function = (Function)element;
|
// 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;
|
// return false;
|
||||||
}, functions);
|
// }, functions);
|
||||||
for(Function function : functions){
|
// for(Function function : functions){
|
||||||
provider.mapUses(clazz, function);
|
// provider.mapUses(clazz, function);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
provider.complete();
|
// provider.complete();
|
||||||
return true;
|
// return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final Parser<JavaElement> PARSER = new JavaParser();
|
private static final Parser<JavaElement> PARSER = new JavaParser();
|
||||||
|
|
|
@ -2,6 +2,7 @@ package dev.peerat.mapping.providers;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
|
import dev.peerat.mapping.Ship;
|
||||||
import dev.peerat.parser.java.Class;
|
import dev.peerat.parser.java.Class;
|
||||||
import dev.peerat.parser.java.Function;
|
import dev.peerat.parser.java.Function;
|
||||||
|
|
||||||
|
@ -16,4 +17,6 @@ public interface Provider{
|
||||||
void mapUses(Class clazz, Function function);
|
void mapUses(Class clazz, Function function);
|
||||||
|
|
||||||
void complete();
|
void complete();
|
||||||
|
|
||||||
|
void register(Ship ship) throws Exception;
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,8 @@ package dev.peerat.mapping.providers;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import dev.peerat.mapping.Ship;
|
||||||
|
|
||||||
public class ProviderManager{
|
public class ProviderManager{
|
||||||
|
|
||||||
private static final ProviderManager SINGLETON = new ProviderManager();
|
private static final ProviderManager SINGLETON = new ProviderManager();
|
||||||
|
@ -21,6 +23,10 @@ public class ProviderManager{
|
||||||
this.providers.put(name, provider);
|
this.providers.put(name, provider);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void register(Ship ship) throws Exception{
|
||||||
|
this.providers.get(ship.getType()).register(ship);
|
||||||
|
}
|
||||||
|
|
||||||
public Provider getProvider(String name){
|
public Provider getProvider(String name){
|
||||||
return this.providers.get(name);
|
return this.providers.get(name);
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,9 +5,11 @@ import java.io.File;
|
||||||
import java.io.FileWriter;
|
import java.io.FileWriter;
|
||||||
import java.lang.reflect.Modifier;
|
import java.lang.reflect.Modifier;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import dev.peerat.mapping.Ship;
|
||||||
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.ElementBuilder.Builder;
|
||||||
|
@ -17,7 +19,11 @@ 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;
|
||||||
import dev.peerat.parser.java.Value.MethodCallValue;
|
import dev.peerat.parser.java.Value.MethodCallValue;
|
||||||
|
import dev.peerat.parser.java.Variable;
|
||||||
|
import dev.peerat.parser.java.operation.CatchOperation;
|
||||||
|
import dev.peerat.parser.java.operation.MethodCallOperation;
|
||||||
import dev.peerat.parser.java.operation.ReturnOperation;
|
import dev.peerat.parser.java.operation.ReturnOperation;
|
||||||
|
import dev.peerat.parser.java.operation.TryOperation;
|
||||||
|
|
||||||
public class MySQLProvider implements Provider{
|
public class MySQLProvider implements Provider{
|
||||||
|
|
||||||
|
@ -87,8 +93,30 @@ public class MySQLProvider implements Provider{
|
||||||
Modifier.PUBLIC,
|
Modifier.PUBLIC,
|
||||||
null,
|
null,
|
||||||
new Token(0,0,base.getReturnType().getValue(), null),
|
new Token(0,0,base.getReturnType().getValue(), null),
|
||||||
new Token(0,0,base.getName().getValue(),null),
|
new Token(0,0,"getter_"+base.getName().getValue(),null),
|
||||||
base.getParameters());
|
base.getParameters());
|
||||||
|
|
||||||
|
TryOperation tryOp = new TryOperation();
|
||||||
|
tryOp.addOperation(new MethodCallOperation((Value)null, new Token(0,0,"ensureConnection()",null), null));
|
||||||
|
tryOp.addVariable(
|
||||||
|
new Variable(
|
||||||
|
null,
|
||||||
|
0,
|
||||||
|
new Token(0,0,"PreparedStatement",null),
|
||||||
|
new Token(0,0,"stmt",null),
|
||||||
|
false,
|
||||||
|
new MethodCallValue(
|
||||||
|
new Value(new Token(0,0,"con",null)),
|
||||||
|
null,
|
||||||
|
new Token(0,0,"prepareStatement",null),
|
||||||
|
Arrays.asList(new Value(new Token(0,0,request.build(),null))))));
|
||||||
|
|
||||||
|
CatchOperation catchOp = new CatchOperation(Arrays.asList(new Token(0,0,"Exception",null)), new Token(0,0,"e", null));
|
||||||
|
catchOp.addOperation(new MethodCallOperation(new Value(new Token(0,0,"e",null)), new Token(0,0,"printStackTrace()", null), null));
|
||||||
|
|
||||||
|
func.addOperation(tryOp);
|
||||||
|
func.addOperation(catchOp);
|
||||||
|
|
||||||
clazz.addFunction(func);
|
clazz.addFunction(func);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -104,4 +132,21 @@ public class MySQLProvider implements Provider{
|
||||||
throw new RuntimeException(ex);
|
throw new RuntimeException(ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void register(Ship ship) throws Exception {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* try{
|
||||||
|
* ensureConnection();
|
||||||
|
* PreparedStatement stmt = con.prepareStatement(REQUEST);
|
||||||
|
* //bind
|
||||||
|
* //execute
|
||||||
|
* //build object
|
||||||
|
* }catch(Exception ex){
|
||||||
|
* ex.printStackTrace();
|
||||||
|
* }
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue