ASTPrinter verbessern

This commit is contained in:
JanUlrich 2017-06-29 01:19:13 +02:00
parent 726eb60eb3
commit 0aa18c74ba

View File

@ -19,13 +19,22 @@ public class ASTPrinter {
}
private static class OutputGenerator implements ASTVisitor{
private static final String TAB = " ";
String tabs = "";
private final StringBuilder out;
OutputGenerator(StringBuilder out){
this.out = out;
}
public void tab() {
tabs += TAB;
}
public void untab() {
tabs = tabs.substring(0,tabs.length()-TAB.length());
}
@Override
public void visit(SourceFile sourceFile) {
for(ClassOrInterface cl : sourceFile.getClasses()){
@ -46,7 +55,7 @@ public class ASTPrinter {
@Override
public void visit(GenericTypeVar genericTypeVar) {
out.append(genericTypeVar.getName());
out.append(genericTypeVar.getName().toString());
}
@Override
@ -83,6 +92,7 @@ public class ASTPrinter {
out.append(" " + method.getName());
method.getParameterList().accept(this);
method.block.accept(this);
out.append("\n");
}
@Override
@ -105,22 +115,27 @@ public class ASTPrinter {
}else{
out.append("class ");
}
out.append(classOrInterface.getClassName());
out.append(classOrInterface.getClassName().toString());
classOrInterface.getGenerics().accept(this);
out.append(" {\n");
out.append(" {\n\n");
tab();
for(Field f : classOrInterface.getFieldDecl()){
out.append(tabs);
f.accept(this);
out.append("\n");
}
for(Method m : classOrInterface.getMethods()){
out.append(tabs);
m.accept(this);
out.append("\n");
}
untab();
out.append("}");
}
@Override
public void visit(RefType refType) {
out.append(refType.getName());
out.append(refType.getName().toString());
Iterator<RefTypeOrTPHOrWildcardOrGeneric> genericIterator = refType.getParaList().iterator();
if(genericIterator.hasNext()){
out.append("<");
@ -151,7 +166,7 @@ public class ASTPrinter {
@Override
public void visit(GenericRefType genericRefType) {
out.append(genericRefType.getName());
out.append(genericRefType.getName().toString());
}
@Override
@ -175,11 +190,15 @@ public class ASTPrinter {
@Override
public void visit(Block block) {
tab();
out.append("{\n");
for(Statement stmt : block.getStatements()){
out.append(tabs);
stmt.accept(this);
out.append(";\n");
}
untab();
out.append(tabs);
out.append("}");
}