/** * Returns the position of the opening peer character (backward search). Any scopes introduced by closing peers * are skipped. All peers accounted for must reside in the default partition. * * <p>Note that <code>start</code> must not point to the closing 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 findOpeningPeer(int start, char openingPeer, char closingPeer) { return findOpeningPeer(start, UNBOUND, openingPeer, closingPeer); }
/** * Returns the position of the opening peer character (backward search). Any scopes introduced by closing peers * are skipped. All peers accounted for must reside in the default partition. * * <p>Note that <code>start</code> must not point to the closing 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 findOpeningPeer(int start, char openingPeer, char closingPeer) { return findOpeningPeer(start, UNBOUND, openingPeer, closingPeer); }
/** * Returns the position of the opening peer character (backward search). Any scopes introduced by closing peers * are skipped. All peers accounted for must reside in the default partition. * * <p>Note that <code>start</code> must not point to the closing 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 findOpeningPeer(int start, char openingPeer, char closingPeer) { return findOpeningPeer(start, UNBOUND, openingPeer, closingPeer); }
return true; case TokenRPAREN: position= findOpeningPeer(fPos, LPAREN, RPAREN); if (position > 0) { switch (previousToken(position - 1, bound)) {
return true; case TokenRPAREN: position= findOpeningPeer(fPos, LPAREN, RPAREN); if (position > 0) { switch (previousToken(position - 1, bound)) {
/** * 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); }
return true; case TokenRPAREN: position= findOpeningPeer(fPos, LPAREN, RPAREN); if (position > 0) { switch (previousToken(position - 1, bound)) {
protected final int guessMethodContextInformationPosition(ContentAssistInvocationContext context) { final int contextPosition= context.getInvocationOffset(); IDocument document= context.getDocument(); JavaHeuristicScanner scanner= new JavaHeuristicScanner(document); int bound= Math.max(-1, contextPosition - 2000); // try the innermost scope of parentheses that looks like a method call int pos= contextPosition - 1; do { int paren= scanner.findOpeningPeer(pos, bound, '(', ')'); if (paren == JavaHeuristicScanner.NOT_FOUND) break; int token= scanner.previousToken(paren - 1, bound); // next token must be a method name (identifier) or the closing angle of a // constructor call of a parameterized type. if (token == Symbols.TokenIDENT || token == Symbols.TokenGREATERTHAN) return paren + 1; pos= paren - 1; } while (true); return contextPosition; }
protected final int guessMethodContextInformationPosition(ContentAssistInvocationContext context) { final int contextPosition= context.getInvocationOffset(); IDocument document= context.getDocument(); JavaHeuristicScanner scanner= new JavaHeuristicScanner(document); int bound= Math.max(-1, contextPosition - 2000); // try the innermost scope of parentheses that looks like a method call int pos= contextPosition - 1; do { int paren= scanner.findOpeningPeer(pos, bound, '(', ')'); if (paren == JavaHeuristicScanner.NOT_FOUND) break; int token= scanner.previousToken(paren - 1, bound); // next token must be a method name (identifier) or the closing angle of a // constructor call of a parameterized type. if (token == Symbols.TokenIDENT || token == Symbols.TokenGREATERTHAN) return paren + 1; pos= paren - 1; } while (true); return contextPosition; }
/** * 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; } }
protected int guessContextInformationPosition(ContentAssistInvocationContext context) { final int contextPosition= context.getInvocationOffset(); IDocument document= context.getDocument(); JavaHeuristicScanner scanner= new JavaHeuristicScanner(document); int bound= Math.max(-1, contextPosition - 200); // try the innermost scope of parentheses that looks like a method call int pos= contextPosition - 1; do { int paren= scanner.findOpeningPeer(pos, bound, '(', ')'); if (paren == JavaHeuristicScanner.NOT_FOUND) break; int token= scanner.previousToken(paren - 1, bound); // next token must be a method name (identifier) or the closing angle of a // constructor call of a parameterized type. if (token == Symbols.TokenIDENT || token == Symbols.TokenGREATERTHAN) return paren + 1; pos= paren - 1; } while (true); return super.guessContextInformationPosition(context); } }
/** * 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; } }
@Override protected int guessContextInformationPosition(ContentAssistInvocationContext context) { final int contextPosition= context.getInvocationOffset(); IDocument document= context.getDocument(); JavaHeuristicScanner scanner= new JavaHeuristicScanner(document); int bound= Math.max(-1, contextPosition - 200); // try the innermost scope of angle brackets that looks like a generic type argument list try { int pos= contextPosition - 1; do { int angle= scanner.findOpeningPeer(pos, bound, '<', '>'); if (angle == JavaHeuristicScanner.NOT_FOUND) break; int token= scanner.previousToken(angle - 1, bound); // next token must be a method name that is a generic type if (token == Symbols.TokenIDENT) { int off= scanner.getPosition() + 1; int end= angle; String ident= document.get(off, end - off).trim(); if (JavaHeuristicScanner.isGenericStarter(ident)) return angle + 1; } pos= angle - 1; } while (true); } catch (BadLocationException x) { } return super.guessContextInformationPosition(context); }
@Override protected int guessContextInformationPosition(ContentAssistInvocationContext context) { final int contextPosition= context.getInvocationOffset(); IDocument document= context.getDocument(); JavaHeuristicScanner scanner= new JavaHeuristicScanner(document); int bound= Math.max(-1, contextPosition - 200); // try the innermost scope of angle brackets that looks like a generic type argument list try { int pos= contextPosition - 1; do { int angle= scanner.findOpeningPeer(pos, bound, '<', '>'); if (angle == JavaHeuristicScanner.NOT_FOUND) break; int token= scanner.previousToken(angle - 1, bound); // next token must be a method name that is a generic type if (token == Symbols.TokenIDENT) { int off= scanner.getPosition() + 1; int end= angle; String ident= document.get(off, end - off).trim(); if (JavaHeuristicScanner.isGenericStarter(ident)) return angle + 1; } pos= angle - 1; } while (true); } catch (BadLocationException x) { } return super.guessContextInformationPosition(context); }
protected int guessContextInformationPosition(ContentAssistInvocationContext context) { final int contextPosition= context.getInvocationOffset(); IDocument document= context.getDocument(); JavaHeuristicScanner scanner= new JavaHeuristicScanner(document); int bound= Math.max(-1, contextPosition - 200); // try the innermost scope of angle brackets that looks like a generic type argument list try { int pos= contextPosition - 1; do { int angle= scanner.findOpeningPeer(pos, bound, '<', '>'); if (angle == JavaHeuristicScanner.NOT_FOUND) break; int token= scanner.previousToken(angle - 1, bound); // next token must be a method name that is a generic type if (token == Symbols.TokenIDENT) { int off= scanner.getPosition() + 1; int end= angle; String ident= document.get(off, end - off).trim(); if (JavaHeuristicScanner.isGenericStarter(ident)) return angle + 1; } pos= angle - 1; } while (true); } catch (BadLocationException x) { } return super.guessContextInformationPosition(context); }
break; int openingParen= scanner.findOpeningPeer(closingParen - 1, '(', ')');
openingParen= scanner.findOpeningPeer(closingParen - 1, '(', ')');