Simplify mismatched annotation check, update prebuilt

Removes unnecessary description check, unused skipNoJavadoc
option, and multi-line description handling. Fixes issue
where description was required.

Bug: 32998581
Test: ran checkstyle on compat/*
Change-Id: Ifc3d71a301e3d315db6bd9f3be8b7573c9d8a43a
diff --git a/development/checkstyle/prebuilt/com.android.support.checkstyle.jar b/development/checkstyle/prebuilt/com.android.support.checkstyle.jar
index 1ba9941..180b19d 100644
--- a/development/checkstyle/prebuilt/com.android.support.checkstyle.jar
+++ b/development/checkstyle/prebuilt/com.android.support.checkstyle.jar
Binary files differ
diff --git a/development/checkstyle/src/com/android/support/checkstyle/MismatchedAnnotationCheck.java b/development/checkstyle/src/com/android/support/checkstyle/MismatchedAnnotationCheck.java
index 654901f..56bbe2e 100644
--- a/development/checkstyle/src/com/android/support/checkstyle/MismatchedAnnotationCheck.java
+++ b/development/checkstyle/src/com/android/support/checkstyle/MismatchedAnnotationCheck.java
@@ -26,7 +26,6 @@
 import com.puppycrawl.tools.checkstyle.utils.AnnotationUtility;
 import com.puppycrawl.tools.checkstyle.utils.CommonUtils;
 
-import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
 /**
@@ -54,24 +53,6 @@
  *                          and {@literal @}hide Javadoc tag." />
  *     </module>
  * </pre>
- * <p>
- * Additionally, you can configure this check with skipNoJavadoc option to
- * ignore cases when JavaDoc is missing and the annotation is present::
- * <pre>
- *     &lt;property name="skipNoJavadoc" value="true" /&gt;
- * </pre>
- * <p>
- * Examples of validating source code with skipNoJavadoc:
- * <pre>
- * <code>
- * {@literal @}RestrictTo
- * public static final int MY_CONST = 123456; // no violation
- *
- * &#47;** This javadoc is missing hide tag. *&#47;
- * {@literal @}RestrictTo
- * public static final int COUNTER = 10; // violation as javadoc exists
- * </code>
- * </pre>
  */
 @SuppressWarnings("unused")
 public final class MismatchedAnnotationCheck extends AbstractCheck {
@@ -82,25 +63,12 @@
     /** Key for the warning message text by check properties. */
     private static final String MSG_KEY_JAVADOC_MISSING = "javadoc.missing";
 
-    /** Compiled regexp to look for a continuation of the comment. */
-    private static final Pattern MATCH_HIDE_MULTILINE_CONT =
-            CommonUtils.createPattern("(\\*/|@|[^\\s\\*])");
-
-    /** Multiline finished at end of comment. */
-    private static final String END_JAVADOC = "*/";
-
-    /** Multiline finished at next Javadoc. */
-    private static final String NEXT_TAG = "@";
-
     /** Javadoc tag. */
     private String mTag;
 
-    /** Compiled regexp to match Javadoc tag with no argument. */
+    /** Pattern for matching javadoc tag. */
     private Pattern mMatchTag;
 
-    /** Compiled regexp to match first part of multilineJavadoc tags. */
-    private Pattern mMatchTagMultilineStart;
-
     /** Simple annotation name. */
     private String mAnnotationSimpleName;
 
@@ -110,19 +78,6 @@
     /** Key for the warning message text specified by check properties. */
     private String mMessageKey;
 
-    /** Is tagged element valid without javadoc? */
-    private boolean mSkipNoJavadoc;
-
-    /**
-     * Sets skipJavadoc value.
-     *
-     * @param skipNoJavadoc user's value of skipJavadoc
-     */
-    @SuppressWarnings("unused")
-    public void setSkipNoJavadoc(boolean skipNoJavadoc) {
-        mSkipNoJavadoc = skipNoJavadoc;
-    }
-
     @Override
     public int[] getDefaultTokens() {
         return getAcceptableTokens();
@@ -136,9 +91,7 @@
     @SuppressWarnings("unused")
     public void setTag(String tag) {
         mTag = tag;
-
-        mMatchTag = CommonUtils.createPattern("@(" + tag + ")\\s+\\S");
-        mMatchTagMultilineStart = CommonUtils.createPattern("@(" + tag + ")\\s*$");
+        mMatchTag = CommonUtils.createPattern("@" + tag + "\\s");
     }
 
     /**
@@ -153,7 +106,7 @@
         // Extract the simple class name.
         final int lastDollar = annotation.lastIndexOf('$');
         final int lastSep = lastDollar >= 0 ? lastDollar : annotation.lastIndexOf('.');
-        mAnnotationSimpleName = annotation.substring(lastSep);
+        mAnnotationSimpleName = annotation.substring(lastSep + 1);
     }
 
 
@@ -189,15 +142,11 @@
 
     @Override
     public void visitToken(final DetailAST ast) {
-        final TextBlock javadoc = getFileContents().getJavadocBefore(ast.getLineNo());
-
         final boolean containsAnnotation =
                 AnnotationUtility.containsAnnotation(ast, mAnnotationSimpleName)
                         || AnnotationUtility.containsAnnotation(ast, mAnnotation);
-
-        final boolean containsJavadocTag = containsJavadocTag(javadoc);
-
-        if (containsAnnotation ^ containsJavadocTag && !(mSkipNoJavadoc && javadoc == null)) {
+        final boolean containsJavadocTag = containsJavadocTag(ast);
+        if (containsAnnotation ^ containsJavadocTag) {
             log(ast.getLineNo(), mMessageKey);
         }
     }
@@ -205,76 +154,29 @@
     /**
      * Checks to see if the text block contains the tag.
      *
-     * @param javadoc the javadoc of the AST
+     * @param ast the AST being visited
      * @return true if contains the tag
      */
-    private boolean containsJavadocTag(final TextBlock javadoc) {
+    private boolean containsJavadocTag(final DetailAST ast) {
+        final TextBlock javadoc = getFileContents().getJavadocBefore(ast.getLineNo());
         if (javadoc == null) {
             return false;
         }
 
-        final String[] lines = javadoc.getText();
         int currentLine = javadoc.getStartLineNo();
-
         boolean found = false;
 
-        for (int i = 0; i < lines.length; i++) {
-            final String line = lines[i];
-            final Matcher javadocNoArgMatcher = mMatchTag.matcher(line);
-            if (javadocNoArgMatcher.find()) {
+        final String[] lines = javadoc.getText();
+        for (String line : lines) {
+            if (mMatchTag.matcher(line).find()) {
                 if (found) {
                     log(currentLine, MSG_KEY_JAVADOC_DUPLICATE_TAG, mTag);
                 }
                 found = true;
-            } else {
-                final Matcher noArgMultilineStart = mMatchTagMultilineStart.matcher(line);
-                if (noArgMultilineStart.find()) {
-                    found = checkTagAtTheRestOfComment(lines, found, currentLine, i);
-                }
             }
             currentLine++;
         }
 
         return found;
     }
-
-    /**
-     * Looks for the rest of the comment if all we saw was the tag and the
-     * name. Stops when we see '*' (end of Javadoc), '{@literal @}' (start of
-     * next tag), or anything that's not whitespace or '*' characters.
-     *
-     * @param lines all lines
-     * @param foundBefore flag from parent method
-     * @param currentLine current line
-     * @param index som index
-     * @return true if Tag is found
-     */
-    private boolean checkTagAtTheRestOfComment(String[] lines, boolean foundBefore, int currentLine,
-            int index) {
-        boolean found = false;
-
-        for (int reindex = index + 1; reindex < lines.length;) {
-            final Matcher multilineCont = MATCH_HIDE_MULTILINE_CONT.matcher(lines[reindex]);
-            if (multilineCont.find()) {
-                reindex = lines.length;
-
-                final String lFin = multilineCont.group(1);
-                if (lFin.equals(NEXT_TAG) || lFin.equals(END_JAVADOC)) {
-                    log(currentLine, MSG_KEY_JAVADOC_MISSING);
-                    if (foundBefore) {
-                        log(currentLine, MSG_KEY_JAVADOC_DUPLICATE_TAG, mTag);
-                    }
-                    found = true;
-                } else {
-                    if (foundBefore) {
-                        log(currentLine, MSG_KEY_JAVADOC_DUPLICATE_TAG, mTag);
-                    }
-                    found = true;
-                }
-            }
-            reindex++;
-        }
-
-        return found;
-    }
 }