List of usage examples for org.eclipse.jdt.internal.compiler.parser Scanner getCurrentTokenStartPosition
public int getCurrentTokenStartPosition()
From source file:com.bsiag.eclipse.jdt.java.formatter.Token.java
License:Open Source License
public static Token fromCurrent(Scanner scanner, int currentToken) { int start = scanner.getCurrentTokenStartPosition(); int end = scanner.getCurrentTokenEndPosition(); if (currentToken == TokenNameCOMMENT_LINE) { // don't include line separator while (end >= start) { char c = scanner.source[end]; if (c != '\r' && c != '\n') break; end--;/*from ww w.ja v a 2 s. c om*/ } } Token token = new Token(start, end, currentToken); return token; }
From source file:com.codenvy.ide.ext.java.server.internal.core.search.matching.MatchLocator.java
License:Open Source License
/** * Finds the accurate positions of the sequence of tokens given by qualifiedName * in the source and reports a reference to this parameterized type name * to the search requestor.// w w w .j a v a2s.c o m * @since 3.1 */ protected void reportAccurateParameterizedMethodReference(SearchMatch match, ASTNode statement, TypeReference[] typeArguments) throws CoreException { if (match.getRule() == 0) return; if (!encloses((IJavaElement) match.getElement())) return; // If there's type arguments, look for end (i.e. char '>') of last one. int start = match.getOffset(); if (typeArguments != null && typeArguments.length > 0) { boolean isErasureMatch = (this.pattern instanceof OrPattern) ? ((OrPattern) this.pattern).isErasureMatch() : ((JavaSearchPattern) this.pattern).isErasureMatch(); if (!isErasureMatch) { // Initialize scanner Scanner scanner = this.parser.scanner; char[] source = this.currentPossibleMatch.getContents(); scanner.setSource(source); // Search previous opening '<' start = typeArguments[0].sourceStart; int end = statement.sourceEnd; scanner.resetTo(start, end); int lineStart = start; try { linesUp: while (true) { while (scanner.source[scanner.currentPosition] != '\n') { scanner.currentPosition--; if (scanner.currentPosition == 0) break linesUp; } lineStart = scanner.currentPosition + 1; scanner.resetTo(lineStart, end); while (!scanner.atEnd()) { if (scanner.getNextToken() == TerminalTokens.TokenNameLESS) { start = scanner.getCurrentTokenStartPosition(); break linesUp; } } end = lineStart - 2; scanner.currentPosition = end; } } catch (InvalidInputException ex) { // give up } } } // Report match match.setOffset(start); match.setLength(statement.sourceEnd - start + 1); report(match); }
From source file:org.eclipse.che.jdt.internal.core.search.matching.MatchLocator.java
License:Open Source License
/** * Finds the accurate positions of the sequence of tokens given by qualifiedName * in the source and reports a reference to this parameterized type name * to the search requestor.//from w w w. j a v a 2s. c o m * @since 3.1 */ protected void reportAccurateParameterizedMethodReference(SearchMatch match, ASTNode statement, TypeReference[] typeArguments) throws CoreException { if (match.getRule() == 0) return; if (!encloses((IJavaElement) match.getElement())) return; // If there's type arguments, look for end (i.e. char '>') of last one. int start = match.getOffset(); if (typeArguments != null && typeArguments.length > 0) { boolean isErasureMatch = (this.pattern instanceof OrPattern) ? ((OrPattern) this.pattern).isErasureMatch() : ((JavaSearchPattern) this.pattern).isErasureMatch(); if (!isErasureMatch) { // Initialize scanner Scanner scanner = this.parser.scanner; char[] source = this.currentPossibleMatch.getContents(); scanner.setSource(source); // Search previous opening '<' start = typeArguments[0].sourceStart; int end = statement.sourceEnd; scanner.resetTo(start, end); int lineStart = start; try { linesUp: while (true) { while (scanner.source[scanner.currentPosition] != '\n') { scanner.currentPosition--; if (scanner.currentPosition == 0) break linesUp; } lineStart = scanner.currentPosition + 1; scanner.resetTo(lineStart, end); while (!scanner.atEnd()) { if (scanner.getNextToken() == TerminalTokens.TokenNameLESS) { start = scanner.getCurrentTokenStartPosition(); break linesUp; } } end = lineStart - 2; scanner.currentPosition = end; } } catch (InvalidInputException ex) { // give up } } } // Report match match.setOffset(start); match.setLength(statement.sourceEnd - start + 1); report(match); }