Redirect bag -> more custom & Class with name, extends, implements
This commit is contained in:
parent
5edc98ad3e
commit
8d0e9f0ee7
5 changed files with 56 additions and 43 deletions
|
@ -10,20 +10,16 @@ public class Class extends JavaElement{
|
||||||
|
|
||||||
private List<Annotation> annotations;
|
private List<Annotation> annotations;
|
||||||
|
|
||||||
private String name;
|
private Token name;
|
||||||
private String extend;
|
private Token extend;
|
||||||
private String implement;
|
private Token implement;
|
||||||
|
|
||||||
private List<JavaElement> elements;
|
private List<JavaElement> elements;
|
||||||
|
|
||||||
public Class(Bag bag){
|
public Class(Bag bag){
|
||||||
this.name = bag.<Bag>get("name").<Token>get().getValue();
|
this.name = bag.get("name");
|
||||||
|
this.extend = bag.get("extend");
|
||||||
Bag extendBag = bag.<Bag>get("extend");
|
this.implement = bag.get("implement");
|
||||||
if(extendBag != null) this.extend = extendBag.<Token>get().getValue();
|
|
||||||
|
|
||||||
Bag implementBag = bag.<Bag>get("implement");
|
|
||||||
if(implementBag != null) this.implement = implementBag.<Token>get().getValue();
|
|
||||||
|
|
||||||
this.annotations = new ArrayList<>();
|
this.annotations = new ArrayList<>();
|
||||||
this.elements = new ArrayList<>();
|
this.elements = new ArrayList<>();
|
||||||
|
|
|
@ -43,7 +43,8 @@ public class JavaParser extends Parser<JavaFile> {
|
||||||
public JavaParser(){
|
public JavaParser(){
|
||||||
Tokenizer tokenizer = new Tokenizer();
|
Tokenizer tokenizer = new Tokenizer();
|
||||||
|
|
||||||
StateTree<JavaFile> modifier = new StateTree<JavaFile>().then((validator) -> {
|
StateTree<JavaFile> modifier = new StateTree<JavaFile>();
|
||||||
|
modifier.then((validator) -> {
|
||||||
boolean mod = false;
|
boolean mod = false;
|
||||||
while(validator.validate(
|
while(validator.validate(
|
||||||
(token) -> getModifier(token.getValue()) > 0,
|
(token) -> getModifier(token.getValue()) > 0,
|
||||||
|
@ -53,14 +54,14 @@ public class JavaParser extends Parser<JavaFile> {
|
||||||
bag.set(current == null ? m : current+m);
|
bag.set(current == null ? m : current+m);
|
||||||
})) mod = true;
|
})) mod = true;
|
||||||
return mod;
|
return mod;
|
||||||
});
|
}).end((a,b) -> a);
|
||||||
modifier.end((a,b) -> a);
|
|
||||||
|
|
||||||
StateTree<JavaFile> type = new StateTree<JavaFile>().then((validator) ->
|
StateTree<JavaFile> type = new StateTree<JavaFile>();
|
||||||
|
StateTree<JavaFile> type_ = type.then((validator) ->
|
||||||
validator.validate(
|
validator.validate(
|
||||||
(token) -> token.getType().equals(TokenType.NAME),
|
(token) -> token.getType().equals(TokenType.NAME),
|
||||||
(bag, token) -> bag.set(token)));
|
(bag, token) -> bag.set(token)));
|
||||||
StateTree<JavaFile> type_generic_begin = type.then((validator) -> validator.validate(
|
StateTree<JavaFile> type_generic_begin = type_.then((validator) -> validator.validate(
|
||||||
(token) -> token.getValue().equals("<"),
|
(token) -> token.getValue().equals("<"),
|
||||||
(bag, token) -> bag.set(bag.<Token>get().concat(token))));
|
(bag, token) -> bag.set(bag.<Token>get().concat(token))));
|
||||||
StateTree<JavaFile> type_generic_name = type_generic_begin.then((validator) ->
|
StateTree<JavaFile> type_generic_name = type_generic_begin.then((validator) ->
|
||||||
|
@ -74,7 +75,7 @@ public class JavaParser extends Parser<JavaFile> {
|
||||||
(token) -> token.getValue().equals(">"),
|
(token) -> token.getValue().equals(">"),
|
||||||
(bag, token) -> bag.set(bag.<Token>get().concat(token)))).loop();
|
(bag, token) -> bag.set(bag.<Token>get().concat(token)))).loop();
|
||||||
|
|
||||||
type.end((a,b) -> a);
|
type_.end((a,b) -> a);
|
||||||
type_generic_begin.then(type_generic_name);
|
type_generic_begin.then(type_generic_name);
|
||||||
type_generic_split.then(type_generic_name);
|
type_generic_split.then(type_generic_name);
|
||||||
type_generic_end.then(type_generic_name);
|
type_generic_end.then(type_generic_name);
|
||||||
|
@ -85,11 +86,27 @@ public class JavaParser extends Parser<JavaFile> {
|
||||||
StateTree<JavaFile> clazz = new StateTree<>();
|
StateTree<JavaFile> clazz = new StateTree<>();
|
||||||
|
|
||||||
StateTree<JavaFile> clazz_base = clazz.then((validator) -> validator.validate((token) -> token.getValue().equals("class")))
|
StateTree<JavaFile> clazz_base = clazz.then((validator) -> validator.validate((token) -> token.getValue().equals("class")))
|
||||||
.then(new RedirectStateTree<>(type, (bag) -> "name"));
|
.then(new RedirectStateTree<>(type, (global, local) -> global.set("name", local.get())));
|
||||||
clazz_base.then((validator) -> validator.validate((token) -> token.getValue().equals("{")))
|
clazz_base.then((validator) -> validator.validate((token) -> token.getValue().equals("{")))
|
||||||
.end((javafile, bag) -> new Class(bag));
|
.end((javafile, bag) -> new Class(bag));
|
||||||
|
StateTree<JavaFile> clazz_implement = clazz_base.then((validator) -> validator.validate((token) -> token.getValue().equals("implements")));
|
||||||
|
StateTree<JavaFile> clazz_implement_name = clazz_implement.then(new RedirectStateTree<>(type, (global, local) -> {
|
||||||
|
Token token = global.get("implement");
|
||||||
|
if(token == null) token = local.get();
|
||||||
|
else token = token.concat(local.get());
|
||||||
|
global.set("implement", token);
|
||||||
|
}));
|
||||||
|
clazz_implement_name.then((validator) -> validator.validate((token) -> token.getValue().equals(","))).then(clazz_implement_name);
|
||||||
|
clazz_implement_name.then((validator) -> validator.validate((token) -> token.getValue().equals("{")))
|
||||||
|
.end((javafile, bag) -> new Class(bag));
|
||||||
|
StateTree<JavaFile> clazz_extend = clazz_base.then((validator) -> validator.validate((token) -> token.getValue().equals("extends")))
|
||||||
|
.then(new RedirectStateTree<>(type, (global, local) -> global.set("extend", local)));
|
||||||
|
clazz_extend.then((validator) -> validator.validate((token) -> token.getValue().equals("{")))
|
||||||
|
.end((javafile, bag) -> new Class(bag));
|
||||||
|
clazz_extend.then(clazz_implement);
|
||||||
|
|
||||||
StateTree<JavaFile> clazz_mod = clazz_.then(new RedirectStateTree<>(modifier, (bag) -> "modifier"));
|
|
||||||
|
StateTree<JavaFile> clazz_mod = clazz_.then(new RedirectStateTree<>(modifier, (global, local) -> global.set("modifier", local)));
|
||||||
clazz_mod.then(clazz);
|
clazz_mod.then(clazz);
|
||||||
|
|
||||||
StateTree<JavaFile> importState = new StateTree<>();
|
StateTree<JavaFile> importState = new StateTree<>();
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package be.jeffcheasey88.peeratcode.parser.state;
|
package be.jeffcheasey88.peeratcode.parser.state;
|
||||||
|
|
||||||
import java.util.function.Function;
|
import java.util.function.BiConsumer;
|
||||||
|
|
||||||
import be.jeffcheasey88.peeratcode.parser.Bag;
|
import be.jeffcheasey88.peeratcode.parser.Bag;
|
||||||
import be.jeffcheasey88.peeratcode.parser.TokenValidator;
|
import be.jeffcheasey88.peeratcode.parser.TokenValidator;
|
||||||
|
@ -8,9 +8,9 @@ import be.jeffcheasey88.peeratcode.parser.TokenValidator;
|
||||||
public class RedirectStateTree<E, T extends E> extends StateTree<T>{
|
public class RedirectStateTree<E, T extends E> extends StateTree<T>{
|
||||||
|
|
||||||
private StateTree<E> redirect;
|
private StateTree<E> redirect;
|
||||||
private Function<Bag, String> group;
|
private BiConsumer<Bag, Bag> group;
|
||||||
|
|
||||||
public RedirectStateTree(StateTree<E> redirect, Function<Bag, String> group){
|
public RedirectStateTree(StateTree<E> redirect, BiConsumer<Bag, Bag> group){
|
||||||
super();
|
super();
|
||||||
this.redirect = redirect;
|
this.redirect = redirect;
|
||||||
this.group = group;
|
this.group = group;
|
||||||
|
@ -26,7 +26,7 @@ public class RedirectStateTree<E, T extends E> extends StateTree<T>{
|
||||||
Object builded = redirect.internalSeed(branch, (E) element);
|
Object builded = redirect.internalSeed(branch, (E) element);
|
||||||
if(builded == null) return null;
|
if(builded == null) return null;
|
||||||
|
|
||||||
currentBag.set(this.group.apply(currentBag), localBag);
|
this.group.accept(currentBag, localBag);
|
||||||
branch.setBag(currentBag);
|
branch.setBag(currentBag);
|
||||||
validator.merge(branch);
|
validator.merge(branch);
|
||||||
|
|
||||||
|
|
|
@ -137,8 +137,8 @@ public class ParserComposantGenerator {
|
||||||
|
|
||||||
parent.currentDeclared = comp;
|
parent.currentDeclared = comp;
|
||||||
return parent;
|
return parent;
|
||||||
}).then(new RedirectStateTree<>(sub_operations, (bag) -> {
|
}).then(new RedirectStateTree<>(sub_operations, (global, local) -> {
|
||||||
return "operations";
|
global.set("operations", local);
|
||||||
}))
|
}))
|
||||||
.end((composant, bag) -> {
|
.end((composant, bag) -> {
|
||||||
((Composant)composant).currentDeclared = null;
|
((Composant)composant).currentDeclared = null;
|
||||||
|
@ -168,17 +168,17 @@ public class ParserComposantGenerator {
|
||||||
|
|
||||||
StateTree<Element> op_childs = new StateTree<>();
|
StateTree<Element> op_childs = new StateTree<>();
|
||||||
op_childs.then((v) -> v.validate((t) -> t.getValue().equals("(")))
|
op_childs.then((v) -> v.validate((t) -> t.getValue().equals("(")))
|
||||||
.then(new RedirectStateTree<>(operations, (bag) -> {
|
.then(new RedirectStateTree<>(operations, (global, local) -> {
|
||||||
return "operations";
|
global.set("operations", local);
|
||||||
}))
|
}))
|
||||||
.then((v) -> v.validate((t) -> t.getValue().equals(")")))
|
.then((v) -> v.validate((t) -> t.getValue().equals(")")))
|
||||||
.end((composant, bag) -> {
|
.end((composant, bag) -> {
|
||||||
return composant;
|
return composant;
|
||||||
});
|
});
|
||||||
|
|
||||||
operation.then(new RedirectStateTree<>(gotoValidator, (bag) -> "goto")).end((a,b) -> a);
|
operation.then(new RedirectStateTree<>(gotoValidator, (global, local) -> global.set("goto", local))).end((a,b) -> a);
|
||||||
|
|
||||||
StateTree<Element> op_validator = operation.then(new RedirectStateTree<>(validator, (bag) -> "validator"));
|
StateTree<Element> op_validator = operation.then(new RedirectStateTree<>(validator, (global, local) -> global.set("validator", local)));
|
||||||
op_validator.<Element>end((composant, bag) -> {
|
op_validator.<Element>end((composant, bag) -> {
|
||||||
Validator result = bag.<Bag>get("validator").<Validator>get();
|
Validator result = bag.<Bag>get("validator").<Validator>get();
|
||||||
bag.set(result);
|
bag.set(result);
|
||||||
|
@ -186,14 +186,14 @@ public class ParserComposantGenerator {
|
||||||
result.composant = comp;
|
result.composant = comp;
|
||||||
return comp;
|
return comp;
|
||||||
}).then(op_childs);
|
}).then(op_childs);
|
||||||
op_validator.then(new RedirectStateTree<>(namedValidator, (bag) -> "namedValidator")).<Element>end((composant, bag) -> {
|
op_validator.then(new RedirectStateTree<>(namedValidator, (global, local) -> global.set("namedValidator", local))).<Element>end((composant, bag) -> {
|
||||||
NamedElement result = null;
|
NamedElement result = null;
|
||||||
(result = bag.<Bag>get("namedValidator").<NamedElement>get()).child = bag.<Bag>get("validator").<Validator>get();
|
(result = bag.<Bag>get("namedValidator").<NamedElement>get()).child = bag.<Bag>get("validator").<Validator>get();
|
||||||
bag.set(result);
|
bag.set(result);
|
||||||
return new Composant();
|
return new Composant();
|
||||||
}).then(op_childs);
|
}).then(op_childs);
|
||||||
|
|
||||||
StateTree<Element> op_call = operation.then(new RedirectStateTree<>(methodCall, (bag) -> "methodCall"));
|
StateTree<Element> op_call = operation.then(new RedirectStateTree<>(methodCall, (global, local) -> global.set("methodCall", local)));
|
||||||
op_call.<Element>end((composant, bag) -> {
|
op_call.<Element>end((composant, bag) -> {
|
||||||
ComposantCall result = bag.<Bag>get("methodCall").<ComposantCall>get();
|
ComposantCall result = bag.<Bag>get("methodCall").<ComposantCall>get();
|
||||||
bag.set(result);
|
bag.set(result);
|
||||||
|
@ -201,14 +201,14 @@ public class ParserComposantGenerator {
|
||||||
result.composant = comp;
|
result.composant = comp;
|
||||||
return comp;
|
return comp;
|
||||||
}).then(op_childs);
|
}).then(op_childs);
|
||||||
op_call.then(new RedirectStateTree<>(namedValidator, (bag) -> "namedValidator")).<Element>end((composant, bag) -> {
|
op_call.then(new RedirectStateTree<>(namedValidator, (global, local) -> global.set("namedValidator", local))).<Element>end((composant, bag) -> {
|
||||||
NamedElement result = null;
|
NamedElement result = null;
|
||||||
(result = bag.<Bag>get("namedValidator").<NamedElement>get()).child = bag.<Bag>get("methodCall").<Validator>get();
|
(result = bag.<Bag>get("namedValidator").<NamedElement>get()).child = bag.<Bag>get("methodCall").<Validator>get();
|
||||||
bag.set(result);
|
bag.set(result);
|
||||||
return new Composant();
|
return new Composant();
|
||||||
}).then(op_childs);
|
}).then(op_childs);
|
||||||
|
|
||||||
StateTree<Element> op_redirect = operation.then(new RedirectStateTree<>(redirection, (bag) -> "redirection"));
|
StateTree<Element> op_redirect = operation.then(new RedirectStateTree<>(redirection, (global, local) -> global.set("redirection", local)));
|
||||||
op_redirect.<Element>end((composant, bag) -> {
|
op_redirect.<Element>end((composant, bag) -> {
|
||||||
Redirection result = bag.<Bag>get("redirection").<Redirection>get();
|
Redirection result = bag.<Bag>get("redirection").<Redirection>get();
|
||||||
bag.set(result);
|
bag.set(result);
|
||||||
|
@ -216,18 +216,18 @@ public class ParserComposantGenerator {
|
||||||
result.composant = comp;
|
result.composant = comp;
|
||||||
return comp;
|
return comp;
|
||||||
}).then(op_childs);
|
}).then(op_childs);
|
||||||
op_redirect.then(new RedirectStateTree<>(namedValidator, (bag) -> "namedValidator")).<Element>end((composant, bag) -> {
|
op_redirect.then(new RedirectStateTree<>(namedValidator, (global, local) -> global.set("namedValidator", local))).<Element>end((composant, bag) -> {
|
||||||
NamedElement result = null;
|
NamedElement result = null;
|
||||||
(result = bag.<Bag>get("namedValidator").<NamedElement>get()).child = bag.<Bag>get("redirection").<Validator>get();
|
(result = bag.<Bag>get("namedValidator").<NamedElement>get()).child = bag.<Bag>get("redirection").<Validator>get();
|
||||||
bag.set(result);
|
bag.set(result);
|
||||||
return new Composant();
|
return new Composant();
|
||||||
}).then(op_childs);
|
}).then(op_childs);
|
||||||
|
|
||||||
StateTree<Element> suit = operations.then(new RedirectStateTree<>(operation, (bag) -> {
|
StateTree<Element> suit = operations.then(new RedirectStateTree<>(operation, (global, local) -> {
|
||||||
Integer count = bag.get("count");
|
Integer count = global.get("count");
|
||||||
if(count == null) count = 0;
|
if(count == null) count = 0;
|
||||||
bag.set("count", count+1);
|
global.set("count", count+1);
|
||||||
return "operation"+count;
|
global.set("operation"+count, local);
|
||||||
})).loop();
|
})).loop();
|
||||||
suit.then((v) -> v.validate((t) -> t.getValue().equals(",")))
|
suit.then((v) -> v.validate((t) -> t.getValue().equals(",")))
|
||||||
.end((composant, bag) -> {
|
.end((composant, bag) -> {
|
||||||
|
@ -280,11 +280,11 @@ public class ParserComposantGenerator {
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
StateTree<Element> sub_suit = sub_operations.then(new RedirectStateTree<>(operation, (bag) -> {
|
StateTree<Element> sub_suit = sub_operations.then(new RedirectStateTree<>(operation, (global, local) -> {
|
||||||
Integer count = bag.get("count");
|
Integer count = global.get("count");
|
||||||
if(count == null) count = 0;
|
if(count == null) count = 0;
|
||||||
bag.set("count", count+1);
|
global.set("count", count+1);
|
||||||
return "operation"+count;
|
global.set("operation"+count, local);
|
||||||
})).loop();
|
})).loop();
|
||||||
sub_suit.then((v) -> v.validate((t) -> t.getValue().equals(",")))
|
sub_suit.then((v) -> v.validate((t) -> t.getValue().equals(",")))
|
||||||
.end((composant, bag) -> {
|
.end((composant, bag) -> {
|
||||||
|
@ -353,7 +353,7 @@ public class ParserComposantGenerator {
|
||||||
child.parent = base;
|
child.parent = base;
|
||||||
base.register(child.title, child);
|
base.register(child.title, child);
|
||||||
return child;
|
return child;
|
||||||
}).then(new RedirectStateTree<>(op_childs, (bag) -> "content"))
|
}).then(new RedirectStateTree<>(op_childs, (global, local) -> global.set("content", local)))
|
||||||
.then(composant);
|
.then(composant);
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,7 @@ class GlobalCover {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
System.out.println("Load time : "+((System.currentTimeMillis()-time)/1000.0)+"s");
|
System.out.println("Load time : "+((System.currentTimeMillis()-time)/1000.0)+"s");
|
||||||
System.out.println(((validated/tokens)*100.0)+"% validated in "+count+" files !");
|
System.out.printf("%.3f%% ("+validated+") validated in "+count+" files !\n", ((validated/tokens)*100.0));
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<File> files(File dir){
|
private List<File> files(File dir){
|
||||||
|
|
Loading…
Add table
Reference in a new issue