for(int j = scanStartOffset; j >= tokenListOffset  - len; j--)
for(int j = scanStartOffset; j > tokenListOffset - len; j--)
	public static int findMatchingBracket(Buffer buffer, int line, int offset)		throws BadLocationException	{		if(buffer.getLength() == 0)			return -1;		Element map = buffer.getDefaultRootElement();		Element lineElement = map.getElement(line);		Segment lineText = new Segment();		int lineStart = lineElement.getStartOffset();		buffer.getText(lineStart,lineElement.getEndOffset() - lineStart - 1,			lineText);		char c = lineText.array[lineText.offset + offset];		char cprime; // c` - corresponding character		boolean direction; // true = back, false = forward		switch(c)		{		case '(': cprime = ')'; direction = false; break;		case ')': cprime = '('; direction = true; break;		case '[': cprime = ']'; direction = false; break;		case ']': cprime = '['; direction = true; break;		case '{': cprime = '}'; direction = false; break;		case '}': cprime = '{'; direction = true; break;		default: return -1;		}		int count;		TokenMarker tokenMarker = buffer.getTokenMarker();		// Get the syntax token at 'offset'		// only tokens with the same type will be checked for		// the corresponding bracket		byte idOfBracket = Token.NULL;		TokenMarker.LineInfo lineInfo = tokenMarker.markTokens(lineText,line);		Token lineTokens = lineInfo.firstToken;		int tokenListOffset = 0;		for(;;)		{			if(lineTokens.id == Token.END)				throw new InternalError("offset > line length");				if(tokenListOffset + lineTokens.length > offset)			{				idOfBracket = lineTokens.id;				break;			}			else			{				tokenListOffset += lineTokens.length;				lineTokens = lineTokens.next;			}		}		if(direction)		{			// scan backwards			count = 0;			for(int i = line; i >= 0; i--)			{				// get text				lineElement = map.getElement(i);				lineStart = lineElement.getStartOffset();				int lineLength = lineElement.getEndOffset()					- lineStart - 1;				buffer.getText(lineStart,lineLength,lineText);				int scanStartOffset;				if(i != line)				{					lineTokens = tokenMarker.markTokens(lineText,i).lastToken;					tokenListOffset = scanStartOffset = lineLength - 1;				}				else				{ 					if(tokenListOffset != lineLength) 						tokenListOffset += lineTokens.length;					//lineTokens = lineInfo.lastToken;					scanStartOffset = offset;					/*System.err.println("sso=" + scanStartOffset + ",tlo=" + tokenListOffset);					Token __ = lineTokens;					 for(;;)					{						if(__ == null)							break;						System.err.println(__);						__ = __.prev;					} */				}				// only check tokens with id 'idOfBracket'				while(lineTokens != null)				{					byte id = lineTokens.id;					if(id == Token.END)					{						lineTokens = lineTokens.prev;						continue;					}					//System.err.println(lineTokens);					int len = lineTokens.length;					if(id == idOfBracket)					{						for(int j = scanStartOffset; j >= tokenListOffset  - len; j--)						{							/* if(j >= lineText.count)								System.err.println("WARNING: " + j + " >= " + lineText.count);							else if(j < 0)							{								System.err.println("sso=" + scanStartOffset + ", tlo=" + tokenListOffset + ",len=" + len);								System.err.println("WARNING: " + j + " < 0");							} */							char ch = lineText.array[lineText.offset + j];							//System.err.print(ch);							if(ch == c)								count++;							else if(ch == cprime)							{								if(--count == 0)									return lineStart + j;							}						}						//System.err.println();					}					scanStartOffset = tokenListOffset = tokenListOffset - len;					lineTokens = lineTokens.prev;				}			}		}		else		{			// scan forwards			count = 0;			for(int i = line; i < map.getElementCount(); i++)			{				// get text				lineElement = map.getElement(i);				lineStart = lineElement.getStartOffset();				buffer.getText(lineStart,lineElement.getEndOffset()					- lineStart - 1,lineText);				int scanStartOffset;				if(i != line)				{					lineTokens = tokenMarker.markTokens(lineText,i).firstToken;					tokenListOffset = 0;					scanStartOffset = 0;				}				else					scanStartOffset = offset + 1;				// only check tokens with id 'idOfBracket'				for(;;)				{					byte id = lineTokens.id;					if(id == Token.END)						break;					int len = lineTokens.length;					if(id == idOfBracket)					{						for(int j = scanStartOffset; j < tokenListOffset + len; j++)						{							char ch = lineText.array[lineText.offset + j];							if(ch == c)								count++;							else if(ch == cprime)							{								if(count-- == 0)									return lineStart + j;							}						}					}					scanStartOffset = tokenListOffset = tokenListOffset + len;					lineTokens = lineTokens.next;				}			}		}		// Nothing found		return -1;	}