Search in sources :

Example 6 with Def_Testcase

use of org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Testcase in project titan.EclipsePlug-ins by eclipse.

the class ChangeCreator method createFileChange.

/**
 * Creates the {@link #change} object, which contains all the inserted and edited texts
 * in the selected resources.
 */
private Change createFileChange(final IFile toVisit) {
    if (toVisit == null) {
        return null;
    }
    final ProjectSourceParser sourceParser = GlobalParser.getProjectSourceParser(toVisit.getProject());
    final Module module = sourceParser.containedModule(toVisit);
    if (module == null) {
        return null;
    }
    // 
    // collect functions
    Set<Definition> funcs;
    final FunctionCollector vis = new FunctionCollector();
    if (defSelection == null) {
        module.accept(vis);
        funcs = vis.getResult();
    } else {
        if (defSelection instanceof Def_Function || defSelection instanceof Def_Testcase) {
            // TODO any other possibilities for the type of 'defSelection'?
            funcs = new HashSet<Definition>();
            funcs.add(defSelection);
        } else {
            ErrorReporter.logError("Variable scope reduction called for " + defSelection.getIdentifier().getDisplayName() + ", but it is only supported for functions and testcases. ");
            return null;
        }
    }
    // create edits
    final List<Edit> allEdits = new ArrayList<Edit>();
    for (Definition def : funcs) {
        final List<Edit> edits = analyzeFunction(def);
        if (edits == null) {
            continue;
        }
        allEdits.addAll(edits);
    }
    if (allEdits.isEmpty()) {
        return null;
    }
    final String fileContents = loadFileContent(toVisit);
    // create text edits
    // 
    final TextFileChange tfc = new TextFileChange(toVisit.getName(), toVisit);
    final MultiTextEdit rootEdit = new MultiTextEdit();
    tfc.setEdit(rootEdit);
    // TODO this is an O(n^2) algorithm
    // merge overlapping DeleteEdits
    // used, when removing all parts of a multi-declaration statement:
    // the DeleteEdit for removing the last part covers all the DeleteEdits for the other parts
    // WARNING merging edits might make debugging more difficult, since the overlapping edit errors are avoided
    final List<TextEdit> allTes = new LinkedList<TextEdit>();
    // collect processed (insert) edits with their created insert edit
    final Map<Edit, InsertEdit> editsDone = new HashMap<Edit, InsertEdit>();
    for (Edit e : allEdits) {
        final TextEdit[] tes = createTextEdit(toVisit, fileContents, e, editsDone);
        for (TextEdit te : tes) {
            if (!(te instanceof DeleteEdit)) {
                allTes.add(te);
                // System.err.println("$ nonde added: " + te.getOffset() + "-" + te.getExclusiveEnd());
                continue;
            }
            DeleteEdit dte = (DeleteEdit) te;
            final ListIterator<TextEdit> it = allTes.listIterator();
            while (it.hasNext()) {
                final TextEdit currTe = it.next();
                if (!(currTe instanceof DeleteEdit)) {
                    continue;
                }
                final DeleteEdit currDte = (DeleteEdit) currTe;
                // if the new edit (dte) overlaps currDte, merge them
                if (doesDeleteEditsOverlap(dte, currDte)) {
                    // System.err.println("$ de removed: " + currDte.getOffset() + "-" + currDte.getExclusiveEnd());
                    it.remove();
                    dte = mergeDeleteEdits(dte, currDte);
                // System.err.println("$ merged des: " + dte.getOffset() + "-" + dte.getExclusiveEnd());
                }
            }
            // System.err.println("$ de added: " + dte.getOffset() + "-" + dte.getExclusiveEnd());
            allTes.add(dte);
        }
    }
    Collections.reverse(allTes);
    for (TextEdit te : allTes) {
        rootEdit.addChild(te);
    }
    return tfc;
}
Also used : InsertEdit(org.eclipse.text.edits.InsertEdit) Def_Testcase(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Testcase) HashMap(java.util.HashMap) Definition(org.eclipse.titan.designer.AST.TTCN3.definitions.Definition) ArrayList(java.util.ArrayList) Edit(org.eclipse.titanium.refactoring.scope.nodes.Edit) InsertEdit(org.eclipse.text.edits.InsertEdit) MultiTextEdit(org.eclipse.text.edits.MultiTextEdit) TextEdit(org.eclipse.text.edits.TextEdit) DeleteEdit(org.eclipse.text.edits.DeleteEdit) TextFileChange(org.eclipse.ltk.core.refactoring.TextFileChange) DeleteEdit(org.eclipse.text.edits.DeleteEdit) ProjectSourceParser(org.eclipse.titan.designer.parsers.ProjectSourceParser) Def_Function(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Function) LinkedList(java.util.LinkedList) MultiTextEdit(org.eclipse.text.edits.MultiTextEdit) TextEdit(org.eclipse.text.edits.TextEdit) Module(org.eclipse.titan.designer.AST.Module) MultiTextEdit(org.eclipse.text.edits.MultiTextEdit)

Example 7 with Def_Testcase

use of org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Testcase in project titan.EclipsePlug-ins by eclipse.

the class RefersExpression method evaluateValue.

@Override
public /**
 * {@inheritDoc}
 */
IValue evaluateValue(final CompilationTimeStamp timestamp, final Expected_Value_type expectedValue, final IReferenceChain referenceChain) {
    if (lastTimeChecked != null && !lastTimeChecked.isLess(timestamp)) {
        return lastValue;
    }
    isErroneous = false;
    lastTimeChecked = timestamp;
    lastValue = this;
    if (referred == null) {
        return lastValue;
    }
    checkExpressionOperands(timestamp, expectedValue, referenceChain);
    if (getIsErroneous(timestamp) || referredAssignment == null) {
        return lastValue;
    }
    if (isUnfoldable(timestamp, referenceChain)) {
        return lastValue;
    }
    switch(referredAssignment.getAssignmentType()) {
        case A_FUNCTION:
        case A_FUNCTION_RTEMP:
        case A_FUNCTION_RVAL:
            lastValue = new Function_Reference_Value((Def_Function) referredAssignment);
            lastValue.copyGeneralProperties(this);
            break;
        case A_EXT_FUNCTION:
        case A_EXT_FUNCTION_RTEMP:
        case A_EXT_FUNCTION_RVAL:
            lastValue = new Function_Reference_Value((Def_Extfunction) referredAssignment);
            lastValue.copyGeneralProperties(this);
            break;
        case A_ALTSTEP:
            lastValue = new Altstep_Reference_Value((Def_Altstep) referredAssignment);
            lastValue.copyGeneralProperties(this);
            break;
        case A_TESTCASE:
            lastValue = new Testcase_Reference_Value((Def_Testcase) referredAssignment);
            lastValue.copyGeneralProperties(this);
            break;
        default:
            setIsErroneous(true);
            break;
    }
    return lastValue;
}
Also used : Def_Extfunction(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Extfunction) Altstep_Reference_Value(org.eclipse.titan.designer.AST.TTCN3.values.Altstep_Reference_Value) Testcase_Reference_Value(org.eclipse.titan.designer.AST.TTCN3.values.Testcase_Reference_Value) Def_Testcase(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Testcase) Def_Altstep(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Altstep) Function_Reference_Value(org.eclipse.titan.designer.AST.TTCN3.values.Function_Reference_Value) Def_Function(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Function)

Example 8 with Def_Testcase

use of org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Testcase in project titan.EclipsePlug-ins by eclipse.

the class ExecuteDereferedExpression method generateCodeExpressionExpression.

@Override
public /**
 * {@inheritDoc}
 */
void generateCodeExpressionExpression(final JavaGenData aData, final ExpressionStruct expression) {
    final IReferenceChain chain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
    final IValue last = value.getValueRefdLast(CompilationTimeStamp.getBaseTimestamp(), chain);
    chain.release();
    if (last.getValuetype() == Value_type.TESTCASE_REFERENCE_VALUE) {
        // the referred testcase is known
        final Def_Testcase testcase = ((Testcase_Reference_Value) last).getReferredTestcase();
        expression.expression.append(MessageFormat.format("{0}(", testcase.getGenNameFromScope(aData, expression.expression, myScope, "testcase_")));
        actualParameters.generateCodeAlias(aData, expression);
    } else {
        // the referred testcase is unknown
        value.generateCodeExpressionMandatory(aData, expression, true);
        expression.expression.append(".execute(");
        actualParameters.generateCodeAlias(aData, expression);
    }
    if (actualParameters.getNofParameters() > 0) {
        expression.expression.append(", ");
    }
    if (timerValue != null) {
        expression.expression.append("true, ");
        timerValue.generateCodeExpression(aData, expression, true);
        expression.expression.append(')');
    } else {
        expression.expression.append("false, new TitanFloat( new Ttcn3Float( 0.0 ) ))");
    }
}
Also used : IValue(org.eclipse.titan.designer.AST.IValue) Def_Testcase(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Testcase) Testcase_Reference_Value(org.eclipse.titan.designer.AST.TTCN3.values.Testcase_Reference_Value) IReferenceChain(org.eclipse.titan.designer.AST.IReferenceChain)

Example 9 with Def_Testcase

