* initialReconcile()
*/
@Override
public void initialReconcile() {
final List<Position> ranges = new ArrayList<Position>();
Parser p = new Parser(new Formatter() {
private Stack<PositionedElement> stack = new Stack<PositionedElement>();
@Override
public void uri(String arg0) {
}
@Override
public void syntaxError(String arg0, String arg1,
List<String> arg2, String arg3, Integer arg4) {
}
@Override
public void step(Step arg0) {
}
private boolean isStepContainer(BasicStatement stmt) {
return stmt instanceof Scenario
|| stmt instanceof ScenarioOutline
|| stmt instanceof Background;
}
private boolean isExamples(BasicStatement stmt) {
return stmt instanceof Examples;
}
@Override
public void scenarioOutline(ScenarioOutline arg0) {
try {
handleStepContainer(arg0);
} catch (BadLocationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
private void handleStepContainer(DescribedStatement stmt)
throws BadLocationException {
if (isExamples(stack.peek().getStatement())) {
PositionedElement pos = stack.pop();
pos.setEndLine(stmt.getLine() - 1);
ranges.add(pos.toPosition());
}
if (isStepContainer(stack.peek().getStatement())) {
PositionedElement pos = stack.pop();
pos.setEndLine(stmt.getLine() - 1);
ranges.add(pos.toPosition());
}
stack.push(new PositionedElement(document, stmt));
}
@Override
public void scenario(Scenario arg0) {
try {
handleStepContainer(arg0);
} catch (BadLocationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@Override
public void feature(Feature arg0) {
stack.push(new PositionedElement(document, arg0));
}
@Override
public void examples(Examples arg0) {
stack.push(new PositionedElement(document, arg0));
}
@Override
public void eof() {
int lastline = document.getNumberOfLines();
while (!stack.isEmpty()) {
PositionedElement pos = stack.pop();
try {
pos.setEndLine(lastline);
ranges.add(pos.toPosition());
} catch (BadLocationException e) {
}
}
}
@Override
public void done() {
}
@Override
public void close() {
}
@Override
public void background(Background arg0) {
try {
handleStepContainer(arg0);
} catch (BadLocationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
try {
p.parse(document.get(), "", 0);
Display.getDefault().asyncExec(new Runnable() {
public void run() {
editor.updateFoldingStructure(ranges);
}