Hi all.
I need to develop code folding. And create code snippet for it.
I parse xml via antlr, then make positions and add it to the TextArea
If there are xml only parsing, everything is fine.
private void calculatePositions() {
fPositions.clear();
String string = fDocument.get();
try {
XMLNodeInfo makeNodesInfo = XMLParserVisitor.makeNodesInfo(string);
fillPositions(fPositions, makeNodesInfo);
}
Display.getDefault().asyncExec(new Runnable() {
public void run() {
editor.updateFoldingStructure(fPositions);
}
});
} catch (Exception e) {
e.printStackTrace();
}
}
But when I need to add the parsing of xml only between XML>><<XML tags I have a lot of problem with positions of the collaplse/expand points.
There aren't a lot of changes, but it's working in incorrect way. collapse/expand points is occurs in not appropriate places/
See my changes bellow
private void calculatePositions() {
fPositions.clear();
String string = fDocument.get();
try {
while (string.length() > 0) {
int startIndex = string.indexOf("XML>>");
int endIndex = string.indexOf("<<XML");
if (!(startIndex >= 0 && endIndex > 0))
break;
String substring = string.substring(startIndex + "XML>>".length(), endIndex);
XMLNodeInfo makeNodesInfo = XMLParserVisitor.makeNodesInfo(substring);
fillPositions(fPositions, makeNodesInfo);
string = string.substring(endIndex + "<<XML".length());
}
Display.getDefault().asyncExec(new Runnable() {
public void run() {
editor.updateFoldingStructure(fPositions);
}
});
} catch (Exception e) {
e.printStackTrace();
}
}
There is github of my project https://github.com/vladimirkozhaev/simpleeditor
branch "tags"
So, where I'm wrong?