use of org.eclipse.titan.designer.AST.IVisitableNode in project titan.EclipsePlug-ins by eclipse.
the class TemplateParser method process.
@Override
public Scope process(IVisitableNode node) {
if (node instanceof Identifier) {
name = node.toString();
// TODO : find a more sophisticated way of storing symbols (e.g. SymbolTable)
myASTVisitor.nodeNameNodeTypeHashMap.put(name, "template");
}
if (node instanceof Type) {
type = Util.getTypeName((Type) node);
template = new Template(name, type);
return Action.skip(Type.class, this);
}
if (node instanceof FormalParameterList) {
return new FormalParameterParser(this, template);
}
// is a modification
if (node instanceof Reference) {
Reference reference = (Reference) node;
String basename = reference.getId().toString();
Template base = registry.find(basename);
// TODO : templates need a base value as a fallback
// TODO : this base value should be used as a reference, to diff against
// TODO : this was a hotfix for the union types to work
String type = base.getValue().getType();
template.setValue(new Value(type, (code, indent) -> code.append("(", type, ") ").append(basename, "()")));
isModification = true;
return Action.skip(Reference.class, this);
}
if (node instanceof TTCN3Template) {
if (isModification) {
return ModificationParser.getScope(this, template, "", type, node);
}
return TemplateValueParser.getScope(this, template, type, node);
}
return this;
}
use of org.eclipse.titan.designer.AST.IVisitableNode 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("*************************");
}
use of org.eclipse.titan.designer.AST.IVisitableNode in project titan.EclipsePlug-ins by eclipse.
the class StatementBlockContext method process_internal.
@Override
protected void process_internal() {
localVarIds = new ArrayList<Identifier>();
final Context bottom = getBottom();
final IVisitableNode bottomNode = bottom.getNode();
if (!(bottomNode instanceof Log_Statement)) {
ErrorReporter.logError("StatementBlockContext.process_internal(): Warning! Context chain bottom node is not a Log_Statement! ");
return;
}
final Log_Statement logst = (Log_Statement) bottomNode;
final Location logLoc = logst.getLocation();
//
final StatementBlock sb = getNode();
final StatementBlockVisitor vis = new StatementBlockVisitor(logLoc);
sb.accept(vis);
localVarIds.addAll(vis.getIdsFound());
}
use of org.eclipse.titan.designer.AST.IVisitableNode in project titan.EclipsePlug-ins by eclipse.
the class ContextFinder method createContextChain.
/**
* Iteration order when creating contexts is: from bottom (log statement) to root (module).
*/
protected Context createContextChain() {
final Iterator<IVisitableNode> it = ancestorStack.iterator();
Context prev = null;
Context curr = null;
if (it.hasNext()) {
prev = factory.createContext(it.next(), null, settings);
}
while (it.hasNext()) {
curr = factory.createContext(it.next(), prev, settings);
curr.setChild(prev);
prev.setParent(curr);
prev = curr;
}
return curr;
}
use of org.eclipse.titan.designer.AST.IVisitableNode in project titan.EclipsePlug-ins by eclipse.
the class AnalyzerBuilder method addProblem.
/**
* @param problemType
* the analyzer will use this code smell
* @return this for method chaining
*/
public AnalyzerBuilder addProblem(final CodeSmellType problemType) {
if (exhausted) {
throw new IllegalStateException("One must not use the builder after build() method is called");
}
if (spotters.get(problemType) != null) {
for (final BaseModuleCodeSmellSpotter spotter : spotters.get(problemType)) {
final Queue<Class<? extends IVisitableNode>> subtypes = new ArrayDeque<Class<? extends IVisitableNode>>();
subtypes.addAll(spotter.getStartNode());
while (!subtypes.isEmpty()) {
final Class<? extends IVisitableNode> sub = subtypes.poll();
if (StaticData.TYPE_HIERARCHY.get(sub) != null) {
Collections.addAll(subtypes, StaticData.TYPE_HIERARCHY.get(sub));
}
if (actions.get(sub) == null) {
actions.put(sub, new HashSet<BaseModuleCodeSmellSpotter>());
}
actions.get(sub).add(spotter);
}
}
} else if (projectSpotters.get(problemType) != null) {
for (final BaseProjectCodeSmellSpotter spotter : projectSpotters.get(problemType)) {
projectActions.add(spotter);
}
}
return this;
}
Aggregations