Search in sources :

Example 6 with IVisitableNode

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;
}
Also used : IVisitableNode(org.eclipse.titan.designer.AST.IVisitableNode) Reference(org.eclipse.titan.designer.AST.Reference) Type(org.eclipse.titan.designer.AST.Type) Scope(org.eclipse.titan.codegenerator.Scope) Def_Template(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Template) TTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.TTCN3Template) org.eclipse.titan.codegenerator.myASTVisitor(org.eclipse.titan.codegenerator.myASTVisitor) Identifier(org.eclipse.titan.designer.AST.Identifier) FormalParameterList(org.eclipse.titan.designer.AST.TTCN3.definitions.FormalParameterList) Type(org.eclipse.titan.designer.AST.Type) FormalParameterList(org.eclipse.titan.designer.AST.TTCN3.definitions.FormalParameterList) Identifier(org.eclipse.titan.designer.AST.Identifier) Reference(org.eclipse.titan.designer.AST.Reference) TTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.TTCN3Template) Def_Template(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Template) TTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.TTCN3Template)

Example 7 with IVisitableNode

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("*************************");
}
Also used : ComponentTypeBody(org.eclipse.titan.designer.AST.TTCN3.types.ComponentTypeBody) IFile(org.eclipse.core.resources.IFile) Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Statement) Reference(org.eclipse.titan.designer.AST.Reference) Definition(org.eclipse.titan.designer.AST.TTCN3.definitions.Definition) ProjectSourceParser(org.eclipse.titan.designer.parsers.ProjectSourceParser) ASTVisitor(org.eclipse.titan.designer.AST.ASTVisitor) IVisitableNode(org.eclipse.titan.designer.AST.IVisitableNode) Assignment(org.eclipse.titan.designer.AST.Assignment) Identifier(org.eclipse.titan.designer.AST.Identifier) Module(org.eclipse.titan.designer.AST.Module) Map(java.util.Map) StatementBlock(org.eclipse.titan.designer.AST.TTCN3.statements.StatementBlock)

Example 8 with IVisitableNode

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());
}
Also used : Identifier(org.eclipse.titan.designer.AST.Identifier) Log_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Log_Statement) StatementBlock(org.eclipse.titan.designer.AST.TTCN3.statements.StatementBlock) IVisitableNode(org.eclipse.titan.designer.AST.IVisitableNode) Location(org.eclipse.titan.designer.AST.Location)

Example 9 with IVisitableNode

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;
}
Also used : Context(org.eclipse.titanium.refactoring.logging.context.Context) IVisitableNode(org.eclipse.titan.designer.AST.IVisitableNode)

Example 10 with IVisitableNode

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;
}
Also used : BaseModuleCodeSmellSpotter(org.eclipse.titanium.markers.spotters.BaseModuleCodeSmellSpotter) ArrayDeque(java.util.ArrayDeque) BaseProjectCodeSmellSpotter(org.eclipse.titanium.markers.spotters.BaseProjectCodeSmellSpotter) IVisitableNode(org.eclipse.titan.designer.AST.IVisitableNode)

Aggregations

IVisitableNode (org.eclipse.titan.designer.AST.IVisitableNode)13 StatementBlock (org.eclipse.titan.designer.AST.TTCN3.statements.StatementBlock)6 Identifier (org.eclipse.titan.designer.AST.Identifier)5 Reference (org.eclipse.titan.designer.AST.Reference)4 Counter (org.eclipse.titanium.metrics.visitors.Counter)4 CounterVisitor (org.eclipse.titanium.metrics.visitors.CounterVisitor)4 Map (java.util.Map)2 Scope (org.eclipse.titan.codegenerator.Scope)2 org.eclipse.titan.codegenerator.myASTVisitor (org.eclipse.titan.codegenerator.myASTVisitor)2 ASTVisitor (org.eclipse.titan.designer.AST.ASTVisitor)2 Assignment (org.eclipse.titan.designer.AST.Assignment)2 LargeLocation (org.eclipse.titan.designer.AST.LargeLocation)2 Definition (org.eclipse.titan.designer.AST.TTCN3.definitions.Definition)2 Statement (org.eclipse.titan.designer.AST.TTCN3.statements.Statement)2 ComponentTypeBody (org.eclipse.titan.designer.AST.TTCN3.types.ComponentTypeBody)2 Type (org.eclipse.titan.designer.AST.Type)2 ArrayDeque (java.util.ArrayDeque)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1