use of org.eclipse.titan.designer.AST.ASTVisitor in project titan.EclipsePlug-ins by eclipse.
the class Export_Debug_AST_Action method exportDebugAST.
private void exportDebugAST(final ZipOutputStream out, final Module module) throws Exception {
out.putNextEntry(new ZipEntry("DebugAST_for_" + module.getIdentifier().getName() + ".txt"));
out.write("*************************".getBytes());
out.write(lineend);
out.write(("Printing DEBUG information for module `" + module.getName() + "':").getBytes());
out.write(lineend);
out.write("*************************".getBytes());
out.write(lineend);
module.accept(new ASTVisitor() {
private int padding = 0;
@Override
public int visit(IVisitableNode node) {
if (node instanceof Assignment) {
Assignment assignment = (Assignment) node;
printInfoln(out, padding, assignment.getAssignmentName(), assignment.getFullName(), assignment.getLastTimeChecked(), assignment.getLocation());
} else if (node instanceof Identifier) {
printInfoln(out, padding, "identifier", ((Identifier) node).getDisplayName(), null, ((Identifier) node).getLocation());
} else if (node instanceof Statement) {
Statement statement = (Statement) node;
printInfoln(out, padding, "statement", statement.getFullName(), statement.getLastTimeChecked(), statement.getLocation());
} else if (node instanceof Reference) {
Reference ref = (Reference) node;
printInfoln(out, padding, "reference", ref.getFullName(), ref.getLastTimeChecked(), ref.getLocation());
Assignment old = ref.getAssOld();
if (old != null) {
printInfoln(out, padding + 1, "This reference was last pointing to " + old.getFullName() + " analyzed at " + old.getLastTimeChecked());
}
} else if (node instanceof ComponentTypeBody) {
ComponentTypeBody body = (ComponentTypeBody) node;
Map<String, Definition> map = body.getDefinitionMap();
printInfoln(out, padding + 1, " contains definitions:");
if (map != null) {
for (Map.Entry<String, Definition> entry : map.entrySet()) {
printInfoln(out, padding + 2, entry.getKey() + " was last checked at " + entry.getValue().getLastTimeChecked());
}
}
}
if (node instanceof StatementBlock || node instanceof Definition) {
padding++;
}
return super.visit(node);
}
@Override
public int leave(IVisitableNode node) {
if (node instanceof StatementBlock || node instanceof Definition) {
padding--;
}
return super.leave(node);
}
});
out.write("*************************".getBytes());
out.write(lineend);
out.write(("Printing DEBUG information for module `" + module.getName() + "' finished").getBytes());
out.write(lineend);
out.write("*************************".getBytes());
out.write(lineend);
out.closeEntry();
}
use of org.eclipse.titan.designer.AST.ASTVisitor in project titan.EclipsePlug-ins by eclipse.
the class Export_Debug_AST method run.
@Override
public void run(IAction action) {
if (targetEditor == null)
return;
IFile file = (IFile) targetEditor.getEditorInput().getAdapter(IFile.class);
ProjectSourceParser parser = GlobalParser.getProjectSourceParser(file.getProject());
Module module = parser.containedModule(file);
if (module == null) {
TITANDebugConsole.getConsole().newMessageStream().println("No module was found");
}
TITANDebugConsole.getConsole().newMessageStream().println("*************************");
TITANDebugConsole.getConsole().newMessageStream().println("Printing DEBUG information for module `" + module.getName() + "':");
TITANDebugConsole.getConsole().newMessageStream().println("*************************");
module.accept(new ASTVisitor() {
private int padding = 0;
@Override
public int visit(IVisitableNode node) {
if (node instanceof Assignment) {
Assignment assignment = (Assignment) node;
printInfoln(padding, assignment.getAssignmentName(), assignment.getFullName(), assignment.getLastTimeChecked(), assignment.getLocation());
} else if (node instanceof Identifier) {
printInfoln(padding, "identifier", ((Identifier) node).getDisplayName(), null, ((Identifier) node).getLocation());
} else if (node instanceof Statement) {
Statement statement = (Statement) node;
printInfoln(padding, "statement", statement.getFullName(), statement.getLastTimeChecked(), statement.getLocation());
} else if (node instanceof Reference) {
Reference ref = (Reference) node;
printInfoln(padding, "reference", ref.getFullName(), ref.getLastTimeChecked(), ref.getLocation());
Assignment old = ref.getAssOld();
if (old != null) {
printInfoln(padding + 1, "This reference was last pointing to " + old.getFullName() + " analyzed at " + old.getLastTimeChecked());
}
} else if (node instanceof ComponentTypeBody) {
ComponentTypeBody body = (ComponentTypeBody) node;
Map<String, Definition> map = body.getDefinitionMap();
printInfoln(padding + 1, " contains definitions:");
for (Map.Entry<String, Definition> entry : map.entrySet()) {
printInfoln(padding + 2, entry.getKey() + " was last checked at " + entry.getValue().getLastTimeChecked());
}
}
if (node instanceof StatementBlock || node instanceof Definition) {
padding++;
}
return super.visit(node);
}
@Override
public int leave(IVisitableNode node) {
if (node instanceof StatementBlock || node instanceof Definition) {
padding--;
}
return super.leave(node);
}
});
TITANDebugConsole.getConsole().newMessageStream().println("*************************");
TITANDebugConsole.getConsole().newMessageStream().println("Printing DEBUG information for module `" + module.getName() + "' finished");
TITANDebugConsole.getConsole().newMessageStream().println("*************************");
}
Aggregations