Merge "Follow rename of tagsouplib to tagsoup" am: 2328a856db am: f41e16b37b am: 7b989d85ce  -s ours
am: 8fd9d692aa  -s ours

Change-Id: Ib5175e2dee41d05bcc22626a10eff7e07011ef62
diff --git a/src/com/google/doclava/Doclava.java b/src/com/google/doclava/Doclava.java
index e1c92f1..49ea37c 100644
--- a/src/com/google/doclava/Doclava.java
+++ b/src/com/google/doclava/Doclava.java
@@ -773,6 +773,9 @@
     if (option.equals("-showAnnotation")) {
       return 2;
     }
+    if (option.equals("-hideAnnotation")) {
+      return 2;
+    }
     if (option.equals("-showAnnotationOverridesVisibility")) {
       return 1;
     }
diff --git a/src/com/google/doclava/MethodInfo.java b/src/com/google/doclava/MethodInfo.java
index e5761c1..6a7fbb8 100644
--- a/src/com/google/doclava/MethodInfo.java
+++ b/src/com/google/doclava/MethodInfo.java
@@ -889,8 +889,6 @@
           + " to " + mInfo.scope());
     }
 
-    // Changing the deprecated annotation is binary- and source-compatible, but
-    // we still need to log the API change.
     if (!isDeprecated() == mInfo.isDeprecated()) {
       Errors.error(Errors.CHANGED_DEPRECATED, mInfo.position(), "Method "
           + mInfo.prettyQualifiedSignature() + " has changed deprecation state " + isDeprecated()
@@ -898,14 +896,16 @@
       consistent = false;
     }
 
-    // Changing the synchronized modifier is binary- and source-compatible (see
-    // JLS 3 13.4.20), but we still need to log the API change.
+    // see JLS 3 13.4.20 "Adding or deleting a synchronized modifier of a method does not break "
+    // "compatibility with existing binaries."
+    /*
     if (mIsSynchronized != mInfo.mIsSynchronized) {
       Errors.error(Errors.CHANGED_SYNCHRONIZED, mInfo.position(), "Method " + mInfo.qualifiedName()
           + " has changed 'synchronized' qualifier from " + mIsSynchronized + " to "
           + mInfo.mIsSynchronized);
       consistent = false;
     }
+    */
 
     for (ClassInfo exception : thrownExceptions()) {
       if (!mInfo.throwsException(exception)) {
diff --git a/src/com/google/doclava/Stubs.java b/src/com/google/doclava/Stubs.java
index 4dc859d..b7e8f8a 100644
--- a/src/com/google/doclava/Stubs.java
+++ b/src/com/google/doclava/Stubs.java
@@ -639,6 +639,7 @@
     int N = enumConstants.size();
     int i = 0;
     for (FieldInfo field : enumConstants) {
+      writeAnnotations(stream, field.annotations(), field.isDeprecated());
       if (!field.constantLiteralValue().equals("null")) {
         stream.println(field.name() + "(" + field.constantLiteralValue()
             + (i == N - 1 ? ");" : "),"));
@@ -1017,6 +1018,14 @@
     stream.println(";");
   }
 
+  public static void writeXml(PrintStream xmlWriter, Collection<PackageInfo> pkgs, boolean strip) {
+    if (strip) {
+      Stubs.writeXml(xmlWriter, pkgs);
+    } else {
+      Stubs.writeXml(xmlWriter, pkgs, c -> true);
+    }
+  }
+
   public static void writeXml(PrintStream xmlWriter, Collection<PackageInfo> pkgs,
       Predicate<ClassInfo> notStrippable) {
 
diff --git a/src/com/google/doclava/apicheck/ApiCheck.java b/src/com/google/doclava/apicheck/ApiCheck.java
index 5dda8d2..5c5229a 100644
--- a/src/com/google/doclava/apicheck/ApiCheck.java
+++ b/src/com/google/doclava/apicheck/ApiCheck.java
@@ -71,7 +71,11 @@
     } else if (originalArgs.length == 4 && "-new_api".equals(originalArgs[0])) {
       // command syntax: -new_api oldapi.txt newapi.txt diff.xml
       // TODO: Support reading in other options for new_api, such as ignored classes/packages.
-      System.exit(newApi(originalArgs[1], originalArgs[2], originalArgs[3]));
+      System.exit(newApi(originalArgs[1], originalArgs[2], originalArgs[3], true));
+    } else if (originalArgs.length == 4 && "-new_api_no_strip".equals(originalArgs[0])) {
+      // command syntax: -new_api oldapi.txt newapi.txt diff.xml
+      // TODO: Support reading in other options for new_api, such as ignored classes/packages.
+      System.exit(newApi(originalArgs[1], originalArgs[2], originalArgs[3], false));
     } else {
       ApiCheck acheck = new ApiCheck();
       Report report = acheck.checkApi(originalArgs);
@@ -288,7 +292,7 @@
       System.err.println("can't open file: " + dst);
     }
 
-    Stubs.writeXml(apiWriter, api.getPackages().values(), c -> true);
+    Stubs.writeXml(apiWriter, api.getPackages().values(), strip);
 
     return 0;
   }
@@ -298,9 +302,10 @@
    * @param origApiPath path to old API text file
    * @param newApiPath path to new API text file
    * @param outputPath output XML path for the generated diff
+   * @param strip true if any unknown classes should be stripped from the output, false otherwise
    * @return
    */
-  static int newApi(String origApiPath, String newApiPath, String outputPath) {
+  static int newApi(String origApiPath, String newApiPath, String outputPath, boolean strip) {
     ApiInfo origApi, newApi;
     try {
       origApi = parseApi(origApiPath);
@@ -324,7 +329,7 @@
       } catch (FileNotFoundException ex) {
         System.err.println("can't open file: " + outputPath);
       }
-      Stubs.writeXml(apiWriter, pkgInfoDiff);
+      Stubs.writeXml(apiWriter, pkgInfoDiff, strip);
     } else {
       System.err.println("No API change detected, not generating diff.");
     }
diff --git a/test/doclava/ApiCheckTest.java b/test/doclava/ApiCheckTest.java
index ce0464a..98cb020 100644
--- a/test/doclava/ApiCheckTest.java
+++ b/test/doclava/ApiCheckTest.java
@@ -17,31 +17,26 @@
 package doclava;
 
 import com.google.doclava.Errors;
+import com.google.doclava.Errors.Error;
 import com.google.doclava.Errors.ErrorMessage;
 import com.google.doclava.apicheck.ApiCheck;
 import com.google.doclava.apicheck.ApiCheck.Report;
 
-import org.junit.Before;
-import org.junit.Test;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotSame;
-import static org.junit.Assert.assertTrue;
+import junit.framework.TestCase;
 
 import java.util.Iterator;
 
-public class ApiCheckTest {
-
-  @Before
+public class ApiCheckTest extends TestCase {
+  /**
+   * Clear all errors and make sure all future errors will be recorded.
+   */
   public void setUp() {
-    // Clear all errors and make sure all future errors will be recorded.
     Errors.clearErrors();
     for (Errors.Error error : Errors.sErrors) {
       Errors.setErrorLevel(error.code, Errors.ERROR);
     }
   }
 
-  @Test
   public void testEquivalentApi() {
     String[] args = { "test/api/medium.xml", "test/api/medium.xml" };
     ApiCheck apiCheck = new ApiCheck();
@@ -49,7 +44,6 @@
     assertEquals(report.errors().size(), 0);
   }
 
-  @Test
   public void testMethodReturnTypeChanged() {
     String[] args = { "test/api/return-type-changed-1.xml", "test/api/return-type-changed-2.xml" };
     ApiCheck apiCheck = new ApiCheck();
@@ -58,7 +52,6 @@
     assertEquals(Errors.CHANGED_TYPE, report.errors().iterator().next().error());
   }
 
-  @Test
   public void testMethodParameterChanged() {
     String[] args = { "test/api/parameter-changed-1.xml", "test/api/parameter-changed-2.xml" };
     ApiCheck apiCheck = new ApiCheck();
@@ -73,7 +66,6 @@
     assertTrue(m2.error().equals(Errors.ADDED_METHOD) || m2.error().equals(Errors.REMOVED_METHOD));
   }
 
-  @Test
   public void testConstructorParameterChanged() {
     String[] args = { "test/api/parameter-changed-1.xml", "test/api/parameter-changed-3.xml" };
     ApiCheck apiCheck = new ApiCheck();
@@ -87,7 +79,6 @@
     assertTrue(m2.error().equals(Errors.ADDED_METHOD) || m2.error().equals(Errors.REMOVED_METHOD));
   }
 
-  @Test
   public void testAddedClass() {
     String[] args = { "test/api/simple.xml", "test/api/added-class.xml" };
     ApiCheck apiCheck = new ApiCheck();
@@ -96,7 +87,6 @@
     assertEquals(Errors.ADDED_CLASS, report.errors().iterator().next().error());
   }
 
-  @Test
   public void testRemovedClass() {
     String[] args = { "test/api/added-class.xml", "test/api/simple.xml" };
     ApiCheck apiCheck = new ApiCheck();
@@ -105,7 +95,6 @@
     assertEquals(Errors.REMOVED_CLASS, report.errors().iterator().next().error());
   }
 
-  @Test
   public void testRemovedDeprecatedClass() {
     String[] args = { "test/api/added-deprecated-class.xml", "test/api/simple.xml" };
     ApiCheck apiCheck = new ApiCheck();
@@ -114,7 +103,6 @@
     assertEquals(Errors.REMOVED_DEPRECATED_CLASS, report.errors().iterator().next().error());
   }
 
-  @Test
   public void testChangedSuper() {
     String[] args = { "test/api/simple.xml", "test/api/changed-super.xml" };
     ApiCheck apiCheck = new ApiCheck();
@@ -123,7 +111,6 @@
     assertEquals(Errors.CHANGED_SUPERCLASS, report.errors().iterator().next().error());
   }
 
-  @Test
   public void testChangedAssignableReturn() {
     String[] args = {
         "test/api/changed-assignable-return-1.xml",
@@ -135,7 +122,6 @@
     assertEquals(Errors.CHANGED_TYPE, report.errors().iterator().next().error());
   }
 
-  @Test
   public void testInsertedSuper() {
     String[] args = { "test/api/inserted-super-1.xml", "test/api/inserted-super-2.xml" };
     ApiCheck apiCheck = new ApiCheck();
@@ -143,7 +129,6 @@
     assertEquals(0, report.errors().size());
   }
 
-  @Test
   public void testAddedInterface() {
     String[] args = { "test/api/removed-interface.xml", "test/api/medium.xml" };
     ApiCheck apiCheck = new ApiCheck();
@@ -152,7 +137,6 @@
     assertEquals(Errors.ADDED_INTERFACE, report.errors().iterator().next().error());
   }
 
-  @Test
   public void testRemovedInterface() {
     String[] args = { "test/api/medium.xml", "test/api/removed-interface.xml" };
     ApiCheck apiCheck = new ApiCheck();
@@ -161,7 +145,6 @@
     assertEquals(Errors.REMOVED_INTERFACE, report.errors().iterator().next().error());
   }
 
-  @Test
   public void testChangedAbstractClass() {
     String[] args = { "test/api/medium.xml", "test/api/changed-abstract.xml" };
     ApiCheck apiCheck = new ApiCheck();
@@ -170,7 +153,6 @@
     assertEquals(Errors.CHANGED_ABSTRACT, report.errors().iterator().next().error());
   }
 
-  @Test
   public void testChangedAbstractClass2() {
     String[] args = { "test/api/changed-abstract.xml", "test/api/medium.xml" };
     ApiCheck apiCheck = new ApiCheck();
@@ -179,7 +161,6 @@
     assertEquals(Errors.CHANGED_ABSTRACT, report.errors().iterator().next().error());
   }
 
-  @Test
   public void testChangedAbstractMethod() {
     String[] args = { "test/api/medium.xml", "test/api/changed-abstract2.xml" };
     ApiCheck apiCheck = new ApiCheck();
@@ -188,7 +169,6 @@
     assertEquals(Errors.CHANGED_ABSTRACT, report.errors().iterator().next().error());
   }
 
-  @Test
   public void testChangedAbstractMethod2() {
     String[] args = { "test/api/changed-abstract2.xml", "test/api/medium.xml" };
     ApiCheck apiCheck = new ApiCheck();
@@ -197,7 +177,6 @@
     assertEquals(Errors.CHANGED_ABSTRACT, report.errors().iterator().next().error());
   }
 
-  @Test
   public void testAddedPackage() {
     String[] args = { "test/api/medium.xml", "test/api/added-package.xml" };
     ApiCheck apiCheck = new ApiCheck();
@@ -206,7 +185,6 @@
     assertEquals(Errors.ADDED_PACKAGE, report.errors().iterator().next().error());
   }
 
-  @Test
   public void testRemovedPackage() {
     String[] args = { "test/api/added-package.xml", "test/api/medium.xml" };
     ApiCheck apiCheck = new ApiCheck();
@@ -215,7 +193,6 @@
     assertEquals(Errors.REMOVED_PACKAGE, report.errors().iterator().next().error());
   }
 
-  @Test
   public void testChangedValue() {
     String[] args = { "test/api/constants.xml", "test/api/changed-value.xml" };
     ApiCheck apiCheck = new ApiCheck();
@@ -224,7 +201,6 @@
     assertEquals(Errors.CHANGED_VALUE, report.errors().iterator().next().error());
   }
 
-  @Test
   public void testChangedValue2() {
     String[] args = { "test/api/constants.xml", "test/api/changed-value2.xml" };
     ApiCheck apiCheck = new ApiCheck();
@@ -233,7 +209,6 @@
     assertEquals(Errors.CHANGED_VALUE, report.errors().iterator().next().error());
   }
 
-  @Test
   public void testChangedType() {
     String[] args = { "test/api/constants.xml", "test/api/changed-type.xml" };
     ApiCheck apiCheck = new ApiCheck();
@@ -242,7 +217,6 @@
     assertEquals(Errors.CHANGED_TYPE, report.errors().iterator().next().error());
   }
 
-  @Test
   public void testAddedFinalField() {
     String[] args = { "test/api/constants.xml", "test/api/changed-final.xml" };
     ApiCheck apiCheck = new ApiCheck();
@@ -251,7 +225,6 @@
     assertEquals(Errors.ADDED_FINAL, report.errors().iterator().next().error());
   }
 
-  @Test
   public void testAddedFinalMethod() {
     String[] args = { "test/api/constants.xml", "test/api/changed-final2.xml" };
     ApiCheck apiCheck = new ApiCheck();
@@ -260,7 +233,6 @@
     assertEquals(Errors.ADDED_FINAL, report.errors().iterator().next().error());
   }
 
-  @Test
   public void testAddedFinalClass() {
     String[] args = { "test/api/constants.xml", "test/api/changed-final3.xml" };
     ApiCheck apiCheck = new ApiCheck();
@@ -270,7 +242,6 @@
     assertEquals(Errors.ADDED_FINAL, report.errors().iterator().next().error());
   }
 
-  @Test
   public void testRemovedFinalClass() {
     String[] args = { "test/api/changed-final3.xml", "test/api/constants.xml" };
     ApiCheck apiCheck = new ApiCheck();
@@ -280,7 +251,6 @@
     assertEquals(Errors.REMOVED_FINAL, report.errors().iterator().next().error());
   }
 
-  @Test
   public void testAddedField() {
     String[] args = { "test/api/constants.xml", "test/api/added-field.xml" };
     ApiCheck apiCheck = new ApiCheck();
@@ -289,7 +259,6 @@
     assertEquals(Errors.ADDED_FIELD, report.errors().iterator().next().error());
   }
 
-  @Test
   public void testRemovedField() {
     String[] args = { "test/api/added-field.xml", "test/api/constants.xml" };
     ApiCheck apiCheck = new ApiCheck();
@@ -298,7 +267,6 @@
     assertEquals(Errors.REMOVED_FIELD, report.errors().iterator().next().error());
   }
 
-  @Test
   public void testRemovedDeprecatedField() {
     String[] args = { "test/api/added-deprecated-field.xml", "test/api/constants.xml" };
     ApiCheck apiCheck = new ApiCheck();
@@ -307,7 +275,6 @@
     assertEquals(Errors.REMOVED_DEPRECATED_FIELD, report.errors().iterator().next().error());
   }
 
-  @Test
   public void testAddedMethod() {
     String[] args = { "test/api/constants.xml", "test/api/added-method.xml" };
     ApiCheck apiCheck = new ApiCheck();
@@ -316,7 +283,6 @@
     assertEquals(Errors.ADDED_METHOD, report.errors().iterator().next().error());
   }
 
-  @Test
   public void testRemovedMethod() {
     String[] args = { "test/api/added-method.xml", "test/api/constants.xml" };
     ApiCheck apiCheck = new ApiCheck();
@@ -325,7 +291,6 @@
     assertEquals(Errors.REMOVED_METHOD, report.errors().iterator().next().error());
   }
 
-  @Test
   public void testRemovedDeprecatedMethod() {
     String[] args = { "test/api/added-deprecated-method.xml", "test/api/constants.xml" };
     ApiCheck apiCheck = new ApiCheck();
@@ -334,7 +299,6 @@
     assertEquals(Errors.REMOVED_DEPRECATED_METHOD, report.errors().iterator().next().error());
   }
 
-  @Test
   public void testChangedStaticMethod() {
     String[] args = { "test/api/constants.xml", "test/api/changed-static.xml" };
     ApiCheck apiCheck = new ApiCheck();
@@ -343,7 +307,6 @@
     assertEquals(Errors.CHANGED_STATIC, report.errors().iterator().next().error());
   }
 
-  @Test
   public void testChangedStaticClass() {
     String[] args = { "test/api/constants.xml", "test/api/changed-static2.xml" };
     ApiCheck apiCheck = new ApiCheck();
@@ -352,7 +315,6 @@
     assertEquals(Errors.CHANGED_STATIC, report.errors().iterator().next().error());
   }
 
-  @Test
   public void testChangedStaticField() {
     String[] args = { "test/api/constants.xml", "test/api/changed-static3.xml" };
     ApiCheck apiCheck = new ApiCheck();
@@ -361,7 +323,6 @@
     assertEquals(Errors.CHANGED_STATIC, report.errors().iterator().next().error());
   }
 
-  @Test
   public void testChangedTransient() {
     String[] args = { "test/api/constants.xml", "test/api/changed-transient.xml" };
     ApiCheck apiCheck = new ApiCheck();
@@ -370,15 +331,13 @@
     assertEquals(Errors.CHANGED_TRANSIENT, report.errors().iterator().next().error());
   }
 
-  @Test
   public void testChangedSynchronized() {
     String[] args = { "test/api/constants.xml", "test/api/changed-synchronized.xml" };
     ApiCheck apiCheck = new ApiCheck();
     Report report = apiCheck.checkApi(args);
-    assertEquals(1, report.errors().size());
+    assertEquals(0, report.errors().size());
   }
 
-  @Test
   public void testChangedVolatile() {
     String[] args = { "test/api/constants.xml", "test/api/changed-volatile.xml" };
     ApiCheck apiCheck = new ApiCheck();
@@ -387,7 +346,6 @@
     assertEquals(Errors.CHANGED_VOLATILE, report.errors().iterator().next().error());
   }
 
-  @Test
   public void testChangedNative() {
     String[] args = { "test/api/constants.xml", "test/api/changed-native.xml" };
     ApiCheck apiCheck = new ApiCheck();
@@ -396,7 +354,6 @@
     assertEquals(Errors.CHANGED_NATIVE, report.errors().iterator().next().error());
   }
 
-  @Test
   public void testChangedScopeMethod() {
     String[] args = { "test/api/constants.xml", "test/api/changed-scope.xml" };
     ApiCheck apiCheck = new ApiCheck();
@@ -405,7 +362,6 @@
     assertEquals(Errors.CHANGED_SCOPE, report.errors().iterator().next().error());
   }
 
-  @Test
   public void testChangedScopeClass() {
     String[] args = { "test/api/changed-scope.xml", "test/api/constants.xml" };
     ApiCheck apiCheck = new ApiCheck();
@@ -414,7 +370,6 @@
     assertEquals(Errors.CHANGED_SCOPE, report.errors().iterator().next().error());
   }
 
-  @Test
   public void testChangedScopeClass2() {
     String[] args = { "test/api/constants.xml", "test/api/changed-scope2.xml" };
     ApiCheck apiCheck = new ApiCheck();
@@ -423,7 +378,6 @@
     assertEquals(Errors.CHANGED_SCOPE, report.errors().iterator().next().error());
   }
 
-  @Test
   public void testChangedScopeField() {
     String[] args = { "test/api/constants.xml", "test/api/changed-scope3.xml" };
     ApiCheck apiCheck = new ApiCheck();
@@ -432,7 +386,6 @@
     assertEquals(Errors.CHANGED_SCOPE, report.errors().iterator().next().error());
   }
 
-  @Test
   public void testChangedConstructorScope() {
     String[] args = { "test/api/constants.xml", "test/api/changed-scope4.xml" };
     ApiCheck apiCheck = new ApiCheck();
@@ -441,7 +394,6 @@
     assertEquals(Errors.CHANGED_SCOPE, report.errors().iterator().next().error());
   }
 
-  @Test
   public void testChangedMethodThrows() {
     String[] args = { "test/api/throws.xml", "test/api/removed-exception.xml" };
     ApiCheck apiCheck = new ApiCheck();
@@ -450,7 +402,6 @@
     assertEquals(Errors.CHANGED_THROWS, report.errors().iterator().next().error());
   }
 
-  @Test
   public void testChangedMethodThrows2() {
     String[] args = { "test/api/removed-exception.xml", "test/api/throws.xml" };
     ApiCheck apiCheck = new ApiCheck();
@@ -459,7 +410,6 @@
     assertEquals(Errors.CHANGED_THROWS, report.errors().iterator().next().error());
   }
 
-  @Test
   public void testChangedConstructorThrows() {
     String[] args = { "test/api/throws.xml", "test/api/added-exception.xml" };
     ApiCheck apiCheck = new ApiCheck();
@@ -468,7 +418,6 @@
     assertEquals(Errors.CHANGED_THROWS, report.errors().iterator().next().error());
   }
 
-  @Test
   public void testChangedConstructorThrows2() {
     String[] args = { "test/api/added-exception.xml", "test/api/throws.xml" };
     ApiCheck apiCheck = new ApiCheck();
@@ -477,7 +426,6 @@
     assertEquals(Errors.CHANGED_THROWS, report.errors().iterator().next().error());
   }
 
-  @Test
   public void testChangedMethodDeprecated() {
     String[] args = { "test/api/constants.xml", "test/api/changed-deprecated.xml" };
     ApiCheck apiCheck = new ApiCheck();
@@ -486,7 +434,6 @@
     assertEquals(Errors.CHANGED_DEPRECATED, report.errors().iterator().next().error());
   }
 
-  @Test
   public void testChangedConstructorDeprecated() {
     String[] args = { "test/api/constants.xml", "test/api/changed-deprecated2.xml" };
     ApiCheck apiCheck = new ApiCheck();
@@ -495,7 +442,6 @@
     assertEquals(Errors.CHANGED_DEPRECATED, report.errors().iterator().next().error());
   }
 
-  @Test
   public void testChangedFieldDeprecated() {
     String[] args = { "test/api/constants.xml", "test/api/changed-deprecated3.xml" };
     ApiCheck apiCheck = new ApiCheck();
@@ -504,7 +450,6 @@
     assertEquals(Errors.CHANGED_DEPRECATED, report.errors().iterator().next().error());
   }
 
-  @Test
   public void testChangedClassToInterface() {
     String[] args = { "test/api/changed-class-info2.xml", "test/api/changed-class-info.xml" };
     ApiCheck apiCheck = new ApiCheck();
@@ -513,7 +458,6 @@
     assertEquals(Errors.CHANGED_CLASS, report.errors().iterator().next().error());
   }
 
-  @Test
   public void testChangedInterfaceToClass() {
     String[] args = { "test/api/changed-class-info.xml", "test/api/changed-class-info2.xml" };
     ApiCheck apiCheck = new ApiCheck();