/** * Finds a closing parenthesis to the left of <code>position</code> in document, where that parenthesis is only * separated by whitespace from <code>position</code>. If no such parenthesis can be found, <code>position</code> is returned. * * @param scanner the java heuristic scanner set up on the document * @param position the first character position in <code>document</code> to be considered * @return the position of a closing parenthesis left to <code>position</code> separated only by whitespace, or <code>position</code> if no parenthesis can be found */ private static int findClosingParenToLeft(JavaHeuristicScanner scanner, int position) { if (position < 1) return position; if (scanner.previousToken(position - 1, JavaHeuristicScanner.UNBOUND) == Symbols.TokenRPAREN) return scanner.getPosition() + 1; return position; }
/** * Finds a closing parenthesis to the left of <code>position</code> in document, where that parenthesis is only * separated by whitespace from <code>position</code>. If no such parenthesis can be found, <code>position</code> is returned. * * @param scanner the java heuristic scanner set up on the document * @param position the first character position in <code>document</code> to be considered * @return the position of a closing parenthesis left to <code>position</code> separated only by whitespace, or <code>position</code> if no parenthesis can be found */ private static int findClosingParenToLeft(JavaHeuristicScanner scanner, int position) { if (position < 1) return position; if (scanner.previousToken(position - 1, JavaHeuristicScanner.UNBOUND) == Symbols.TokenRPAREN) return scanner.getPosition() + 1; return position; }
/** * Finds a closing parenthesis to the left of <code>position</code> in document, where that parenthesis is only * separated by whitespace from <code>position</code>. If no such parenthesis can be found, <code>position</code> is returned. * * @param scanner the java heuristic scanner set up on the document * @param position the first character position in <code>document</code> to be considered * @return the position of a closing parenthesis left to <code>position</code> separated only by whitespace, or <code>position</code> if no parenthesis can be found */ private static int findClosingParenToLeft(JavaHeuristicScanner scanner, int position) { if (position < 1) return position; if (scanner.previousToken(position - 1, JavaHeuristicScanner.UNBOUND) == Symbols.TokenRPAREN) return scanner.getPosition() + 1; return position; }
/** * Reads the next token in backward direction of <code>start</code> from * the heuristic scanner and sets the fields <code>fToken, fPreviousPosition</code> * and <code>fPosition</code> accordingly. * * @param start the start offset from which to scan backwards */ private void nextToken(int start) { fToken= fScanner.previousToken(start - 1, JavaHeuristicScanner.UNBOUND); fPreviousPos= start; fPosition= fScanner.getPosition() + 1; try { fLine= fDocument.getLineOfOffset(fPosition); } catch (BadLocationException e) { fLine= -1; } }
/** * Reads the next token in backward direction of <code>start</code> from * the heuristic scanner and sets the fields <code>fToken, fPreviousPosition</code> * and <code>fPosition</code> accordingly. * * @param start the start offset from which to scan backwards */ private void nextToken(int start) { fToken= fScanner.previousToken(start - 1, JavaHeuristicScanner.UNBOUND); fPreviousPos= start; fPosition= fScanner.getPosition() + 1; try { fLine= fDocument.getLineOfOffset(fPosition); } catch (BadLocationException e) { fLine= -1; } }
/** * Reads the next token in backward direction of <code>start</code> from * the heuristic scanner and sets the fields <code>fToken, fPreviousPosition</code> * and <code>fPosition</code> accordingly. * * @param start the start offset from which to scan backwards */ private void nextToken(int start) { fToken= fScanner.previousToken(start - 1, JavaHeuristicScanner.UNBOUND); fPreviousPos= start; fPosition= fScanner.getPosition() + 1; try { fLine= fDocument.getLineOfOffset(fPosition); } catch (BadLocationException e) { fLine= -1; } }
int token= previousToken(start - 1, bound); if (token == Symbols.TokenIDENT) { // type name token= previousToken(getPosition(), bound); while (token == Symbols.TokenOTHER) { // dot of qualification token= previousToken(getPosition(), bound); if (token != Symbols.TokenIDENT) // qualification name return false; token= previousToken(getPosition(), bound);
int token= previousToken(start - 1, bound); if (token == Symbols.TokenIDENT) { // type name token= previousToken(getPosition(), bound); while (token == Symbols.TokenOTHER) { // dot of qualification token= previousToken(getPosition(), bound); if (token != Symbols.TokenIDENT) // qualification name return false; token= previousToken(getPosition(), bound);
int token= previousToken(start - 1, bound); if (token == Symbols.TokenIDENT) { // type name token= previousToken(getPosition(), bound); while (token == Symbols.TokenOTHER) { // dot of qualification token= previousToken(getPosition(), bound); if (token != Symbols.TokenIDENT) // qualification name return false; token= previousToken(getPosition(), bound);
/** * Checks if the angular bracket at <code>offset</code> is a type parameter closing bracket. * * @param offset the offset of the closing bracket * @param document the document * @param scanner a java heuristic scanner on <code>document</code> * @return <code>true</code> if the bracket is part of a type parameter, <code>false</code> * otherwise * @since 3.8 */ private boolean isTypeParameterClosingBracket(int offset, IDocument document, JavaHeuristicScanner scanner) { /* * type parameter closing brackets come after question marks, other type parameter * closing brackets, or after a Type name (heuristic: starts with capital character) */ try { IRegion line= document.getLineInformationOfOffset(offset); int prevToken= scanner.previousToken(offset - 1, line.getOffset()); int prevTokenOffset= scanner.getPosition() + 1; String previous= prevToken == Symbols.TokenEOF ? null : document.get(prevTokenOffset, offset - prevTokenOffset).trim(); if ((prevToken == Symbols.TokenIDENT && (previous.length() > 0 && Character.isUpperCase(previous.charAt(0)))) || prevToken == Symbols.TokenEOF || prevToken == Symbols.TokenGREATERTHAN || prevToken == Symbols.TokenQUESTIONMARK) return true; } catch (BadLocationException e) { return false; } return false; }
p= scanner.getPosition();
/** * Checks if the angular bracket at <code>offset</code> is a type parameter closing bracket. * * @param offset the offset of the closing bracket * @param document the document * @param scanner a java heuristic scanner on <code>document</code> * @return <code>true</code> if the bracket is part of a type parameter, <code>false</code> * otherwise * @since 3.8 */ private boolean isTypeParameterClosingBracket(int offset, IDocument document, JavaHeuristicScanner scanner) { /* * type parameter closing brackets come after question marks, other type parameter * closing brackets, or after a Type name (heuristic: starts with capital character) */ try { IRegion line= document.getLineInformationOfOffset(offset); int prevToken= scanner.previousToken(offset - 1, line.getOffset()); int prevTokenOffset= scanner.getPosition() + 1; String previous= prevToken == Symbols.TokenEOF ? null : document.get(prevTokenOffset, offset - prevTokenOffset).trim(); if ((prevToken == Symbols.TokenIDENT && (previous.length() > 0 && Character.isUpperCase(previous.charAt(0)))) || prevToken == Symbols.TokenEOF || prevToken == Symbols.TokenGREATERTHAN || prevToken == Symbols.TokenQUESTIONMARK) return true; } catch (BadLocationException e) { return false; } return false; }
p= scanner.getPosition();
int prevTokenOffset= scanner.getPosition() + 1; String previous= prevToken == Symbols.TokenEOF ? null : document.get(prevTokenOffset, offset - prevTokenOffset).trim();
int prevTokenOffset= scanner.getPosition() + 1; String previous= prevToken == Symbols.TokenEOF ? null : document.get(prevTokenOffset, offset - prevTokenOffset).trim();
int prevTokenOffset= scanner.getPosition() + 1; String previous= prevToken == Symbols.TokenEOF ? null : document.get(prevTokenOffset, offset - prevTokenOffset).trim();
@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); }
@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); }