AbstractDocument doc = (AbstractDocument) context.getDocument();
doc.readLock();
try {
TokenHierarchy th = TokenHierarchy.get(doc);
TokenSequence ts = th.tokenSequence();
Token token = findTokenAtContext(ts, context.getSearchOffset());
if (token == null) {
return null;
}
int ordinal = token.id().ordinal();
for (BracePair bp : bracePairs) {
if (ordinal == bp.open) {
originToken = bp.open;
matchToken = bp.close;
searchForward = true;
ret = new int[]{ts.offset(), ts.offset() + token.length()};
} else if (ordinal == bp.close) {
originToken = bp.close;
matchToken = bp.open;
searchForward = false;
ret = new int[]{ts.offset(), ts.offset() + token.length()};
}
}
} finally {
((AbstractDocument) context.getDocument()).readUnlock();
}