Search in sources :

Example 6 with InvalidInputException

use of org.eclipse.jdt.core.compiler.InvalidInputException in project che by eclipse.

the class CommentAnalyzer method normalizeReference.

/**
	 * Removes comments and whitespace
	 * @param reference the type reference
	 * @return the reference only consisting of dots and java identifier characters
	 */
public static String normalizeReference(String reference) {
    IScanner scanner = ToolFactory.createScanner(false, false, false, false);
    scanner.setSource(reference.toCharArray());
    StringBuffer sb = new StringBuffer();
    try {
        int tokenType = scanner.getNextToken();
        while (tokenType != ITerminalSymbols.TokenNameEOF) {
            sb.append(scanner.getRawTokenSource());
            tokenType = scanner.getNextToken();
        }
    } catch (InvalidInputException e) {
        Assert.isTrue(false, reference);
    }
    reference = sb.toString();
    return reference;
}
Also used : IScanner(org.eclipse.jdt.core.compiler.IScanner) InvalidInputException(org.eclipse.jdt.core.compiler.InvalidInputException)

Example 7 with InvalidInputException

use of org.eclipse.jdt.core.compiler.InvalidInputException in project che by eclipse.

the class Util method isJustWhitespaceOrComment.

private static boolean isJustWhitespaceOrComment(int start, int end, IBuffer buffer) {
    if (start == end)
        return true;
    Assert.isTrue(start <= end);
    String trimmedText = buffer.getText(start, end - start).trim();
    if (0 == trimmedText.length()) {
        return true;
    } else {
        IScanner scanner = ToolFactory.createScanner(false, false, false, null);
        scanner.setSource(trimmedText.toCharArray());
        try {
            return scanner.getNextToken() == ITerminalSymbols.TokenNameEOF;
        } catch (InvalidInputException e) {
            return false;
        }
    }
}
Also used : IScanner(org.eclipse.jdt.core.compiler.IScanner) InvalidInputException(org.eclipse.jdt.core.compiler.InvalidInputException)

Aggregations

IScanner (org.eclipse.jdt.core.compiler.IScanner)7 InvalidInputException (org.eclipse.jdt.core.compiler.InvalidInputException)7 IMethod (org.eclipse.jdt.core.IMethod)1 MethodDeclarationMatch (org.eclipse.jdt.core.search.MethodDeclarationMatch)1 MethodReferenceMatch (org.eclipse.jdt.core.search.MethodReferenceMatch)1