Compare commits
No commits in common. "90007dc0d2055c541bc9d2e7dd8294b0d7f8ba4f" and "e405d8e380441e9807640f4cfd59b6e50c88985d" have entirely different histories.
90007dc0d2
...
e405d8e380
14 changed files with 89 additions and 148 deletions
|
@ -1,6 +1,5 @@
|
||||||
package be.jeffcheasey88.peeratcode.parser.java;
|
package be.jeffcheasey88.peeratcode.parser.java;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
||||||
|
@ -8,11 +7,9 @@ import be.jeffcheasey88.peeratcode.parser.Token;
|
||||||
|
|
||||||
public class Annotation extends JavaElement{
|
public class Annotation extends JavaElement{
|
||||||
|
|
||||||
public static interface AnnotableBuffer{
|
public static interface Annotable{
|
||||||
|
|
||||||
void addAnnotationBuffer(Annotation annotation);
|
void addAnnotation(Annotation annotation);
|
||||||
|
|
||||||
List<Annotation> getAnnotationBuffer();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import be.jeffcheasey88.peeratcode.parser.Token;
|
import be.jeffcheasey88.peeratcode.parser.Token;
|
||||||
import be.jeffcheasey88.peeratcode.parser.java.Annotation.AnnotableBuffer;
|
import be.jeffcheasey88.peeratcode.parser.java.Annotation.Annotable;
|
||||||
import be.jeffcheasey88.peeratcode.parser.java.Function.FunctionContainer;
|
import be.jeffcheasey88.peeratcode.parser.java.Function.FunctionContainer;
|
||||||
import be.jeffcheasey88.peeratcode.parser.java.Variable.VariableContainer;
|
import be.jeffcheasey88.peeratcode.parser.java.Variable.VariableContainer;
|
||||||
|
|
||||||
|
@ -14,9 +14,8 @@ interface ClassContainer{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Class extends JavaElement implements AnnotableBuffer, ClassContainer, FunctionContainer, VariableContainer{
|
public class Class extends JavaElement implements Annotable, ClassContainer, FunctionContainer, VariableContainer{
|
||||||
|
|
||||||
private List<Annotation> annotationBuffer;
|
|
||||||
|
|
||||||
private List<Annotation> annotations;
|
private List<Annotation> annotations;
|
||||||
|
|
||||||
|
@ -26,14 +25,14 @@ public class Class extends JavaElement implements AnnotableBuffer, ClassContaine
|
||||||
|
|
||||||
private List<JavaElement> elements;
|
private List<JavaElement> elements;
|
||||||
|
|
||||||
public Class(List<Annotation> annotations, Token name){
|
public Class(Token name){
|
||||||
this.annotations = annotations;
|
|
||||||
this.name = name;
|
this.name = name;
|
||||||
|
this.annotations = new ArrayList<>();
|
||||||
this.elements = new ArrayList<>();
|
this.elements = new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Class(List<Annotation> annotations, Token name, Token extend, Token implement){
|
public Class(Token name, Token extend, Token implement){
|
||||||
this(annotations, name);
|
this(name);
|
||||||
this.extend = extend;
|
this.extend = extend;
|
||||||
this.implement = implement;
|
this.implement = implement;
|
||||||
}
|
}
|
||||||
|
@ -43,6 +42,11 @@ public class Class extends JavaElement implements AnnotableBuffer, ClassContaine
|
||||||
this.elements.add(function);
|
this.elements.add(function);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addAnnotation(Annotation annotation) {
|
||||||
|
this.annotations.add(annotation);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addVariable(Variable variable) {
|
public void addVariable(Variable variable) {
|
||||||
this.elements.add(variable);
|
this.elements.add(variable);
|
||||||
|
@ -55,30 +59,14 @@ public class Class extends JavaElement implements AnnotableBuffer, ClassContaine
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <E extends JavaElement> E find(java.util.function.Function<JavaElement, Boolean> finder){
|
public <E extends JavaElement> E find(java.util.function.Function<JavaElement, Boolean> finder){
|
||||||
if(annotations != null){
|
|
||||||
for(Annotation annotation : this.annotations){
|
for(Annotation annotation : this.annotations){
|
||||||
if(finder.apply(annotation)) return (E) annotation;
|
if(finder.apply(annotation)) return (E) annotation;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if(elements != null){
|
|
||||||
for(JavaElement element : this.elements){
|
for(JavaElement element : this.elements){
|
||||||
if(finder.apply(element)) return (E) element;
|
if(finder.apply(element)) return (E) element;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void addAnnotationBuffer(Annotation annotation){
|
|
||||||
if(annotationBuffer == null) annotationBuffer = new ArrayList<>();
|
|
||||||
annotationBuffer.add(annotation);
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Annotation> getAnnotationBuffer(){
|
|
||||||
List<Annotation> list = this.annotationBuffer;
|
|
||||||
this.annotationBuffer = null;
|
|
||||||
return list;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,10 +4,11 @@ import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import be.jeffcheasey88.peeratcode.parser.Token;
|
import be.jeffcheasey88.peeratcode.parser.Token;
|
||||||
|
import be.jeffcheasey88.peeratcode.parser.java.Annotation.Annotable;
|
||||||
import be.jeffcheasey88.peeratcode.parser.java.Operation.OperationContainer;
|
import be.jeffcheasey88.peeratcode.parser.java.Operation.OperationContainer;
|
||||||
import be.jeffcheasey88.peeratcode.parser.java.Variable.VariableContainer;
|
import be.jeffcheasey88.peeratcode.parser.java.Variable.VariableContainer;
|
||||||
|
|
||||||
public class Function extends JavaElement implements VariableContainer, OperationContainer{
|
public class Function extends JavaElement implements Annotable, VariableContainer, OperationContainer{
|
||||||
|
|
||||||
public static interface FunctionContainer{
|
public static interface FunctionContainer{
|
||||||
|
|
||||||
|
@ -26,29 +27,34 @@ public class Function extends JavaElement implements VariableContainer, Operatio
|
||||||
|
|
||||||
private List<JavaElement> elements;
|
private List<JavaElement> elements;
|
||||||
|
|
||||||
public Function(List<Annotation> annotations, int mod, Token type, Token name){
|
public Function(int mod, Token type, Token name){
|
||||||
this.annotations = annotations;
|
|
||||||
this.mod = mod;
|
this.mod = mod;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
|
this.annotations = new ArrayList<>();
|
||||||
this.elements = new ArrayList<>();
|
this.elements = new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Function(List<Annotation> annotations, int mod, Token generic, Token type, Token name){
|
public Function(int mod, Token generic, Token type, Token name){
|
||||||
this(annotations, mod, type, name);
|
this(mod, type, name);
|
||||||
this.generic = generic;
|
this.generic = generic;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Function(List<Annotation> annotations, int mod, Token generic, Token type, Token name, List<Variable> parameters){
|
public Function(int mod, Token generic, Token type, Token name, List<Variable> parameters){
|
||||||
this(annotations, mod, generic, type, name);
|
this(mod, generic, type, name);
|
||||||
this.parameters = parameters;
|
this.parameters = parameters;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Function(List<Annotation> annotations, int mod, Token generic, Token type, Token name, List<Variable> parameters, List<Token> throwables){
|
public Function(int mod, Token generic, Token type, Token name, List<Variable> parameters, List<Token> throwables){
|
||||||
this(annotations, mod, generic, type, name, parameters);
|
this(mod, generic, type, name, parameters);
|
||||||
this.throwables = throwables;
|
this.throwables = throwables;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addAnnotation(Annotation annotation) {
|
||||||
|
this.annotations.add(annotation);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addVariable(Variable variable) {
|
public void addVariable(Variable variable) {
|
||||||
this.elements.add(variable);
|
this.elements.add(variable);
|
||||||
|
@ -61,21 +67,15 @@ public class Function extends JavaElement implements VariableContainer, Operatio
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <E extends JavaElement> E find(java.util.function.Function<JavaElement, Boolean> finder) {
|
public <E extends JavaElement> E find(java.util.function.Function<JavaElement, Boolean> finder) {
|
||||||
if(annotations != null){
|
|
||||||
for(Annotation annotation : this.annotations){
|
for(Annotation annotation : this.annotations){
|
||||||
if(finder.apply(annotation)) return (E) annotation;
|
if(finder.apply(annotation)) return (E) annotation;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if(parameters != null){
|
|
||||||
for(Variable param : this.parameters){
|
for(Variable param : this.parameters){
|
||||||
if(finder.apply(param)) return (E) param;
|
if(finder.apply(param)) return (E) param;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if(elements != null){
|
|
||||||
for(JavaElement content : this.elements){
|
for(JavaElement content : this.elements){
|
||||||
if(finder.apply(content)) return (E) content;
|
if(finder.apply(content)) return (E) content;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,11 +6,8 @@ import java.util.function.Function;
|
||||||
|
|
||||||
import be.jeffcheasey88.peeratcode.parser.Bag;
|
import be.jeffcheasey88.peeratcode.parser.Bag;
|
||||||
import be.jeffcheasey88.peeratcode.parser.Token;
|
import be.jeffcheasey88.peeratcode.parser.Token;
|
||||||
import be.jeffcheasey88.peeratcode.parser.java.Annotation.AnnotableBuffer;
|
|
||||||
|
|
||||||
public class JavaFile extends JavaElement implements ClassContainer, AnnotableBuffer{
|
public class JavaFile extends JavaElement implements ClassContainer{
|
||||||
|
|
||||||
private List<Annotation> annotationBuffer;
|
|
||||||
|
|
||||||
private List<Token> pack;
|
private List<Token> pack;
|
||||||
private List<List<Token>> imports;
|
private List<List<Token>> imports;
|
||||||
|
@ -54,16 +51,4 @@ public class JavaFile extends JavaElement implements ClassContainer, AnnotableBu
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void addAnnotationBuffer(Annotation annotation){
|
|
||||||
if(annotationBuffer == null) annotationBuffer = new ArrayList<>();
|
|
||||||
annotationBuffer.add(annotation);
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Annotation> getAnnotationBuffer(){
|
|
||||||
List<Annotation> list = this.annotationBuffer;
|
|
||||||
this.annotationBuffer = null;
|
|
||||||
return list;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,7 @@ import be.jeffcheasey88.peeratcode.parser.Token;
|
||||||
import be.jeffcheasey88.peeratcode.parser.TokenType;
|
import be.jeffcheasey88.peeratcode.parser.TokenType;
|
||||||
import be.jeffcheasey88.peeratcode.parser.TokenValidator;
|
import be.jeffcheasey88.peeratcode.parser.TokenValidator;
|
||||||
import be.jeffcheasey88.peeratcode.parser.Tokenizer;
|
import be.jeffcheasey88.peeratcode.parser.Tokenizer;
|
||||||
import be.jeffcheasey88.peeratcode.parser.java.Annotation.AnnotableBuffer;
|
import be.jeffcheasey88.peeratcode.parser.java.Annotation.Annotable;
|
||||||
import be.jeffcheasey88.peeratcode.parser.java.Function.FunctionContainer;
|
import be.jeffcheasey88.peeratcode.parser.java.Function.FunctionContainer;
|
||||||
import be.jeffcheasey88.peeratcode.parser.java.Variable.VariableContainer;
|
import be.jeffcheasey88.peeratcode.parser.java.Variable.VariableContainer;
|
||||||
import be.jeffcheasey88.peeratcode.parser.state.BuilderStateTree;
|
import be.jeffcheasey88.peeratcode.parser.state.BuilderStateTree;
|
||||||
|
@ -294,7 +294,6 @@ public class JavaParser extends Parser<JavaElement> {
|
||||||
StateTree<JavaElement> value_arg_end = value_arg_begin.then((validator) -> validator.validate((token) -> token.getValue().equals(")")));
|
StateTree<JavaElement> value_arg_end = value_arg_begin.then((validator) -> validator.validate((token) -> token.getValue().equals(")")));
|
||||||
value_arg_end.end((a,b) -> a);
|
value_arg_end.end((a,b) -> a);
|
||||||
value_arg_end.then(value_call);
|
value_arg_end.then(value_call);
|
||||||
value_arg_end.then(value_array_begin);
|
|
||||||
StateTree<JavaElement> value_generic_begin = value_name.then((validator) -> validator.validate((token) -> token.getValue().equals("<")));
|
StateTree<JavaElement> value_generic_begin = value_name.then((validator) -> validator.validate((token) -> token.getValue().equals("<")));
|
||||||
StateTree<JavaElement> value_generic_name = value_generic_begin.then((validator) -> validator.validate((token) -> token.getType().equals(TokenType.NAME)));
|
StateTree<JavaElement> value_generic_name = value_generic_begin.then((validator) -> validator.validate((token) -> token.getType().equals(TokenType.NAME)));
|
||||||
StateTree<JavaElement> value_generic_split = value_generic_name.then((validator) -> validator.validate((token) -> token.getValue().equals(",")));
|
StateTree<JavaElement> value_generic_split = value_generic_name.then((validator) -> validator.validate((token) -> token.getValue().equals(",")));
|
||||||
|
@ -450,7 +449,7 @@ public class JavaParser extends Parser<JavaElement> {
|
||||||
annotation_name.end((parent, bag) -> {
|
annotation_name.end((parent, bag) -> {
|
||||||
Annotation result = new Annotation(bag.get("name"));
|
Annotation result = new Annotation(bag.get("name"));
|
||||||
bag.set(result);
|
bag.set(result);
|
||||||
if(parent instanceof AnnotableBuffer) ((AnnotableBuffer)parent).addAnnotationBuffer(result);
|
if(parent instanceof Annotable) ((Annotable)parent).addAnnotation(result);
|
||||||
return null;
|
return null;
|
||||||
});
|
});
|
||||||
StateTree<JavaElement> annotation_begin = annotation_name.then((validator) -> validator.validate((token) -> token.getValue().equals("(")));
|
StateTree<JavaElement> annotation_begin = annotation_name.then((validator) -> validator.validate((token) -> token.getValue().equals("(")));
|
||||||
|
@ -458,7 +457,7 @@ public class JavaParser extends Parser<JavaElement> {
|
||||||
annotation_end.end((parent, bag) -> {
|
annotation_end.end((parent, bag) -> {
|
||||||
Annotation result = new Annotation(bag.get("name"), bag.get("values"));
|
Annotation result = new Annotation(bag.get("name"), bag.get("values"));
|
||||||
bag.set(result);
|
bag.set(result);
|
||||||
if(parent instanceof AnnotableBuffer) ((AnnotableBuffer)parent).addAnnotationBuffer(result);
|
if(parent instanceof Annotable) ((Annotable)parent).addAnnotation(result);
|
||||||
return null;
|
return null;
|
||||||
});
|
});
|
||||||
StateTree<JavaElement> annotation_var = annotation_begin.then((validator) -> validator.validate(
|
StateTree<JavaElement> annotation_var = annotation_begin.then((validator) -> validator.validate(
|
||||||
|
@ -490,9 +489,7 @@ public class JavaParser extends Parser<JavaElement> {
|
||||||
Token vtype = bag.get("type");
|
Token vtype = bag.get("type");
|
||||||
Map<Token, Value> map = bag.get("vars");
|
Map<Token, Value> map = bag.get("vars");
|
||||||
for(Entry<Token, Value> vars : map.entrySet()){
|
for(Entry<Token, Value> vars : map.entrySet()){
|
||||||
List<Annotation> annotations = null;
|
Variable result = new Variable(mod == null ? 0 : mod, vtype, vars.getKey(), false, vars.getValue());
|
||||||
if(parent instanceof AnnotableBuffer) annotations = (((AnnotableBuffer)parent).getAnnotationBuffer());
|
|
||||||
Variable result = new Variable(annotations, mod == null ? 0 : mod, vtype, vars.getKey(), false, vars.getValue());
|
|
||||||
bag.set(result);
|
bag.set(result);
|
||||||
if(parent instanceof VariableContainer) ((VariableContainer)parent).addVariable(result);
|
if(parent instanceof VariableContainer) ((VariableContainer)parent).addVariable(result);
|
||||||
}
|
}
|
||||||
|
@ -733,9 +730,7 @@ public class JavaParser extends Parser<JavaElement> {
|
||||||
BiFunction<JavaElement, Bag, JavaElement> function_builder = (parent, bag) -> {
|
BiFunction<JavaElement, Bag, JavaElement> function_builder = (parent, bag) -> {
|
||||||
buildVariable(bag);
|
buildVariable(bag);
|
||||||
Integer mod = bag.get("mod");
|
Integer mod = bag.get("mod");
|
||||||
List<Annotation> annotations = null;
|
Function function = new Function(mod == null ? 0 : mod, bag.get("generic"), bag.get("type"), bag.get("name"), bag.get("param"), bag.get("throws"));
|
||||||
if(parent instanceof AnnotableBuffer) annotations = (((AnnotableBuffer)parent).getAnnotationBuffer());
|
|
||||||
Function function = new Function(annotations, mod == null ? 0 : mod, bag.get("generic"), bag.get("type"), bag.get("name"), bag.get("param"), bag.get("throws"));
|
|
||||||
if(parent instanceof FunctionContainer) ((FunctionContainer)parent).addFunction(function);
|
if(parent instanceof FunctionContainer) ((FunctionContainer)parent).addFunction(function);
|
||||||
return function;
|
return function;
|
||||||
};
|
};
|
||||||
|
@ -743,7 +738,7 @@ public class JavaParser extends Parser<JavaElement> {
|
||||||
InitialStateTree<JavaElement> function = new InitialStateTree<>();
|
InitialStateTree<JavaElement> function = new InitialStateTree<>();
|
||||||
function.multiple(annotation);
|
function.multiple(annotation);
|
||||||
BuilderStateTree<JavaElement,JavaElement> function_static = function.then((validator) -> validator.validate((token) -> token.getValue().equals("static")) && validator.validate((token) -> token.getValue().equals("{"))).end((parent, bag) -> {
|
BuilderStateTree<JavaElement,JavaElement> function_static = function.then((validator) -> validator.validate((token) -> token.getValue().equals("static")) && validator.validate((token) -> token.getValue().equals("{"))).end((parent, bag) -> {
|
||||||
Function build = new Function((((AnnotableBuffer)parent).getAnnotationBuffer()), Modifier.STATIC, null, null);
|
Function build = new Function(Modifier.STATIC, null, null);
|
||||||
if(parent instanceof FunctionContainer) ((FunctionContainer)parent).addFunction(build);
|
if(parent instanceof FunctionContainer) ((FunctionContainer)parent).addFunction(build);
|
||||||
return build;
|
return build;
|
||||||
});
|
});
|
||||||
|
@ -832,40 +827,27 @@ public class JavaParser extends Parser<JavaElement> {
|
||||||
StateTree<JavaElement> clazz_base = clazz.then((validator) -> validator.validate((token) -> token.getValue().equals("class")))
|
StateTree<JavaElement> clazz_base = clazz.then((validator) -> validator.validate((token) -> token.getValue().equals("class")))
|
||||||
.then(new RedirectStateTree<>(type, (global, local) -> global.set("name", local.get())));
|
.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("{")))
|
||||||
.<JavaElement>end((parent, bag) -> {
|
.<JavaElement>end((JavaElement, bag) -> null)
|
||||||
Class current = new Class((((AnnotableBuffer)parent).getAnnotationBuffer()), bag.get("name"));
|
|
||||||
if(parent instanceof ClassContainer) ((ClassContainer)parent).addClass(current);
|
|
||||||
return current;
|
|
||||||
})
|
|
||||||
.multiple(clazz_container)
|
.multiple(clazz_container)
|
||||||
.unique((validator) -> validator.validate((token) -> token.getValue().equals("}")))
|
.unique((validator) -> validator.validate((token) -> token.getValue().equals("}")))
|
||||||
.end((a,b) -> a);
|
.end((a,b) -> a);
|
||||||
StateTree<JavaElement> clazz_implement = clazz_base.then((validator) -> validator.validate((token) -> token.getValue().equals("implements")));
|
StateTree<JavaElement> clazz_implement = clazz_base.then((validator) -> validator.validate((token) -> token.getValue().equals("implements")));
|
||||||
StateTree<JavaElement> clazz_implement_name = clazz_implement.then(new RedirectStateTree<>(type, (global, local) -> {
|
StateTree<JavaElement> clazz_implement_name = clazz_implement.then(new RedirectStateTree<>(type, (global, local) -> {
|
||||||
Token token = global.get("implement");
|
Token token = global.get("implement");
|
||||||
if(token == null) global.set("implement", local.get());
|
// if(token == null) token = local.get();
|
||||||
else global.set("implement", token.concat(local.get()));
|
// else token = token.concat(local.get());
|
||||||
|
global.set("implement", token);
|
||||||
}));
|
}));
|
||||||
clazz_implement_name.then((validator) -> validator.validate(
|
clazz_implement_name.then((validator) -> validator.validate((token) -> token.getValue().equals(","))).then(clazz_implement_name);
|
||||||
(token) -> token.getValue().equals(","),
|
|
||||||
(bag, token) -> bag.set("implement", bag.<Token>get("implement").concat(token)))).then(clazz_implement_name);
|
|
||||||
clazz_implement_name.then((validator) -> validator.validate((token) -> token.getValue().equals("{")))
|
clazz_implement_name.then((validator) -> validator.validate((token) -> token.getValue().equals("{")))
|
||||||
.<JavaElement>end((parent, bag) -> {
|
.<JavaElement>end((JavaElement, bag) -> null)
|
||||||
Class current = new Class((((AnnotableBuffer)parent).getAnnotationBuffer()), bag.get("name"), bag.get("extend"), bag.get("implements"));
|
|
||||||
if(parent instanceof ClassContainer) ((ClassContainer)parent).addClass(current);
|
|
||||||
return current;
|
|
||||||
})
|
|
||||||
.multiple(clazz_container)
|
.multiple(clazz_container)
|
||||||
.unique((validator) -> validator.validate((token) -> token.getValue().equals("}")))
|
.unique((validator) -> validator.validate((token) -> token.getValue().equals("}")))
|
||||||
.end((a,b) -> a);
|
.end((a,b) -> a);
|
||||||
StateTree<JavaElement> clazz_extend = clazz_base.then((validator) -> validator.validate((token) -> token.getValue().equals("extends")))
|
StateTree<JavaElement> clazz_extend = clazz_base.then((validator) -> validator.validate((token) -> token.getValue().equals("extends")))
|
||||||
.then(new RedirectStateTree<>(type, (global, local) -> global.set("extend", local.get())));
|
.then(new RedirectStateTree<>(type, (global, local) -> global.set("extend", local.get())));
|
||||||
clazz_extend.then((validator) -> validator.validate((token) -> token.getValue().equals("{")))
|
clazz_extend.then((validator) -> validator.validate((token) -> token.getValue().equals("{")))
|
||||||
.<JavaElement>end((parent, bag) -> {
|
.<JavaElement>end((JavaElement, bag) -> null)
|
||||||
Class current = new Class((((AnnotableBuffer)parent).getAnnotationBuffer()), bag.get("name"), bag.get("extend"), bag.get("implements"));
|
|
||||||
if(parent instanceof ClassContainer) ((ClassContainer)parent).addClass(current);
|
|
||||||
return current;
|
|
||||||
})
|
|
||||||
.multiple(clazz_container)
|
.multiple(clazz_container)
|
||||||
.unique((validator) -> validator.validate((token) -> token.getValue().equals("}")))
|
.unique((validator) -> validator.validate((token) -> token.getValue().equals("}")))
|
||||||
.end((a,b) -> a);
|
.end((a,b) -> a);
|
||||||
|
@ -999,7 +981,6 @@ public class JavaParser extends Parser<JavaElement> {
|
||||||
System.out.println("init");
|
System.out.println("init");
|
||||||
}
|
}
|
||||||
|
|
||||||
//TAKE ANNOTATIONS ???????
|
|
||||||
private static void buildVariable(Bag bag){
|
private static void buildVariable(Bag bag){
|
||||||
if(!bag.has("arg_name")) return;
|
if(!bag.has("arg_name")) return;
|
||||||
|
|
||||||
|
@ -1011,7 +992,7 @@ public class JavaParser extends Parser<JavaElement> {
|
||||||
|
|
||||||
Integer mod = bag.get("arg_mod");
|
Integer mod = bag.get("arg_mod");
|
||||||
|
|
||||||
Variable variable = new Variable(null, mod == null ? 0 : mod, bag.<Token>get("arg_type"), bag.<Token>get("arg_name"), bag.get("arg_elips") == Boolean.TRUE);
|
Variable variable = new Variable(mod == null ? 0 : mod, bag.<Token>get("arg_type"), bag.<Token>get("arg_name"), bag.get("arg_elips") == Boolean.TRUE);
|
||||||
bag.remove("arg_name");
|
bag.remove("arg_name");
|
||||||
bag.remove("arg_mod");
|
bag.remove("arg_mod");
|
||||||
bag.remove("arg_type");
|
bag.remove("arg_type");
|
||||||
|
@ -1041,7 +1022,7 @@ public class JavaParser extends Parser<JavaElement> {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception{
|
public static void main(String[] args) throws Exception{
|
||||||
File file = new File("C:\\Users\\jeffc\\eclipse-workspace\\peer-at-code-backend\\test\\dev\\peerat\\backend\\routes\\PlayerDetailsTests.java");
|
File file = new File("C:\\Users\\jeffc\\eclipse-workspace\\peer-at-code-backend\\src\\dev\\peerat\\backend\\bonus\\extract\\RouteExtracter.java");
|
||||||
|
|
||||||
BufferedReader reader = new BufferedReader(new FileReader(file));
|
BufferedReader reader = new BufferedReader(new FileReader(file));
|
||||||
|
|
||||||
|
@ -1051,13 +1032,6 @@ public class JavaParser extends Parser<JavaElement> {
|
||||||
JavaFile jFile = new JavaFile();
|
JavaFile jFile = new JavaFile();
|
||||||
parser.parse(reader, jFile);
|
parser.parse(reader, jFile);
|
||||||
|
|
||||||
System.out.println();
|
|
||||||
|
|
||||||
jFile.find((e) -> {
|
|
||||||
System.out.println(e);
|
|
||||||
return false;
|
|
||||||
});
|
|
||||||
|
|
||||||
System.out.println((System.currentTimeMillis()-time)+"ms");
|
System.out.println((System.currentTimeMillis()-time)+"ms");
|
||||||
|
|
||||||
System.out.println(TokenValidator.MAX_VALIDATE+" / "+TokenValidator.TOKENS);
|
System.out.println(TokenValidator.MAX_VALIDATE+" / "+TokenValidator.TOKENS);
|
||||||
|
|
|
@ -5,8 +5,9 @@ import java.util.List;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
||||||
import be.jeffcheasey88.peeratcode.parser.Token;
|
import be.jeffcheasey88.peeratcode.parser.Token;
|
||||||
|
import be.jeffcheasey88.peeratcode.parser.java.Annotation.Annotable;
|
||||||
|
|
||||||
public class Variable extends JavaElement{
|
public class Variable extends JavaElement implements Annotable{
|
||||||
|
|
||||||
public static interface VariableContainer{
|
public static interface VariableContainer{
|
||||||
|
|
||||||
|
@ -22,20 +23,20 @@ public class Variable extends JavaElement{
|
||||||
private boolean elips;
|
private boolean elips;
|
||||||
private Value value;
|
private Value value;
|
||||||
|
|
||||||
public Variable(List<Annotation> annotations, int mod, Token type, Token name){
|
public Variable(int mod, Token type, Token name){
|
||||||
this.mod = mod;
|
this.mod = mod;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.annotations = new ArrayList<>();
|
this.annotations = new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Variable(List<Annotation> annotations, int mod, Token type, Token name, boolean elips){
|
public Variable(int mod, Token type, Token name, boolean elips){
|
||||||
this(annotations, mod, type, name);
|
this(mod, type, name);
|
||||||
this.elips = elips;
|
this.elips = elips;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Variable(List<Annotation> annotations, int mod, Token type, Token name, boolean elips, Value value){
|
public Variable(int mod, Token type, Token name, boolean elips, Value value){
|
||||||
this(annotations, mod, type, name, elips);
|
this(mod, type, name, elips);
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,13 +45,16 @@ public class Variable extends JavaElement{
|
||||||
return "Variable[mod="+mod+", type="+type+", name="+name+", elips="+elips+", value="+value+"]";
|
return "Variable[mod="+mod+", type="+type+", name="+name+", elips="+elips+", value="+value+"]";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addAnnotation(Annotation annotation){
|
||||||
|
this.annotations.add(annotation);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <E extends JavaElement> E find(Function<JavaElement, Boolean> finder){
|
public <E extends JavaElement> E find(Function<JavaElement, Boolean> finder){
|
||||||
if(annotations != null){
|
|
||||||
for(Annotation annotation : this.annotations){
|
for(Annotation annotation : this.annotations){
|
||||||
if(finder.apply(annotation)) return (E) annotation;
|
if(finder.apply(annotation)) return (E) annotation;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return value != null ? finder.apply(value) ? (E)value : null : null;
|
return value != null ? finder.apply(value) ? (E)value : null : null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,16 +44,12 @@ public class ForOperation extends OperationBag{
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <E extends JavaElement> E find(Function<JavaElement, Boolean> finder){
|
public <E extends JavaElement> E find(Function<JavaElement, Boolean> finder){
|
||||||
if(init_vars != null){
|
|
||||||
for(Variable variable : this.init_vars){
|
for(Variable variable : this.init_vars){
|
||||||
if(finder.apply(variable)) return (E)variable;
|
if(finder.apply(variable)) return (E)variable;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if(init_values != null){
|
|
||||||
for(Value value : this.init_values){
|
for(Value value : this.init_values){
|
||||||
if(finder.apply(value)) return (E)value;
|
if(finder.apply(value)) return (E)value;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if(finder.apply(condition)) return (E)condition;
|
if(finder.apply(condition)) return (E)condition;
|
||||||
for(Value value : this.updates){
|
for(Value value : this.updates){
|
||||||
if(finder.apply(value)) return (E)value;
|
if(finder.apply(value)) return (E)value;
|
||||||
|
|
|
@ -30,11 +30,9 @@ public class OperationBag extends Operation implements VariableContainer, Operat
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <E extends JavaElement> E find(Function<JavaElement, Boolean> finder){
|
public <E extends JavaElement> E find(Function<JavaElement, Boolean> finder){
|
||||||
if(elements != null){
|
|
||||||
for(JavaElement element : this.elements){
|
for(JavaElement element : this.elements){
|
||||||
if(finder.apply(element)) return (E)element;
|
if(finder.apply(element)) return (E)element;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,7 @@ public class ReturnOperation extends Operation{
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <E extends JavaElement> E find(Function<JavaElement, Boolean> finder) {
|
public <E extends JavaElement> E find(Function<JavaElement, Boolean> finder) {
|
||||||
return value != null ? finder.apply(value) ? (E)value : null : null;
|
return finder.apply(value) ? (E)value : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,7 @@ public class TryOperation extends OperationBag{
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <E extends JavaElement> E find(Function<JavaElement, Boolean> finder){
|
public <E extends JavaElement> E find(Function<JavaElement, Boolean> finder){
|
||||||
return resource != null ? finder.apply(resource) ? (E)resource : super.find(finder) : super.find(finder);
|
if(finder.apply(resource)) return (E)resource;
|
||||||
|
return super.find(finder);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,8 @@ import be.jeffcheasey88.peeratcode.parser.Parser;
|
||||||
import be.jeffcheasey88.peeratcode.parser.Token;
|
import be.jeffcheasey88.peeratcode.parser.Token;
|
||||||
import be.jeffcheasey88.peeratcode.parser.TokenType;
|
import be.jeffcheasey88.peeratcode.parser.TokenType;
|
||||||
import be.jeffcheasey88.peeratcode.parser.TokenValidator;
|
import be.jeffcheasey88.peeratcode.parser.TokenValidator;
|
||||||
import be.jeffcheasey88.peeratcode.parser.java.Annotation.AnnotableBuffer;
|
import be.jeffcheasey88.peeratcode.parser.java.Annotation.Annotable;
|
||||||
|
import be.jeffcheasey88.peeratcode.parser.java.Function.FunctionContainer;
|
||||||
import be.jeffcheasey88.peeratcode.parser.state.RedirectStateTree;
|
import be.jeffcheasey88.peeratcode.parser.state.RedirectStateTree;
|
||||||
import be.jeffcheasey88.peeratcode.parser.state.StateTree;
|
import be.jeffcheasey88.peeratcode.parser.state.StateTree;
|
||||||
|
|
||||||
|
@ -40,7 +41,7 @@ public class AnnotationTests {
|
||||||
annotation_name.end((parent, bag) -> {
|
annotation_name.end((parent, bag) -> {
|
||||||
Annotation result = new Annotation(bag.get("name"));
|
Annotation result = new Annotation(bag.get("name"));
|
||||||
bag.set(result);
|
bag.set(result);
|
||||||
if(parent instanceof AnnotableBuffer) ((AnnotableBuffer)parent).addAnnotationBuffer(result);
|
if(parent instanceof Annotable) ((Annotable)parent).addAnnotation(result);
|
||||||
return null;
|
return null;
|
||||||
});
|
});
|
||||||
StateTree<JavaElement> annotation_begin = annotation_name.then((validator) -> validator.validate((token) -> token.getValue().equals("(")));
|
StateTree<JavaElement> annotation_begin = annotation_name.then((validator) -> validator.validate((token) -> token.getValue().equals("(")));
|
||||||
|
@ -48,7 +49,7 @@ public class AnnotationTests {
|
||||||
annotation_end.end((parent, bag) -> {
|
annotation_end.end((parent, bag) -> {
|
||||||
Annotation result = new Annotation(bag.get("name"), bag.get("values"));
|
Annotation result = new Annotation(bag.get("name"), bag.get("values"));
|
||||||
bag.set(result);
|
bag.set(result);
|
||||||
if(parent instanceof AnnotableBuffer) ((AnnotableBuffer)parent).addAnnotationBuffer(result);
|
if(parent instanceof Annotable) ((Annotable)parent).addAnnotation(result);
|
||||||
return null;
|
return null;
|
||||||
});
|
});
|
||||||
StateTree<JavaElement> annotation_var = annotation_begin.then((validator) -> validator.validate(
|
StateTree<JavaElement> annotation_var = annotation_begin.then((validator) -> validator.validate(
|
||||||
|
|
|
@ -7,7 +7,6 @@ import org.junit.jupiter.api.Test;
|
||||||
import be.jeffcheasey88.peeratcode.parser.Parser;
|
import be.jeffcheasey88.peeratcode.parser.Parser;
|
||||||
import be.jeffcheasey88.peeratcode.parser.Token;
|
import be.jeffcheasey88.peeratcode.parser.Token;
|
||||||
import be.jeffcheasey88.peeratcode.parser.TokenValidator;
|
import be.jeffcheasey88.peeratcode.parser.TokenValidator;
|
||||||
import be.jeffcheasey88.peeratcode.parser.java.Annotation.AnnotableBuffer;
|
|
||||||
import be.jeffcheasey88.peeratcode.parser.state.RedirectStateTree;
|
import be.jeffcheasey88.peeratcode.parser.state.RedirectStateTree;
|
||||||
import be.jeffcheasey88.peeratcode.parser.state.StateTree;
|
import be.jeffcheasey88.peeratcode.parser.state.StateTree;
|
||||||
|
|
||||||
|
@ -23,7 +22,7 @@ public class ClassTests{
|
||||||
.then(new RedirectStateTree<>(TypeTests.get(), (global, local) -> global.set("name", local.get())));
|
.then(new RedirectStateTree<>(TypeTests.get(), (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("{")))
|
||||||
.<JavaElement>end((parent, bag) -> {
|
.<JavaElement>end((parent, bag) -> {
|
||||||
Class current = new Class((((AnnotableBuffer)parent).getAnnotationBuffer()), bag.get("name"));
|
Class current = new Class(bag.get("name"));
|
||||||
if(parent instanceof ClassContainer) ((ClassContainer)parent).addClass(current);
|
if(parent instanceof ClassContainer) ((ClassContainer)parent).addClass(current);
|
||||||
return current;
|
return current;
|
||||||
})
|
})
|
||||||
|
@ -41,7 +40,7 @@ public class ClassTests{
|
||||||
(bag, token) -> bag.set("implement", bag.<Token>get("implement").concat(token)))).then(clazz_implement_name);
|
(bag, token) -> bag.set("implement", bag.<Token>get("implement").concat(token)))).then(clazz_implement_name);
|
||||||
clazz_implement_name.then((validator) -> validator.validate((token) -> token.getValue().equals("{")))
|
clazz_implement_name.then((validator) -> validator.validate((token) -> token.getValue().equals("{")))
|
||||||
.<JavaElement>end((parent, bag) -> {
|
.<JavaElement>end((parent, bag) -> {
|
||||||
Class current = new Class((((AnnotableBuffer)parent).getAnnotationBuffer()),bag.get("name"), bag.get("extend"), bag.get("implements"));
|
Class current = new Class(bag.get("name"), bag.get("extend"), bag.get("implements"));
|
||||||
if(parent instanceof ClassContainer) ((ClassContainer)parent).addClass(current);
|
if(parent instanceof ClassContainer) ((ClassContainer)parent).addClass(current);
|
||||||
return current;
|
return current;
|
||||||
})
|
})
|
||||||
|
@ -52,7 +51,7 @@ public class ClassTests{
|
||||||
.then(new RedirectStateTree<>(TypeTests.get(), (global, local) -> global.set("extend", local.get())));
|
.then(new RedirectStateTree<>(TypeTests.get(), (global, local) -> global.set("extend", local.get())));
|
||||||
clazz_extend.then((validator) -> validator.validate((token) -> token.getValue().equals("{")))
|
clazz_extend.then((validator) -> validator.validate((token) -> token.getValue().equals("{")))
|
||||||
.<JavaElement>end((parent, bag) -> {
|
.<JavaElement>end((parent, bag) -> {
|
||||||
Class current = new Class((((AnnotableBuffer)parent).getAnnotationBuffer()), bag.get("name"), bag.get("extend"), bag.get("implements"));
|
Class current = new Class(bag.get("name"), bag.get("extend"), bag.get("implements"));
|
||||||
if(parent instanceof ClassContainer) ((ClassContainer)parent).addClass(current);
|
if(parent instanceof ClassContainer) ((ClassContainer)parent).addClass(current);
|
||||||
return current;
|
return current;
|
||||||
})
|
})
|
||||||
|
|
|
@ -13,7 +13,6 @@ import be.jeffcheasey88.peeratcode.parser.Parser;
|
||||||
import be.jeffcheasey88.peeratcode.parser.Token;
|
import be.jeffcheasey88.peeratcode.parser.Token;
|
||||||
import be.jeffcheasey88.peeratcode.parser.TokenType;
|
import be.jeffcheasey88.peeratcode.parser.TokenType;
|
||||||
import be.jeffcheasey88.peeratcode.parser.TokenValidator;
|
import be.jeffcheasey88.peeratcode.parser.TokenValidator;
|
||||||
import be.jeffcheasey88.peeratcode.parser.java.Annotation.AnnotableBuffer;
|
|
||||||
import be.jeffcheasey88.peeratcode.parser.java.Function.FunctionContainer;
|
import be.jeffcheasey88.peeratcode.parser.java.Function.FunctionContainer;
|
||||||
import be.jeffcheasey88.peeratcode.parser.state.BuilderStateTree;
|
import be.jeffcheasey88.peeratcode.parser.state.BuilderStateTree;
|
||||||
import be.jeffcheasey88.peeratcode.parser.state.InitialStateTree;
|
import be.jeffcheasey88.peeratcode.parser.state.InitialStateTree;
|
||||||
|
@ -27,7 +26,7 @@ public class FunctionTests {
|
||||||
BiFunction<JavaElement, Bag, JavaElement> function_builder = (parent, bag) -> {
|
BiFunction<JavaElement, Bag, JavaElement> function_builder = (parent, bag) -> {
|
||||||
buildVariable(bag);
|
buildVariable(bag);
|
||||||
Integer mod = bag.get("mod");
|
Integer mod = bag.get("mod");
|
||||||
Function function = new Function((((AnnotableBuffer)parent).getAnnotationBuffer()), mod == null ? 0 : mod, bag.get("generic"), bag.get("type"), bag.get("name"), bag.get("param"), bag.get("throws"));
|
Function function = new Function(mod == null ? 0 : mod, bag.get("generic"), bag.get("type"), bag.get("name"), bag.get("param"), bag.get("throws"));
|
||||||
if(parent instanceof FunctionContainer) ((FunctionContainer)parent).addFunction(function);
|
if(parent instanceof FunctionContainer) ((FunctionContainer)parent).addFunction(function);
|
||||||
return function;
|
return function;
|
||||||
};
|
};
|
||||||
|
@ -115,7 +114,7 @@ public class FunctionTests {
|
||||||
|
|
||||||
Integer mod = bag.get("arg_mod");
|
Integer mod = bag.get("arg_mod");
|
||||||
|
|
||||||
Variable variable = new Variable(null, mod == null ? 0 : mod, bag.<Token>get("arg_type"), bag.<Token>get("arg_name"), bag.get("arg_elips") == Boolean.TRUE);
|
Variable variable = new Variable(mod == null ? 0 : mod, bag.<Token>get("arg_type"), bag.<Token>get("arg_name"), bag.get("arg_elips") == Boolean.TRUE);
|
||||||
bag.remove("arg_name");
|
bag.remove("arg_name");
|
||||||
bag.remove("arg_mod");
|
bag.remove("arg_mod");
|
||||||
bag.remove("arg_type");
|
bag.remove("arg_type");
|
||||||
|
|
|
@ -14,7 +14,6 @@ import be.jeffcheasey88.peeratcode.parser.Parser;
|
||||||
import be.jeffcheasey88.peeratcode.parser.Token;
|
import be.jeffcheasey88.peeratcode.parser.Token;
|
||||||
import be.jeffcheasey88.peeratcode.parser.TokenType;
|
import be.jeffcheasey88.peeratcode.parser.TokenType;
|
||||||
import be.jeffcheasey88.peeratcode.parser.TokenValidator;
|
import be.jeffcheasey88.peeratcode.parser.TokenValidator;
|
||||||
import be.jeffcheasey88.peeratcode.parser.java.Annotation.AnnotableBuffer;
|
|
||||||
import be.jeffcheasey88.peeratcode.parser.java.Variable.VariableContainer;
|
import be.jeffcheasey88.peeratcode.parser.java.Variable.VariableContainer;
|
||||||
import be.jeffcheasey88.peeratcode.parser.state.InitialStateTree;
|
import be.jeffcheasey88.peeratcode.parser.state.InitialStateTree;
|
||||||
import be.jeffcheasey88.peeratcode.parser.state.RedirectStateTree;
|
import be.jeffcheasey88.peeratcode.parser.state.RedirectStateTree;
|
||||||
|
@ -28,7 +27,7 @@ public class VariableTests{
|
||||||
Token type = bag.get("type");
|
Token type = bag.get("type");
|
||||||
Map<Token, Value> map = bag.get("vars");
|
Map<Token, Value> map = bag.get("vars");
|
||||||
for(Entry<Token, Value> vars : map.entrySet()){
|
for(Entry<Token, Value> vars : map.entrySet()){
|
||||||
Variable result = new Variable((((AnnotableBuffer)parent).getAnnotationBuffer()), mod == null ? 0 : mod, type, vars.getKey(), false, vars.getValue());
|
Variable result = new Variable(mod == null ? 0 : mod, type, vars.getKey(), false, vars.getValue());
|
||||||
bag.set(result);
|
bag.set(result);
|
||||||
if(parent instanceof VariableContainer) ((VariableContainer)parent).addVariable(result);
|
if(parent instanceof VariableContainer) ((VariableContainer)parent).addVariable(result);
|
||||||
}
|
}
|
||||||
|
@ -80,7 +79,7 @@ public class VariableTests{
|
||||||
TokenValidator.TOKENS = 0;
|
TokenValidator.TOKENS = 0;
|
||||||
TokenValidator.MAX_VALIDATE = 0;
|
TokenValidator.MAX_VALIDATE = 0;
|
||||||
|
|
||||||
JavaElement result = new Class(null, new Token(0, 0, "Test", TokenType.NAME));
|
JavaElement result = new Class(new Token(0, 0, "Test", TokenType.NAME));
|
||||||
|
|
||||||
parser.parse(value, result);
|
parser.parse(value, result);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue