Search in sources :

Example 1 with Context

use of org.eclipse.titanium.refactoring.logging.context.Context 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 2 with Context

use of org.eclipse.titanium.refactoring.logging.context.Context 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 3 with Context

use of org.eclipse.titanium.refactoring.logging.context.Context 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)

Example 4 with Context

use of org.eclipse.titanium.refactoring.logging.context.Context 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)

Aggregations

Context (org.eclipse.titanium.refactoring.logging.context.Context)4 Log_Statement (org.eclipse.titan.designer.AST.TTCN3.statements.Log_Statement)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 InsertEdit (org.eclipse.text.edits.InsertEdit)1 IVisitableNode (org.eclipse.titan.designer.AST.IVisitableNode)1 Location (org.eclipse.titan.designer.AST.Location)1