Search in sources :

Example 46 with Module

use of org.eclipse.titan.designer.AST.Module in project titan.EclipsePlug-ins by eclipse.

the class ExternalFeatureEnvyDetector method visit.

@Override
public int visit(final IVisitableNode node) {
    if (node instanceof Reference) {
        final Reference reference = (Reference) node;
        final Assignment assignment = reference.getRefdAssignment(CompilationTimeStamp.getBaseTimestamp(), false);
        if (assignment != null) {
            final Module module = assignment.getMyScope().getModuleScope();
            if (ownModule != module) {
                count.inc();
            }
        }
    }
    return V_CONTINUE;
}
Also used : Assignment(org.eclipse.titan.designer.AST.Assignment) Reference(org.eclipse.titan.designer.AST.Reference) Module(org.eclipse.titan.designer.AST.Module)

Example 47 with Module

use of org.eclipse.titan.designer.AST.Module in project titan.EclipsePlug-ins by eclipse.

the class ProjectStatNode method getChildren.

@Override
public Object[] getChildren(final MetricData data) {
    if (initialized) {
        return children;
    }
    final List<? super IContentNode> c = new ArrayList<IContentNode>();
    if (metric instanceof FunctionMetric || metric instanceof AltstepMetric || metric instanceof TestcaseMetric) {
        for (final Module m : data.getModules()) {
            final IContentNode n = new ModuleStatNode(metric, m);
            if (n.hasChildren(data)) {
                c.add(n);
            }
        }
    } else if (metric instanceof ModuleMetric) {
        for (final Module m : data.getModules()) {
            c.add(new ModuleNode((ModuleMetric) metric, m));
        }
    } else {
        throw new AssertionError("ProjectStatNode should have a subProject-metric");
    }
    children = c.toArray();
    initialized = true;
    return children;
}
Also used : TestcaseMetric(org.eclipse.titanium.metrics.TestcaseMetric) ModuleMetric(org.eclipse.titanium.metrics.ModuleMetric) AltstepMetric(org.eclipse.titanium.metrics.AltstepMetric) ArrayList(java.util.ArrayList) FunctionMetric(org.eclipse.titanium.metrics.FunctionMetric) Module(org.eclipse.titan.designer.AST.Module)

Example 48 with Module

use of org.eclipse.titan.designer.AST.Module in project titan.EclipsePlug-ins by eclipse.

the class TMInEnvy method measure.

@Override
public Number measure(final MetricData data, final Def_Testcase testcase) {
    final Counter count = new Counter(0);
    final Module myModule = testcase.getMyScope().getModuleScope();
    testcase.accept(new InternalFeatureEnvyDetector(myModule, count));
    return count.val();
}
Also used : Counter(org.eclipse.titanium.metrics.visitors.Counter) InternalFeatureEnvyDetector(org.eclipse.titanium.metrics.visitors.InternalFeatureEnvyDetector) Module(org.eclipse.titan.designer.AST.Module)

Example 49 with Module

use of org.eclipse.titan.designer.AST.Module in project titan.EclipsePlug-ins by eclipse.

the class MarkerHandler method showAll.

/**
 * Asynchronously create and show the all markers known to this
 * <code>MarkerHandler</code> in eclipse.
 * <p>
 * This method starts a new {@link WorkspaceJob} to delete the current
 * markers, and create the new ones. Note that only code smell markers are
 * deleted (those of type {@link CodeSmellType#MARKER_ID}).
 */
public void showAll(final IProject project) {
    final ProjectSourceParser projectSourceParser = GlobalParser.getProjectSourceParser(project);
    final Set<String> knownModuleNames = projectSourceParser.getKnownModuleNames();
    org.eclipse.titan.designer.AST.MarkerHandler.markMarkersForRemoval(CodeSmellType.MARKER_ID, project);
    for (final String moduleName : knownModuleNames) {
        final Module mod = projectSourceParser.getModuleByName(moduleName);
        final IResource moduleResource = mod.getLocation().getFile();
        org.eclipse.titan.designer.AST.MarkerHandler.markMarkersForRemoval(CodeSmellType.MARKER_ID, moduleResource);
    }
    for (final IResource res : markersByResource.keySet()) {
        refresh(res);
    }
    org.eclipse.titan.designer.AST.MarkerHandler.removeMarkedMarkers(CodeSmellType.MARKER_ID, project);
    for (final String moduleName : knownModuleNames) {
        final Module mod = projectSourceParser.getModuleByName(moduleName);
        final IResource moduleResource = mod.getLocation().getFile();
        org.eclipse.titan.designer.AST.MarkerHandler.removeMarkedMarkers(CodeSmellType.MARKER_ID, moduleResource);
    }
}
Also used : Module(org.eclipse.titan.designer.AST.Module) ProjectSourceParser(org.eclipse.titan.designer.parsers.ProjectSourceParser) IResource(org.eclipse.core.resources.IResource)

