List of usage examples for org.eclipse.jdt.internal.compiler.parser Scanner getNextChar
public final int getNextChar()
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 ww . ja va 2 s . com*/ * @since 3.1 */ protected void reportAccurateParameterizedTypeReference(SearchMatch match, TypeReference typeRef, int index, 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 end = typeRef.sourceEnd; if (typeArguments != null) { boolean shouldMatchErasure = (this.pattern instanceof OrPattern) ? ((OrPattern) this.pattern).isErasureMatch() : ((JavaSearchPattern) this.pattern).isErasureMatch(); boolean hasSignatures = (this.pattern instanceof OrPattern) ? ((OrPattern) this.pattern).hasSignatures() : ((JavaSearchPattern) this.pattern).hasSignatures(); if (shouldMatchErasure || !hasSignatures) { // if pattern is erasure only, then select the end of the reference if (typeRef instanceof QualifiedTypeReference && index >= 0) { long[] positions = ((QualifiedTypeReference) typeRef).sourcePositions; end = (int) positions[index]; } else if (typeRef instanceof ArrayTypeReference) { end = ((ArrayTypeReference) typeRef).originalSourceEnd; } } else { // Initialize scanner Scanner scanner = this.parser.scanner; char[] source = this.currentPossibleMatch.getContents(); scanner.setSource(source); // Set scanner position at end of last type argument scanner.resetTo(end, source.length - 1); int depth = 0; for (int i = typeArguments.length - 1; i >= 0; i--) { if (typeArguments[i] != null) { long lastTypeArgInfo = findLastTypeArgumentInfo(typeArguments[i]); depth = (int) (lastTypeArgInfo >>> 32) + 1; scanner.resetTo(((int) lastTypeArgInfo) + 1, scanner.eofPosition - 1); break; } } // Now, scan to search next closing '>' while (depth-- > 0) { while (!scanner.atEnd()) { if (scanner.getNextChar() == '>') { end = scanner.currentPosition - 1; break; } } } } } // Report match match.setLength(end - match.getOffset() + 1); report(match); }