Compare commits

..

No commits in common. "3f4d824b3380b4790a004cfd31b687d3b4e894ac" and "d319163f60dd7014f298466a1a52999ac2337703" have entirely different histories.

9 changed files with 149 additions and 146 deletions

View file

@ -17,66 +17,6 @@ public class Annotation extends JavaElement{
}
public static abstract class Annotable extends JavaElement{
private List<Annotation> annotations;
public Annotable(List<Annotation> annotations){
this.annotations = annotations;
}
public List<Annotation> getAnnotations(){
return this.annotations;
}
public Annotation findAnnotation(Function<Annotation, Boolean> finder){
if(annotations != null){
for(Annotation annotation : this.annotations){
if(finder.apply(annotation)) return annotation;
}
}
return null;
}
public boolean hasAnnotation(Function<Annotation, Boolean> finder){
if(annotations != null){
for(Annotation annotation : this.annotations){
if(finder.apply(annotation)) return true;
}
}
return false;
}
@Override
public void build(Builder builder) throws Exception{
if(annotations != null){
for(Annotation annotation : this.annotations){
annotation.build(builder);
}
}
}
@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;
}
}
return null;
}
@Override
public <E extends JavaElement> void findAll(Function<JavaElement, Boolean> finder, List<E> list){
if(annotations != null){
for(Annotation annotation : this.annotations){
if(finder.apply(annotation)) list.add((E) annotation);
annotation.findAll(finder, list);
}
}
}
}
private Token name;
private Map<Token, Value> values;

View file

