package bluej.parser.nodes;
import threadchecker.OnThread;
import threadchecker.Tag;
import bluej.editor.moe.MoeSyntaxDocument;
import bluej.parser.nodes.NodeTree.NodeAndPosition;
| An abstract ParsedNode which delegates to child nodes.
|
| @author Davin McCall
|
public abstract class ParentParsedNode
extends ParsedNode{
protected ParentParsedNode()
{
super();
}
public ParentParsedNode(ParsedNode myParent)
{
super(myParent);
}
@Override
public int textInserted(MoeSyntaxDocument document, int nodePos, int insPos,
int length, NodeStructureListener listener)
{
int newSize = getSize() + length;
resize(newSize);
NodeAndPosition<ParsedNode> child = getNodeTree().findNodeAtOrAfter(insPos, nodePos);
if (child != null && (child.getPosition() < insPos
|| child.getPosition() == insPos && child.getNode().growsForward())) {
ParsedNode cnode = child.getNode();
int r = cnode.textInserted(document, child.getPosition(), insPos, length, listener);
if (r == NODE_GREW || r == NODE_SHRUNK) {
newSize = child.getNode().getSize();
child = new NodeAndPosition<ParsedNode>(cnode, child.getPosition(), newSize);
childResized(document, nodePos, child);
document.scheduleReparse(child.getPosition() + newSize, 0);
return ALL_OK;
}
else if (r == REMOVE_NODE) {
removeChild(child, listener);
document.scheduleReparse(child.getPosition(), child.getSize());
return ALL_OK;
}
return ALL_OK;
}
else {
if (child != null) {
child.getNode().getContainingNodeTree().slideNode(length);
}
return handleInsertion(document, nodePos, insPos, length, listener);
}
}
| Handle the case of text being inserted directly into this node (not a child).
|
@OnThread(Tag.FXPlatform)
protected int handleInsertion(MoeSyntaxDocument document, int nodePos, int insPos, int length,
NodeStructureListener listener)
{
((MoeSyntaxDocument) document).scheduleReparse(insPos, length);
return ALL_OK;
}
@Override
public int textRemoved(MoeSyntaxDocument document, int nodePos, int delPos,
int length, NodeStructureListener listener)
{
int newSize = getSize() - length;
resize(newSize);
int endPos = delPos + length;
NodeAndPosition<ParsedNode> child = getNodeTree().findNodeAtOrAfter(delPos, nodePos);
while (child != null && child.getEnd() == delPos){
if (! child.getNode().marksOwnEnd()) {
child.getNode().setComplete(false);
}
child = child.nextSibling();
}
if (child != null && child.getPosition() < delPos) {
int childEndPos = child.getEnd();
if (childEndPos >= endPos) {
int r = child.getNode().textRemoved(document, child.getPosition(), delPos, length, listener);
if (r == REMOVE_NODE) {
removeChild(child, listener);
document.scheduleReparse(child.getPosition(), child.getSize());
}
else if (r != ALL_OK) {
newSize = child.getNode().getSize();
if (newSize < child.getSize()) {
document.scheduleReparse(child.getPosition() + newSize, child.getSize() - newSize);
}
else {
document.scheduleReparse(child.getPosition() + newSize, 0);
}
}
return ALL_OK;
}
int rlength = childEndPos - delPos;
NodeAndPosition<ParsedNode> next = child.nextSibling();
while (next != null && next.getPosition() < endPos){
NodeAndPosition<ParsedNode> nnext = next.nextSibling();
removeChild(next, listener);
next = nnext;
}
if (next != null) {
next.getNode().slide(rlength - length);
}
int r = child.getNode().textRemoved(document, child.getPosition(), delPos, rlength, listener);
int reparseOffset;
if (r == REMOVE_NODE) {
reparseOffset = child.getPosition();
removeChild(child, listener);
}
else {
reparseOffset = child.getPosition() + child.getNode().getSize();
}
return handleDeletion(document, nodePos, reparseOffset, listener);
}
while (child != null && child.getPosition() < endPos){
NodeAndPosition<ParsedNode> nextChild = child.nextSibling();
removeChild(child, listener);
child = nextChild;
}
if (child != null) {
child.slide(-length);
if (child.getPosition() == delPos && child.getNode().growsForward()) {
removeChild(child, listener);
}
}
return handleDeletion(document, nodePos, delPos, listener);
}
| Handle the case of text being removed directly from this node (rather than a
| child node).
|
@OnThread(Tag.FXPlatform)
protected int handleDeletion(MoeSyntaxDocument document, int nodePos, int dpos,
NodeStructureListener listener)
{
if (nodePos + getSize() == dpos && marksOwnEnd()) {
complete = false;
}
((MoeSyntaxDocument)document).scheduleReparse(dpos, 0);
return ALL_OK;
}
|
| Default implementation, just causes the parent to re-parse
|
@Override
@OnThread(Tag.FXPlatform)
protected int reparseNode(MoeSyntaxDocument document, int nodePos, int offset, int maxParse, NodeStructureListener listener)
{
return REMOVE_NODE;
}
@Override
@OnThread(Tag.FXPlatform)
protected boolean growChild(MoeSyntaxDocument document, NodeAndPosition<ParsedNode> child,
NodeStructureListener listener)
{
return false;
}
}
top,
use,
map,
abstract class ParentParsedNode
. ParentParsedNode
. ParentParsedNode
. textInserted
. handleInsertion
. textRemoved
. handleDeletion
. reparseNode
. growChild
253 neLoCode
+ 7 LoComm