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());
}
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);
}
}
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);
}
}
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;
}
Aggregations