/**
  * Adds a set of tokens the check is interested in.
  *
  * @param aStrRep the string representation of the tokens interested in
  */
 public final void setIgnoreOccurrenceContext(String[] aStrRep) {
   mIgnoreOccurrenceContext.clear();
   for (final String s : aStrRep) {
     final int type = TokenTypes.getTokenId(s);
     mIgnoreOccurrenceContext.set(type);
   }
 }
Пример #2
0
  /**
   * Register a check for a given configuration.
   *
   * @param aCheck the check to register
   * @throws CheckstyleException if an error occurs
   */
  private void registerCheck(Check aCheck) throws CheckstyleException {
    final int[] tokens;
    final Set<String> checkTokens = aCheck.getTokenNames();
    if (!checkTokens.isEmpty()) {
      tokens = aCheck.getRequiredTokens();

      // register configured tokens
      final int acceptableTokens[] = aCheck.getAcceptableTokens();
      Arrays.sort(acceptableTokens);
      for (String token : checkTokens) {
        try {
          final int tokenId = TokenTypes.getTokenId(token);
          if (Arrays.binarySearch(acceptableTokens, tokenId) >= 0) {
            registerCheck(token, aCheck);
          }
          // TODO: else log warning
        } catch (final IllegalArgumentException ex) {
          throw new CheckstyleException("illegal token \"" + token + "\" in check " + aCheck, ex);
        }
      }
    } else {
      tokens = aCheck.getDefaultTokens();
    }
    for (int element : tokens) {
      registerCheck(element, aCheck);
    }
    mAllChecks.add(aCheck);
  }
Пример #3
0
 /**
  * Notify interested checks that leaving a node.
  *
  * @param aAST the node to notify for
  */
 private void notifyLeave(DetailAST aAST) {
   final Collection<Check> visitors = mTokenToChecks.get(TokenTypes.getTokenName(aAST.getType()));
   for (Check ch : visitors) {
     ch.leaveToken(aAST);
   }
 }
Пример #4
0
 /**
  * Register a check for a specified token id.
  *
  * @param aTokenID the id of the token
  * @param aCheck the check to register
  */
 private void registerCheck(int aTokenID, Check aCheck) {
   registerCheck(TokenTypes.getTokenName(aTokenID), aCheck);
 }