Exemplo n.º 1
0
 @Override
 protected final void logLoadError(Token ident) {
   logLoadErrorImpl(
       ident.getLineNo(),
       ident.getColumnNo(),
       MSG_CLASS_INFO,
       JavadocTagInfo.THROWS.getText(),
       ident.getText());
 }
Exemplo n.º 2
0
  /**
   * Checks a set of tags for matching throws.
   *
   * @param tags the tags to check
   * @param throwsList the throws to check
   * @param reportExpectedTags whether we should report if do not find expected tag
   */
  private void checkThrowsTags(
      List<JavadocTag> tags, List<ExceptionInfo> throwsList, boolean reportExpectedTags) {
    // Loop over the tags, checking to see they exist in the throws.
    // The foundThrows used for performance only
    final Set<String> foundThrows = Sets.newHashSet();
    final ListIterator<JavadocTag> tagIt = tags.listIterator();
    while (tagIt.hasNext()) {
      final JavadocTag tag = tagIt.next();

      if (!tag.isThrowsTag()) {
        continue;
      }
      tagIt.remove();

      // Loop looking for matching throw
      final String documentedEx = tag.getFirstArg();
      final Token token = new Token(tag.getFirstArg(), tag.getLineNo(), tag.getColumnNo());
      final AbstractClassInfo documentedCI = createClassInfo(token, getCurrentClassName());
      final boolean found =
          foundThrows.contains(documentedEx) || isInThrows(throwsList, documentedCI, foundThrows);

      // Handle extra JavadocTag.
      if (!found) {
        boolean reqd = true;
        if (allowUndeclaredRTE) {
          reqd = !isUnchecked(documentedCI.getClazz());
        }

        if (reqd && validateThrows) {
          log(
              tag.getLineNo(),
              tag.getColumnNo(),
              MSG_UNUSED_TAG,
              JavadocTagInfo.THROWS.getText(),
              tag.getFirstArg());
        }
      }
    }
    // Now dump out all throws without tags :- unless
    // the user has chosen to suppress these problems
    if (!allowMissingThrowsTags && reportExpectedTags) {
      for (ExceptionInfo ei : throwsList) {
        if (!ei.isFound()) {
          final Token fi = ei.getName();
          log(
              fi.getLineNo(),
              fi.getColumnNo(),
              MSG_EXCPECTED_TAG,
              JavadocTagInfo.THROWS.getText(),
              fi.getText());
        }
      }
    }
  }
  public void testNextToken() {
    String script = "   bean = * com;\n    bean2 = * blablabla();\n \n   \n\r \r\n";
    ScriptTokenizer tokenizer =
        new ScriptTokenizer(new ScriptTokenizerInputBuffer(new StringReader(script)));

    Token token = tokenizer.nextToken();
    assertEquals(1, token.getLineNo());
    assertEquals(4, token.length());
    assertEquals(3, token.getFrom());
    assertEquals('b', token.getBuffer()[token.getFrom()]);
    assertEquals('e', token.getBuffer()[token.getFrom() + 1]);
    assertEquals('a', token.getBuffer()[token.getFrom() + 2]);
    assertEquals('n', token.getBuffer()[token.getFrom() + 3]);

    assertEquals(4, token.getCharNoBefore());
    //        assertEquals(, );

    token = tokenizer.nextToken();
    assertEquals(1, token.getLineNo());
    assertEquals(1, token.length());
    assertEquals(8, token.getFrom());
    assertEquals('=', token.getBuffer()[token.getFrom()]);

    token = tokenizer.nextToken();
    assertEquals(1, token.getLineNo());
    assertEquals(1, token.length());
    assertEquals(10, token.getFrom());
    assertEquals('*', token.getBuffer()[token.getFrom()]);

    token = tokenizer.nextToken();
    assertEquals(1, token.getLineNo());
    assertEquals(3, token.length());
    assertEquals(12, token.getFrom());
    assertEquals('c', token.getBuffer()[token.getFrom()]);
    assertEquals('o', token.getBuffer()[token.getFrom() + 1]);
    assertEquals('m', token.getBuffer()[token.getFrom() + 2]);

    token = tokenizer.nextToken();
    assertEquals(1, token.getLineNo());
    assertEquals(1, token.length());
    assertEquals(15, token.getFrom());
    assertEquals(';', token.getBuffer()[token.getFrom()]);

    // line 2
    token = tokenizer.nextToken();
    assertEquals(2, token.getLineNo());
    assertEquals(5, token.length());
    assertEquals(21, token.getFrom());
    assertEquals('b', token.getBuffer()[token.getFrom()]);
    assertEquals('e', token.getBuffer()[token.getFrom() + 1]);
    assertEquals('a', token.getBuffer()[token.getFrom() + 2]);
    assertEquals('n', token.getBuffer()[token.getFrom() + 3]);
    assertEquals('2', token.getBuffer()[token.getFrom() + 4]);

    token = tokenizer.nextToken();
    assertEquals(2, token.getLineNo());
    assertEquals(1, token.length());
    assertEquals(27, token.getFrom());
    assertEquals('=', token.getBuffer()[token.getFrom()]);

    token = tokenizer.nextToken();
    assertEquals(2, token.getLineNo());
    assertEquals(1, token.length());
    assertEquals(29, token.getFrom());
    assertEquals('*', token.getBuffer()[token.getFrom()]);

    token = tokenizer.nextToken();
    assertEquals(2, token.getLineNo());
    assertEquals(9, token.length());
    assertEquals(31, token.getFrom());
    assertEquals('b', token.getBuffer()[token.getFrom()]);
    assertEquals('l', token.getBuffer()[token.getFrom() + 1]);
    assertEquals('a', token.getBuffer()[token.getFrom() + 2]);
    assertEquals('b', token.getBuffer()[token.getFrom() + 3]);
    assertEquals('l', token.getBuffer()[token.getFrom() + 4]);
    assertEquals('a', token.getBuffer()[token.getFrom() + 5]);
    assertEquals('b', token.getBuffer()[token.getFrom() + 6]);
    assertEquals('l', token.getBuffer()[token.getFrom() + 7]);
    assertEquals('a', token.getBuffer()[token.getFrom() + 8]);

    token = tokenizer.nextToken();
    assertEquals(2, token.getLineNo());
    assertEquals(1, token.length());
    assertEquals(40, token.getFrom());
    assertEquals('(', token.getBuffer()[token.getFrom()]);

    token = tokenizer.nextToken();
    assertEquals(2, token.getLineNo());
    assertEquals(1, token.length());
    assertEquals(41, token.getFrom());
    assertEquals(')', token.getBuffer()[token.getFrom()]);

    token = tokenizer.nextToken();
    assertEquals(2, token.getLineNo());
    assertEquals(1, token.length());
    assertEquals(42, token.getFrom());
    assertEquals(';', token.getBuffer()[token.getFrom()]);

    token = tokenizer.nextToken();
    assertNull(token);
  }