List of usage examples for org.eclipse.jdt.internal.compiler.parser Scanner getCurrentTokenEndPosition
public int getCurrentTokenEndPosition()
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 w ww . ja v a 2 s . co m } } 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 each valid token in the source and * reports a reference to this token to the search requestor. * A token is valid if it has an accuracy which is not -1. *///www . java 2 s. c o m protected void reportAccurateEnumConstructorReference(SearchMatch match, FieldDeclaration field, AllocationExpression allocation) throws CoreException { // Verify that field declaration is really an enum constant if (allocation == null || allocation.enumConstant == null) { report(match); return; } // Get scan area int sourceStart = match.getOffset() + match.getLength(); if (allocation.arguments != null && allocation.arguments.length > 0) { sourceStart = allocation.arguments[allocation.arguments.length - 1].sourceEnd + 1; } int sourceEnd = field.declarationSourceEnd; if (allocation instanceof QualifiedAllocationExpression) { QualifiedAllocationExpression qualifiedAllocation = (QualifiedAllocationExpression) allocation; if (qualifiedAllocation.anonymousType != null) { sourceEnd = qualifiedAllocation.anonymousType.sourceStart - 1; } } // Scan to find last closing parenthesis Scanner scanner = this.parser.scanner; scanner.setSource(this.currentPossibleMatch.getContents()); scanner.resetTo(sourceStart, sourceEnd); try { int token = scanner.getNextToken(); while (token != TerminalTokens.TokenNameEOF) { if (token == TerminalTokens.TokenNameRPAREN) { sourceEnd = scanner.getCurrentTokenEndPosition(); } token = scanner.getNextToken(); } } catch (InvalidInputException iie) { // give up } // Report match match.setLength(sourceEnd - match.getOffset() + 1); report(match); }