Search in sources :

Example 1 with Nonempty

use of com.helger.commons.annotation.Nonempty in project ph-css by phax.

the class LoggingCSSParseErrorHandler method createLoggingStringParseError.

@Nonnull
@Nonempty
public static String createLoggingStringParseError(@Nonnull final Token aLastValidToken, @Nonnull final int[][] aExpectedTokenSequencesVal, @Nonnull final String[] aTokenImageVal, @Nullable final Token aLastSkippedToken) {
    ValueEnforcer.notNull(aLastValidToken, "LastValidToken");
    ValueEnforcer.notNull(aExpectedTokenSequencesVal, "ExpectedTokenSequencesVal");
    ValueEnforcer.notNull(aTokenImageVal, "TokenImageVal");
    final StringBuilder aExpected = new StringBuilder();
    int nMaxSize = 0;
    for (final int[] aExpectedTokens : aExpectedTokenSequencesVal) {
        if (nMaxSize < aExpectedTokens.length)
            nMaxSize = aExpectedTokens.length;
        if (aExpected.length() > 0)
            aExpected.append(',');
        for (final int nExpectedToken : aExpectedTokens) aExpected.append(' ').append(aTokenImageVal[nExpectedToken]);
    }
    final StringBuilder retval = new StringBuilder(1024);
    retval.append('[').append(aLastValidToken.next.beginLine).append(':').append(aLastValidToken.next.beginColumn).append(']');
    if (aLastSkippedToken != null) {
        retval.append("-[").append(aLastSkippedToken.endLine).append(':').append(aLastSkippedToken.endColumn).append(']');
    }
    retval.append(" Encountered");
    Token aCurToken = aLastValidToken.next;
    for (int i = 0; i < nMaxSize; i++) {
        retval.append(' ');
        if (aCurToken.kind == TOKEN_EOF) {
            retval.append(aTokenImageVal[TOKEN_EOF]);
            break;
        }
        retval.append("text '").append(aCurToken.image).append("' corresponding to token ").append(aTokenImageVal[aCurToken.kind]);
        aCurToken = aCurToken.next;
    }
    retval.append(". ");
    if (aLastSkippedToken != null)
        retval.append("Skipped until token ").append(aLastSkippedToken).append(". ");
    retval.append(aExpectedTokenSequencesVal.length == 1 ? "Was expecting:" : "Was expecting one of:").append(aExpected);
    return retval.toString();
}
Also used : Token(com.helger.css.parser.Token) Nonnull(javax.annotation.Nonnull) Nonempty(com.helger.commons.annotation.Nonempty)

Aggregations

Nonempty (com.helger.commons.annotation.Nonempty)1 Token (com.helger.css.parser.Token)1 Nonnull (javax.annotation.Nonnull)1