use of org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Testcase in project titan.EclipsePlug-ins by eclipse.

the class RunsOnScopeReduction method process.

@Override
protected void process(IVisitableNode node, Problems problems) {
    final Set<Identifier> definitions = new HashSet<Identifier>();
    final Identifier componentIdentifier;
    final CompilationTimeStamp timestamp = CompilationTimeStamp.getBaseTimestamp();
    final Identifier identifier;
    boolean isTestCase = false;
    if (node instanceof Def_Function) {
        final Def_Function variable = (Def_Function) node;
        final Component_Type componentType = variable.getRunsOnType(timestamp);
        if (componentType == null) {
            return;
        }
        componentIdentifier = componentType.getComponentBody().getIdentifier();
        identifier = variable.getIdentifier();
    } else if (node instanceof Def_Altstep) {
        final Def_Altstep variable = (Def_Altstep) node;
        final Component_Type componentType = variable.getRunsOnType(timestamp);
        if (componentType == null) {
            return;
        }
        componentIdentifier = componentType.getComponentBody().getIdentifier();
        identifier = variable.getIdentifier();
    } else {
        final Def_Testcase variable = (Def_Testcase) node;
        final Component_Type componentType = variable.getRunsOnType(timestamp);
        if (componentType == null) {
            return;
        }
        componentIdentifier = componentType.getComponentBody().getIdentifier();
        identifier = variable.getIdentifier();
        isTestCase = true;
    }
    final ReferenceCheck chek = new ReferenceCheck();
    node.accept(chek);
    definitions.addAll(chek.getIdentifiers());
    if (definitions.isEmpty()) {
        if (isTestCase) {
            problems.report(identifier.getLocation(), MessageFormat.format("The runs on component `{0}'' seems to be never used. Use empty component.", componentIdentifier.getDisplayName()));
        } else {
            problems.report(identifier.getLocation(), MessageFormat.format("The runs on component `{0}'' seems to be never used, can be removed.", componentIdentifier.getDisplayName()));
        }
    } else if (!definitions.contains(componentIdentifier)) {
        ArrayList<Identifier> list = new ArrayList<Identifier>(definitions);
        if (definitions.size() == 1) {
            problems.report(identifier.getLocation(), MessageFormat.format("The runs on component `{0}'' seems to be never used. Use `{1}'' component.", componentIdentifier.getName(), list.get(0).getDisplayName()));
        } else {
            // FIXME: implement other cases
            problems.report(identifier.getLocation(), MessageFormat.format("The runs on component `{0}'' seems to be never used.", componentIdentifier.getDisplayName()));
        }
    }
}
Also used : Identifier(org.eclipse.titan.designer.AST.Identifier) Def_Testcase(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Testcase) CompilationTimeStamp(org.eclipse.titan.designer.parsers.CompilationTimeStamp) ArrayList(java.util.ArrayList) Component_Type(org.eclipse.titan.designer.AST.TTCN3.types.Component_Type) Def_Altstep(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Altstep) Def_Function(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Function) HashSet(java.util.HashSet)

Example 10 with Def_Testcase

use of org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Testcase in project titan.EclipsePlug-ins by eclipse.

the class MetricData method measure.

/**
 * Execute the metrics on the project and compose the results.
 * <p>
 * Note that internally the project is locked.
 *
 * @param project
 *            the project to analyze
 *
 * @return the composed result of the measurements
 */
