JavaElement -> Abstract to Interface + 'Function<E, Boolean>' to 'Predicate<E>' + Visitor Concat in JavaArrayAccessValueVisitor Operator Count little refractor
This commit is contained in:
parent
e04b0f0262
commit
fb96c287cf
48 changed files with 511 additions and 336 deletions
|
@ -1,9 +1,11 @@
|
||||||
package dev.peerat.parser.java;
|
package dev.peerat.parser.java;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
import dev.peerat.parser.Token;
|
import dev.peerat.parser.Token;
|
||||||
import dev.peerat.parser.java.value.Value;
|
import dev.peerat.parser.java.value.Value;
|
||||||
|
@ -11,7 +13,7 @@ import dev.peerat.parser.java.visitor.JavaVisitor;
|
||||||
import dev.peerat.parser.visitor.Visitor;
|
import dev.peerat.parser.visitor.Visitor;
|
||||||
import dev.peerat.parser.visitor.VisitorBag;
|
import dev.peerat.parser.visitor.VisitorBag;
|
||||||
|
|
||||||
public class Annotation extends JavaElement{
|
public class Annotation implements JavaElement{
|
||||||
|
|
||||||
public static interface AnnotableBuffer{
|
public static interface AnnotableBuffer{
|
||||||
|
|
||||||
|
@ -21,7 +23,7 @@ public class Annotation extends JavaElement{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static abstract class Annotable extends JavaElement{
|
public static abstract class Annotable implements JavaElement{
|
||||||
|
|
||||||
private List<Annotation> annotations;
|
private List<Annotation> annotations;
|
||||||
|
|
||||||
|
@ -52,21 +54,21 @@ public class Annotation extends JavaElement{
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <E extends JavaElement> E find(Function<JavaElement, Boolean> finder){
|
public <E extends JavaElement> E find(Predicate<JavaElement> finder) {
|
||||||
if(annotations != null){
|
if(annotations != null){
|
||||||
for(Annotation annotation : this.annotations){
|
for(Annotation annotation : this.annotations){
|
||||||
if(finder.apply(annotation)) return (E) annotation;
|
if(finder.test(annotation)) return (E) annotation;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <E extends JavaElement> void findAll(Function<JavaElement, Boolean> finder, List<E> list){
|
public <E extends JavaElement> void findAll(Predicate<JavaElement> finder, Collection<E> collector) {
|
||||||
if(annotations != null){
|
if(annotations != null){
|
||||||
for(Annotation annotation : this.annotations){
|
for(Annotation annotation : this.annotations){
|
||||||
if(finder.apply(annotation)) list.add((E) annotation);
|
if(finder.test(annotation)) collector.add((E) annotation);
|
||||||
annotation.findAll(finder, list);
|
annotation.findAll(finder, collector);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -93,25 +95,25 @@ public class Annotation extends JavaElement{
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <E extends JavaElement> E find(Function<JavaElement, Boolean> finder){
|
public <E extends JavaElement> E find(Predicate<JavaElement> finder) {
|
||||||
if(this.values != null){
|
if(this.values != null){
|
||||||
for(Value value : this.values.values()){
|
for(Value value : this.values.values()){
|
||||||
if(finder.apply(value)) return (E)value;
|
if(finder.test(value)) return (E)value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <E extends JavaElement> void findAll(Function<JavaElement, Boolean> finder, List<E> list){
|
public <E extends JavaElement> void findAll(Predicate<JavaElement> finder, Collection<E> collector) {
|
||||||
if(this.values != null){
|
if(this.values != null){
|
||||||
for(Value value : this.values.values()){
|
for(Value value : this.values.values()){
|
||||||
if(finder.apply(value)) list.add((E)value);
|
if(finder.test(value)) collector.add((E)value);
|
||||||
value.findAll(finder, list);
|
value.findAll(finder, collector);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public VisitorBag visit(Visitor<JavaElement> visitor) {
|
public VisitorBag visit(Visitor<JavaElement> visitor) {
|
||||||
if(visitor.canVisit(getClass())) return visitor.visit(this);
|
if(visitor.canVisit(getClass())) return visitor.visit(this);
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
package dev.peerat.parser.java;
|
package dev.peerat.parser.java;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
import dev.peerat.parser.Token;
|
import dev.peerat.parser.Token;
|
||||||
import dev.peerat.parser.java.visitor.JavaVisitor;
|
import dev.peerat.parser.java.visitor.JavaVisitor;
|
||||||
|
@ -41,27 +43,27 @@ public class AnnotationClass extends ClassBase{
|
||||||
public List<JavaElement> getElements(){
|
public List<JavaElement> getElements(){
|
||||||
return this.elements;
|
return this.elements;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <E extends JavaElement> E find(java.util.function.Function<JavaElement, Boolean> finder){
|
public <E extends JavaElement> E find(Predicate<JavaElement> finder) {
|
||||||
E annotation = super.find(finder);
|
E annotation = super.find(finder);
|
||||||
if(annotation != null) return annotation;
|
if(annotation != null) return annotation;
|
||||||
|
|
||||||
if(elements != null){
|
if(elements != null){
|
||||||
for(JavaElement element : this.elements){
|
for(JavaElement element : this.elements){
|
||||||
if(finder.apply(element)) return (E) element;
|
if(finder.test(element)) return (E) element;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <E extends JavaElement> void findAll(java.util.function.Function<JavaElement, Boolean> finder, List<E> list){
|
public <E extends JavaElement> void findAll(Predicate<JavaElement> finder, Collection<E> collector) {
|
||||||
super.findAll(finder, list);
|
super.findAll(finder, collector);
|
||||||
if(elements != null){
|
if(elements != null){
|
||||||
for(JavaElement element : this.elements){
|
for(JavaElement element : this.elements){
|
||||||
if(finder.apply(element)) list.add((E) element);
|
if(finder.test(element)) collector.add((E) element);
|
||||||
element.findAll(finder, list);
|
element.findAll(finder, collector);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
package dev.peerat.parser.java;
|
package dev.peerat.parser.java;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
import dev.peerat.parser.Token;
|
import dev.peerat.parser.Token;
|
||||||
import dev.peerat.parser.visitor.Visitor;
|
import dev.peerat.parser.visitor.Visitor;
|
||||||
|
@ -51,27 +53,27 @@ public class Class extends ClassBase{
|
||||||
public List<JavaElement> getElements(){
|
public List<JavaElement> getElements(){
|
||||||
return this.elements;
|
return this.elements;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <E extends JavaElement> E find(java.util.function.Function<JavaElement, Boolean> finder){
|
public <E extends JavaElement> E find(Predicate<JavaElement> finder) {
|
||||||
E annotation = super.find(finder);
|
E annotation = super.find(finder);
|
||||||
if(annotation != null) return annotation;
|
if(annotation != null) return annotation;
|
||||||
|
|
||||||
if(elements != null){
|
if(elements != null){
|
||||||
for(JavaElement element : this.elements){
|
for(JavaElement element : this.elements){
|
||||||
if(finder.apply(element)) return (E) element;
|
if(finder.test(element)) return (E) element;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <E extends JavaElement> void findAll(java.util.function.Function<JavaElement, Boolean> finder, List<E> list){
|
public <E extends JavaElement> void findAll(Predicate<JavaElement> finder, Collection<E> collector) {
|
||||||
super.findAll(finder, list);
|
super.findAll(finder, collector);
|
||||||
if(elements != null){
|
if(elements != null){
|
||||||
for(JavaElement element : this.elements){
|
for(JavaElement element : this.elements){
|
||||||
if(finder.apply(element)) list.add((E) element);
|
if(finder.test(element)) collector.add((E) element);
|
||||||
element.findAll(finder, list);
|
element.findAll(finder, collector);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
package dev.peerat.parser.java;
|
package dev.peerat.parser.java;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
import dev.peerat.parser.Token;
|
import dev.peerat.parser.Token;
|
||||||
import dev.peerat.parser.java.visitor.JavaVisitor;
|
import dev.peerat.parser.java.visitor.JavaVisitor;
|
||||||
|
@ -46,27 +48,27 @@ public class Enumeration extends ClassBase{
|
||||||
public List<JavaElement> getElements(){
|
public List<JavaElement> getElements(){
|
||||||
return this.elements;
|
return this.elements;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <E extends JavaElement> E find(java.util.function.Function<JavaElement, Boolean> finder){
|
public <E extends JavaElement> E find(Predicate<JavaElement> finder) {
|
||||||
E annotation = super.find(finder);
|
E annotation = super.find(finder);
|
||||||
if(annotation != null) return annotation;
|
if(annotation != null) return annotation;
|
||||||
|
|
||||||
if(elements != null){
|
if(elements != null){
|
||||||
for(JavaElement element : this.elements){
|
for(JavaElement element : this.elements){
|
||||||
if(finder.apply(element)) return (E) element;
|
if(finder.test(element)) return (E) element;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <E extends JavaElement> void findAll(java.util.function.Function<JavaElement, Boolean> finder, List<E> list){
|
public <E extends JavaElement> void findAll(Predicate<JavaElement> finder, Collection<E> collector) {
|
||||||
super.findAll(finder, list);
|
super.findAll(finder, collector);
|
||||||
if(elements != null){
|
if(elements != null){
|
||||||
for(JavaElement element : this.elements){
|
for(JavaElement element : this.elements){
|
||||||
if(finder.apply(element)) list.add((E) element);
|
if(finder.test(element)) collector.add((E) element);
|
||||||
element.findAll(finder, list);
|
element.findAll(finder, collector);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,9 @@ package dev.peerat.parser.java;
|
||||||
|
|
||||||
import java.lang.reflect.Modifier;
|
import java.lang.reflect.Modifier;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
import dev.peerat.parser.Token;
|
import dev.peerat.parser.Token;
|
||||||
import dev.peerat.parser.TokenType;
|
import dev.peerat.parser.TokenType;
|
||||||
|
@ -100,36 +102,36 @@ public class Function extends Annotable implements VariableContainer, OperationC
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <E extends JavaElement> E find(java.util.function.Function<JavaElement, Boolean> finder){
|
public <E extends JavaElement> E find(Predicate<JavaElement> finder) {
|
||||||
E annotation = super.find(finder);
|
E annotation = super.find(finder);
|
||||||
if(annotation != null) return annotation;
|
if(annotation != null) return annotation;
|
||||||
|
|
||||||
if(parameters != null){
|
if(parameters != null){
|
||||||
for(Variable param : this.parameters){
|
for(Variable param : this.parameters){
|
||||||
if(finder.apply(param)) return (E) param;
|
if(finder.test(param)) return (E) param;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(elements != null){
|
if(elements != null){
|
||||||
for(JavaElement content : this.elements){
|
for(JavaElement content : this.elements){
|
||||||
if(finder.apply(content)) return (E) content;
|
if(finder.test(content)) return (E) content;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <E extends JavaElement> void findAll(java.util.function.Function<JavaElement, Boolean> finder, List<E> list){
|
public <E extends JavaElement> void findAll(Predicate<JavaElement> finder, Collection<E> collector) {
|
||||||
super.findAll(finder, list);
|
super.findAll(finder, collector);
|
||||||
if(parameters != null){
|
if(parameters != null){
|
||||||
for(Variable param : this.parameters){
|
for(Variable param : this.parameters){
|
||||||
if(finder.apply(param)) list.add((E) param);
|
if(finder.test(param)) collector.add((E) param);
|
||||||
param.findAll(finder, list);
|
param.findAll(finder, collector);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(elements != null){
|
if(elements != null){
|
||||||
for(JavaElement content : this.elements){
|
for(JavaElement content : this.elements){
|
||||||
if(finder.apply(content)) list.add((E) content);
|
if(finder.test(content)) collector.add((E) content);
|
||||||
content.findAll(finder, list);
|
content.findAll(finder, collector);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,14 +1,16 @@
|
||||||
package dev.peerat.parser.java;
|
package dev.peerat.parser.java;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
import dev.peerat.parser.Token;
|
import dev.peerat.parser.Token;
|
||||||
import dev.peerat.parser.java.visitor.JavaVisitor;
|
import dev.peerat.parser.java.visitor.JavaVisitor;
|
||||||
import dev.peerat.parser.visitor.Visitor;
|
import dev.peerat.parser.visitor.Visitor;
|
||||||
import dev.peerat.parser.visitor.VisitorBag;
|
import dev.peerat.parser.visitor.VisitorBag;
|
||||||
|
|
||||||
public class Import extends JavaElement{
|
public class Import implements JavaElement{
|
||||||
|
|
||||||
private boolean isStatic;
|
private boolean isStatic;
|
||||||
private Token value;
|
private Token value;
|
||||||
|
@ -27,15 +29,15 @@ public class Import extends JavaElement{
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <E extends JavaElement> E find(Function<JavaElement, Boolean> finder) {
|
public <E extends JavaElement> E find(Predicate<JavaElement> finder) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <E extends JavaElement> void findAll(Function<JavaElement, Boolean> finder, List<E> list) {
|
public <E extends JavaElement> void findAll(Predicate<JavaElement> finder, Collection<E> collector) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public VisitorBag visit(Visitor<JavaElement> visitor) {
|
public VisitorBag visit(Visitor<JavaElement> visitor) {
|
||||||
if(visitor.canVisit(getClass())) return visitor.visit(this);
|
if(visitor.canVisit(getClass())) return visitor.visit(this);
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
package dev.peerat.parser.java;
|
package dev.peerat.parser.java;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
import dev.peerat.parser.Token;
|
import dev.peerat.parser.Token;
|
||||||
import dev.peerat.parser.java.visitor.JavaVisitor;
|
import dev.peerat.parser.java.visitor.JavaVisitor;
|
||||||
|
@ -46,27 +48,27 @@ public class Interface extends ClassBase{
|
||||||
public List<JavaElement> getElements(){
|
public List<JavaElement> getElements(){
|
||||||
return this.elements;
|
return this.elements;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <E extends JavaElement> E find(java.util.function.Function<JavaElement, Boolean> finder){
|
public <E extends JavaElement> E find(Predicate<JavaElement> finder) {
|
||||||
E annotation = super.find(finder);
|
E annotation = super.find(finder);
|
||||||
if(annotation != null) return annotation;
|
if(annotation != null) return annotation;
|
||||||
|
|
||||||
if(elements != null){
|
if(elements != null){
|
||||||
for(JavaElement element : this.elements){
|
for(JavaElement element : this.elements){
|
||||||
if(finder.apply(element)) return (E) element;
|
if(finder.test(element)) return (E) element;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <E extends JavaElement> void findAll(java.util.function.Function<JavaElement, Boolean> finder, List<E> list){
|
public <E extends JavaElement> void findAll(Predicate<JavaElement> finder, Collection<E> collector) {
|
||||||
super.findAll(finder, list);
|
super.findAll(finder, collector);
|
||||||
if(elements != null){
|
if(elements != null){
|
||||||
for(JavaElement element : this.elements){
|
for(JavaElement element : this.elements){
|
||||||
if(finder.apply(element)) list.add((E) element);
|
if(finder.test(element)) collector.add((E) element);
|
||||||
element.findAll(finder, list);
|
element.findAll(finder, collector);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,16 +1,16 @@
|
||||||
package dev.peerat.parser.java;
|
package dev.peerat.parser.java;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.Collection;
|
||||||
import java.util.function.Function;
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
import dev.peerat.parser.visitor.Visitor;
|
import dev.peerat.parser.visitor.Visitor;
|
||||||
import dev.peerat.parser.visitor.VisitorBag;
|
import dev.peerat.parser.visitor.VisitorBag;
|
||||||
|
|
||||||
public abstract class JavaElement{
|
public interface JavaElement{
|
||||||
|
|
||||||
public abstract <E extends JavaElement> E find(Function<JavaElement, Boolean> finder);
|
<E extends JavaElement> E find(Predicate<JavaElement> finder);
|
||||||
|
|
||||||
public abstract <E extends JavaElement> void findAll(Function<JavaElement, Boolean> finder, List<E> list);
|
<E extends JavaElement> void findAll(Predicate<JavaElement> finder, Collection<E> collector);
|
||||||
|
|
||||||
public abstract VisitorBag visit(Visitor<JavaElement> visitor);
|
VisitorBag visit(Visitor<JavaElement> visitor);
|
||||||
}
|
}
|
|
@ -1,8 +1,10 @@
|
||||||
package dev.peerat.parser.java;
|
package dev.peerat.parser.java;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
import dev.peerat.parser.Token;
|
import dev.peerat.parser.Token;
|
||||||
import dev.peerat.parser.java.Annotation.AnnotableBuffer;
|
import dev.peerat.parser.java.Annotation.AnnotableBuffer;
|
||||||
|
@ -10,7 +12,7 @@ import dev.peerat.parser.java.visitor.JavaVisitor;
|
||||||
import dev.peerat.parser.visitor.Visitor;
|
import dev.peerat.parser.visitor.Visitor;
|
||||||
import dev.peerat.parser.visitor.VisitorBag;
|
import dev.peerat.parser.visitor.VisitorBag;
|
||||||
|
|
||||||
public class JavaFile extends JavaElement implements ClassContainer, AnnotableBuffer{
|
public class JavaFile implements JavaElement, ClassContainer, AnnotableBuffer{
|
||||||
|
|
||||||
private List<Annotation> annotationBuffer;
|
private List<Annotation> annotationBuffer;
|
||||||
|
|
||||||
|
@ -67,24 +69,24 @@ public class JavaFile extends JavaElement implements ClassContainer, AnnotableBu
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <E extends JavaElement> E find(Function<JavaElement, Boolean> finder){
|
public <E extends JavaElement> E find(Predicate<JavaElement> finder) {
|
||||||
if(finder.apply(mainClazz)) return (E) mainClazz;
|
if(finder.test(mainClazz)) return (E) mainClazz;
|
||||||
for(ClassBase clazz : subClazz){
|
for(ClassBase clazz : subClazz){
|
||||||
if(finder.apply(clazz)) return (E) clazz;
|
if(finder.test(clazz)) return (E) clazz;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <E extends JavaElement> void findAll(Function<JavaElement, Boolean> finder, List<E> list){
|
public <E extends JavaElement> void findAll(Predicate<JavaElement> finder, Collection<E> collector) {
|
||||||
if(finder.apply(mainClazz)) list.add((E) mainClazz);
|
if(finder.test(mainClazz)) collector.add((E) mainClazz);
|
||||||
mainClazz.findAll(finder, list);
|
mainClazz.findAll(finder, collector);
|
||||||
for(ClassBase clazz : subClazz){
|
for(ClassBase clazz : subClazz){
|
||||||
if(finder.apply(clazz)) list.add((E) clazz);
|
if(finder.test(clazz)) collector.add((E) clazz);
|
||||||
clazz.findAll(finder, list);
|
clazz.findAll(finder, collector);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public VisitorBag visit(Visitor<JavaElement> visitor){
|
public VisitorBag visit(Visitor<JavaElement> visitor){
|
||||||
if(visitor.canVisit(getClass())) return visitor.visit(this);
|
if(visitor.canVisit(getClass())) return visitor.visit(this);
|
||||||
|
|
|
@ -1,13 +1,14 @@
|
||||||
package dev.peerat.parser.java;
|
package dev.peerat.parser.java;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.function.Function;
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
import dev.peerat.parser.visitor.Visitor;
|
import dev.peerat.parser.visitor.Visitor;
|
||||||
import dev.peerat.parser.visitor.VisitorBag;
|
import dev.peerat.parser.visitor.VisitorBag;
|
||||||
|
|
||||||
public class JavaProject extends JavaElement{
|
public class JavaProject implements JavaElement{
|
||||||
|
|
||||||
private List<JavaFile> files;
|
private List<JavaFile> files;
|
||||||
|
|
||||||
|
@ -22,14 +23,14 @@ public class JavaProject extends JavaElement{
|
||||||
public List<JavaFile> getFiles(){
|
public List<JavaFile> getFiles(){
|
||||||
return this.files;
|
return this.files;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <E extends JavaElement> E find(Function<JavaElement, Boolean> finder) {
|
public <E extends JavaElement> E find(Predicate<JavaElement> finder) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <E extends JavaElement> void findAll(Function<JavaElement, Boolean> finder, List<E> list) {
|
public <E extends JavaElement> void findAll(Predicate<JavaElement> finder, Collection<E> collector) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
package dev.peerat.parser.java;
|
package dev.peerat.parser.java;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
import dev.peerat.parser.Token;
|
import dev.peerat.parser.Token;
|
||||||
import dev.peerat.parser.java.Annotation.Annotable;
|
import dev.peerat.parser.java.Annotation.Annotable;
|
||||||
|
@ -64,21 +66,21 @@ public class Variable extends Annotable{
|
||||||
public Value getValue(){
|
public Value getValue(){
|
||||||
return this.value;
|
return this.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <E extends JavaElement> E find(Function<JavaElement, Boolean> finder){
|
public <E extends JavaElement> E find(Predicate<JavaElement> finder) {
|
||||||
E annotation = super.find(finder);
|
E annotation = super.find(finder);
|
||||||
if(annotation != null) return annotation;
|
if(annotation != null) return annotation;
|
||||||
|
|
||||||
return value != null ? finder.apply(value) ? (E)value : null : null;
|
return value != null ? finder.test(value) ? (E)value : null : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <E extends JavaElement> void findAll(Function<JavaElement, Boolean> finder, List<E> list){
|
public <E extends JavaElement> void findAll(Predicate<JavaElement> finder, Collection<E> collector) {
|
||||||
super.findAll(finder, list);
|
super.findAll(finder, collector);
|
||||||
if(value != null){
|
if(value != null){
|
||||||
if(finder.apply(value)) list.add((E)value);
|
if(finder.test(value)) collector.add((E)value);
|
||||||
value.findAll(finder, list);
|
value.findAll(finder, collector);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
package dev.peerat.parser.java.builder;
|
package dev.peerat.parser.java.builder;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
import dev.peerat.parser.Parser;
|
import dev.peerat.parser.Parser;
|
||||||
import dev.peerat.parser.java.JavaElement;
|
import dev.peerat.parser.java.JavaElement;
|
||||||
|
@ -28,7 +30,7 @@ public class JavaOperationBuilder extends JavaBuilder<Operation>{
|
||||||
return this.operation;
|
return this.operation;
|
||||||
}
|
}
|
||||||
|
|
||||||
class Container extends JavaElement implements OperationContainer{
|
class Container implements JavaElement, OperationContainer{
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addOperation(Operation operation){
|
public void addOperation(Operation operation){
|
||||||
|
@ -36,12 +38,14 @@ public class JavaOperationBuilder extends JavaBuilder<Operation>{
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <E extends JavaElement> E find(Function<JavaElement, Boolean> finder) {
|
public <E extends JavaElement> E find(Predicate<JavaElement> finder) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <E extends JavaElement> void findAll(Function<JavaElement, Boolean> finder, List<E> list) {
|
public <E extends JavaElement> void findAll(Predicate<JavaElement> finder, Collection<E> collector) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
package dev.peerat.parser.java.builder;
|
package dev.peerat.parser.java.builder;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
import dev.peerat.parser.Parser;
|
import dev.peerat.parser.Parser;
|
||||||
import dev.peerat.parser.Token;
|
import dev.peerat.parser.Token;
|
||||||
|
@ -121,7 +123,7 @@ public class JavaValueBuilder extends JavaBuilder<Value>{
|
||||||
return this.value;
|
return this.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
class Container extends JavaElement implements ValueContainer{
|
class Container implements JavaElement, ValueContainer{
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addValue(Value value) {
|
public void addValue(Value value) {
|
||||||
|
@ -129,14 +131,12 @@ public class JavaValueBuilder extends JavaBuilder<Value>{
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <E extends JavaElement> E find(Function<JavaElement, Boolean> finder) {
|
public <E extends JavaElement> E find(Predicate<JavaElement> finder) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <E extends JavaElement> void findAll(Function<JavaElement, Boolean> finder, List<E> list) {
|
public <E extends JavaElement> void findAll(Predicate<JavaElement> finder, Collection<E> collector) {}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public VisitorBag visit(Visitor<JavaElement> visitor) {
|
public VisitorBag visit(Visitor<JavaElement> visitor) {
|
||||||
|
|
|
@ -1,11 +1,10 @@
|
||||||
package dev.peerat.parser.java.operation;
|
package dev.peerat.parser.java.operation;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.Collection;
|
||||||
import java.util.function.Function;
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
import dev.peerat.parser.java.JavaElement;
|
import dev.peerat.parser.java.JavaElement;
|
||||||
import dev.peerat.parser.java.value.Value;
|
import dev.peerat.parser.java.value.Value;
|
||||||
import dev.peerat.parser.java.visitor.JavaVisitor;
|
|
||||||
import dev.peerat.parser.visitor.Visitor;
|
import dev.peerat.parser.visitor.Visitor;
|
||||||
import dev.peerat.parser.visitor.VisitorBag;
|
import dev.peerat.parser.visitor.VisitorBag;
|
||||||
|
|
||||||
|
@ -28,16 +27,16 @@ public class AssignOperation extends Operation{
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <E extends JavaElement> E find(Function<JavaElement, Boolean> finder){
|
public <E extends JavaElement> E find(Predicate<JavaElement> finder) {
|
||||||
return finder.apply(left) ? (E)left : finder.apply(right) ? (E)right : null;
|
return finder.test(left) ? (E)left : finder.test(right) ? (E)right : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <E extends JavaElement> void findAll(Function<JavaElement, Boolean> finder, List<E> list){
|
public <E extends JavaElement> void findAll(Predicate<JavaElement> finder, Collection<E> collector) {
|
||||||
if(finder.apply(left)) list.add((E) left);
|
if(finder.test(left)) collector.add((E) left);
|
||||||
left.findAll(finder, list);
|
left.findAll(finder, collector);
|
||||||
if(finder.apply(right)) list.add((E) right);
|
if(finder.test(right)) collector.add((E) right);
|
||||||
right.findAll(finder, list);
|
right.findAll(finder, collector);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
package dev.peerat.parser.java.operation;
|
package dev.peerat.parser.java.operation;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
import dev.peerat.parser.java.JavaElement;
|
import dev.peerat.parser.java.JavaElement;
|
||||||
import dev.peerat.parser.java.visitor.JavaVisitor;
|
import dev.peerat.parser.java.visitor.JavaVisitor;
|
||||||
|
@ -13,12 +15,16 @@ public class BreakOperation extends Operation{
|
||||||
public BreakOperation(){}
|
public BreakOperation(){}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <E extends JavaElement> E find(Function<JavaElement, Boolean> finder){
|
public <E extends JavaElement> E find(Predicate<JavaElement> finder) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <E extends JavaElement> void findAll(Function<JavaElement, Boolean> finder, List<E> list){}
|
public <E extends JavaElement> void findAll(Predicate<JavaElement> finder, Collection<E> collector) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public VisitorBag visit(Visitor<JavaElement> visitor) {
|
public VisitorBag visit(Visitor<JavaElement> visitor) {
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
package dev.peerat.parser.java.operation;
|
package dev.peerat.parser.java.operation;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
import dev.peerat.parser.java.JavaElement;
|
import dev.peerat.parser.java.JavaElement;
|
||||||
import dev.peerat.parser.java.visitor.JavaVisitor;
|
import dev.peerat.parser.java.visitor.JavaVisitor;
|
||||||
|
@ -11,12 +13,16 @@ import dev.peerat.parser.visitor.VisitorBag;
|
||||||
public class ContinueOperation extends Operation{
|
public class ContinueOperation extends Operation{
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <E extends JavaElement> E find(Function<JavaElement, Boolean> finder){
|
public <E extends JavaElement> E find(Predicate<JavaElement> finder) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <E extends JavaElement> void findAll(Function<JavaElement, Boolean> finder, List<E> list){}
|
public <E extends JavaElement> void findAll(Predicate<JavaElement> finder, Collection<E> collector) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public VisitorBag visit(Visitor<JavaElement> visitor) {
|
public VisitorBag visit(Visitor<JavaElement> visitor) {
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
package dev.peerat.parser.java.operation;
|
package dev.peerat.parser.java.operation;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
import dev.peerat.parser.java.JavaElement;
|
import dev.peerat.parser.java.JavaElement;
|
||||||
import dev.peerat.parser.java.Variable;
|
import dev.peerat.parser.java.Variable;
|
||||||
|
@ -44,50 +46,50 @@ public class ForOperation extends OperationBag{
|
||||||
public List<Value> getUpdates(){
|
public List<Value> getUpdates(){
|
||||||
return this.updates;
|
return this.updates;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <E extends JavaElement> E find(Function<JavaElement, Boolean> finder){
|
public <E extends JavaElement> E find(Predicate<JavaElement> finder) {
|
||||||
if(init_vars != null){
|
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.test(variable)) return (E)variable;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(init_values != null){
|
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.test(value)) return (E)value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(finder.apply(condition)) return (E)condition;
|
if(finder.test(condition)) return (E)condition;
|
||||||
if(this.updates != null){
|
if(this.updates != null){
|
||||||
for(Value value : this.updates){
|
for(Value value : this.updates){
|
||||||
if(finder.apply(value)) return (E)value;
|
if(finder.test(value)) return (E)value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return super.find(finder);
|
return super.find(finder);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <E extends JavaElement> void findAll(Function<JavaElement, Boolean> finder, List<E> list){
|
public <E extends JavaElement> void findAll(Predicate<JavaElement> finder, Collection<E> collector) {
|
||||||
if(init_vars != null){
|
if(init_vars != null){
|
||||||
for(Variable variable : this.init_vars){
|
for(Variable variable : this.init_vars){
|
||||||
if(finder.apply(variable)) list.add((E)variable);
|
if(finder.test(variable)) collector.add((E)variable);
|
||||||
variable.findAll(finder, list);
|
variable.findAll(finder, collector);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(init_values != null){
|
if(init_values != null){
|
||||||
for(Value value : this.init_values){
|
for(Value value : this.init_values){
|
||||||
if(finder.apply(value)) list.add((E)value);
|
if(finder.test(value)) collector.add((E)value);
|
||||||
value.findAll(finder, list);
|
value.findAll(finder, collector);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(finder.apply(condition)) list.add((E)condition);
|
if(finder.test(condition)) collector.add((E)condition);
|
||||||
if(this.updates != null){
|
if(this.updates != null){
|
||||||
for(Value value : this.updates){
|
for(Value value : this.updates){
|
||||||
if(finder.apply(value)) list.add((E)value);
|
if(finder.test(value)) collector.add((E)value);
|
||||||
value.findAll(finder, list);
|
value.findAll(finder, collector);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
super.findAll(finder, list);
|
super.findAll(finder, collector);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
package dev.peerat.parser.java.operation;
|
package dev.peerat.parser.java.operation;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
import dev.peerat.parser.Token;
|
import dev.peerat.parser.Token;
|
||||||
import dev.peerat.parser.java.JavaElement;
|
import dev.peerat.parser.java.JavaElement;
|
||||||
|
@ -35,18 +37,17 @@ public class ForeachOperation extends OperationBag{
|
||||||
public Value getIterator(){
|
public Value getIterator(){
|
||||||
return this.iterator;
|
return this.iterator;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <E extends JavaElement> E find(Function<JavaElement, Boolean> finder){
|
public <E extends JavaElement> E find(Predicate<JavaElement> finder) {
|
||||||
if(finder.apply(iterator)) return (E)iterator;
|
// TODO Auto-generated method stub
|
||||||
return super.find(finder);
|
return super.find(finder);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <E extends JavaElement> void findAll(Function<JavaElement, Boolean> finder, List<E> list){
|
public <E extends JavaElement> void findAll(Predicate<JavaElement> finder, Collection<E> collector) {
|
||||||
if(finder.apply(iterator)) list.add((E)iterator);
|
// TODO Auto-generated method stub
|
||||||
iterator.findAll(finder, list);
|
super.findAll(finder, collector);
|
||||||
super.findAll(finder, list);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
package dev.peerat.parser.java.operation;
|
package dev.peerat.parser.java.operation;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
import dev.peerat.parser.java.JavaElement;
|
import dev.peerat.parser.java.JavaElement;
|
||||||
import dev.peerat.parser.java.value.Value;
|
import dev.peerat.parser.java.value.Value;
|
||||||
|
@ -21,20 +23,20 @@ public class IfOperation extends OperationBag{
|
||||||
public Value getCondition(){
|
public Value getCondition(){
|
||||||
return this.condition;
|
return this.condition;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public <E extends JavaElement> E find(Function<JavaElement, Boolean> finder){
|
|
||||||
if(finder.apply(condition)) return (E)condition;
|
|
||||||
return super.find(finder);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <E extends JavaElement> void findAll(Function<JavaElement, Boolean> finder, List<E> list){
|
public <E extends JavaElement> E find(Predicate<JavaElement> finder) {
|
||||||
if(finder.apply(condition)) list.add((E)condition);
|
if(finder.test(condition)) return (E)condition;
|
||||||
condition.findAll(finder, list);
|
return super.find(finder);
|
||||||
super.findAll(finder, list);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <E extends JavaElement> void findAll(Predicate<JavaElement> finder, Collection<E> collector) {
|
||||||
|
if(finder.test(condition)) collector.add((E)condition);
|
||||||
|
condition.findAll(finder, collector);
|
||||||
|
super.findAll(finder, collector);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public VisitorBag visit(Visitor<JavaElement> visitor) {
|
public VisitorBag visit(Visitor<JavaElement> visitor) {
|
||||||
if(visitor.canVisit(getClass())) return visitor.visit(this);
|
if(visitor.canVisit(getClass())) return visitor.visit(this);
|
||||||
|
|
|
@ -2,7 +2,7 @@ package dev.peerat.parser.java.operation;
|
||||||
|
|
||||||
import dev.peerat.parser.java.JavaElement;
|
import dev.peerat.parser.java.JavaElement;
|
||||||
|
|
||||||
public abstract class Operation extends JavaElement{
|
public abstract class Operation implements JavaElement{
|
||||||
|
|
||||||
public static interface OperationContainer{
|
public static interface OperationContainer{
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
package dev.peerat.parser.java.operation;
|
package dev.peerat.parser.java.operation;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
import dev.peerat.parser.java.JavaElement;
|
import dev.peerat.parser.java.JavaElement;
|
||||||
import dev.peerat.parser.java.Variable;
|
import dev.peerat.parser.java.Variable;
|
||||||
|
@ -40,27 +42,28 @@ public abstract class OperationBag extends Operation implements VariableContaine
|
||||||
public List<JavaElement> getElements(){
|
public List<JavaElement> getElements(){
|
||||||
return this.elements;
|
return this.elements;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <E extends JavaElement> E find(Function<JavaElement, Boolean> finder){
|
public <E extends JavaElement> E find(Predicate<JavaElement> finder) {
|
||||||
if(elements != null){
|
if(elements != null){
|
||||||
for(JavaElement element : this.elements){
|
for(JavaElement element : this.elements){
|
||||||
if(finder.apply(element)) return (E)element;
|
if(finder.test(element)) return (E)element;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <E extends JavaElement> void findAll(Function<JavaElement, Boolean> finder, List<E> list){
|
public <E extends JavaElement> void findAll(Predicate<JavaElement> finder, Collection<E> collector) {
|
||||||
if(elements != null){
|
if(elements != null){
|
||||||
for(JavaElement element : this.elements){
|
for(JavaElement element : this.elements){
|
||||||
if(finder.apply(element)) list.add((E)element);
|
if(finder.test(element)) collector.add((E)element);
|
||||||
element.findAll(finder, list);
|
element.findAll(finder, collector);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public VisitorBag visit(Visitor<JavaElement> visitor){
|
public VisitorBag visit(Visitor<JavaElement> visitor){
|
||||||
VisitorBag bag = new VisitorBag();
|
VisitorBag bag = new VisitorBag();
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
package dev.peerat.parser.java.operation;
|
package dev.peerat.parser.java.operation;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
import dev.peerat.parser.java.JavaElement;
|
import dev.peerat.parser.java.JavaElement;
|
||||||
import dev.peerat.parser.java.value.Value;
|
import dev.peerat.parser.java.value.Value;
|
||||||
|
@ -20,17 +22,17 @@ public class ReturnOperation extends Operation{
|
||||||
public Value getValue(){
|
public Value getValue(){
|
||||||
return this.value;
|
return this.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <E extends JavaElement> E find(Function<JavaElement, Boolean> finder){
|
public <E extends JavaElement> E find(Predicate<JavaElement> finder) {
|
||||||
return value != null ? finder.apply(value) ? (E)value : null : null;
|
return value != null ? finder.test(value) ? (E)value : null : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <E extends JavaElement> void findAll(Function<JavaElement, Boolean> finder, List<E> list){
|
public <E extends JavaElement> void findAll(Predicate<JavaElement> finder, Collection<E> collector) {
|
||||||
if(value != null){
|
if(value != null){
|
||||||
if(finder.apply(value)) list.add((E) value);
|
if(finder.test(value)) collector.add((E) value);
|
||||||
value.findAll(finder, list);
|
value.findAll(finder, collector);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
package dev.peerat.parser.java.operation;
|
package dev.peerat.parser.java.operation;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
import dev.peerat.parser.java.JavaElement;
|
import dev.peerat.parser.java.JavaElement;
|
||||||
import dev.peerat.parser.java.visitor.JavaVisitor;
|
import dev.peerat.parser.java.visitor.JavaVisitor;
|
||||||
|
@ -13,12 +15,16 @@ public class SwitchOperation extends Operation{
|
||||||
//+ AND OBJECT FOR CONTAINING EVERY CASE OP
|
//+ AND OBJECT FOR CONTAINING EVERY CASE OP
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <E extends JavaElement> E find(Function<JavaElement, Boolean> finder) {
|
public <E extends JavaElement> E find(Predicate<JavaElement> finder) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <E extends JavaElement> void findAll(Function<JavaElement, Boolean> finder, List<E> list){}
|
public <E extends JavaElement> void findAll(Predicate<JavaElement> finder, Collection<E> collector) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public VisitorBag visit(Visitor<JavaElement> visitor) {
|
public VisitorBag visit(Visitor<JavaElement> visitor) {
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
package dev.peerat.parser.java.operation;
|
package dev.peerat.parser.java.operation;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
import dev.peerat.parser.java.JavaElement;
|
import dev.peerat.parser.java.JavaElement;
|
||||||
import dev.peerat.parser.java.value.Value;
|
import dev.peerat.parser.java.value.Value;
|
||||||
|
@ -21,20 +23,20 @@ public class SynchronizedOperation extends OperationBag{
|
||||||
public Value getValue(){
|
public Value getValue(){
|
||||||
return this.value;
|
return this.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public <E extends JavaElement> E find(Function<JavaElement, Boolean> finder){
|
|
||||||
if(finder.apply(value)) return (E)value;
|
|
||||||
return super.find(finder);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <E extends JavaElement> void findAll(Function<JavaElement, Boolean> finder, List<E> list){
|
public <E extends JavaElement> E find(Predicate<JavaElement> finder) {
|
||||||
if(finder.apply(value)) list.add((E)value);
|
if(finder.test(value)) return (E)value;
|
||||||
value.findAll(finder, list);
|
return super.find(finder);
|
||||||
super.findAll(finder, list);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <E extends JavaElement> void findAll(Predicate<JavaElement> finder, Collection<E> collector) {
|
||||||
|
if(finder.test(value)) collector.add((E)value);
|
||||||
|
value.findAll(finder, collector);
|
||||||
|
super.findAll(finder, collector);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public VisitorBag visit(Visitor<JavaElement> visitor) {
|
public VisitorBag visit(Visitor<JavaElement> visitor) {
|
||||||
if(visitor.canVisit(getClass())) return visitor.visit(this);
|
if(visitor.canVisit(getClass())) return visitor.visit(this);
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
package dev.peerat.parser.java.operation;
|
package dev.peerat.parser.java.operation;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
import dev.peerat.parser.java.JavaElement;
|
import dev.peerat.parser.java.JavaElement;
|
||||||
import dev.peerat.parser.java.value.Value;
|
import dev.peerat.parser.java.value.Value;
|
||||||
|
@ -20,16 +22,16 @@ public class ThrowOperation extends Operation{
|
||||||
public Value getValue(){
|
public Value getValue(){
|
||||||
return this.value;
|
return this.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public <E extends JavaElement> E find(Function<JavaElement, Boolean> finder) {
|
|
||||||
return finder.apply(value) ? (E)value : null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <E extends JavaElement> void findAll(Function<JavaElement, Boolean> finder, List<E> list){
|
public <E extends JavaElement> E find(Predicate<JavaElement> finder) {
|
||||||
if(finder.apply(value)) list.add((E) value);
|
return finder.test(value) ? (E)value : null;
|
||||||
value.findAll(finder, list);
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <E extends JavaElement> void findAll(Predicate<JavaElement> finder, Collection<E> collector) {
|
||||||
|
if(finder.test(value)) collector.add((E) value);
|
||||||
|
value.findAll(finder, collector);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
package dev.peerat.parser.java.operation;
|
package dev.peerat.parser.java.operation;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
import dev.peerat.parser.java.JavaElement;
|
import dev.peerat.parser.java.JavaElement;
|
||||||
import dev.peerat.parser.java.Variable;
|
import dev.peerat.parser.java.Variable;
|
||||||
|
@ -25,21 +27,21 @@ public class TryOperation extends OperationBag{
|
||||||
public Variable getResource(){
|
public Variable getResource(){
|
||||||
return this.resource;
|
return this.resource;
|
||||||
}
|
}
|
||||||
|
|
||||||
@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);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <E extends JavaElement> void findAll(Function<JavaElement, Boolean> finder, List<E> list){
|
public <E extends JavaElement> E find(Predicate<JavaElement> finder) {
|
||||||
if(resource != null){
|
return resource != null ? finder.test(resource) ? (E)resource : super.find(finder) : super.find(finder);
|
||||||
if(finder.apply(resource)) list.add((E) resource);
|
|
||||||
resource.findAll(finder, list);
|
|
||||||
}
|
|
||||||
super.findAll(finder, list);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <E extends JavaElement> void findAll(Predicate<JavaElement> finder, Collection<E> collector) {
|
||||||
|
if(resource != null){
|
||||||
|
if(finder.test(resource)) collector.add((E) resource);
|
||||||
|
resource.findAll(finder, collector);
|
||||||
|
}
|
||||||
|
super.findAll(finder, collector);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public VisitorBag visit(Visitor<JavaElement> visitor) {
|
public VisitorBag visit(Visitor<JavaElement> visitor) {
|
||||||
if(visitor.canVisit(getClass())) return visitor.visit(this);
|
if(visitor.canVisit(getClass())) return visitor.visit(this);
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
package dev.peerat.parser.java.operation;
|
package dev.peerat.parser.java.operation;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
import dev.peerat.parser.java.JavaElement;
|
import dev.peerat.parser.java.JavaElement;
|
||||||
import dev.peerat.parser.java.value.Value;
|
import dev.peerat.parser.java.value.Value;
|
||||||
|
@ -20,20 +22,20 @@ public class WhileOperation extends OperationBag{
|
||||||
public Value getCondition(){
|
public Value getCondition(){
|
||||||
return this.condition;
|
return this.condition;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <E extends JavaElement> E find(Function<JavaElement, Boolean> finder){
|
public <E extends JavaElement> E find(Predicate<JavaElement> finder) {
|
||||||
if(finder.apply(condition)) return (E)condition;
|
if(finder.test(condition)) return (E)condition;
|
||||||
return super.find(finder);
|
return super.find(finder);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <E extends JavaElement> void findAll(Function<JavaElement, Boolean> finder, List<E> list){
|
public <E extends JavaElement> void findAll(Predicate<JavaElement> finder, Collection<E> collector) {
|
||||||
if(finder.apply(condition)) list.add((E) condition);
|
if(finder.test(condition)) collector.add((E) condition);
|
||||||
condition.findAll(finder, list);
|
condition.findAll(finder, collector);
|
||||||
super.findAll(finder, list);
|
super.findAll(finder, collector);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public VisitorBag visit(Visitor<JavaElement> visitor) {
|
public VisitorBag visit(Visitor<JavaElement> visitor) {
|
||||||
if(visitor.canVisit(getClass())) return visitor.visit(this);
|
if(visitor.canVisit(getClass())) return visitor.visit(this);
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
package dev.peerat.parser.java.value;
|
package dev.peerat.parser.java.value;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
import dev.peerat.parser.java.JavaElement;
|
import dev.peerat.parser.java.JavaElement;
|
||||||
import dev.peerat.parser.visitor.Visitor;
|
import dev.peerat.parser.visitor.Visitor;
|
||||||
|
@ -24,14 +26,16 @@ public class ArrayAccessValue extends Value{
|
||||||
public Value getAccessor(){
|
public Value getAccessor(){
|
||||||
return this.access;
|
return this.access;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <E extends JavaElement> E find(Function<JavaElement, Boolean> finder) {
|
public <E extends JavaElement> E find(Predicate<JavaElement> finder) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <E extends JavaElement> void findAll(Function<JavaElement, Boolean> finder, List<E> list) {
|
public <E extends JavaElement> void findAll(Predicate<JavaElement> finder, Collection<E> collector) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
package dev.peerat.parser.java.value;
|
package dev.peerat.parser.java.value;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
import dev.peerat.parser.java.JavaElement;
|
import dev.peerat.parser.java.JavaElement;
|
||||||
import dev.peerat.parser.visitor.Visitor;
|
import dev.peerat.parser.visitor.Visitor;
|
||||||
|
@ -20,12 +22,14 @@ public class ArrayValue extends Value{
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <E extends JavaElement> E find(Function<JavaElement, Boolean> finder) {
|
public <E extends JavaElement> E find(Predicate<JavaElement> finder) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <E extends JavaElement> void findAll(Function<JavaElement, Boolean> finder, List<E> list) {
|
public <E extends JavaElement> void findAll(Predicate<JavaElement> finder, Collection<E> collector) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
package dev.peerat.parser.java.value;
|
package dev.peerat.parser.java.value;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
import dev.peerat.parser.java.JavaElement;
|
import dev.peerat.parser.java.JavaElement;
|
||||||
import dev.peerat.parser.java.visitor.JavaVisitor;
|
import dev.peerat.parser.java.visitor.JavaVisitor;
|
||||||
|
@ -33,12 +35,14 @@ public class BiValue extends Value{
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <E extends JavaElement> E find(Function<JavaElement, Boolean> finder) {
|
public <E extends JavaElement> E find(Predicate<JavaElement> finder) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <E extends JavaElement> void findAll(Function<JavaElement, Boolean> finder, List<E> list) {
|
public <E extends JavaElement> void findAll(Predicate<JavaElement> finder, Collection<E> collector) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
package dev.peerat.parser.java.value;
|
package dev.peerat.parser.java.value;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
import dev.peerat.parser.Token;
|
import dev.peerat.parser.Token;
|
||||||
import dev.peerat.parser.java.JavaElement;
|
import dev.peerat.parser.java.JavaElement;
|
||||||
|
@ -27,12 +29,14 @@ public class CastValue extends Value{
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <E extends JavaElement> E find(Function<JavaElement, Boolean> finder) {
|
public <E extends JavaElement> E find(Predicate<JavaElement> finder) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <E extends JavaElement> void findAll(Function<JavaElement, Boolean> finder, List<E> list) {
|
public <E extends JavaElement> void findAll(Predicate<JavaElement> finder, Collection<E> collector) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,84 +1,95 @@
|
||||||
package dev.peerat.parser.java.value;
|
package dev.peerat.parser.java.value;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.function.Function;
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
import dev.peerat.parser.Token;
|
import dev.peerat.parser.Token;
|
||||||
|
import dev.peerat.parser.java.Annotation;
|
||||||
import dev.peerat.parser.java.Annotation.AnnotableBuffer;
|
import dev.peerat.parser.java.Annotation.AnnotableBuffer;
|
||||||
import dev.peerat.parser.java.Function.FunctionContainer;
|
import dev.peerat.parser.java.Function.FunctionContainer;
|
||||||
import dev.peerat.parser.java.Annotation;
|
|
||||||
import dev.peerat.parser.java.JavaElement;
|
import dev.peerat.parser.java.JavaElement;
|
||||||
import dev.peerat.parser.java.Variable;
|
import dev.peerat.parser.java.Variable;
|
||||||
import dev.peerat.parser.java.Variable.VariableContainer;
|
import dev.peerat.parser.java.Variable.VariableContainer;
|
||||||
import dev.peerat.parser.visitor.Visitor;
|
import dev.peerat.parser.visitor.Visitor;
|
||||||
import dev.peerat.parser.visitor.VisitorBag;
|
import dev.peerat.parser.visitor.VisitorBag;
|
||||||
|
|
||||||
public class InstanceValue extends Value implements VariableContainer, FunctionContainer, AnnotableBuffer{ //TODO LIKE A CLASS, CAN CONTAINS CLASS
|
public class InstanceValue extends Value implements VariableContainer, FunctionContainer, AnnotableBuffer { // TODO LIKE
|
||||||
|
// A CLASS,
|
||||||
|
// CAN
|
||||||
|
// CONTAINS
|
||||||
|
// CLASS
|
||||||
|
|
||||||
private Token token;
|
private Token token;
|
||||||
private List<Value> parameters;
|
private List<Value> parameters;
|
||||||
|
|
||||||
private List<JavaElement> elements;
|
private List<JavaElement> elements;
|
||||||
private List<Annotation> annotationBuffer;
|
private List<Annotation> annotationBuffer;
|
||||||
|
|
||||||
public InstanceValue(Token token, List<Value> parameters){
|
public InstanceValue(Token token, List<Value> parameters) {
|
||||||
this.token = token;
|
this.token = token;
|
||||||
this.parameters = parameters;
|
this.parameters = parameters;
|
||||||
this.elements = new ArrayList<>();
|
this.elements = new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Token getToken(){
|
public Token getToken() {
|
||||||
return token;
|
return token;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Value> getParameters(){
|
public List<Value> getParameters() {
|
||||||
return this.parameters;
|
return this.parameters;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<JavaElement> getElements(){
|
public List<JavaElement> getElements() {
|
||||||
return this.elements;
|
return this.elements;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addFunction(dev.peerat.parser.java.Function function){
|
public void addFunction(dev.peerat.parser.java.Function function) {
|
||||||
this.elements.add(function);
|
this.elements.add(function);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addVariable(Variable variable){
|
public void addVariable(Variable variable) {
|
||||||
this.elements.add(variable);
|
this.elements.add(variable);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addAnnotationBuffer(Annotation annotation){
|
public void addAnnotationBuffer(Annotation annotation) {
|
||||||
if(annotationBuffer == null) annotationBuffer = new ArrayList<>();
|
if (annotationBuffer == null)
|
||||||
|
annotationBuffer = new ArrayList<>();
|
||||||
annotationBuffer.add(annotation);
|
annotationBuffer.add(annotation);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Annotation> getAnnotationBuffer(){
|
public List<Annotation> getAnnotationBuffer() {
|
||||||
List<Annotation> list = this.annotationBuffer;
|
List<Annotation> list = this.annotationBuffer;
|
||||||
this.annotationBuffer = null;
|
this.annotationBuffer = null;
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <E extends JavaElement> E find(Function<JavaElement, Boolean> finder) {
|
public <E extends JavaElement> E find(Predicate<JavaElement> finder) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <E extends JavaElement> void findAll(Function<JavaElement, Boolean> finder, List<E> list) {
|
public <E extends JavaElement> void findAll(Predicate<JavaElement> finder, Collection<E> collector) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public VisitorBag visit(Visitor<JavaElement> visitor) {
|
public VisitorBag visit(Visitor<JavaElement> visitor) {
|
||||||
if(visitor.canVisit(getClass())) return visitor.visit(this);
|
if (visitor.canVisit(getClass()))
|
||||||
|
return visitor.visit(this);
|
||||||
VisitorBag bag = new VisitorBag();
|
VisitorBag bag = new VisitorBag();
|
||||||
|
|
||||||
for(Value value : parameters) bag.merge(value.visit(visitor));
|
for (Value value : parameters)
|
||||||
for(JavaElement content : elements) bag.merge(content.visit(visitor));
|
bag.merge(value.visit(visitor));
|
||||||
|
for (JavaElement content : elements)
|
||||||
|
bag.merge(content.visit(visitor));
|
||||||
return bag;
|
return bag;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
package dev.peerat.parser.java.value;
|
package dev.peerat.parser.java.value;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
import dev.peerat.parser.Token;
|
import dev.peerat.parser.Token;
|
||||||
import dev.peerat.parser.java.JavaElement;
|
import dev.peerat.parser.java.JavaElement;
|
||||||
|
@ -53,12 +55,14 @@ public class LambdaValue extends Value implements OperationContainer, VariableCo
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <E extends JavaElement> E find(Function<JavaElement, Boolean> finder) {
|
public <E extends JavaElement> E find(Predicate<JavaElement> finder) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <E extends JavaElement> void findAll(Function<JavaElement, Boolean> finder, List<E> list) {
|
public <E extends JavaElement> void findAll(Predicate<JavaElement> finder, Collection<E> collector) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
package dev.peerat.parser.java.value;
|
package dev.peerat.parser.java.value;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
import dev.peerat.parser.Token;
|
import dev.peerat.parser.Token;
|
||||||
import dev.peerat.parser.java.JavaElement;
|
import dev.peerat.parser.java.JavaElement;
|
||||||
|
@ -39,12 +41,14 @@ public class MethodCallValue extends Value{
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <E extends JavaElement> E find(Function<JavaElement, Boolean> finder) {
|
public <E extends JavaElement> E find(Predicate<JavaElement> finder) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <E extends JavaElement> void findAll(Function<JavaElement, Boolean> finder, List<E> list) {
|
public <E extends JavaElement> void findAll(Predicate<JavaElement> finder, Collection<E> collector) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
package dev.peerat.parser.java.value;
|
package dev.peerat.parser.java.value;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
import dev.peerat.parser.Token;
|
import dev.peerat.parser.Token;
|
||||||
import dev.peerat.parser.java.JavaElement;
|
import dev.peerat.parser.java.JavaElement;
|
||||||
|
@ -27,12 +29,14 @@ public class ModifierValue extends Value{
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <E extends JavaElement> E find(Function<JavaElement, Boolean> finder) {
|
public <E extends JavaElement> E find(Predicate<JavaElement> finder) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <E extends JavaElement> void findAll(Function<JavaElement, Boolean> finder, List<E> list) {
|
public <E extends JavaElement> void findAll(Predicate<JavaElement> finder, Collection<E> collector) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
package dev.peerat.parser.java.value;
|
package dev.peerat.parser.java.value;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
import dev.peerat.parser.Token;
|
import dev.peerat.parser.Token;
|
||||||
import dev.peerat.parser.java.JavaElement;
|
import dev.peerat.parser.java.JavaElement;
|
||||||
|
@ -21,15 +23,16 @@ public class StaticValue extends Value{
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <E extends JavaElement> E find(Function<JavaElement, Boolean> finder) {
|
public <E extends JavaElement> E find(Predicate<JavaElement> finder) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <E extends JavaElement> void findAll(Function<JavaElement, Boolean> finder, List<E> list) {
|
public <E extends JavaElement> void findAll(Predicate<JavaElement> finder, Collection<E> collector) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString(){
|
public String toString(){
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
package dev.peerat.parser.java.value;
|
package dev.peerat.parser.java.value;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
import dev.peerat.parser.java.JavaElement;
|
import dev.peerat.parser.java.JavaElement;
|
||||||
import dev.peerat.parser.visitor.Visitor;
|
import dev.peerat.parser.visitor.Visitor;
|
||||||
|
@ -32,12 +34,14 @@ public class TriValue extends Value{
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <E extends JavaElement> E find(Function<JavaElement, Boolean> finder) {
|
public <E extends JavaElement> E find(Predicate<JavaElement> finder) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <E extends JavaElement> void findAll(Function<JavaElement, Boolean> finder, List<E> list) {
|
public <E extends JavaElement> void findAll(Predicate<JavaElement> finder, Collection<E> collector) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ package dev.peerat.parser.java.value;
|
||||||
|
|
||||||
import dev.peerat.parser.java.JavaElement;
|
import dev.peerat.parser.java.JavaElement;
|
||||||
|
|
||||||
public abstract class Value extends JavaElement{
|
public abstract class Value implements JavaElement{
|
||||||
|
|
||||||
//Only for TESTS purpose!
|
//Only for TESTS purpose!
|
||||||
public static interface ValueContainer{
|
public static interface ValueContainer{
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
package dev.peerat.parser.java.value;
|
package dev.peerat.parser.java.value;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
import dev.peerat.parser.Token;
|
import dev.peerat.parser.Token;
|
||||||
import dev.peerat.parser.java.JavaElement;
|
import dev.peerat.parser.java.JavaElement;
|
||||||
|
@ -27,15 +29,17 @@ public class VariableAccessValue extends Value{
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <E extends JavaElement> E find(Function<JavaElement, Boolean> finder) {
|
public <E extends JavaElement> E find(Predicate<JavaElement> finder) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <E extends JavaElement> void findAll(Function<JavaElement, Boolean> finder, List<E> list) {
|
public <E extends JavaElement> void findAll(Predicate<JavaElement> finder, Collection<E> collector) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public VisitorBag visit(Visitor<JavaElement> visitor) {
|
public VisitorBag visit(Visitor<JavaElement> visitor) {
|
||||||
if(visitor.canVisit(getClass())) return visitor.visit(this);
|
if(visitor.canVisit(getClass())) return visitor.visit(this);
|
||||||
|
|
71
src/dev/peerat/parser/java/visitor/JavaFileVisitor.java
Normal file
71
src/dev/peerat/parser/java/visitor/JavaFileVisitor.java
Normal file
|
@ -0,0 +1,71 @@
|
||||||
|
package dev.peerat.parser.java.visitor;
|
||||||
|
|
||||||
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
|
import dev.peerat.parser.java.JavaElement;
|
||||||
|
import dev.peerat.parser.java.JavaFile;
|
||||||
|
import dev.peerat.parser.visitor.Visitor;
|
||||||
|
import dev.peerat.parser.visitor.VisitorBag;
|
||||||
|
|
||||||
|
public class JavaFileVisitor extends JavaVisitor<JavaFile>{
|
||||||
|
|
||||||
|
private boolean checkPackage;
|
||||||
|
private boolean checkNoPackage;
|
||||||
|
private Predicate<String> pack;
|
||||||
|
private Visitor<JavaElement> imports;
|
||||||
|
private Visitor<JavaElement> classes;
|
||||||
|
|
||||||
|
public JavaFileVisitor(boolean propagate){
|
||||||
|
super(JavaFile.class, propagate);
|
||||||
|
}
|
||||||
|
|
||||||
|
public JavaFileVisitor hasPackage(){
|
||||||
|
this.checkPackage = true;
|
||||||
|
this.checkNoPackage = false;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public JavaFileVisitor hasNoPackage(){
|
||||||
|
this.checkPackage = false;
|
||||||
|
this.checkNoPackage = true;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public JavaFileVisitor packaged(Predicate<String> predicate){
|
||||||
|
this.pack = predicate;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public JavaFileVisitor imp(Visitor<JavaElement> visitor){
|
||||||
|
this.imports = visitor;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public JavaFileVisitor clazz(Visitor<JavaElement> visitor){
|
||||||
|
this.classes = visitor;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public VisitorBag visitElement(JavaFile element){
|
||||||
|
VisitorBag bag = new VisitorBag();
|
||||||
|
|
||||||
|
if(this.checkPackage && element.getPackage() == null) return bag;
|
||||||
|
else if(this.checkNoPackage && element.getPackage() != null) return bag;
|
||||||
|
|
||||||
|
if(this.pack != null && element.getPackage() != null && !this.pack.test(element.getPackage().getValue())) return bag;
|
||||||
|
|
||||||
|
if(this.imports != null && validates(bag, element.getImports(), this.imports)) return bag;
|
||||||
|
if(this.classes != null){
|
||||||
|
VisitorBag resultMain = this.classes.visit(element.getMainClass());
|
||||||
|
if(resultMain.isValidated()) bag.merge(resultMain);
|
||||||
|
if(!(validates(bag, element.getSubClasses(), this.classes) || resultMain.isValidated())) return bag;
|
||||||
|
}
|
||||||
|
|
||||||
|
bag.compute(element);
|
||||||
|
return bag;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -5,11 +5,10 @@ import java.util.function.Predicate;
|
||||||
import dev.peerat.parser.java.Variable;
|
import dev.peerat.parser.java.Variable;
|
||||||
import dev.peerat.parser.visitor.VisitorBag;
|
import dev.peerat.parser.visitor.VisitorBag;
|
||||||
|
|
||||||
public class JavaVariableVisitor extends JavaVisitor<Variable>{
|
public class JavaVariableVisitor extends JavaModifiableVisitor<Variable, JavaVariableVisitor>{
|
||||||
|
|
||||||
private Predicate<String> typeFilter;
|
private Predicate<String> typeFilter;
|
||||||
private Predicate<String> nameFilter;
|
private Predicate<String> nameFilter;
|
||||||
private Predicate<Integer> modifierFilter;
|
|
||||||
|
|
||||||
public JavaVariableVisitor(boolean propagate){
|
public JavaVariableVisitor(boolean propagate){
|
||||||
super(Variable.class, propagate);
|
super(Variable.class, propagate);
|
||||||
|
@ -25,54 +24,6 @@ public class JavaVariableVisitor extends JavaVisitor<Variable>{
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public JavaVariableVisitor isPublic(){
|
|
||||||
Predicate<Integer> validator = (mod) -> (mod & 0x1) != 0;
|
|
||||||
this.modifierFilter = (this.modifierFilter == null) ? validator : this.modifierFilter.and(validator);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public JavaVariableVisitor isPrivate(){
|
|
||||||
Predicate<Integer> validator = (mod) -> (mod & 0x2) != 0;
|
|
||||||
this.modifierFilter = (this.modifierFilter == null) ? validator : this.modifierFilter.and(validator);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public JavaVariableVisitor isProtected(){
|
|
||||||
Predicate<Integer> validator = (mod) -> (mod & 0x4) != 0;
|
|
||||||
this.modifierFilter = (this.modifierFilter == null) ? validator : this.modifierFilter.and(validator);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public JavaVariableVisitor isStatic(){
|
|
||||||
Predicate<Integer> validator = (mod) -> (mod & 0x8) != 0;
|
|
||||||
this.modifierFilter = (this.modifierFilter == null) ? validator : this.modifierFilter.and(validator);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public JavaVariableVisitor isFinal(){
|
|
||||||
Predicate<Integer> validator = (mod) -> (mod & 0x10) != 0;
|
|
||||||
this.modifierFilter = (this.modifierFilter == null) ? validator : this.modifierFilter.and(validator);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public JavaVariableVisitor isVolatile(){
|
|
||||||
Predicate<Integer> validator = (mod) -> (mod & 0x40) != 0;
|
|
||||||
this.modifierFilter = (this.modifierFilter == null) ? validator : this.modifierFilter.and(validator);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public JavaVariableVisitor isTransient(){
|
|
||||||
Predicate<Integer> validator = (mod) -> (mod & 0x80) != 0;
|
|
||||||
this.modifierFilter = (this.modifierFilter == null) ? validator : this.modifierFilter.and(validator);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public JavaVariableVisitor isPackageLevel(){
|
|
||||||
Predicate<Integer> validator = (mod) -> (mod & 0x1) == 0 && (mod & 0x2) == 0 && (mod & 0x4) == 0;
|
|
||||||
this.modifierFilter = (this.modifierFilter == null) ? validator : this.modifierFilter.and(validator);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public VisitorBag visitElement(Variable element){
|
public VisitorBag visitElement(Variable element){
|
||||||
VisitorBag bag = new VisitorBag();
|
VisitorBag bag = new VisitorBag();
|
||||||
|
|
|
@ -54,6 +54,10 @@ public abstract class JavaVisitor<T extends JavaElement> extends Visitor<JavaEle
|
||||||
return javaElement(true);
|
return javaElement(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static JavaFileVisitor allFile(){
|
||||||
|
return new JavaFileVisitor(true);
|
||||||
|
}
|
||||||
|
|
||||||
public static JavaClassBaseVisitor allClassBase(){
|
public static JavaClassBaseVisitor allClassBase(){
|
||||||
return new JavaClassBaseVisitor(true);
|
return new JavaClassBaseVisitor(true);
|
||||||
}
|
}
|
||||||
|
@ -153,6 +157,10 @@ public abstract class JavaVisitor<T extends JavaElement> extends Visitor<JavaEle
|
||||||
return javaElement(false);
|
return javaElement(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static JavaFileVisitor file(){
|
||||||
|
return new JavaFileVisitor(false);
|
||||||
|
}
|
||||||
|
|
||||||
public static JavaClassBaseVisitor classBase(){
|
public static JavaClassBaseVisitor classBase(){
|
||||||
return new JavaClassBaseVisitor(false);
|
return new JavaClassBaseVisitor(false);
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ package dev.peerat.parser.java.visitor.value;
|
||||||
import dev.peerat.parser.java.value.ArrayAccessValue;
|
import dev.peerat.parser.java.value.ArrayAccessValue;
|
||||||
import dev.peerat.parser.java.value.Value;
|
import dev.peerat.parser.java.value.Value;
|
||||||
import dev.peerat.parser.java.visitor.JavaVisitor;
|
import dev.peerat.parser.java.visitor.JavaVisitor;
|
||||||
|
import dev.peerat.parser.visitor.Operator;
|
||||||
import dev.peerat.parser.visitor.Visitor;
|
import dev.peerat.parser.visitor.Visitor;
|
||||||
import dev.peerat.parser.visitor.VisitorBag;
|
import dev.peerat.parser.visitor.VisitorBag;
|
||||||
|
|
||||||
|
@ -16,12 +17,12 @@ public class JavaArrayAccessValueVisitor extends JavaVisitor<ArrayAccessValue>{
|
||||||
}
|
}
|
||||||
|
|
||||||
public JavaArrayAccessValueVisitor checkBase(Visitor<Value> visitor){
|
public JavaArrayAccessValueVisitor checkBase(Visitor<Value> visitor){
|
||||||
this.basePredicate = visitor;
|
this.basePredicate = this.basePredicate == null ? visitor : Operator.and(this.basePredicate, visitor);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public JavaArrayAccessValueVisitor accessor(Visitor<Value> visitor){
|
public JavaArrayAccessValueVisitor accessor(Visitor<Value> visitor){
|
||||||
this.accessPredicate = visitor;
|
this.accessPredicate = this.accessPredicate == null ? visitor : Operator.and(this.accessPredicate, visitor);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,10 +24,14 @@ public class StateTree<E>{
|
||||||
}
|
}
|
||||||
|
|
||||||
public void seed(TokenValidator validator, E container) throws SyntaxMissMatchException{
|
public void seed(TokenValidator validator, E container) throws SyntaxMissMatchException{
|
||||||
BuilderStateTree<E, ?> build = internalSeed(validator, container);
|
int parsed = 0;
|
||||||
if(build == null) throw new SyntaxMissMatchException(validator);
|
while(validator.hasNext()){
|
||||||
build.build(validator, container);
|
BuilderStateTree<E, ?> build = internalSeed(validator, container);
|
||||||
if(validator.hasNext()) throw new SyntaxMissMatchException(validator);
|
if(build != null) build.build(validator, container);
|
||||||
|
int current = validator.getValidatedTokenCount();
|
||||||
|
if(parsed == current) throw new SyntaxMissMatchException(validator);
|
||||||
|
parsed = current;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BuilderStateTree<E, ?> internalSeed(TokenValidator validator, E element){
|
BuilderStateTree<E, ?> internalSeed(TokenValidator validator, E element){
|
||||||
|
|
|
@ -3,8 +3,14 @@ package dev.peerat.parser.visitor;
|
||||||
import static dev.peerat.parser.java.visitor.JavaVisitor.*;
|
import static dev.peerat.parser.java.visitor.JavaVisitor.*;
|
||||||
import static dev.peerat.parser.visitor.Operator.*;
|
import static dev.peerat.parser.visitor.Operator.*;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import dev.peerat.parser.java.Import;
|
||||||
import dev.peerat.parser.java.JavaFile;
|
import dev.peerat.parser.java.JavaFile;
|
||||||
import dev.peerat.parser.java.JavaParser;
|
import dev.peerat.parser.java.JavaParser;
|
||||||
|
import dev.peerat.parser.java.JavaProject;
|
||||||
|
import dev.peerat.parser.java.Class;
|
||||||
|
|
||||||
public class Example {
|
public class Example {
|
||||||
|
|
||||||
|
@ -12,18 +18,23 @@ public class Example {
|
||||||
|
|
||||||
JavaParser parser = new JavaParser();
|
JavaParser parser = new JavaParser();
|
||||||
JavaFile container = new JavaFile();
|
JavaFile container = new JavaFile();
|
||||||
parser.parse("package dev.peerat.test; public class Example{ private int i = j, j; public void helloTest(){ System.out.println(\"hello\"); } }", container);
|
parser.parse("package dev.peerat.test; import a; import b; public class C{} public class D{}",
|
||||||
|
container);
|
||||||
|
|
||||||
VisitorBag result = container.visit(
|
JavaProject project = new JavaProject();
|
||||||
key(allClass()
|
project.addFile(container);
|
||||||
.isPublic()
|
|
||||||
.elements(
|
|
||||||
value(allVariable()
|
|
||||||
)
|
|
||||||
)
|
|
||||||
));
|
|
||||||
|
|
||||||
System.out.println("allJavaElement in class : "+result.toList());
|
System.out.println(project.visit(
|
||||||
|
allFile().clazz(key(allClass())).imp(value(allImport()))
|
||||||
|
).toList());
|
||||||
|
|
||||||
|
// Map<Class, List<Import>> map = project.visit(
|
||||||
|
// and(
|
||||||
|
// allFile().imp(value(allImport()))
|
||||||
|
// ,
|
||||||
|
// allFile().clazz(key(allClass()))
|
||||||
|
// )).toMapValues();
|
||||||
|
// System.out.println(map);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package dev.peerat.parser.visitor;
|
package dev.peerat.parser.visitor;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
|
@ -12,9 +13,11 @@ public class Operator{
|
||||||
return new Visitor<E>(){
|
return new Visitor<E>(){
|
||||||
@Override
|
@Override
|
||||||
public VisitorBag visit(E element){
|
public VisitorBag visit(E element){
|
||||||
|
System.out.println("and "+Arrays.toString(visitors)+" -> "+element);
|
||||||
VisitorBag bag = new VisitorBag();
|
VisitorBag bag = new VisitorBag();
|
||||||
Set<Object> set = new HashSet<>();
|
Set<Object> set = new HashSet<>();
|
||||||
for(Visitor<E> visitor : visitors){
|
for(Visitor<E> visitor : visitors){
|
||||||
|
if(!visitor.canVisit(element.getClass())) continue;
|
||||||
VisitorBag vbag = visitor.visit(element);
|
VisitorBag vbag = visitor.visit(element);
|
||||||
if(!vbag.isValidated()) return new VisitorBag();
|
if(!vbag.isValidated()) return new VisitorBag();
|
||||||
bag.merge(vbag);
|
bag.merge(vbag);
|
||||||
|
@ -138,24 +141,24 @@ public class Operator{
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <E, T extends Visitor<E>> T count(T visitor, Predicate<Integer> validator){
|
public static <E> Visitor<E> count(Visitor<E> visitor, Predicate<Integer> validator){
|
||||||
return (T) new Visitor<E>(){
|
return new Visitor<E>(){
|
||||||
@Override
|
@Override
|
||||||
public VisitorBag visit(E element){
|
public VisitorBag visit(E element){
|
||||||
VisitorBag visited = visitor.visit(element);
|
VisitorBag visited = visitor.visit(element);
|
||||||
return validator.test(visited.toList().size()) ? visited : new VisitorBag();
|
return visited.isValidated() && validator.test(visited.toList().size()) ? visited : new VisitorBag();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canVisit(Class<?> type) {
|
public boolean canVisit(Class<?> type){
|
||||||
return true;
|
return visitor.canVisit(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canPropagate(){
|
public boolean canPropagate(){
|
||||||
return true;
|
return visitor.canPropagate();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package dev.peerat.parser.visitor;
|
package dev.peerat.parser.visitor;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
import dev.peerat.parser.Token;
|
import dev.peerat.parser.Token;
|
||||||
|
|
||||||
public abstract class Visitor<T>{
|
public abstract class Visitor<T>{
|
||||||
|
@ -18,4 +20,15 @@ public abstract class Visitor<T>{
|
||||||
|
|
||||||
public abstract VisitorBag visit(T element);
|
public abstract VisitorBag visit(T element);
|
||||||
|
|
||||||
|
protected <E> boolean validates(VisitorBag bag, Collection<? extends E> list, Visitor<E> visitor){
|
||||||
|
boolean validateOne = false;
|
||||||
|
for(E element : list){
|
||||||
|
VisitorBag result = visitor.visit(element);
|
||||||
|
if(result.isValidated()){
|
||||||
|
validateOne = true;
|
||||||
|
bag.merge(result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return validateOne;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -96,5 +96,10 @@ public class VisitorBag{
|
||||||
public List<V> getValues(){
|
public List<V> getValues(){
|
||||||
return (List<V>) this.values;
|
return (List<V>) this.values;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString(){
|
||||||
|
return "[key="+key+", values="+values+"]";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Add table
Reference in a new issue