Search in sources :

Example 1 with Log_Statement

use of org.eclipse.titan.designer.AST.TTCN3.statements.Log_Statement 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 2 with Log_Statement

use of org.eclipse.titan.designer.AST.TTCN3.statements.Log_Statement in project titan.EclipsePlug-ins by eclipse.

the class ChangeCreator method createTextEdit.

private TextEdit createTextEdit(final Log_Statement toEdit, final Context toAdd) {
    // get insert location
    final LogInsertLocationFinder vis = new LogInsertLocationFinder();
    toEdit.accept(vis);
    int insertOffset = vis.calculateEndOffset();
    if (insertOffset < 0) {
        ErrorReporter.logError("ChangeCreator.createTextEdit(): Warning! No arguments in log statement! ");
        insertOffset = toEdit.getLocation().getEndOffset() - 1;
    }
    // find variable names that are already present in the log statement
    final Set<String> varsAlreadyPresent;
    final Context bottomContext = toAdd.getBottom();
    if (bottomContext.getNode() instanceof Log_Statement) {
        final LoggedVariableFinder vis2 = new LoggedVariableFinder();
        final Log_Statement logst = (Log_Statement) bottomContext.getNode();
        logst.accept(vis2);
        varsAlreadyPresent = vis2.getVarsAlreadyPresent();
    } else {
        varsAlreadyPresent = new HashSet<String>();
    }
    // create inserted text
    toAdd.process();
    final List<String> contextInfos = toAdd.createLogParts(varsAlreadyPresent);
    final int len = Math.min(contextInfos.size(), toAdd.getVarCountLimitOption());
    if (len == 0) {
        return null;
    }
    final StringBuilder sb = new StringBuilder();
    for (int i = 0; i < len; i++) {
        sb.append(contextInfos.get(i));
    }
    // create edit from location and text
    return new InsertEdit(insertOffset, sb.toString());
}
Also used : Context(org.eclipse.titanium.refactoring.logging.context.Context) InsertEdit(org.eclipse.text.edits.InsertEdit) Log_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Log_Statement)

Example 3 with Log_Statement

use of org.eclipse.titan.designer.AST.TTCN3.statements.Log_Statement in project titan.EclipsePlug-ins by eclipse.

the class ChangeCreator method performOnSelectionOnly.

private void performOnSelectionOnly(final Module module) {
    final Location selLoc = new Location(file, textSelection.getStartLine(), textSelection.getOffset(), textSelection.getOffset() + textSelection.getLength());
    final SelectionVisitor vis = new SelectionVisitor(selLoc);
    module.accept(vis);
    final Map<Log_Statement, Context> res = vis.getResult();
    final MultiTextEdit rootEdit = new MultiTextEdit();
    for (Map.Entry<Log_Statement, Context> e : res.entrySet()) {
        final TextEdit edit = createTextEdit(e.getKey(), e.getValue());
        if (edit != null) {
            rootEdit.addChild(edit);
        }
    }
    if (rootEdit.hasChildren()) {
        change = new TextFileChange("Context logging", file);
        change.setEdit(rootEdit);
    }
}
Also used : Context(org.eclipse.titanium.refactoring.logging.context.Context) MultiTextEdit(org.eclipse.text.edits.MultiTextEdit) TextEdit(org.eclipse.text.edits.TextEdit) TextFileChange(org.eclipse.ltk.core.refactoring.TextFileChange) Map(java.util.Map) Log_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Log_Statement) MultiTextEdit(org.eclipse.text.edits.MultiTextEdit) Location(org.eclipse.titan.designer.AST.Location)

Example 4 with Log_Statement

use of org.eclipse.titan.designer.AST.TTCN3.statements.Log_Statement in project titan.EclipsePlug-ins by eclipse.

the class ChangeCreator method performOnWholeModule.

private void performOnWholeModule(final Module module) {
    final ContextFinder vis = new ContextFinder(settings);
    module.accept(vis);
    final Map<Log_Statement, Context> res = vis.getResult();
    final MultiTextEdit rootEdit = new MultiTextEdit();
    for (Map.Entry<Log_Statement, Context> e : res.entrySet()) {
        final TextEdit edit = createTextEdit(e.getKey(), e.getValue());
        if (edit != null) {
            rootEdit.addChild(edit);
        }
    }
    if (rootEdit.hasChildren()) {
        change = new TextFileChange("Context logging", file);
        change.setEdit(rootEdit);
    }
}
Also used : Context(org.eclipse.titanium.refactoring.logging.context.Context) MultiTextEdit(org.eclipse.text.edits.MultiTextEdit) TextEdit(org.eclipse.text.edits.TextEdit) TextFileChange(org.eclipse.ltk.core.refactoring.TextFileChange) Map(java.util.Map) Log_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Log_Statement) MultiTextEdit(org.eclipse.text.edits.MultiTextEdit)

Aggregations

Log_Statement (org.eclipse.titan.designer.AST.TTCN3.statements.Log_Statement)4 Context (org.eclipse.titanium.refactoring.logging.context.Context)3 Map (java.util.Map)2 TextFileChange (org.eclipse.ltk.core.refactoring.TextFileChange)2 MultiTextEdit (org.eclipse.text.edits.MultiTextEdit)2 TextEdit (org.eclipse.text.edits.TextEdit)2 Location (org.eclipse.titan.designer.AST.Location)2 InsertEdit (org.eclipse.text.edits.InsertEdit)1 IVisitableNode (org.eclipse.titan.designer.AST.IVisitableNode)1 Identifier (org.eclipse.titan.designer.AST.Identifier)1 StatementBlock (org.eclipse.titan.designer.AST.TTCN3.statements.StatementBlock)1