[AST] add getters
This commit is contained in:
parent
90007dc0d2
commit
3844a6cf06
7 changed files with 150 additions and 33 deletions
|
@ -32,6 +32,10 @@ public class Annotation extends JavaElement{
|
|||
return name;
|
||||
}
|
||||
|
||||
public Map<Token, Value> getParameters(){
|
||||
return this.values;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <E extends JavaElement> E find(Function<JavaElement, Boolean> finder){
|
||||
for(Value value : this.values.values()){
|
||||
|
|
|
@ -53,6 +53,38 @@ public class Class extends JavaElement implements AnnotableBuffer, ClassContaine
|
|||
this.elements.add(clazz);
|
||||
}
|
||||
|
||||
public List<Annotation> getAnnotations(){
|
||||
return this.annotations;
|
||||
}
|
||||
|
||||
public Token getName(){
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public Token getExtension(){
|
||||
return this.extend;
|
||||
}
|
||||
|
||||
public Token getImplementations(){
|
||||
return this.implement;
|
||||
}
|
||||
|
||||
public List<JavaElement> getElements(){
|
||||
return this.elements;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addAnnotationBuffer(Annotation annotation){
|
||||
if(annotationBuffer == null) annotationBuffer = new ArrayList<>();
|
||||
annotationBuffer.add(annotation);
|
||||
}
|
||||
|
||||
public List<Annotation> getAnnotationBuffer(){
|
||||
List<Annotation> list = this.annotationBuffer;
|
||||
this.annotationBuffer = null;
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <E extends JavaElement> E find(java.util.function.Function<JavaElement, Boolean> finder){
|
||||
if(annotations != null){
|
||||
|
@ -68,17 +100,5 @@ public class Class extends JavaElement implements AnnotableBuffer, ClassContaine
|
|||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addAnnotationBuffer(Annotation annotation){
|
||||
if(annotationBuffer == null) annotationBuffer = new ArrayList<>();
|
||||
annotationBuffer.add(annotation);
|
||||
}
|
||||
|
||||
public List<Annotation> getAnnotationBuffer(){
|
||||
List<Annotation> list = this.annotationBuffer;
|
||||
this.annotationBuffer = null;
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -59,6 +59,38 @@ 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;
|
||||
}
|
||||
|
||||
public Token getGeneric(){
|
||||
return this.generic;
|
||||
}
|
||||
|
||||
public Token getReturnType(){
|
||||
return this.type;
|
||||
}
|
||||
|
||||
public Token getName(){
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public List<Variable> getParameters(){
|
||||
return this.parameters;
|
||||
}
|
||||
|
||||
public List<Token> getThrowables(){
|
||||
return this.throwables;
|
||||
}
|
||||
|
||||
public List<JavaElement> getElements(){
|
||||
return this.elements;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <E extends JavaElement> E find(java.util.function.Function<JavaElement, Boolean> finder){
|
||||
if(annotations != null){
|
||||
|
|
23
src/be/jeffcheasey88/peeratcode/parser/java/Import.java
Normal file
23
src/be/jeffcheasey88/peeratcode/parser/java/Import.java
Normal file
|
@ -0,0 +1,23 @@
|
|||
package be.jeffcheasey88.peeratcode.parser.java;
|
||||
|
||||
import be.jeffcheasey88.peeratcode.parser.Token;
|
||||
|
||||
public class Import{
|
||||
|
||||
private boolean isStatic;
|
||||
private Token value;
|
||||
|
||||
public Import(boolean isStatic, Token value){
|
||||
this.isStatic = isStatic;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public boolean isStatic(){
|
||||
return this.isStatic;
|
||||
}
|
||||
|
||||
public Token getValue(){
|
||||
return this.value;
|
||||
}
|
||||
|
||||
}
|
|
@ -12,8 +12,8 @@ public class JavaFile extends JavaElement implements ClassContainer, AnnotableBu
|
|||
|
||||
private List<Annotation> annotationBuffer;
|
||||
|
||||
private List<Token> pack;
|
||||
private List<List<Token>> imports;
|
||||
private Token pack;
|
||||
private List<Import> imports;
|
||||
private Class mainClazz;
|
||||
private List<Class> subClazz;
|
||||
|
||||
|
@ -23,29 +23,37 @@ public class JavaFile extends JavaElement implements ClassContainer, AnnotableBu
|
|||
}
|
||||
|
||||
JavaFile setPackage(Bag bag){
|
||||
this.pack = bag.<List<Token>>get();
|
||||
// System.out.println("setPackage "+pack);
|
||||
this.pack = bag.<Token>get();
|
||||
return this;
|
||||
}
|
||||
|
||||
JavaFile addImport(Bag bag){
|
||||
this.imports.add(bag.<List<Token>>get());
|
||||
// System.out.println("addImport "+imports.get(imports.size()-1));
|
||||
JavaFile addImport(Import value){
|
||||
this.imports.add(value);
|
||||
return this;
|
||||
}
|
||||
|
||||
// Class setClass(Class clazz){
|
||||
// this.mainClazz = clazz;
|
||||
//// System.out.println("setClass "+clazz);
|
||||
// return clazz;
|
||||
// }
|
||||
|
||||
@Override
|
||||
public void addClass(Class clazz){
|
||||
if(mainClazz == null) this.mainClazz = clazz;
|
||||
else subClazz.add(clazz);
|
||||
}
|
||||
|
||||
public Token getPackage(){
|
||||
return this.pack;
|
||||
}
|
||||
|
||||
public List<Import> getImports(){
|
||||
return this.imports;
|
||||
}
|
||||
|
||||
public Class getMainClass(){
|
||||
return this.mainClazz;
|
||||
}
|
||||
|
||||
public List<Class> getSubClasses(){
|
||||
return this.subClazz;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <E extends JavaElement> E find(Function<JavaElement, Boolean> finder){
|
||||
if(finder.apply(mainClazz)) return (E) mainClazz;
|
||||
|
|
|
@ -945,8 +945,7 @@ public class JavaParser extends Parser<JavaElement> {
|
|||
StateTree<JavaElement> importState = new StateTree<>();
|
||||
importState.then((validator) -> {
|
||||
if(validator.validate(
|
||||
(token) -> token.getValue().equals("import"),
|
||||
(bag, token) -> bag.set(new LinkedList<>()))){
|
||||
(token) -> token.getValue().equals("import"))){
|
||||
|
||||
validator.validate(
|
||||
(token) -> token.getValue().equals("static"),
|
||||
|
@ -954,14 +953,18 @@ public class JavaParser extends Parser<JavaElement> {
|
|||
|
||||
while(validator.validate(
|
||||
(token) -> !token.getValue().equals(";"),
|
||||
(bag, token) -> bag.<List<Token>>get().add(token))
|
||||
(bag, token) -> {
|
||||
Token current = bag.get();
|
||||
if(current == null) bag.set(token);
|
||||
else bag.set(current.concat(token));
|
||||
})
|
||||
);
|
||||
|
||||
return validator.validate((token) -> token.getValue().equals(";"));
|
||||
}
|
||||
return false;
|
||||
}).<JavaElement>end((parent, bag) -> {
|
||||
((JavaFile)parent).addImport(bag);
|
||||
((JavaFile)parent).addImport(new Import(bag.has("static"), bag.get()));
|
||||
return parent;
|
||||
});
|
||||
|
||||
|
@ -971,12 +974,15 @@ public class JavaParser extends Parser<JavaElement> {
|
|||
//PACKAGE
|
||||
StateTree<JavaElement> pack = main.then((validator) -> {
|
||||
if(validator.validate(
|
||||
(token) -> token.getValue().equals("package"),
|
||||
(bag, token) -> bag.set(new LinkedList<>()))){
|
||||
(token) -> token.getValue().equals("package"))){
|
||||
|
||||
while(validator.validate(
|
||||
(token) -> !token.getValue().equals(";"),
|
||||
(bag, token) -> bag.<List<Token>>get().add(token))
|
||||
(bag, token) -> {
|
||||
Token current = bag.get();
|
||||
if(current == null) bag.set(token);
|
||||
else bag.set(current.concat(token));
|
||||
})
|
||||
);
|
||||
return validator.validate((token) -> token.getValue().equals(";"));
|
||||
}
|
||||
|
|
|
@ -44,6 +44,30 @@ 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;
|
||||
}
|
||||
|
||||
public Token getType(){
|
||||
return this.type;
|
||||
}
|
||||
|
||||
public Token getName(){
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public boolean isElipsis(){
|
||||
return this.elips;
|
||||
}
|
||||
|
||||
public Value getValue(){
|
||||
return this.value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <E extends JavaElement> E find(Function<JavaElement, Boolean> finder){
|
||||
if(annotations != null){
|
||||
|
|
Loading…
Add table
Reference in a new issue