public static MetricData measure(final IProject project) {
    synchronized (project) {
        // reading the lists of altsteps, testcases, functions and modules
        // that are to be measured
        final ProjectSourceParser parser = GlobalParser.getProjectSourceParser(project);
        final Risks risks = new Risks();
        final MutableMetricData data = new MutableMetricData(risks);
        final List<Module> modules = new ArrayList<Module>();
        final Map<Module, List<Def_Function>> functions = new HashMap<Module, List<Def_Function>>();
        final Map<Module, List<Def_Testcase>> testcases = new HashMap<Module, List<Def_Testcase>>();
        final Map<Module, List<Def_Altstep>> altsteps = new HashMap<Module, List<Def_Altstep>>();
        for (final String modName : parser.getKnownModuleNames()) {
            final Module module = parser.getModuleByName(modName);
            modules.add(module);
        }
        for (final Module module : modules) {
            final List<Def_Function> funs = new ArrayList<Def_Function>();
            final List<Def_Testcase> tcs = new ArrayList<Def_Testcase>();
            final List<Def_Altstep> als = new ArrayList<Def_Altstep>();
            module.accept(new DefinitionCollector(funs, tcs, als));
            functions.put(module, funs);
            testcases.put(module, tcs);
            altsteps.put(module, als);
        }
        data.modules = Collections.unmodifiableList(modules);
        data.functions = Collections.unmodifiableMap(functions);
        data.testcases = Collections.unmodifiableMap(testcases);
        data.altsteps = Collections.unmodifiableMap(altsteps);
        MetricData immutableData = new MetricData(project, data);
        // initiate the metrics
        final Metrics metrics = new Metrics();
        for (final AltstepMetric am : AltstepMetric.values()) {
            metrics.get(am).init(immutableData);
        }
        for (final FunctionMetric fm : FunctionMetric.values()) {
            metrics.get(fm).init(immutableData);
        }
        for (final TestcaseMetric tm : TestcaseMetric.values()) {
            metrics.get(tm).init(immutableData);
        }
        for (final ModuleMetric mm : ModuleMetric.values()) {
            metrics.get(mm).init(immutableData);
        }
        for (final ProjectMetric pm : ProjectMetric.values()) {
            metrics.get(pm).init(immutableData);
        }
        // altstep metrics and statistics
        for (final AltstepMetric am : AltstepMetric.values()) {
            final Statistics projectStats = measureEntities(data.altsteps, metrics.get(am), immutableData, data.altstepMetrics, data.altstepModuleStats);
            data.altstepProjectStats.put(am, projectStats);
            immutableData = new MetricData(project, data);
        }
        // function metrics and statistics
        for (final FunctionMetric fm : FunctionMetric.values()) {
            final Statistics projectStats = measureEntities(data.functions, metrics.get(fm), immutableData, data.functionMetrics, data.functionModuleStats);
            data.functionProjectStats.put(fm, projectStats);
            immutableData = new MetricData(project, data);
        }
        // testcase metrics and statistics
        for (final TestcaseMetric tm : TestcaseMetric.values()) {
            final Statistics projectStats = measureEntities(data.testcases, metrics.get(tm), immutableData, data.testcaseMetrics, data.testcaseModuleStats);
            data.testcaseProjectStats.put(tm, projectStats);
            immutableData = new MetricData(project, data);
        }
        // module metrics and statistics
        for (final ModuleMetric mm : ModuleMetric.values()) {
            final Map<Module, Number> metricResults = new HashMap<Module, Number>();
            final int numberOfModules = data.modules.size();
            double[] projectLevelResults = new double[numberOfModules];
            int projectLevelCounter = 0;
            for (final Module module : data.modules) {
                final Number result = metrics.get(mm).measure(immutableData, module);
                projectLevelResults[projectLevelCounter++] = result.doubleValue();
                metricResults.put(module, result);
            }
            data.moduleMetrics.put(mm, metricResults);
            data.moduleProjectStats.put(mm, new Statistics(projectLevelResults, mm, risks.getRisk(mm)));
        }
        // project metrics
        for (final ProjectMetric pm : ProjectMetric.values()) {
            final Number result = metrics.get(pm).measure(immutableData, project);
            data.projectMetrics.put(pm, result);
        }
        return immutableData;
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ProjectSourceParser(org.eclipse.titan.designer.parsers.ProjectSourceParser) Metrics(org.eclipse.titanium.metrics.implementation.Metrics) ArrayList(java.util.ArrayList) List(java.util.List) Def_Altstep(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Altstep) Def_Testcase(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Testcase) Def_Function(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Function) Module(org.eclipse.titan.designer.AST.Module)

Aggregations

Def_Testcase (org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Testcase)12 Def_Function (org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Function)8 Def_Altstep (org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Altstep)5 ArrayList (java.util.ArrayList)4 IValue (org.eclipse.titan.designer.AST.IValue)3 Testcase_Reference_Value (org.eclipse.titan.designer.AST.TTCN3.values.Testcase_Reference_Value)3 HashMap (java.util.HashMap)2 DeleteEdit (org.eclipse.text.edits.DeleteEdit)2 InsertEdit (org.eclipse.text.edits.InsertEdit)2 MultiTextEdit (org.eclipse.text.edits.MultiTextEdit)2 TextEdit (org.eclipse.text.edits.TextEdit)2 IReferenceChain (org.eclipse.titan.designer.AST.IReferenceChain)2 Identifier (org.eclipse.titan.designer.AST.Identifier)2 Module (org.eclipse.titan.designer.AST.Module)2 Definition (org.eclipse.titan.designer.AST.TTCN3.definitions.Definition)2 StatementBlock (org.eclipse.titan.designer.AST.TTCN3.statements.StatementBlock)2 Component_Type (org.eclipse.titan.designer.AST.TTCN3.types.Component_Type)2 Edit (org.eclipse.titanium.refactoring.scope.nodes.Edit)2 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1