Refractor Annotation buffer
This commit is contained in:
parent
4445a76672
commit
aab4cd5fd8
10 changed files with 105 additions and 66 deletions
|
@ -1,5 +1,6 @@
|
||||||
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;
|
||||||
|
|
||||||
|
@ -7,9 +8,11 @@ import be.jeffcheasey88.peeratcode.parser.Token;
|
||||||
|
|
||||||
public class Annotation extends JavaElement{
|
public class Annotation extends JavaElement{
|
||||||
|
|
||||||
public static interface Annotable{
|
public static interface AnnotableBuffer{
|
||||||
|
|
||||||
void addAnnotation(Annotation annotation);
|
void addAnnotationBuffer(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.Annotable;
|
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.java.Variable.VariableContainer;
|
import be.jeffcheasey88.peeratcode.parser.java.Variable.VariableContainer;
|
||||||
|
|
||||||
|
@ -14,8 +14,9 @@ interface ClassContainer{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Class extends JavaElement implements Annotable, ClassContainer, FunctionContainer, VariableContainer{
|
public class Class extends JavaElement implements AnnotableBuffer, ClassContainer, FunctionContainer, VariableContainer{
|
||||||
|
|
||||||
|
private List<Annotation> annotationBuffer;
|
||||||
|
|
||||||
private List<Annotation> annotations;
|
private List<Annotation> annotations;
|
||||||
|
|
||||||
|
@ -25,14 +26,14 @@ public class Class extends JavaElement implements Annotable, ClassContainer, Fun
|
||||||
|
|
||||||
private List<JavaElement> elements;
|
private List<JavaElement> elements;
|
||||||
|
|
||||||
public Class(Token name){
|
public Class(List<Annotation> annotations, 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(Token name, Token extend, Token implement){
|
public Class(List<Annotation> annotations, Token name, Token extend, Token implement){
|
||||||
this(name);
|
this(annotations, name);
|
||||||
this.extend = extend;
|
this.extend = extend;
|
||||||
this.implement = implement;
|
this.implement = implement;
|
||||||
}
|
}
|
||||||
|
@ -42,11 +43,6 @@ public class Class extends JavaElement implements Annotable, ClassContainer, Fun
|
||||||
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);
|
||||||
|
@ -68,5 +64,17 @@ public class Class extends JavaElement implements Annotable, ClassContainer, Fun
|
||||||
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,11 +4,10 @@ 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 Annotable, VariableContainer, OperationContainer{
|
public class Function extends JavaElement implements VariableContainer, OperationContainer{
|
||||||
|
|
||||||
public static interface FunctionContainer{
|
public static interface FunctionContainer{
|
||||||
|
|
||||||
|
@ -27,34 +26,29 @@ public class Function extends JavaElement implements Annotable, VariableContaine
|
||||||
|
|
||||||
private List<JavaElement> elements;
|
private List<JavaElement> elements;
|
||||||
|
|
||||||
public Function(int mod, Token type, Token name){
|
public Function(List<Annotation> annotations, 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(int mod, Token generic, Token type, Token name){
|
public Function(List<Annotation> annotations, int mod, Token generic, Token type, Token name){
|
||||||
this(mod, type, name);
|
this(annotations, mod, type, name);
|
||||||
this.generic = generic;
|
this.generic = generic;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Function(int mod, Token generic, Token type, Token name, List<Variable> parameters){
|
public Function(List<Annotation> annotations, int mod, Token generic, Token type, Token name, List<Variable> parameters){
|
||||||
this(mod, generic, type, name);
|
this(annotations, mod, generic, type, name);
|
||||||
this.parameters = parameters;
|
this.parameters = parameters;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Function(int mod, Token generic, Token type, Token name, List<Variable> parameters, List<Token> throwables){
|
public Function(List<Annotation> annotations, int mod, Token generic, Token type, Token name, List<Variable> parameters, List<Token> throwables){
|
||||||
this(mod, generic, type, name, parameters);
|
this(annotations, 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);
|
||||||
|
|
|
@ -6,8 +6,11 @@ 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{
|
public class JavaFile extends JavaElement implements ClassContainer, AnnotableBuffer{
|
||||||
|
|
||||||
|
private List<Annotation> annotationBuffer;
|
||||||
|
|
||||||
private List<Token> pack;
|
private List<Token> pack;
|
||||||
private List<List<Token>> imports;
|
private List<List<Token>> imports;
|
||||||
|
@ -51,4 +54,16 @@ public class JavaFile extends JavaElement implements ClassContainer{
|
||||||
}
|
}
|
||||||
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.Annotable;
|
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.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;
|
||||||
|
@ -450,7 +450,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 Annotable) ((Annotable)parent).addAnnotation(result);
|
if(parent instanceof AnnotableBuffer) ((AnnotableBuffer)parent).addAnnotationBuffer(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 +458,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 Annotable) ((Annotable)parent).addAnnotation(result);
|
if(parent instanceof AnnotableBuffer) ((AnnotableBuffer)parent).addAnnotationBuffer(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,7 +490,9 @@ 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()){
|
||||||
Variable result = new Variable(mod == null ? 0 : mod, vtype, vars.getKey(), false, vars.getValue());
|
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());
|
||||||
bag.set(result);
|
bag.set(result);
|
||||||
if(parent instanceof VariableContainer) ((VariableContainer)parent).addVariable(result);
|
if(parent instanceof VariableContainer) ((VariableContainer)parent).addVariable(result);
|
||||||
}
|
}
|
||||||
|
@ -731,7 +733,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");
|
||||||
Function function = new Function(mod == null ? 0 : mod, bag.get("generic"), bag.get("type"), bag.get("name"), bag.get("param"), bag.get("throws"));
|
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"));
|
||||||
if(parent instanceof FunctionContainer) ((FunctionContainer)parent).addFunction(function);
|
if(parent instanceof FunctionContainer) ((FunctionContainer)parent).addFunction(function);
|
||||||
return function;
|
return function;
|
||||||
};
|
};
|
||||||
|
@ -739,7 +741,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(Modifier.STATIC, null, null);
|
Function build = new Function((((AnnotableBuffer)parent).getAnnotationBuffer()), Modifier.STATIC, null, null);
|
||||||
if(parent instanceof FunctionContainer) ((FunctionContainer)parent).addFunction(build);
|
if(parent instanceof FunctionContainer) ((FunctionContainer)parent).addFunction(build);
|
||||||
return build;
|
return build;
|
||||||
});
|
});
|
||||||
|
@ -828,27 +830,40 @@ 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((JavaElement, bag) -> null)
|
.<JavaElement>end((parent, bag) -> {
|
||||||
|
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) token = local.get();
|
if(token == null) global.set("implement", local.get());
|
||||||
// else token = token.concat(local.get());
|
else global.set("implement", 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(","),
|
||||||
|
(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((JavaElement, bag) -> null)
|
.<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;
|
||||||
|
})
|
||||||
.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((JavaElement, bag) -> null)
|
.<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;
|
||||||
|
})
|
||||||
.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);
|
||||||
|
@ -982,6 +997,7 @@ 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;
|
||||||
|
|
||||||
|
@ -993,7 +1009,7 @@ public class JavaParser extends Parser<JavaElement> {
|
||||||
|
|
||||||
Integer mod = bag.get("arg_mod");
|
Integer mod = bag.get("arg_mod");
|
||||||
|
|
||||||
Variable variable = new Variable(mod == null ? 0 : mod, bag.<Token>get("arg_type"), bag.<Token>get("arg_name"), bag.get("arg_elips") == Boolean.TRUE);
|
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);
|
||||||
bag.remove("arg_name");
|
bag.remove("arg_name");
|
||||||
bag.remove("arg_mod");
|
bag.remove("arg_mod");
|
||||||
bag.remove("arg_type");
|
bag.remove("arg_type");
|
||||||
|
@ -1033,6 +1049,13 @@ 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,9 +5,8 @@ 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 implements Annotable{
|
public class Variable extends JavaElement{
|
||||||
|
|
||||||
public static interface VariableContainer{
|
public static interface VariableContainer{
|
||||||
|
|
||||||
|
@ -23,20 +22,20 @@ public class Variable extends JavaElement implements Annotable{
|
||||||
private boolean elips;
|
private boolean elips;
|
||||||
private Value value;
|
private Value value;
|
||||||
|
|
||||||
public Variable(int mod, Token type, Token name){
|
public Variable(List<Annotation> annotations, 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(int mod, Token type, Token name, boolean elips){
|
public Variable(List<Annotation> annotations, int mod, Token type, Token name, boolean elips){
|
||||||
this(mod, type, name);
|
this(annotations, mod, type, name);
|
||||||
this.elips = elips;
|
this.elips = elips;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Variable(int mod, Token type, Token name, boolean elips, Value value){
|
public Variable(List<Annotation> annotations, int mod, Token type, Token name, boolean elips, Value value){
|
||||||
this(mod, type, name, elips);
|
this(annotations, mod, type, name, elips);
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,11 +44,6 @@ public class Variable extends JavaElement implements Annotable{
|
||||||
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){
|
||||||
for(Annotation annotation : this.annotations){
|
for(Annotation annotation : this.annotations){
|
||||||
|
|
|
@ -11,8 +11,7 @@ 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.Annotable;
|
import be.jeffcheasey88.peeratcode.parser.java.Annotation.AnnotableBuffer;
|
||||||
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;
|
||||||
|
|
||||||
|
@ -41,7 +40,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 Annotable) ((Annotable)parent).addAnnotation(result);
|
if(parent instanceof AnnotableBuffer) ((AnnotableBuffer)parent).addAnnotationBuffer(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("(")));
|
||||||
|
@ -49,7 +48,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 Annotable) ((Annotable)parent).addAnnotation(result);
|
if(parent instanceof AnnotableBuffer) ((AnnotableBuffer)parent).addAnnotationBuffer(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,6 +7,7 @@ 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;
|
||||||
|
|
||||||
|
@ -22,7 +23,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(bag.get("name"));
|
Class current = new Class((((AnnotableBuffer)parent).getAnnotationBuffer()), bag.get("name"));
|
||||||
if(parent instanceof ClassContainer) ((ClassContainer)parent).addClass(current);
|
if(parent instanceof ClassContainer) ((ClassContainer)parent).addClass(current);
|
||||||
return current;
|
return current;
|
||||||
})
|
})
|
||||||
|
@ -40,7 +41,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(bag.get("name"), bag.get("extend"), bag.get("implements"));
|
Class current = new Class((((AnnotableBuffer)parent).getAnnotationBuffer()),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;
|
||||||
})
|
})
|
||||||
|
@ -51,7 +52,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(bag.get("name"), bag.get("extend"), bag.get("implements"));
|
Class current = new Class((((AnnotableBuffer)parent).getAnnotationBuffer()), 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,6 +13,7 @@ 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;
|
||||||
|
@ -26,7 +27,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(mod == null ? 0 : mod, bag.get("generic"), bag.get("type"), bag.get("name"), bag.get("param"), bag.get("throws"));
|
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"));
|
||||||
if(parent instanceof FunctionContainer) ((FunctionContainer)parent).addFunction(function);
|
if(parent instanceof FunctionContainer) ((FunctionContainer)parent).addFunction(function);
|
||||||
return function;
|
return function;
|
||||||
};
|
};
|
||||||
|
@ -114,7 +115,7 @@ public class FunctionTests {
|
||||||
|
|
||||||
Integer mod = bag.get("arg_mod");
|
Integer mod = bag.get("arg_mod");
|
||||||
|
|
||||||
Variable variable = new Variable(mod == null ? 0 : mod, bag.<Token>get("arg_type"), bag.<Token>get("arg_name"), bag.get("arg_elips") == Boolean.TRUE);
|
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);
|
||||||
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,6 +14,7 @@ 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;
|
||||||
|
@ -27,7 +28,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(mod == null ? 0 : mod, type, vars.getKey(), false, vars.getValue());
|
Variable result = new Variable((((AnnotableBuffer)parent).getAnnotationBuffer()), 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);
|
||||||
}
|
}
|
||||||
|
@ -79,7 +80,7 @@ public class VariableTests{
|
||||||
TokenValidator.TOKENS = 0;
|
TokenValidator.TOKENS = 0;
|
||||||
TokenValidator.MAX_VALIDATE = 0;
|
TokenValidator.MAX_VALIDATE = 0;
|
||||||
|
|
||||||
JavaElement result = new Class(new Token(0, 0, "Test", TokenType.NAME));
|
JavaElement result = new Class(null, new Token(0, 0, "Test", TokenType.NAME));
|
||||||
|
|
||||||
parser.parse(value, result);
|
parser.parse(value, result);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue