Example usage for org.eclipse.jdt.internal.compiler.parser Scanner atEnd

List of usage examples for org.eclipse.jdt.internal.compiler.parser Scanner atEnd

Introduction

In this page you can find the example usage for org.eclipse.jdt.internal.compiler.parser Scanner atEnd.

Prototype

public final boolean atEnd() 

Source Link

Usage

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.  j a va 2  s  .  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: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./*from  ww  w . ja v a  2s  . c  o m*/
 * @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);
}

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 ww. jav 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);
}