summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Duffin <paulduffin@google.com>2017-07-10 12:52:10 +0100
committerPaul Duffin <paulduffin@google.com>2017-07-12 10:20:10 +0100
commitfe5b873024f043079be99f427cf915c35ce184b1 (patch)
treeb8778c2e523e91bb3c28316a323315b47d694e03
parentfbcec82ee9c1d3370ef595956490340ac1eef134 (diff)
downloadplatform_external_doclava-fe5b873024f043079be99f427cf915c35ce184b1.tar.gz
platform_external_doclava-fe5b873024f043079be99f427cf915c35ce184b1.tar.bz2
platform_external_doclava-fe5b873024f043079be99f427cf915c35ce184b1.zip
Add -convert2xmlnostrip option
The apicheck -convert2xml option will not generate <implements> elements for interfaces that are not included in the api description being converted. That works fine when the input is a complete api description such as frameworks/base/api/current.txt but causes problems when the input describes an optional module, such as frameworks/base/legacy-test/api/legacy-test-current.txt. This adds an extra -convert2xmlnostrip option that will not do any stripping. Tested by using it to convert both files mentioned above. Verified that it had no impact on the api generated for current.txt and that it added the missing <implements> elements. Bug: 35192974 Test: see above Change-Id: I3d20c22ab40e7524f8c5050ce4b0e9610768dc7c
-rw-r--r--src/com/google/doclava/Stubs.java43
-rw-r--r--src/com/google/doclava/apicheck/ApiCheck.java9
2 files changed, 23 insertions, 29 deletions
diff --git a/src/com/google/doclava/Stubs.java b/src/com/google/doclava/Stubs.java
index 59ca505..479b5ae 100644
--- a/src/com/google/doclava/Stubs.java
+++ b/src/com/google/doclava/Stubs.java
@@ -863,7 +863,7 @@ public class Stubs {
* @return {@code true} if the tested method can be safely elided from the
* public API to conserve space.
*/
- static boolean methodIsOverride(HashSet<ClassInfo> notStrippable, MethodInfo mi) {
+ static boolean methodIsOverride(MethodInfo mi) {
// Abstract/static/final methods are always listed in the API description
if (mi.isAbstract() || mi.isStatic() || mi.isFinal()) {
return false;
@@ -1017,30 +1017,12 @@ public class Stubs {
stream.println(";");
}
- static void writeXML(PrintStream xmlWriter, HashMap<PackageInfo, List<ClassInfo>> allClasses,
- HashSet<ClassInfo> notStrippable) {
- // extract the set of packages, sort them by name, and write them out in that order
- Set<PackageInfo> allClassKeys = allClasses.keySet();
- PackageInfo[] allPackages = allClassKeys.toArray(new PackageInfo[allClassKeys.size()]);
- Arrays.sort(allPackages, PackageInfo.comparator);
-
- xmlWriter.println("<api>");
- for (PackageInfo pack : allPackages) {
- writePackageXML(xmlWriter, pack, allClasses.get(pack), notStrippable);
- }
- xmlWriter.println("</api>");
- }
+ public static void writeXml(PrintStream xmlWriter, Collection<PackageInfo> pkgs,
+ Predicate<ClassInfo> notStrippable) {
- public static void writeXml(PrintStream xmlWriter, Collection<PackageInfo> pkgs) {
final PackageInfo[] packages = pkgs.toArray(new PackageInfo[pkgs.size()]);
Arrays.sort(packages, PackageInfo.comparator);
- HashSet<ClassInfo> notStrippable = new HashSet();
- for (PackageInfo pkg: packages) {
- for (ClassInfo cl: pkg.allClasses().values()) {
- notStrippable.add(cl);
- }
- }
xmlWriter.println("<api>");
for (PackageInfo pkg: packages) {
writePackageXML(xmlWriter, pkg, pkg.allClasses().values(), notStrippable);
@@ -1048,8 +1030,17 @@ public class Stubs {
xmlWriter.println("</api>");
}
+ public static void writeXml(PrintStream xmlWriter, Collection<PackageInfo> pkgs) {
+ HashSet<ClassInfo> allClasses = new HashSet<>();
+ for (PackageInfo pkg: pkgs) {
+ allClasses.addAll(pkg.allClasses().values());
+ }
+ Predicate<ClassInfo> notStrippable = allClasses::contains;
+ writeXml(xmlWriter, pkgs, notStrippable);
+ }
+
static void writePackageXML(PrintStream xmlWriter, PackageInfo pack,
- Collection<ClassInfo> classList, HashSet<ClassInfo> notStrippable) {
+ Collection<ClassInfo> classList, Predicate<ClassInfo> notStrippable) {
ClassInfo[] classes = classList.toArray(new ClassInfo[classList.size()]);
Arrays.sort(classes, ClassInfo.comparator);
// Work around the bogus "Array" class we invent for
@@ -1068,7 +1059,7 @@ public class Stubs {
}
- static void writeClassXML(PrintStream xmlWriter, ClassInfo cl, HashSet<ClassInfo> notStrippable) {
+ static void writeClassXML(PrintStream xmlWriter, ClassInfo cl, Predicate<ClassInfo> notStrippable) {
String scope = cl.scope();
String deprecatedString = "";
String declString = (cl.isInterface()) ? "interface" : "class";
@@ -1092,7 +1083,7 @@ public class Stubs {
ArrayList<ClassInfo> interfaces = cl.realInterfaces();
Collections.sort(interfaces, ClassInfo.comparator);
for (ClassInfo iface : interfaces) {
- if (notStrippable.contains(iface)) {
+ if (notStrippable.test(iface)) {
xmlWriter.println("<implements name=\"" + iface.qualifiedName() + "\">");
xmlWriter.println("</implements>");
}
@@ -1107,7 +1098,7 @@ public class Stubs {
ArrayList<MethodInfo> methods = cl.allSelfMethods();
Collections.sort(methods, MethodInfo.comparator);
for (MethodInfo mi : methods) {
- if (!methodIsOverride(notStrippable, mi)) {
+ if (!methodIsOverride(mi)) {
writeMethodXML(xmlWriter, mi);
}
}
@@ -1576,7 +1567,7 @@ public class Stubs {
ArrayList<MethodInfo> methods = cl.allSelfMethods();
Collections.sort(methods, MethodInfo.comparator);
for (MethodInfo mi : methods) {
- if (!methodIsOverride(notStrippable, mi)) {
+ if (!methodIsOverride(mi)) {
writeMethodApi(apiWriter, mi);
}
}
diff --git a/src/com/google/doclava/apicheck/ApiCheck.java b/src/com/google/doclava/apicheck/ApiCheck.java
index 8498d0a..5dda8d2 100644
--- a/src/com/google/doclava/apicheck/ApiCheck.java
+++ b/src/com/google/doclava/apicheck/ApiCheck.java
@@ -26,6 +26,7 @@ import java.util.ArrayList;
import java.util.List;
import java.util.HashSet;
import java.util.Set;
+import java.util.function.Predicate;
import com.google.doclava.Errors;
import com.google.doclava.PackageInfo;
@@ -64,7 +65,9 @@ public class ApiCheck {
if (originalArgs.length == 3 && "-convert".equals(originalArgs[0])) {
System.exit(convertToApi(originalArgs[1], originalArgs[2]));
} else if (originalArgs.length == 3 && "-convert2xml".equals(originalArgs[0])) {
- System.exit(convertToXml(originalArgs[1], originalArgs[2]));
+ System.exit(convertToXml(originalArgs[1], originalArgs[2], true));
+ } else if (originalArgs.length == 3 && "-convert2xmlnostrip".equals(originalArgs[0])) {
+ System.exit(convertToXml(originalArgs[1], originalArgs[2], false));
} 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.
@@ -268,7 +271,7 @@ public class ApiCheck {
return 0;
}
- static int convertToXml(String src, String dst) {
+ static int convertToXml(String src, String dst, boolean strip) {
ApiInfo api;
try {
api = parseApi(src);
@@ -285,7 +288,7 @@ public class ApiCheck {
System.err.println("can't open file: " + dst);
}
- Stubs.writeXml(apiWriter, api.getPackages().values());
+ Stubs.writeXml(apiWriter, api.getPackages().values(), c -> true);
return 0;
}