69 lines
1.7 KiB
Java
69 lines
1.7 KiB
Java
package be.jeffcheasey88.peeratcode.parser.java;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
import java.util.function.Function;
|
|
|
|
import be.jeffcheasey88.peeratcode.parser.Bag;
|
|
import be.jeffcheasey88.peeratcode.parser.Token;
|
|
import be.jeffcheasey88.peeratcode.parser.java.Annotation.AnnotableBuffer;
|
|
|
|
public class JavaFile extends JavaElement implements ClassContainer, AnnotableBuffer{
|
|
|
|
private List<Annotation> annotationBuffer;
|
|
|
|
private List<Token> pack;
|
|
private List<List<Token>> imports;
|
|
private Class mainClazz;
|
|
private List<Class> subClazz;
|
|
|
|
public JavaFile(){
|
|
this.imports = new ArrayList<>();
|
|
this.subClazz = new ArrayList<>();
|
|
}
|
|
|
|
JavaFile setPackage(Bag bag){
|
|
this.pack = bag.<List<Token>>get();
|
|
// System.out.println("setPackage "+pack);
|
|
return this;
|
|
}
|
|
|
|
JavaFile addImport(Bag bag){
|
|
this.imports.add(bag.<List<Token>>get());
|
|
// System.out.println("addImport "+imports.get(imports.size()-1));
|
|
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);
|
|
}
|
|
|
|
@Override
|
|
public <E extends JavaElement> E find(Function<JavaElement, Boolean> finder){
|
|
if(finder.apply(mainClazz)) return (E) mainClazz;
|
|
for(Class clazz : subClazz){
|
|
if(finder.apply(clazz)) return (E) clazz;
|
|
}
|
|
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;
|
|
}
|
|
}
|