Compare commits
2 commits
9b87621a35
...
d402407ae2
Author | SHA1 | Date | |
---|---|---|---|
|
d402407ae2 | ||
|
b78ef3213e |
2 changed files with 40 additions and 11 deletions
|
@ -178,8 +178,8 @@ public class JavaParser extends Parser<JavaElement> {
|
|||
|
||||
StateTree<JavaElement> type = new StateTree<JavaElement>();
|
||||
StateTree<JavaElement> type_ = type.then((validator) -> validator.validate((token) -> token.getType().equals(TokenType.NAME),concat));
|
||||
type_.then((validator) -> validator.validate((token) -> token.getValue().equals("."), concat))
|
||||
.then(type_);
|
||||
// type_.then((validator) -> validator.validate((token) -> token.getValue().equals("."), concat)) //only dot?
|
||||
// .then(type_);
|
||||
StateTree<JavaElement> gen = new StateTree<>();
|
||||
type_.then(gen);
|
||||
StateTree<JavaElement> type_begin = gen.then((validator) -> validator.validate((token) -> token.getValue().equals("<"), concat));
|
||||
|
@ -291,7 +291,10 @@ public class JavaParser extends Parser<JavaElement> {
|
|||
.end((a,b) -> a)
|
||||
.multiple(braces_container)
|
||||
.unique((validator) -> validator.validate((token) -> token.getValue().equals("}"))).end((a,b) -> a);
|
||||
value_name = value_name.then(new RedirectStateTree<>(type, (global, local) -> global.set(local.get())));
|
||||
value_name = value_name.then(new RedirectStateTree<>(type, (global, local) -> {
|
||||
if(global.get() == null) global.set(local.get());
|
||||
else global.set(global.<Token>get().concat(local.get()));
|
||||
}));
|
||||
value_name.end((parent,bag) -> {
|
||||
Value result = new Value(bag.<Token>get());
|
||||
bag.set(result);
|
||||
|
@ -302,8 +305,27 @@ public class JavaParser extends Parser<JavaElement> {
|
|||
.then((validator) -> validator.validate((token) -> token.getType().equals(TokenType.NAME)))
|
||||
.end((a,b) -> a);
|
||||
|
||||
StateTree<JavaElement> value_call = value_name.then((validator) -> validator.validate((token) -> token.getValue().equals(".")));
|
||||
StateTree<JavaElement> value_call = value_name.then((validator) -> validator.validate(
|
||||
(token) -> token.getValue().equals("."),
|
||||
(bag, token) -> {
|
||||
Value prev = bag.get("prev");
|
||||
if(prev == null){
|
||||
bag.set("prev", new Value(bag.<Token>get()));
|
||||
}else{
|
||||
Integer paramters = bag.get("args");
|
||||
List<Value> list = null;
|
||||
if(paramters != null){
|
||||
list = new ArrayList<>();
|
||||
for(int i = 0; i < paramters; i++) list.add(bag.<Bag>get("arg"+i).get());
|
||||
bag.remove("args");
|
||||
}
|
||||
MethodCallValue methodCall = new MethodCallValue(prev, bag.get(), list);
|
||||
bag.set("prev", methodCall);
|
||||
}
|
||||
bag.set(token);
|
||||
}));
|
||||
value_call.end((a,b) -> a);
|
||||
value_call.then(new RedirectStateTree<>(gen, (global, local) -> global.set(global.<Token>get().concat(local.get())))).then(value_name);
|
||||
value_call.then(value_name);
|
||||
StateTree<JavaElement> value_array_begin = value_name.then((validator) -> validator.validate((token) -> token.getValue().equals("[")));
|
||||
StateTree<JavaElement> value_array_end = value_array_begin.then((validator) -> validator.validate((token) -> token.getValue().equals("]")));
|
||||
|
@ -331,9 +353,7 @@ public class JavaParser extends Parser<JavaElement> {
|
|||
for(int i = 0; i < paramters; i++) list.add(bag.<Bag>get("arg"+i).get());
|
||||
}
|
||||
|
||||
MethodCallValue methodCall = new MethodCallValue(bag.get(), list);
|
||||
//take arguments from bag
|
||||
System.out.println("MethodCall "+bag);
|
||||
MethodCallValue methodCall = new MethodCallValue(bag.get("prev"), bag.get(), list);
|
||||
bag.set(methodCall);
|
||||
return null;
|
||||
});
|
||||
|
@ -1161,7 +1181,7 @@ public class JavaParser extends Parser<JavaElement> {
|
|||
}
|
||||
|
||||
public static void main(String[] args) throws Exception{
|
||||
File file = new File("C:\\Users\\jeffc\\eclipse-workspace\\peer-at-code-backend\\src\\dev\\peerat\\backend\\routes\\users\\Register.java");
|
||||
File file = new File("C:\\Users\\jeffc\\eclipse-workspace\\peer-at-code-backend\\src\\dev\\peerat\\backend\\routes\\users\\ChangePassword.java");
|
||||
|
||||
BufferedReader reader = new BufferedReader(new FileReader(file));
|
||||
|
||||
|
@ -1174,7 +1194,7 @@ public class JavaParser extends Parser<JavaElement> {
|
|||
List<Value> values = new ArrayList<>();
|
||||
jFile.findAll((e) -> e instanceof Value, values);
|
||||
System.out.println("Find "+values.size()+" values");
|
||||
for(Value v : values) System.out.println(v);
|
||||
for(Value v : values) System.out.println(v.getClass().getSimpleName()+" ->"+v);
|
||||
|
||||
|
||||
System.out.println((System.currentTimeMillis()-time)+"ms");
|
||||
|
|
|
@ -152,14 +152,20 @@ public class Value extends JavaElement{
|
|||
|
||||
public static class MethodCallValue extends Value{
|
||||
|
||||
private Value base;
|
||||
private Token token;
|
||||
private List<Value> parameters;
|
||||
|
||||
public MethodCallValue(Token token, List<Value> parameters){
|
||||
public MethodCallValue(Value base, Token token, List<Value> parameters){
|
||||
this.base = base;
|
||||
this.token = token;
|
||||
this.parameters = parameters;
|
||||
}
|
||||
|
||||
private Value base(){
|
||||
return this.base;
|
||||
}
|
||||
|
||||
public Token getToken(){
|
||||
return token;
|
||||
}
|
||||
|
@ -170,7 +176,7 @@ public class Value extends JavaElement{
|
|||
|
||||
@Override
|
||||
public String toString(){
|
||||
return token.getValue()+((parameters == null ? "":parameters));
|
||||
return base+token.getValue()+((parameters == null ? "":parameters));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -180,6 +186,7 @@ public class Value extends JavaElement{
|
|||
|
||||
@Override
|
||||
public <E extends JavaElement> E find(Function<JavaElement, Boolean> finder){
|
||||
if(finder.apply(base)) return (E) base;
|
||||
if(parameters != null){
|
||||
for(Value value : parameters){
|
||||
if(finder.apply(value)) return (E) value;
|
||||
|
@ -190,6 +197,8 @@ public class Value extends JavaElement{
|
|||
|
||||
@Override
|
||||
public <E extends JavaElement> void findAll(Function<JavaElement, Boolean> finder, List<E> list){
|
||||
if(finder.apply(base)) list.add((E) base);
|
||||
base.findAll(finder, list);
|
||||
if(parameters != null){
|
||||
for(Value value : parameters){
|
||||
if(finder.apply(value)) list.add((E) value);
|
||||
|
|
Loading…
Add table
Reference in a new issue