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;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
|
||||
|
@ -8,11 +7,9 @@ import be.jeffcheasey88.peeratcode.parser.Token;
|
|||
|
||||
public class Annotation extends JavaElement{
|
||||
|
||||
public static interface AnnotableBuffer{
|
||||
public static interface Annotable{
|
||||
|
||||
void addAnnotationBuffer(Annotation annotation);
|
||||
|
||||
List<Annotation> getAnnotationBuffer();
|
||||
void addAnnotation(Annotation annotation);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
|
||||
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.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;
|
||||
|
||||
|
@ -26,14 +25,14 @@ public class Class extends JavaElement implements AnnotableBuffer, ClassContaine
|
|||
|
||||
private List<JavaElement> elements;
|
||||
|
||||
public Class(List<Annotation> annotations, Token name){
|
||||
this.annotations = annotations;
|
||||
public Class(Token name){
|
||||
this.name = name;
|
||||
this.annotations = new ArrayList<>();
|
||||
this.elements = new ArrayList<>();
|
||||
}
|
||||
|
||||
public Class(List<Annotation> annotations, Token name, Token extend, Token implement){
|
||||
this(annotations, name);
|
||||
public Class(Token name, Token extend, Token implement){
|
||||
this(name);
|
||||
this.extend = extend;
|
||||
this.implement = implement;
|
||||
}
|
||||
|
@ -43,6 +42,11 @@ public class Class extends JavaElement implements AnnotableBuffer, ClassContaine
|
|||
this.elements.add(function);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addAnnotation(Annotation annotation) {
|
||||
this.annotations.add(annotation);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addVariable(Variable variable) {
|
||||
this.elements.add(variable);
|
||||
|
@ -55,30 +59,14 @@ public class Class extends JavaElement implements AnnotableBuffer, ClassContaine
|
|||
|
||||
@Override
|
||||
public <E extends JavaElement> E find(java.util.function.Function<JavaElement, Boolean> finder){
|
||||
if(annotations != null){
|
||||
for(Annotation annotation : this.annotations){
|
||||
if(finder.apply(annotation)) return (E) annotation;
|
||||
}
|
||||
for(Annotation annotation : this.annotations){
|
||||
if(finder.apply(annotation)) return (E) annotation;
|
||||
}
|
||||
if(elements != null){
|
||||
for(JavaElement element : this.elements){
|
||||
if(finder.apply(element)) return (E) element;
|
||||
}
|
||||
for(JavaElement element : this.elements){
|
||||
if(finder.apply(element)) return (E) element;
|
||||
}
|
||||
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 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.Variable.VariableContainer;
|
||||
|
||||
public class Function extends JavaElement implements VariableContainer, OperationContainer{
|
||||
public class Function extends JavaElement implements Annotable, VariableContainer, OperationContainer{
|
||||
|
||||
public static interface FunctionContainer{
|
||||
|
||||
|
@ -26,29 +27,34 @@ public class Function extends JavaElement implements VariableContainer, Operatio
|
|||
|
||||
private List<JavaElement> elements;
|
||||
|
||||
public Function(List<Annotation> annotations, int mod, Token type, Token name){
|
||||
this.annotations = annotations;
|
||||
public Function(int mod, Token type, Token name){
|
||||
this.mod = mod;
|
||||
this.type = type;
|
||||
this.name = name;
|
||||
this.annotations = new ArrayList<>();
|
||||
this.elements = new ArrayList<>();
|
||||
}
|
||||
|
||||
public Function(List<Annotation> annotations, int mod, Token generic, Token type, Token name){
|
||||
this(annotations, mod, type, name);
|
||||
public Function(int mod, Token generic, Token type, Token name){
|
||||
this(mod, type, name);
|
||||
this.generic = generic;
|
||||
}
|
||||
|
||||
public Function(List<Annotation> annotations, int mod, Token generic, Token type, Token name, List<Variable> parameters){
|
||||
this(annotations, mod, generic, type, name);
|
||||
public Function(int mod, Token generic, Token type, Token name, List<Variable> parameters){
|
||||
this(mod, generic, type, name);
|
||||
this.parameters = parameters;
|
||||
}
|
||||
|
||||
public Function(List<Annotation> annotations, int mod, Token generic, Token type, Token name, List<Variable> parameters, List<Token> throwables){
|
||||
this(annotations, mod, generic, type, name, parameters);
|
||||
public Function(int mod, Token generic, Token type, Token name, List<Variable> parameters, List<Token> throwables){
|
||||
this(mod, generic, type, name, parameters);
|
||||
this.throwables = throwables;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addAnnotation(Annotation annotation) {
|
||||
this.annotations.add(annotation);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addVariable(Variable variable) {
|
||||
this.elements.add(variable);
|
||||
|
@ -60,21 +66,15 @@ public class Function extends JavaElement implements VariableContainer, Operatio
|
|||
}
|
||||
|
||||
@Override
|
||||
public <E extends JavaElement> E find(java.util.function.Function<JavaElement, Boolean> finder){
|
||||
if(annotations != null){
|
||||
for(Annotation annotation : this.annotations){
|
||||
if(finder.apply(annotation)) return (E) annotation;
|
||||
}
|
||||
public <E extends JavaElement> E find(java.util.function.Function<JavaElement, Boolean> finder) {
|
||||
for(Annotation annotation : this.annotations){
|
||||
if(finder.apply(annotation)) return (E) annotation;
|
||||
}
|
||||
if(parameters != null){
|
||||
for(Variable param : this.parameters){
|
||||
if(finder.apply(param)) return (E) param;
|
||||
}
|
||||
for(Variable param : this.parameters){
|
||||
if(finder.apply(param)) return (E) param;
|
||||
}
|
||||
if(elements != null){
|
||||
for(JavaElement content : this.elements){
|
||||
if(finder.apply(content)) return (E) content;
|
||||
}
|
||||
for(JavaElement content : this.elements){
|
||||
if(finder.apply(content)) return (E) content;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -6,11 +6,8 @@ import java.util.function.Function;
|
|||
|
||||
import be.jeffcheasey88.peeratcode.parser.Bag;
|
||||
import be.jeffcheasey88.peeratcode.parser.Token;
|
||||
import be.jeffcheasey88.peeratcode.parser.java.Annotation.AnnotableBuffer;
|
||||
|
||||
public class JavaFile extends JavaElement implements ClassContainer, AnnotableBuffer{
|
||||
|
||||
private List<Annotation> annotationBuffer;
|
||||
public class JavaFile extends JavaElement implements ClassContainer{
|
||||
|
||||
private List<Token> pack;
|
||||
private List<List<Token>> imports;
|
||||
|
@ -54,16 +51,4 @@ public class JavaFile extends JavaElement implements ClassContainer, AnnotableBu
|
|||
}
|
||||
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.TokenValidator;
|
||||
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.Variable.VariableContainer;
|
||||
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(")")));
|
||||
value_arg_end.end((a,b) -> a);
|
||||
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_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(",")));
|
||||
|
@ -450,7 +449,7 @@ public class JavaParser extends Parser<JavaElement> {
|
|||
annotation_name.end((parent, bag) -> {
|
||||
Annotation result = new Annotation(bag.get("name"));
|
||||
bag.set(result);
|
||||
if(parent instanceof AnnotableBuffer) ((AnnotableBuffer)parent).addAnnotationBuffer(result);
|
||||
if(parent instanceof Annotable) ((Annotable)parent).addAnnotation(result);
|
||||
return null;
|
||||
});
|
||||
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 result = new Annotation(bag.get("name"), bag.get("values"));
|
||||
bag.set(result);
|
||||
if(parent instanceof AnnotableBuffer) ((AnnotableBuffer)parent).addAnnotationBuffer(result);
|
||||
if(parent instanceof Annotable) ((Annotable)parent).addAnnotation(result);
|
||||
return null;
|
||||
});
|
||||
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");
|
||||
Map<Token, Value> map = bag.get("vars");
|
||||
for(Entry<Token, Value> vars : map.entrySet()){
|
||||
List<Annotation> annotations = null;
|
||||
if(parent instanceof AnnotableBuffer) annotations = (((AnnotableBuffer)parent).getAnnotationBuffer());
|
||||
Variable result = new Variable(annotations, mod == null ? 0 : mod, vtype, vars.getKey(), false, vars.getValue());
|
||||
Variable result = new Variable(mod == null ? 0 : mod, vtype, vars.getKey(), false, vars.getValue());
|
||||
bag.set(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) -> {
|
||||
buildVariable(bag);
|
||||
Integer mod = bag.get("mod");
|
||||
List<Annotation> annotations = null;
|
||||
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"));
|
||||
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);
|
||||
return function;
|
||||
};
|
||||
|
@ -743,7 +738,7 @@ public class JavaParser extends Parser<JavaElement> {
|
|||
InitialStateTree<JavaElement> function = new InitialStateTree<>();
|
||||
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) -> {
|
||||
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);
|
||||
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")))
|
||||
.then(new RedirectStateTree<>(type, (global, local) -> global.set("name", local.get())));
|
||||
clazz_base.then((validator) -> validator.validate((token) -> token.getValue().equals("{")))
|
||||
.<JavaElement>end((parent, bag) -> {
|
||||
Class current = new Class((((AnnotableBuffer)parent).getAnnotationBuffer()), bag.get("name"));
|
||||
if(parent instanceof ClassContainer) ((ClassContainer)parent).addClass(current);
|
||||
return current;
|
||||
})
|
||||
.<JavaElement>end((JavaElement, bag) -> null)
|
||||
.multiple(clazz_container)
|
||||
.unique((validator) -> validator.validate((token) -> token.getValue().equals("}")))
|
||||
.end((a,b) -> a);
|
||||
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) -> {
|
||||
Token token = global.get("implement");
|
||||
if(token == null) global.set("implement", local.get());
|
||||
else global.set("implement", token.concat(local.get()));
|
||||
// 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(","),
|
||||
(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(","))).then(clazz_implement_name);
|
||||
clazz_implement_name.then((validator) -> validator.validate((token) -> token.getValue().equals("{")))
|
||||
.<JavaElement>end((parent, bag) -> {
|
||||
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;
|
||||
})
|
||||
.<JavaElement>end((JavaElement, bag) -> null)
|
||||
.multiple(clazz_container)
|
||||
.unique((validator) -> validator.validate((token) -> token.getValue().equals("}")))
|
||||
.end((a,b) -> a);
|
||||
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())));
|
||||
clazz_extend.then((validator) -> validator.validate((token) -> token.getValue().equals("{")))
|
||||
.<JavaElement>end((parent, bag) -> {
|
||||
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;
|
||||
})
|
||||
.<JavaElement>end((JavaElement, bag) -> null)
|
||||
.multiple(clazz_container)
|
||||
.unique((validator) -> validator.validate((token) -> token.getValue().equals("}")))
|
||||
.end((a,b) -> a);
|
||||
|
@ -999,7 +981,6 @@ public class JavaParser extends Parser<JavaElement> {
|
|||
System.out.println("init");
|
||||
}
|
||||
|
||||
//TAKE ANNOTATIONS ???????
|
||||
private static void buildVariable(Bag bag){
|
||||
if(!bag.has("arg_name")) return;
|
||||
|
||||
|
@ -1011,7 +992,7 @@ public class JavaParser extends Parser<JavaElement> {
|
|||
|
||||
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_mod");
|
||||
bag.remove("arg_type");
|
||||
|
@ -1041,7 +1022,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\\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));
|
||||
|
||||
|
@ -1050,13 +1031,6 @@ public class JavaParser extends Parser<JavaElement> {
|
|||
Parser<JavaElement> parser = new JavaParser();
|
||||
JavaFile jFile = new JavaFile();
|
||||
parser.parse(reader, jFile);
|
||||
|
||||
System.out.println();
|
||||
|
||||
jFile.find((e) -> {
|
||||
System.out.println(e);
|
||||
return false;
|
||||
});
|
||||
|
||||
System.out.println((System.currentTimeMillis()-time)+"ms");
|
||||
|
||||
|
|
|
@ -5,8 +5,9 @@ import java.util.List;
|
|||
import java.util.function.Function;
|
||||
|
||||
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{
|
||||
|
||||
|
@ -22,20 +23,20 @@ public class Variable extends JavaElement{
|
|||
private boolean elips;
|
||||
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.type = type;
|
||||
this.name = name;
|
||||
this.annotations = new ArrayList<>();
|
||||
}
|
||||
|
||||
public Variable(List<Annotation> annotations, int mod, Token type, Token name, boolean elips){
|
||||
this(annotations, mod, type, name);
|
||||
public Variable(int mod, Token type, Token name, boolean elips){
|
||||
this(mod, type, name);
|
||||
this.elips = elips;
|
||||
}
|
||||
|
||||
public Variable(List<Annotation> annotations, int mod, Token type, Token name, boolean elips, Value value){
|
||||
this(annotations, mod, type, name, elips);
|
||||
public Variable(int mod, Token type, Token name, boolean elips, Value value){
|
||||
this(mod, type, name, elips);
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
|
@ -44,12 +45,15 @@ public class Variable extends JavaElement{
|
|||
return "Variable[mod="+mod+", type="+type+", name="+name+", elips="+elips+", value="+value+"]";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addAnnotation(Annotation annotation){
|
||||
this.annotations.add(annotation);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <E extends JavaElement> E find(Function<JavaElement, Boolean> finder){
|
||||
if(annotations != null){
|
||||
for(Annotation annotation : this.annotations){
|
||||
if(finder.apply(annotation)) return (E) annotation;
|
||||
}
|
||||
for(Annotation annotation : this.annotations){
|
||||
if(finder.apply(annotation)) return (E) annotation;
|
||||
}
|
||||
return value != null ? finder.apply(value) ? (E)value : null : null;
|
||||
}
|
||||
|
|
|
@ -44,15 +44,11 @@ public class ForOperation extends OperationBag{
|
|||
|
||||
@Override
|
||||
public <E extends JavaElement> E find(Function<JavaElement, Boolean> finder){
|
||||
if(init_vars != null){
|
||||
for(Variable variable : this.init_vars){
|
||||
if(finder.apply(variable)) return (E)variable;
|
||||
}
|
||||
for(Variable variable : this.init_vars){
|
||||
if(finder.apply(variable)) return (E)variable;
|
||||
}
|
||||
if(init_values != null){
|
||||
for(Value value : this.init_values){
|
||||
if(finder.apply(value)) return (E)value;
|
||||
}
|
||||
for(Value value : this.init_values){
|
||||
if(finder.apply(value)) return (E)value;
|
||||
}
|
||||
if(finder.apply(condition)) return (E)condition;
|
||||
for(Value value : this.updates){
|
||||
|
|
|
@ -30,10 +30,8 @@ public class OperationBag extends Operation implements VariableContainer, Operat
|
|||
|
||||
@Override
|
||||
public <E extends JavaElement> E find(Function<JavaElement, Boolean> finder){
|
||||
if(elements != null){
|
||||
for(JavaElement element : this.elements){
|
||||
if(finder.apply(element)) return (E)element;
|
||||
}
|
||||
for(JavaElement element : this.elements){
|
||||
if(finder.apply(element)) return (E)element;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ public class ReturnOperation extends Operation{
|
|||
|
||||
@Override
|
||||
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
|
||||
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.TokenType;
|
||||
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.StateTree;
|
||||
|
||||
|
@ -40,7 +41,7 @@ public class AnnotationTests {
|
|||
annotation_name.end((parent, bag) -> {
|
||||
Annotation result = new Annotation(bag.get("name"));
|
||||
bag.set(result);
|
||||
if(parent instanceof AnnotableBuffer) ((AnnotableBuffer)parent).addAnnotationBuffer(result);
|
||||
if(parent instanceof Annotable) ((Annotable)parent).addAnnotation(result);
|
||||
return null;
|
||||
});
|
||||
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 result = new Annotation(bag.get("name"), bag.get("values"));
|
||||
bag.set(result);
|
||||
if(parent instanceof AnnotableBuffer) ((AnnotableBuffer)parent).addAnnotationBuffer(result);
|
||||
if(parent instanceof Annotable) ((Annotable)parent).addAnnotation(result);
|
||||
return null;
|
||||
});
|
||||
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.Token;
|
||||
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.StateTree;
|
||||
|
||||
|
@ -23,7 +22,7 @@ public class ClassTests{
|
|||
.then(new RedirectStateTree<>(TypeTests.get(), (global, local) -> global.set("name", local.get())));
|
||||
clazz_base.then((validator) -> validator.validate((token) -> token.getValue().equals("{")))
|
||||
.<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);
|
||||
return current;
|
||||
})
|
||||
|
@ -41,7 +40,7 @@ public class ClassTests{
|
|||
(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("{")))
|
||||
.<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);
|
||||
return current;
|
||||
})
|
||||
|
@ -52,7 +51,7 @@ public class ClassTests{
|
|||
.then(new RedirectStateTree<>(TypeTests.get(), (global, local) -> global.set("extend", local.get())));
|
||||
clazz_extend.then((validator) -> validator.validate((token) -> token.getValue().equals("{")))
|
||||
.<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);
|
||||
return current;
|
||||
})
|
||||
|
|
|
@ -13,7 +13,6 @@ import be.jeffcheasey88.peeratcode.parser.Parser;
|
|||
import be.jeffcheasey88.peeratcode.parser.Token;
|
||||
import be.jeffcheasey88.peeratcode.parser.TokenType;
|
||||
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.state.BuilderStateTree;
|
||||
import be.jeffcheasey88.peeratcode.parser.state.InitialStateTree;
|
||||
|
@ -27,7 +26,7 @@ public class FunctionTests {
|
|||
BiFunction<JavaElement, Bag, JavaElement> function_builder = (parent, bag) -> {
|
||||
buildVariable(bag);
|
||||
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);
|
||||
return function;
|
||||
};
|
||||
|
@ -115,7 +114,7 @@ public class FunctionTests {
|
|||
|
||||
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_mod");
|
||||
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.TokenType;
|
||||
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.state.InitialStateTree;
|
||||
import be.jeffcheasey88.peeratcode.parser.state.RedirectStateTree;
|
||||
|
@ -28,7 +27,7 @@ public class VariableTests{
|
|||
Token type = bag.get("type");
|
||||
Map<Token, Value> map = bag.get("vars");
|
||||
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);
|
||||
if(parent instanceof VariableContainer) ((VariableContainer)parent).addVariable(result);
|
||||
}
|
||||
|
@ -80,7 +79,7 @@ public class VariableTests{
|
|||
TokenValidator.TOKENS = 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);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue