Search in sources :

Example 1 with ProjectStructureDataCollector

use of org.eclipse.titan.designer.parsers.ProjectStructureDataCollector in project titan.EclipsePlug-ins by eclipse.

the class ModuleGraphGenerator method createGraph.

@Override
protected void createGraph() {
    // analyze the project if needed
    final ProjectSourceParser sourceParser = GlobalParser.getProjectSourceParser(project);
    if (sourceParser.getLastTimeChecked() == null) {
        WorkspaceJob job = sourceParser.analyzeAll();
        while (job == null) {
            try {
                Thread.sleep(500);
                job = sourceParser.analyzeAll();
            } catch (InterruptedException e) {
                ErrorReporter.logExceptionStackTrace("Error while waiting for analyzis result", e);
            }
        }
        try {
            job.join();
        } catch (InterruptedException e) {
            ErrorReporter.logExceptionStackTrace("Error while parsing the project", e);
        }
    }
    final List<IProject> visitedProjects = ProjectBasedBuilder.getProjectBasedBuilder(project).getAllReachableProjects();
    final Map<String, Identifier> globalKnownModules = new HashMap<String, Identifier>();
    for (int i = 0; i < visitedProjects.size(); ++i) {
        final IProject currentProject = visitedProjects.get(i);
        final ProjectStructureDataCollector collector = GlobalProjectStructureTracker.getDataCollector(currentProject);
        collector.evaulateMissingModules();
        // adding known modules
        for (final Identifier moduleName : collector.knownModules.values()) {
            final NodeDescriptor actNode = new NodeDescriptor(moduleName.getDisplayName(), moduleName.getName(), currentProject, false, moduleName.getLocation());
            globalKnownModules.put(moduleName.getName(), moduleName);
            if (!graph.containsVertex(actNode)) {
                graph.addVertex(actNode);
                labels.put(actNode.getName(), actNode);
            }
        }
        // adding missing modules
        for (final Identifier moduleName : collector.missingModules.values()) {
            if (!globalKnownModules.containsKey(moduleName.getName())) {
                final NodeDescriptor actNode = new NodeDescriptor(moduleName.getDisplayName(), moduleName.getName(), currentProject, true, moduleName.getLocation());
                if (!graph.containsVertex(actNode)) {
                    graph.addVertex(actNode);
                    labels.put(actNode.getName(), actNode);
                }
            }
        }
        // building edges
        for (final String from : collector.importations.keySet()) {
            for (final String to : collector.importations.get(from)) {
                final EdgeDescriptor edge = new EdgeDescriptor(from + "->" + to, Color.black);
                // if(!graph.containsEdge(edge))
                graph.addEdge(edge, labels.get(from), labels.get(to), EdgeType.DIRECTED);
            }
        }
    }
}
Also used : HashMap(java.util.HashMap) WorkspaceJob(org.eclipse.core.resources.WorkspaceJob) NodeDescriptor(org.eclipse.titanium.graph.components.NodeDescriptor) EdgeDescriptor(org.eclipse.titanium.graph.components.EdgeDescriptor) ProjectSourceParser(org.eclipse.titan.designer.parsers.ProjectSourceParser) IProject(org.eclipse.core.resources.IProject) Identifier(org.eclipse.titan.designer.AST.Identifier) ProjectStructureDataCollector(org.eclipse.titan.designer.parsers.ProjectStructureDataCollector)

Aggregations

HashMap (java.util.HashMap)1 IProject (org.eclipse.core.resources.IProject)1 WorkspaceJob (org.eclipse.core.resources.WorkspaceJob)1 Identifier (org.eclipse.titan.designer.AST.Identifier)1 ProjectSourceParser (org.eclipse.titan.designer.parsers.ProjectSourceParser)1 ProjectStructureDataCollector (org.eclipse.titan.designer.parsers.ProjectStructureDataCollector)1 EdgeDescriptor (org.eclipse.titanium.graph.components.EdgeDescriptor)1 NodeDescriptor (org.eclipse.titanium.graph.components.NodeDescriptor)1