Example 50 with Module

use of org.eclipse.titan.designer.AST.Module in project titan.EclipsePlug-ins by eclipse.

the class CycleCheck method process.

@Override
public void process(final IProject project, final Problems problems) {
    final ProjectSourceParser projectSourceParser = GlobalParser.getProjectSourceParser(project);
    final Set<String> knownModuleNames = projectSourceParser.getKnownModuleNames();
    final List<Module> modules = new ArrayList<Module>();
    for (final String moduleName : new TreeSet<String>(knownModuleNames)) {
        modules.add(projectSourceParser.getModuleByName(moduleName));
    }
    Collections.sort(modules, new Comparator<Module>() {

        @Override
        public int compare(final Module o1, final Module o2) {
            return o1.getName().compareTo(o2.getName());
        }
    });
    final CycleCheck check = new CycleCheck(modules);
    for (final List<Module> cycle : check.cycles) {
        final StringBuilder sb = new StringBuilder("Importation cycle detected: ");
        for (final Module module : cycle) {
            sb.append(module.getName());
            sb.append(" -> ");
        }
        sb.append(cycle.get(0).getName());
        final String errMsg = sb.toString();
        // Try to find the locations to report, i.e. the import statements.
        // We handle only the case of TTCN3Module-s.
        final Iterator<Module> it = cycle.iterator();
        Module imported = it.next();
        Module importer;
        while (it.hasNext()) {
            importer = it.next();
            if (importer instanceof TTCN3Module) {
                for (final ImportModule im : ((TTCN3Module) importer).getImports()) {
                    if (im.getName().equals(imported.getName())) {
                        problems.report(im.getLocation(), errMsg);
                    }
                }
            }
            imported = importer;
        }
        importer = cycle.get(0);
        if (importer instanceof TTCN3Module) {
            for (final ImportModule im : ((TTCN3Module) importer).getImports()) {
                if (im.getName().equals(imported.getName())) {
                    problems.report(im.getLocation(), errMsg);
                }
            }
        }
    }
}
Also used : TTCN3Module(org.eclipse.titan.designer.AST.TTCN3.definitions.TTCN3Module) ArrayList(java.util.ArrayList) ProjectSourceParser(org.eclipse.titan.designer.parsers.ProjectSourceParser) ImportModule(org.eclipse.titan.designer.AST.TTCN3.definitions.ImportModule) TreeSet(java.util.TreeSet) ImportModule(org.eclipse.titan.designer.AST.TTCN3.definitions.ImportModule) Module(org.eclipse.titan.designer.AST.Module) TTCN3Module(org.eclipse.titan.designer.AST.TTCN3.definitions.TTCN3Module)

Aggregations

Module (org.eclipse.titan.designer.AST.Module)130 ProjectSourceParser (org.eclipse.titan.designer.parsers.ProjectSourceParser)51 ArrayList (java.util.ArrayList)37 TTCN3Module (org.eclipse.titan.designer.AST.TTCN3.definitions.TTCN3Module)36 IFile (org.eclipse.core.resources.IFile)32 Assignment (org.eclipse.titan.designer.AST.Assignment)22 Identifier (org.eclipse.titan.designer.AST.Identifier)21 Location (org.eclipse.titan.designer.AST.Location)16 Reference (org.eclipse.titan.designer.AST.Reference)16 ImportModule (org.eclipse.titan.designer.AST.TTCN3.definitions.ImportModule)16 HashMap (java.util.HashMap)14 List (java.util.List)13 WorkspaceJob (org.eclipse.core.resources.WorkspaceJob)11 IPreferencesService (org.eclipse.core.runtime.preferences.IPreferencesService)11 IProject (org.eclipse.core.resources.IProject)10 IResource (org.eclipse.core.resources.IResource)10 MultiTextEdit (org.eclipse.text.edits.MultiTextEdit)10 Assignments (org.eclipse.titan.designer.AST.Assignments)9 Scope (org.eclipse.titan.designer.AST.Scope)9 TextSelection (org.eclipse.jface.text.TextSelection)8