Compare commits
2 commits
d319163f60
...
3f4d824b33
Author | SHA1 | Date | |
---|---|---|---|
|
3f4d824b33 | ||
|
9137136ef7 |
9 changed files with 146 additions and 149 deletions
|
@ -17,6 +17,66 @@ 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;
|
||||
|
||||
|
|
|
@ -7,8 +7,6 @@ import dev.peerat.parser.Token;
|
|||
|
||||
public class AnnotationClass extends ClassBase{
|
||||
|
||||
private List<Annotation> annotations;
|
||||
|
||||
//where mod ????
|
||||
private Token name;
|
||||
private Token extend;
|
||||
|
@ -16,7 +14,7 @@ public class AnnotationClass extends ClassBase{
|
|||
private List<JavaElement> elements;
|
||||
|
||||
public AnnotationClass(List<Annotation> annotations, Token name){
|
||||
this.annotations = annotations;
|
||||
super(annotations);
|
||||
this.name = name;
|
||||
this.elements = new ArrayList<>();
|
||||
}
|
||||
|
@ -36,10 +34,6 @@ public class AnnotationClass extends ClassBase{
|
|||
this.elements.add(clazz);
|
||||
}
|
||||
|
||||
public List<Annotation> getAnnotations(){
|
||||
return this.annotations;
|
||||
}
|
||||
|
||||
public Token getName(){
|
||||
return this.name;
|
||||
}
|
||||
|
@ -54,11 +48,7 @@ public class AnnotationClass extends ClassBase{
|
|||
|
||||
@Override
|
||||
public void build(Builder builder) throws Exception{
|
||||
if(annotations != null){
|
||||
for(Annotation annotation : this.annotations){
|
||||
annotation.build(builder);
|
||||
}
|
||||
}
|
||||
super.build(builder);
|
||||
|
||||
builder.append("@interface");
|
||||
builder.append(name);
|
||||
|
@ -77,11 +67,9 @@ public class AnnotationClass extends ClassBase{
|
|||
|
||||
@Override
|
||||
public <E extends JavaElement> E find(java.util.function.Function<JavaElement, Boolean> finder){
|
||||
if(annotations != null){
|
||||
for(Annotation annotation : this.annotations){
|
||||
if(finder.apply(annotation)) return (E) annotation;
|
||||
}
|
||||
}
|
||||
E annotation = super.find(finder);
|
||||
if(annotation != null) return annotation;
|
||||
|
||||
if(elements != null){
|
||||
for(JavaElement element : this.elements){
|
||||
if(finder.apply(element)) return (E) element;
|
||||
|
@ -92,12 +80,7 @@ public class AnnotationClass extends ClassBase{
|
|||
|
||||
@Override
|
||||
public <E extends JavaElement> void findAll(java.util.function.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);
|
||||
}
|
||||
}
|
||||
super.findAll(finder, list);
|
||||
if(elements != null){
|
||||
for(JavaElement element : this.elements){
|
||||
if(finder.apply(element)) list.add((E) element);
|
||||
|
|
|
@ -7,8 +7,6 @@ import dev.peerat.parser.Token;
|
|||
|
||||
public class Class extends ClassBase{
|
||||
|
||||
private List<Annotation> annotations;
|
||||
|
||||
//where mod ????
|
||||
private Token name;
|
||||
private Token extend;
|
||||
|
@ -17,7 +15,7 @@ public class Class extends ClassBase{
|
|||
private List<JavaElement> elements;
|
||||
|
||||
public Class(List<Annotation> annotations, Token name){
|
||||
this.annotations = annotations;
|
||||
super(annotations);
|
||||
this.name = name;
|
||||
this.elements = new ArrayList<>();
|
||||
}
|
||||
|
@ -43,10 +41,6 @@ public class Class extends ClassBase{
|
|||
this.elements.add(clazz);
|
||||
}
|
||||
|
||||
public List<Annotation> getAnnotations(){
|
||||
return this.annotations;
|
||||
}
|
||||
|
||||
public Token getName(){
|
||||
return this.name;
|
||||
}
|
||||
|
@ -65,11 +59,7 @@ public class Class extends ClassBase{
|
|||
|
||||
@Override
|
||||
public void build(Builder builder) throws Exception{
|
||||
if(annotations != null){
|
||||
for(Annotation annotation : this.annotations){
|
||||
annotation.build(builder);
|
||||
}
|
||||
}
|
||||
super.build(builder);
|
||||
|
||||
builder.append("class");
|
||||
builder.append(name);
|
||||
|
@ -92,11 +82,9 @@ public class Class extends ClassBase{
|
|||
|
||||
@Override
|
||||
public <E extends JavaElement> E find(java.util.function.Function<JavaElement, Boolean> finder){
|
||||
if(annotations != null){
|
||||
for(Annotation annotation : this.annotations){
|
||||
if(finder.apply(annotation)) return (E) annotation;
|
||||
}
|
||||
}
|
||||
E annotation = super.find(finder);
|
||||
if(annotation != null) return annotation;
|
||||
|
||||
if(elements != null){
|
||||
for(JavaElement element : this.elements){
|
||||
if(finder.apply(element)) return (E) element;
|
||||
|
@ -107,12 +95,7 @@ public class Class extends ClassBase{
|
|||
|
||||
@Override
|
||||
public <E extends JavaElement> void findAll(java.util.function.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);
|
||||
}
|
||||
}
|
||||
super.findAll(finder, list);
|
||||
if(elements != null){
|
||||
for(JavaElement element : this.elements){
|
||||
if(finder.apply(element)) list.add((E) element);
|
||||
|
|
|
@ -3,6 +3,7 @@ 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;
|
||||
|
@ -13,10 +14,14 @@ interface ClassContainer{
|
|||
|
||||
}
|
||||
|
||||
public abstract class ClassBase extends JavaElement implements AnnotableBuffer, ClassContainer, FunctionContainer, VariableContainer{
|
||||
public abstract class ClassBase extends Annotable 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<>();
|
||||
|
|
|
@ -7,8 +7,6 @@ import dev.peerat.parser.Token;
|
|||
|
||||
public class Enumeration extends ClassBase{
|
||||
|
||||
private List<Annotation> annotations;
|
||||
|
||||
//where mod ????
|
||||
private Token name;
|
||||
private Token extend;
|
||||
|
@ -16,7 +14,7 @@ public class Enumeration extends ClassBase{
|
|||
private List<JavaElement> elements;
|
||||
|
||||
public Enumeration(List<Annotation> annotations, Token name){
|
||||
this.annotations = annotations;
|
||||
super(annotations);
|
||||
this.name = name;
|
||||
this.elements = new ArrayList<>();
|
||||
}
|
||||
|
@ -41,10 +39,6 @@ public class Enumeration extends ClassBase{
|
|||
this.elements.add(clazz);
|
||||
}
|
||||
|
||||
public List<Annotation> getAnnotations(){
|
||||
return this.annotations;
|
||||
}
|
||||
|
||||
public Token getName(){
|
||||
return this.name;
|
||||
}
|
||||
|
@ -59,11 +53,7 @@ public class Enumeration extends ClassBase{
|
|||
|
||||
@Override
|
||||
public void build(Builder builder) throws Exception{
|
||||
if(annotations != null){
|
||||
for(Annotation annotation : this.annotations){
|
||||
annotation.build(builder);
|
||||
}
|
||||
}
|
||||
super.build(builder);
|
||||
|
||||
builder.append("enum");
|
||||
builder.append(name);
|
||||
|
@ -82,11 +72,9 @@ public class Enumeration extends ClassBase{
|
|||
|
||||
@Override
|
||||
public <E extends JavaElement> E find(java.util.function.Function<JavaElement, Boolean> finder){
|
||||
if(annotations != null){
|
||||
for(Annotation annotation : this.annotations){
|
||||
if(finder.apply(annotation)) return (E) annotation;
|
||||
}
|
||||
}
|
||||
E annotation = super.find(finder);
|
||||
if(annotation != null) return annotation;
|
||||
|
||||
if(elements != null){
|
||||
for(JavaElement element : this.elements){
|
||||
if(finder.apply(element)) return (E) element;
|
||||
|
@ -97,12 +85,7 @@ public class Enumeration extends ClassBase{
|
|||
|
||||
@Override
|
||||
public <E extends JavaElement> void findAll(java.util.function.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);
|
||||
}
|
||||
}
|
||||
super.findAll(finder, list);
|
||||
if(elements != null){
|
||||
for(JavaElement element : this.elements){
|
||||
if(finder.apply(element)) list.add((E) element);
|
||||
|
|
|
@ -4,12 +4,15 @@ 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 JavaElement implements VariableContainer, OperationContainer{
|
||||
public class Function extends Annotable implements VariableContainer, OperationContainer{
|
||||
|
||||
public static interface FunctionContainer{
|
||||
|
||||
|
@ -17,8 +20,6 @@ public class Function extends JavaElement implements VariableContainer, Operatio
|
|||
|
||||
}
|
||||
|
||||
private List<Annotation> annotations;
|
||||
|
||||
private int mod;
|
||||
private Token generic;
|
||||
private Token type;
|
||||
|
@ -29,7 +30,7 @@ public class Function extends JavaElement implements VariableContainer, Operatio
|
|||
private List<JavaElement> elements;
|
||||
|
||||
public Function(List<Annotation> annotations, int mod, Token type, Token name){
|
||||
this.annotations = annotations;
|
||||
super(annotations);
|
||||
this.mod = mod;
|
||||
this.type = type;
|
||||
this.name = name;
|
||||
|
@ -61,10 +62,6 @@ public class Function extends JavaElement implements VariableContainer, Operatio
|
|||
this.elements.add(operation);
|
||||
}
|
||||
|
||||
public List<Annotation> getAnnotations(){
|
||||
return this.annotations;
|
||||
}
|
||||
|
||||
public int getModifier(){
|
||||
return this.mod;
|
||||
}
|
||||
|
@ -95,11 +92,7 @@ public class Function extends JavaElement implements VariableContainer, Operatio
|
|||
|
||||
@Override
|
||||
public void build(Builder builder) throws Exception{
|
||||
if(annotations != null){
|
||||
for(Annotation annotation : this.annotations){
|
||||
annotation.build(builder);
|
||||
}
|
||||
}
|
||||
super.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);
|
||||
|
@ -129,11 +122,9 @@ public class Function extends JavaElement implements VariableContainer, Operatio
|
|||
|
||||
@Override
|
||||
public <E extends JavaElement> E find(java.util.function.Function<JavaElement, Boolean> finder){
|
||||
if(annotations != null){
|
||||
for(Annotation annotation : this.annotations){
|
||||
if(finder.apply(annotation)) return (E) annotation;
|
||||
}
|
||||
}
|
||||
E annotation = super.find(finder);
|
||||
if(annotation != null) return annotation;
|
||||
|
||||
if(parameters != null){
|
||||
for(Variable param : this.parameters){
|
||||
if(finder.apply(param)) return (E) param;
|
||||
|
@ -149,12 +140,7 @@ public class Function extends JavaElement implements VariableContainer, Operatio
|
|||
|
||||
@Override
|
||||
public <E extends JavaElement> void findAll(java.util.function.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);
|
||||
}
|
||||
}
|
||||
super.findAll(finder, list);
|
||||
if(parameters != null){
|
||||
for(Variable param : this.parameters){
|
||||
if(finder.apply(param)) list.add((E) param);
|
||||
|
|
|
@ -7,8 +7,6 @@ import dev.peerat.parser.Token;
|
|||
|
||||
public class Interface extends ClassBase{
|
||||
|
||||
private List<Annotation> annotations;
|
||||
|
||||
//where mod ????
|
||||
private Token name;
|
||||
private Token extend;
|
||||
|
@ -16,7 +14,7 @@ public class Interface extends ClassBase{
|
|||
private List<JavaElement> elements;
|
||||
|
||||
public Interface(List<Annotation> annotations, Token name){
|
||||
this.annotations = annotations;
|
||||
super(annotations);
|
||||
this.name = name;
|
||||
this.elements = new ArrayList<>();
|
||||
}
|
||||
|
@ -41,10 +39,6 @@ public class Interface extends ClassBase{
|
|||
this.elements.add(clazz);
|
||||
}
|
||||
|
||||
public List<Annotation> getAnnotations(){
|
||||
return this.annotations;
|
||||
}
|
||||
|
||||
public Token getName(){
|
||||
return this.name;
|
||||
}
|
||||
|
@ -59,11 +53,7 @@ public class Interface extends ClassBase{
|
|||
|
||||
@Override
|
||||
public void build(Builder builder) throws Exception{
|
||||
if(annotations != null){
|
||||
for(Annotation annotation : this.annotations){
|
||||
annotation.build(builder);
|
||||
}
|
||||
}
|
||||
super.build(builder);
|
||||
|
||||
builder.append("interface");
|
||||
builder.append(name);
|
||||
|
@ -82,11 +72,9 @@ public class Interface extends ClassBase{
|
|||
|
||||
@Override
|
||||
public <E extends JavaElement> E find(java.util.function.Function<JavaElement, Boolean> finder){
|
||||
if(annotations != null){
|
||||
for(Annotation annotation : this.annotations){
|
||||
if(finder.apply(annotation)) return (E) annotation;
|
||||
}
|
||||
}
|
||||
E annotation = super.find(finder);
|
||||
if(annotation != null) return annotation;
|
||||
|
||||
if(elements != null){
|
||||
for(JavaElement element : this.elements){
|
||||
if(finder.apply(element)) return (E) element;
|
||||
|
@ -97,12 +85,7 @@ public class Interface extends ClassBase{
|
|||
|
||||
@Override
|
||||
public <E extends JavaElement> void findAll(java.util.function.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);
|
||||
}
|
||||
}
|
||||
super.findAll(finder, list);
|
||||
if(elements != null){
|
||||
for(JavaElement element : this.elements){
|
||||
if(finder.apply(element)) list.add((E) element);
|
||||
|
|
|
@ -26,7 +26,12 @@ 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;
|
||||
|
@ -571,10 +576,16 @@ 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(null)))
|
||||
.then(new RedirectStateTree<>(value_container, (global, local) -> global.set(local.get())))
|
||||
.then((validator) -> validator.validate((token) -> token.getValue().equals(";")))
|
||||
.end((a,b) -> a);
|
||||
.end((parent,bag) -> {
|
||||
ThrowOperation op = new ThrowOperation(bag.get());
|
||||
if(parent instanceof OperationContainer) ((OperationContainer)parent).addOperation(op);
|
||||
return null;
|
||||
});
|
||||
|
||||
operation.then((validator) -> validator.validate((token) -> token.getValue().equals("do")))
|
||||
.then((validator) -> validator.validate((token) -> token.getValue().equals("{")))
|
||||
.end((a,b) -> a)
|
||||
|
@ -627,15 +638,29 @@ 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((a,b) -> a);
|
||||
.end((parent,bag) -> {
|
||||
ContinueOperation op = new ContinueOperation();
|
||||
if(parent instanceof OperationContainer) ((OperationContainer)parent).addOperation(op);
|
||||
return null;
|
||||
});
|
||||
|
||||
operation.then((validator) -> validator.validate((token) -> token.getValue().equals("break")))
|
||||
.then((validator) -> validator.validate((token) -> token.getValue().equals(";")))
|
||||
.end((a,b) -> a);
|
||||
.end((parent,bag) -> {
|
||||
BreakOperation op = new BreakOperation();
|
||||
if(parent instanceof OperationContainer) ((OperationContainer)parent).addOperation(op);
|
||||
return null;
|
||||
});
|
||||
|
||||
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(null)))
|
||||
.then(new RedirectStateTree<>(value_container, (global, local) -> global.set(local.get())))
|
||||
.then((validator) -> validator.validate((token) -> token.getValue().equals(")")))
|
||||
.end((a,b) -> a);
|
||||
.end((parent,bag) -> {
|
||||
IfOperation op = new IfOperation(bag.get());
|
||||
if(parent instanceof OperationContainer) ((OperationContainer)parent).addOperation(op);
|
||||
return op;
|
||||
});
|
||||
operation_if.then(operation);
|
||||
operation_if.then((validator) -> validator.validate((token) -> token.getValue().equals("{")))
|
||||
.end((a,b) -> a)
|
||||
|
@ -736,10 +761,14 @@ 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(null)))
|
||||
.then(new RedirectStateTree<>(value_container, (global, local) -> global.set(local.get())))
|
||||
.then((validator) -> validator.validate((token) -> token.getValue().equals(")")))
|
||||
.then((validator) -> validator.validate((token) -> token.getValue().equals("{")))
|
||||
.end((a,b) -> a)
|
||||
.<JavaElement>end((parent,bag) -> {
|
||||
SynchronizedOperation op = new SynchronizedOperation(bag.get());
|
||||
if(parent instanceof OperationContainer) ((OperationContainer)parent).addOperation(op);
|
||||
return op;
|
||||
})
|
||||
.multiple(function_container)
|
||||
.unique((validator) -> validator.validate((token) -> token.getValue().equals("}")))
|
||||
.end((a,b) -> a);
|
||||
|
|
|
@ -7,8 +7,9 @@ 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 JavaElement{
|
||||
public class Variable extends Annotable{
|
||||
|
||||
public static interface VariableContainer{
|
||||
|
||||
|
@ -16,8 +17,6 @@ public class Variable extends JavaElement{
|
|||
|
||||
}
|
||||
|
||||
private List<Annotation> annotations;
|
||||
|
||||
private int mod;
|
||||
private Token type;
|
||||
private Token name;
|
||||
|
@ -25,10 +24,10 @@ public class Variable extends JavaElement{
|
|||
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){
|
||||
|
@ -46,10 +45,6 @@ public class Variable extends JavaElement{
|
|||
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;
|
||||
}
|
||||
|
@ -72,11 +67,8 @@ public class Variable extends JavaElement{
|
|||
|
||||
@Override
|
||||
public void build(Builder builder) throws Exception{
|
||||
if(annotations != null){
|
||||
for(Annotation annotation : this.annotations){
|
||||
annotation.build(builder);
|
||||
}
|
||||
}
|
||||
super.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);
|
||||
|
@ -90,22 +82,15 @@ public class Variable extends JavaElement{
|
|||
|
||||
@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;
|
||||
}
|
||||
}
|
||||
E annotation = super.find(finder);
|
||||
if(annotation != null) return 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){
|
||||
if(annotations != null){
|
||||
for(Annotation annotation : this.annotations){
|
||||
if(finder.apply(annotation)) list.add((E)annotation);
|
||||
annotation.findAll(finder, list);
|
||||
}
|
||||
}
|
||||
super.findAll(finder, list);
|
||||
if(value != null){
|
||||
if(finder.apply(value)) list.add((E)value);
|
||||
value.findAll(finder, list);
|
||||
|
|
Loading…
Add table
Reference in a new issue