@ -7,6 +7,8 @@ import dev.peerat.parser.Token;
public class AnnotationClass extends ClassBase{
private List<Annotation> annotations;
//where mod ????
private Token name;
private Token extend;
@ -14,7 +16,7 @@ public class AnnotationClass extends ClassBase{
private List<JavaElement> elements;
public AnnotationClass(List<Annotation> annotations, Token name){
super(annotations);
this.annotations = annotations;
this.name = name;
this.elements = new ArrayList<>();
}
@ -34,6 +36,10 @@ public class AnnotationClass extends ClassBase{
this.elements.add(clazz);
}
public List<Annotation> getAnnotations(){
return this.annotations;
}
public Token getName(){
return this.name;
}
@ -48,7 +54,11 @@ public class AnnotationClass extends ClassBase{
@Override
public void build(Builder builder) throws Exception{
super.build(builder);
if(annotations != null){
for(Annotation annotation : this.annotations){
annotation.build(builder);
}
}
builder.append("@interface");
builder.append(name);
@ -67,9 +77,11 @@ public class AnnotationClass extends ClassBase{
@Override
public <E extends JavaElement> E find(java.util.function.Function<JavaElement, Boolean> finder){
E annotation = super.find(finder);
if(annotation != null) return annotation;
if(annotations != null){
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;
@ -80,7 +92,12 @@ public class AnnotationClass extends ClassBase{
@Override
public <E extends JavaElement> void findAll(java.util.function.Function<JavaElement, Boolean> finder, List<E> list){
super.findAll(finder, list);
if(annotations != null){
for(Annotation annotation : this.annotations){
if(finder.apply(annotation)) list.add((E) annotation);
annotation.findAll(finder, list);
}
}
if(elements != null){
for(JavaElement element : this.elements){
if(finder.apply(element)) list.add((E) element);

View file

@ -7,6 +7,8 @@ import dev.peerat.parser.Token;
public class Class extends ClassBase{
private List<Annotation> annotations;
//where mod ????
private Token name;
private Token extend;
@ -15,7 +17,7 @@ public class Class extends ClassBase{
private List<JavaElement> elements;
public Class(List<Annotation> annotations, Token name){
super(annotations);
this.annotations = annotations;
this.name = name;
this.elements = new ArrayList<>();
}
@ -41,6 +43,10 @@ public class Class extends ClassBase{
this.elements.add(clazz);
}
public List<Annotation> getAnnotations(){
return this.annotations;
}
public Token getName(){
return this.name;
}
@ -59,7 +65,11 @@ public class Class extends ClassBase{
@Override
public void build(Builder builder) throws Exception{
super.build(builder);
if(annotations != null){
for(Annotation annotation : this.annotations){
annotation.build(builder);
}
}
builder.append("class");
builder.append(name);
@ -82,9 +92,11 @@ public class Class extends ClassBase{
@Override
public <E extends JavaElement> E find(java.util.function.Function<JavaElement, Boolean> finder){
E annotation = super.find(finder);
if(annotation != null) return annotation;
if(annotations != null){
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;
@ -95,7 +107,12 @@ public class Class extends ClassBase{
@Override
public <E extends JavaElement> void findAll(java.util.function.Function<JavaElement, Boolean> finder, List<E> list){
super.findAll(finder, list);
if(annotations != null){
for(Annotation annotation : this.annotations){
if(finder.apply(annotation)) list.add((E) annotation);
annotation.findAll(finder, list);
}
}
if(elements != null){
for(JavaElement element : this.elements){
if(finder.apply(element)) list.add((E) element);

View file

@ -3,7 +3,6 @@ package dev.peerat.parser.java;
import java.util.ArrayList;
import java.util.List;
import dev.peerat.parser.java.Annotation.Annotable;
import dev.peerat.parser.java.Annotation.AnnotableBuffer;
import dev.peerat.parser.java.Function.FunctionContainer;
import dev.peerat.parser.java.Variable.VariableContainer;
@ -14,14 +13,10 @@ interface ClassContainer{
}
public abstract class ClassBase extends Annotable implements AnnotableBuffer, ClassContainer, FunctionContainer, VariableContainer{
public abstract class ClassBase extends JavaElement implements AnnotableBuffer, ClassContainer, FunctionContainer, VariableContainer{
private List<Annotation> annotationBuffer;
public ClassBase(List<Annotation> annotations){
super(annotations);
}
@Override
public void addAnnotationBuffer(Annotation annotation){
if(annotationBuffer == null) annotationBuffer = new ArrayList<>();

View file

@ -7,6 +7,8 @@ import dev.peerat.parser.Token;
public class Enumeration extends ClassBase{
private List<Annotation> annotations;
//where mod ????
private Token name;
private Token extend;
@ -14,7 +16,7 @@ public class Enumeration extends ClassBase{
private List<JavaElement> elements;
public Enumeration(List<Annotation> annotations, Token name){
super(annotations);
this.annotations = annotations;
this.name = name;
this.elements = new ArrayList<>();
}
@ -39,6 +41,10 @@ public class Enumeration extends ClassBase{
this.elements.add(clazz);
}
public List<Annotation> getAnnotations(){
return this.annotations;
}
public Token getName(){
return this.name;
}
@ -53,7 +59,11 @@ public class Enumeration extends ClassBase{
@Override
public void build(Builder builder) throws Exception{
super.build(builder);
if(annotations != null){
for(Annotation annotation : this.annotations){
annotation.build(builder);
}
}
builder.append("enum");
builder.append(name);
@ -72,9 +82,11 @@ public class Enumeration extends ClassBase{
@Override
public <E extends JavaElement> E find(java.util.function.Function<JavaElement, Boolean> finder){
E annotation = super.find(finder);
if(annotation != null) return annotation;
if(annotations != null){
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;
@ -85,7 +97,12 @@ public class Enumeration extends ClassBase{
@Override
public <E extends JavaElement> void findAll(java.util.function.Function<JavaElement, Boolean> finder, List<E> list){
super.findAll(finder, list);
if(annotations != null){
for(Annotation annotation : this.annotations){
if(finder.apply(annotation)) list.add((E) annotation);
annotation.findAll(finder, list);
}
}
if(elements != null){
for(JavaElement element : this.elements){
if(finder.apply(element)) list.add((E) element);

View file

@ -4,15 +4,12 @@ import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.List;
import javax.xml.crypto.dsig.CanonicalizationMethod;
import dev.peerat.parser.Token;
import dev.peerat.parser.TokenType;
import dev.peerat.parser.java.Annotation.Annotable;
import dev.peerat.parser.java.Operation.OperationContainer;
import dev.peerat.parser.java.Variable.VariableContainer;
public class Function extends Annotable implements VariableContainer, OperationContainer{
public class Function extends JavaElement implements VariableContainer, OperationContainer{
public static interface FunctionContainer{
@ -20,6 +17,8 @@ public class Function extends Annotable implements VariableContainer, OperationC
}
private List<Annotation> annotations;
private int mod;
private Token generic;
private Token type;
@ -30,7 +29,7 @@ public class Function extends Annotable implements VariableContainer, OperationC
private List<JavaElement> elements;
public Function(List<Annotation> annotations, int mod, Token type, Token name){
super(annotations);
this.annotations = annotations;
this.mod = mod;
this.type = type;
this.name = name;
@ -62,6 +61,10 @@ public class Function extends Annotable implements VariableContainer, OperationC
this.elements.add(operation);
}
public List<Annotation> getAnnotations(){
return this.annotations;
}
public int getModifier(){
return this.mod;
}
@ -92,7 +95,11 @@ public class Function extends Annotable implements VariableContainer, OperationC
@Override
public void build(Builder builder) throws Exception{
super.build(builder);
if(annotations != null){
for(Annotation annotation : this.annotations){
annotation.build(builder);
}
}
String mod = Modifier.toString(this.mod);
builder.append(new Token(type.getLineNumber(), type.getCharacterNumber()-(mod.length()+1), mod, TokenType.GROUP));
if(generic != null) builder.append(generic);
@ -122,9 +129,11 @@ public class Function extends Annotable implements VariableContainer, OperationC
@Override
public <E extends JavaElement> E find(java.util.function.Function<JavaElement, Boolean> finder){
E annotation = super.find(finder);
if(annotation != null) return annotation;
if(annotations != null){
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;
@ -140,7 +149,12 @@ public class Function extends Annotable implements VariableContainer, OperationC
@Override
public <E extends JavaElement> void findAll(java.util.function.Function<JavaElement, Boolean> finder, List<E> list){
super.findAll(finder, list);
if(annotations != null){
for(Annotation annotation : this.annotations){
if(finder.apply(annotation)) list.add((E) annotation);
annotation.findAll(finder, list);
}
}
if(parameters != null){
for(Variable param : this.parameters){
if(finder.apply(param)) list.add((E) param);

View file

@ -7,6 +7,8 @@ import dev.peerat.parser.Token;
public class Interface extends ClassBase{
private List<Annotation> annotations;
//where mod ????
private Token name;
private Token extend;
@ -14,7 +16,7 @@ public class Interface extends ClassBase{
private List<JavaElement> elements;
public Interface(List<Annotation> annotations, Token name){
super(annotations);
this.annotations = annotations;
this.name = name;
this.elements = new ArrayList<>();
}
@ -39,6 +41,10 @@ public class Interface extends ClassBase{
this.elements.add(clazz);
}
public List<Annotation> getAnnotations(){
return this.annotations;
}
public Token getName(){
return this.name;
}
@ -53,7 +59,11 @@ public class Interface extends ClassBase{
@Override
public void build(Builder builder) throws Exception{
super.build(builder);
if(annotations != null){
for(Annotation annotation : this.annotations){
annotation.build(builder);
}
}
builder.append("interface");
builder.append(name);
@ -72,9 +82,11 @@ public class Interface extends ClassBase{
@Override
public <E extends JavaElement> E find(java.util.function.Function<JavaElement, Boolean> finder){
E annotation = super.find(finder);
if(annotation != null) return annotation;
if(annotations != null){
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;
@ -85,7 +97,12 @@ public class Interface extends ClassBase{
@Override
public <E extends JavaElement> void findAll(java.util.function.Function<JavaElement, Boolean> finder, List<E> list){
super.findAll(finder, list);
if(annotations != null){
for(Annotation annotation : this.annotations){
if(finder.apply(annotation)) list.add((E) annotation);
annotation.findAll(finder, list);
}
}
if(elements != null){
for(JavaElement element : this.elements){
if(finder.apply(element)) list.add((E) element);

View file

@ -26,12 +26,7 @@ import dev.peerat.parser.java.Function.FunctionContainer;
import dev.peerat.parser.java.Operation.OperationContainer;
import dev.peerat.parser.java.Value.BiValue;
import dev.peerat.parser.java.Variable.VariableContainer;
import dev.peerat.parser.java.operation.BreakOperation;
import dev.peerat.parser.java.operation.ContinueOperation;
import dev.peerat.parser.java.operation.IfOperation;
import dev.peerat.parser.java.operation.ReturnOperation;
import dev.peerat.parser.java.operation.SynchronizedOperation;
import dev.peerat.parser.java.operation.ThrowOperation;
import dev.peerat.parser.state.BuilderStateTree;
import dev.peerat.parser.state.InitialStateTree;
import dev.peerat.parser.state.RedirectStateTree;
@ -576,16 +571,10 @@ public class JavaParser extends Parser<JavaElement> {
if(parent instanceof OperationContainer) ((OperationContainer)parent).addOperation(op);
return null;
});
operation.then((validator) -> validator.validate((token) -> token.getValue().equals("throw")))
.then(new RedirectStateTree<>(value_container, (global, local) -> global.set(local.get())))
.then(new RedirectStateTree<>(value_container, (global, local) -> global.set(null)))
.then((validator) -> validator.validate((token) -> token.getValue().equals(";")))
.end((parent,bag) -> {
ThrowOperation op = new ThrowOperation(bag.get());
if(parent instanceof OperationContainer) ((OperationContainer)parent).addOperation(op);
return null;
});
.end((a,b) -> a);
operation.then((validator) -> validator.validate((token) -> token.getValue().equals("do")))
.then((validator) -> validator.validate((token) -> token.getValue().equals("{")))
.end((a,b) -> a)
@ -638,29 +627,15 @@ public class JavaParser extends Parser<JavaElement> {
operation.then((validator) -> validator.validate((token) -> token.getValue().equals("continue")))
.then((validator) -> validator.validate((token) -> token.getValue().equals(";")))
.end((parent,bag) -> {
ContinueOperation op = new ContinueOperation();
if(parent instanceof OperationContainer) ((OperationContainer)parent).addOperation(op);
return null;
});
.end((a,b) -> a);
operation.then((validator) -> validator.validate((token) -> token.getValue().equals("break")))
.then((validator) -> validator.validate((token) -> token.getValue().equals(";")))
.end((parent,bag) -> {
BreakOperation op = new BreakOperation();
if(parent instanceof OperationContainer) ((OperationContainer)parent).addOperation(op);
return null;
});
.end((a,b) -> a);
StateTree<JavaElement> operation_if = operation.then((validator) -> validator.validate((token) -> token.getValue().equals("if")))
.then((validator) -> validator.validate((token) -> token.getValue().equals("(")))
.then(new RedirectStateTree<>(value_container, (global, local) -> global.set(local.get())))
.then(new RedirectStateTree<>(value_container, (global, local) -> global.set(null)))
.then((validator) -> validator.validate((token) -> token.getValue().equals(")")))
.end((parent,bag) -> {
IfOperation op = new IfOperation(bag.get());
if(parent instanceof OperationContainer) ((OperationContainer)parent).addOperation(op);
return op;
});
.end((a,b) -> a);
operation_if.then(operation);
operation_if.then((validator) -> validator.validate((token) -> token.getValue().equals("{")))
.end((a,b) -> a)
@ -761,14 +736,10 @@ public class JavaParser extends Parser<JavaElement> {
operation.then((validator) -> validator.validate((token) -> token.getValue().equals("synchronized")))
.then((validator) -> validator.validate((token) -> token.getValue().equals("(")))
.then(new RedirectStateTree<>(value_container, (global, local) -> global.set(local.get())))
.then(new RedirectStateTree<>(value_container, (global, local) -> global.set(null)))
.then((validator) -> validator.validate((token) -> token.getValue().equals(")")))
.then((validator) -> validator.validate((token) -> token.getValue().equals("{")))
.<JavaElement>end((parent,bag) -> {
SynchronizedOperation op = new SynchronizedOperation(bag.get());
if(parent instanceof OperationContainer) ((OperationContainer)parent).addOperation(op);
return op;
})
.end((a,b) -> a)
.multiple(function_container)
.unique((validator) -> validator.validate((token) -> token.getValue().equals("}")))
.end((a,b) -> a);

View file

@ -7,9 +7,8 @@ import java.util.function.Function;
import dev.peerat.parser.Token;
import dev.peerat.parser.TokenType;
import dev.peerat.parser.java.Annotation.Annotable;
public class Variable extends Annotable{
public class Variable extends JavaElement{
public static interface VariableContainer{
@ -17,6 +16,8 @@ public class Variable extends Annotable{
}
private List<Annotation> annotations;
private int mod;
private Token type;
private Token name;
@ -24,10 +25,10 @@ public class Variable extends Annotable{
private Value value;
public Variable(List<Annotation> annotations, int mod, Token type, Token name){
super(annotations);
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){
@ -45,6 +46,10 @@ public class Variable extends Annotable{
return "Variable[mod="+mod+", type="+type+", name="+name+", elips="+elips+", value="+value+"]";
}
public List<Annotation> getAnnotations(){
return this.annotations;
}
public int getModifier(){
return this.mod;
}
@ -67,8 +72,11 @@ public class Variable extends Annotable{
@Override
public void build(Builder builder) throws Exception{
super.build(builder);
if(annotations != null){
for(Annotation annotation : this.annotations){
annotation.build(builder);
}
}
String mod = Modifier.toString(this.mod);
builder.append(new Token(type.getLineNumber(), type.getCharacterNumber()-(mod.length()+1), mod, TokenType.GROUP));
builder.append(type);
@ -82,15 +90,22 @@ public class Variable extends Annotable{
@Override
public <E extends JavaElement> E find(Function<JavaElement, Boolean> finder){
E annotation = super.find(finder);
if(annotation != null) return annotation;
if(annotations != null){
for(Annotation annotation : this.annotations){
if(finder.apply(annotation)) return (E) annotation;
}
}
return value != null ? finder.apply(value) ? (E)value : null : null;
}
@Override
public <E extends JavaElement> void findAll(Function<JavaElement, Boolean> finder, List<E> list){
super.findAll(finder, list);
if(annotations != null){
for(Annotation annotation : this.annotations){
if(finder.apply(annotation)) list.add((E)annotation);
annotation.findAll(finder, list);
}
}
if(value != null){
if(finder.apply(value)) list.add((E)value);
value.findAll(finder, list);