Promote NestingCounter to a top-level type

and use it from JavadocWriter.

MOE_MIGRATED_REVID=133601793
diff --git a/core/src/main/java/com/google/googlejavaformat/java/javadoc/JavadocLexer.java b/core/src/main/java/com/google/googlejavaformat/java/javadoc/JavadocLexer.java
index 86f8216..0f9f835 100644
--- a/core/src/main/java/com/google/googlejavaformat/java/javadoc/JavadocLexer.java
+++ b/core/src/main/java/com/google/googlejavaformat/java/javadoc/JavadocLexer.java
@@ -545,29 +545,5 @@
     return compile(format("^</(?:%s)\\b[^>]*>", namePattern), CASE_INSENSITIVE);
   }
 
-  private static final class NestingCounter {
-    private int value;
-
-    void increment() {
-      value++;
-    }
-
-    void incrementIfPositive() {
-      if (value > 0) {
-        value++;
-      }
-    }
-
-    void decrementIfPositive() {
-      if (value > 0) {
-        value--;
-      }
-    }
-
-    boolean isPositive() {
-      return value > 0;
-    }
-  }
-
   static class LexException extends Exception {}
 }
diff --git a/core/src/main/java/com/google/googlejavaformat/java/javadoc/JavadocWriter.java b/core/src/main/java/com/google/googlejavaformat/java/javadoc/JavadocWriter.java
index 02d2973..8ce4bca 100644
--- a/core/src/main/java/com/google/googlejavaformat/java/javadoc/JavadocWriter.java
+++ b/core/src/main/java/com/google/googlejavaformat/java/javadoc/JavadocWriter.java
@@ -50,7 +50,7 @@
    */
   private boolean continuingListItemOfInnermostList;
   private boolean continuingFooterTag;
-  private int continuingListItemCount;
+  private final NestingCounter continuingListItemCount = new NestingCounter();
   private int remainingOnLine;
   private boolean atStartOfLine;
   private RequestedWhitespace requestedWhitespace = NONE;
@@ -102,7 +102,7 @@
      * currently know which of those tags are open.
      */
     continuingListItemOfInnermostList = false;
-    continuingListItemCount = 0;
+    continuingListItemCount.reset();
 
     if (!wroteAnythingSignificant) {
       // Javadoc consists solely of tags. This is frowned upon in general but OK for @Overrides.
@@ -130,9 +130,7 @@
   void writeListClose(Token token) {
     requestNewline();
 
-    if (continuingListItemCount > 0) {
-      continuingListItemCount--;
-    }
+    continuingListItemCount.decrementIfPositive();
     writeToken(token);
 
     // TODO(cushon): only if continuingListItemCount == 0?
@@ -144,13 +142,11 @@
 
     if (continuingListItemOfInnermostList) {
       continuingListItemOfInnermostList = false;
-      if (continuingListItemCount > 0) {
-        continuingListItemCount--;
-      }
+      continuingListItemCount.decrementIfPositive();
     }
     writeToken(token);
     continuingListItemOfInnermostList = true;
-    continuingListItemCount++;
+    continuingListItemCount.increment();
   }
 
   void writeHeaderOpen(Token token) {
@@ -288,7 +284,8 @@
       requestNewline();
     }
 
-    if (requestedWhitespace == BLANK_LINE && (continuingListItemCount > 0 || continuingFooterTag)) {
+    if (requestedWhitespace == BLANK_LINE
+        && (continuingListItemCount.isPositive() || continuingFooterTag)) {
       /*
        * We don't write blank lines inside lists or footer tags, even in cases where we otherwise
        * would (e.g., before a <p> tag). Justification: We don't write blank lines _between_ list
@@ -381,7 +378,7 @@
   }
 
   private int innerIndent() {
-    int innerIndent = continuingListItemCount * 4;
+    int innerIndent = continuingListItemCount.value() * 4;
     if (continuingFooterTag) {
       innerIndent += 4;
     }
diff --git a/core/src/main/java/com/google/googlejavaformat/java/javadoc/NestingCounter.java b/core/src/main/java/com/google/googlejavaformat/java/javadoc/NestingCounter.java
new file mode 100644
index 0000000..43e7125
--- /dev/null
+++ b/core/src/main/java/com/google/googlejavaformat/java/javadoc/NestingCounter.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright 2016 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License. You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
+ * the License.
+ */
+
+package com.google.googlejavaformat.java.javadoc;
+
+/** Mutable integer for tracking the level of nesting. */
+final class NestingCounter {
+  private int value;
+
+  int value() {
+    return value;
+  }
+
+  void increment() {
+    value++;
+  }
+
+  void incrementIfPositive() {
+    if (value > 0) {
+      value++;
+    }
+  }
+
+  void decrementIfPositive() {
+    if (value > 0) {
+      value--;
+    }
+  }
+
+  boolean isPositive() {
+    return value > 0;
+  }
+
+  void reset() {
+    value = 0;
+  }
+}