/** * Returns the position of the closing peer character (forward search). Any scopes introduced by opening peers * are skipped. All peers accounted for must reside in the default partition. * * <p>Note that <code>start</code> must not point to the opening peer, but to the first * character being searched.</p> * * @param start the start position * @param openingPeer the opening peer character (e.g. '{') * @param closingPeer the closing peer character (e.g. '}') * @return the matching peer character position, or <code>NOT_FOUND</code> */ public int findClosingPeer(int start, final char openingPeer, final char closingPeer) { return findClosingPeer(start, UNBOUND, openingPeer, closingPeer); }
/** * Returns the position of the closing peer character (forward search). Any scopes introduced by opening peers * are skipped. All peers accounted for must reside in the default partition. * * <p>Note that <code>start</code> must not point to the opening peer, but to the first * character being searched.</p> * * @param start the start position * @param openingPeer the opening peer character (e.g. '{') * @param closingPeer the closing peer character (e.g. '}') * @return the matching peer character position, or <code>NOT_FOUND</code> */ public int findClosingPeer(int start, final char openingPeer, final char closingPeer) { return findClosingPeer(start, UNBOUND, openingPeer, closingPeer); }
/** * Returns the position of the closing peer character (forward search). Any scopes introduced by opening peers * are skipped. All peers accounted for must reside in the default partition. * * <p>Note that <code>start</code> must not point to the opening peer, but to the first * character being searched.</p> * * @param start the start position * @param openingPeer the opening peer character (e.g. '{') * @param closingPeer the closing peer character (e.g. '}') * @return the matching peer character position, or <code>NOT_FOUND</code> */ public int findClosingPeer(int start, final char openingPeer, final char closingPeer) { return findClosingPeer(start, UNBOUND, openingPeer, closingPeer); }
/** * Computes the surrounding block around <code>offset</code>. The search is started at the * beginning of <code>offset</code>, i.e. an opening brace at <code>offset</code> will not be * part of the surrounding block, but a closing brace will. * * @param offset the offset for which the surrounding block is computed * @return a region describing the surrounding block, or <code>null</code> if none can be found */ public IRegion findSurroundingBlock(int offset) { if (offset < 1 || offset >= fDocument.getLength()) return null; int begin= findOpeningPeer(offset - 1, LBRACE, RBRACE); int end= findClosingPeer(offset, LBRACE, RBRACE); if (begin == NOT_FOUND || end == NOT_FOUND) return null; return new Region(begin, end + 1 - begin); }
/** * Computes the surrounding block around <code>offset</code>. The search is started at the * beginning of <code>offset</code>, i.e. an opening brace at <code>offset</code> will not be * part of the surrounding block, but a closing brace will. * * @param offset the offset for which the surrounding block is computed * @return a region describing the surrounding block, or <code>null</code> if none can be found */ public IRegion findSurroundingBlock(int offset) { if (offset < 1 || offset >= fDocument.getLength()) return null; int begin= findOpeningPeer(offset - 1, LBRACE, RBRACE); int end= findClosingPeer(offset, LBRACE, RBRACE); if (begin == NOT_FOUND || end == NOT_FOUND) return null; return new Region(begin, end + 1 - begin); }
/** * Computes the surrounding block around <code>offset</code>. The search is started at the * beginning of <code>offset</code>, i.e. an opening brace at <code>offset</code> will not be * part of the surrounding block, but a closing brace will. * * @param offset the offset for which the surrounding block is computed * @return a region describing the surrounding block, or <code>null</code> if none can be found */ public IRegion findSurroundingBlock(int offset) { if (offset < 1 || offset >= fDocument.getLength()) return null; int begin= findOpeningPeer(offset - 1, LBRACE, RBRACE); int end= findClosingPeer(offset, LBRACE, RBRACE); if (begin == NOT_FOUND || end == NOT_FOUND) return null; return new Region(begin, end + 1 - begin); }
/** * Returns the block balance, i.e. zero if the blocks are balanced at <code>offset</code>, a * negative number if there are more closing than opening braces, and a positive number if there * are more opening than closing braces. * * @param document the document * @param offset the offset * @param partitioning the partitioning * @return the block balance */ private static int getBlockBalance(IDocument document, int offset, String partitioning) { if (offset < 1) return -1; if (offset >= document.getLength()) return 1; int begin= offset; int end= offset - 1; JavaHeuristicScanner scanner= new JavaHeuristicScanner(document); while (true) { begin= scanner.findOpeningPeer(begin - 1, '{', '}'); end= scanner.findClosingPeer(end + 1, '{', '}'); if (begin == -1 && end == -1) return 0; if (begin == -1) return -1; if (end == -1) return 1; } }
/** * Returns the block balance, i.e. zero if the blocks are balanced at * <code>offset</code>, a negative number if there are more closing than opening * braces, and a positive number if there are more opening than closing braces. * * @param document * @param offset * @param partitioning * @return the block balance */ private static int getBlockBalance(IDocument document, int offset, String partitioning) { if (offset < 1) return -1; if (offset >= document.getLength()) return 1; int begin= offset; int end= offset - 1; JavaHeuristicScanner scanner= new JavaHeuristicScanner(document); while (true) { begin= scanner.findOpeningPeer(begin - 1, '{', '}'); end= scanner.findClosingPeer(end + 1, '{', '}'); if (begin == -1 && end == -1) return 0; if (begin == -1) return -1; if (end == -1) return 1; } }
/** * Returns the block balance, i.e. zero if the blocks are balanced at <code>offset</code>, a * negative number if there are more closing than opening braces, and a positive number if there * are more opening than closing braces. * * @param document the document * @param offset the offset * @param partitioning the partitioning * @return the block balance */ private static int getBlockBalance(IDocument document, int offset, String partitioning) { if (offset < 1) return -1; if (offset >= document.getLength()) return 1; int begin= offset; int end= offset - 1; JavaHeuristicScanner scanner= new JavaHeuristicScanner(document); while (true) { begin= scanner.findOpeningPeer(begin - 1, '{', '}'); end= scanner.findClosingPeer(end + 1, '{', '}'); if (begin == -1 && end == -1) return 0; if (begin == -1) return -1; if (end == -1) return 1; } }