package bluej.editor.moe;
import bluej.parser.nodes.NodeStructureListener;
import bluej.parser.nodes.NodeTree.NodeAndPosition;
import bluej.parser.nodes.ParsedNode;
import threadchecker.OnThread;
import threadchecker.Tag;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
| A representation of document events in a MoeSyntaxDocuments. As well as textual
| changes, this can include information about node structure changes.
|
| @author Davin McCall
|
@OnThread(Tag.Any)
public class MoeSyntaxEvent
implements NodeStructureListener{
private final int offset;
private final int length;
private final MoeSyntaxDocument document;
private final List<NodeAndPosition<ParsedNode>> removedNodes = new ArrayList<>();
private final Map<ParsedNode, NodeChangeRecord> changedNodes = new HashMap<>();
private final boolean insert;
private final boolean remove;
public MoeSyntaxEvent(MoeSyntaxDocument document, int offset, int length, boolean isInsert, boolean isRemove)
{
this.document = document;
this.offset = offset;
this.length = length;
this.insert = isInsert;
this.remove = isRemove;
}
| Get a list of nodes removed as part of this event.
|
public List> getRemovedNodes()
{
return removedNodes;
}
| Get a collection of nodes which changed position as part of this event.
|
public Collection getChangedNodes()
{
return changedNodes.values();
}
@OnThread(value = Tag.FXPlatform, ignoreParent = true)
public void nodeRemoved(NodeAndPosition<ParsedNode> node)
{
removedNodes.add(node);
changedNodes.remove(node.getNode());
}
@OnThread(value = Tag.FXPlatform, ignoreParent = true)
public void nodeChangedLength(NodeAndPosition<ParsedNode> nap, int oldPos,
int oldSize)
{
NodeChangeRecord r = changedNodes.get(nap.getNode());
if (r == null) {
if (nap.getPosition() != oldPos || nap.getSize() != oldSize) {
r = new NodeChangeRecord();
r.nap = nap;
r.originalPos = oldPos;
r.originalSize = oldSize;
changedNodes.put(nap.getNode(), r);
}
}
else {
if (nap.getPosition() == r.originalPos && nap.getSize() == r.originalSize) {
changedNodes.remove(nap.getNode());
}
else {
r.nap = nap;
}
}
}
public int getOffset()
{
return offset;
}
public int getLength()
{
return length;
}
public boolean isInsert()
{
return insert;
}
public boolean isRemove()
{
return remove;
}
| Node change record. Purely used for passing data around, hence public fields.
|
@OnThread(Tag.Any)
public class NodeChangeRecord
{
public int originalPos;
public int originalSize;
public NodeAndPosition<ParsedNode> nap;
}
}
top,
use,
map,
class MoeSyntaxEvent
. MoeSyntaxEvent
. getRemovedNodes
. getChangedNodes
. nodeRemoved
. nodeChangedLength
. getOffset
. getLength
. isInsert
. isRemove
top,
use,
map,
class NodeChangeRecord
147 neLoCode
+ 6 LoComm