summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Banes <chrisbanes@google.com>2015-04-30 10:31:25 +0100
committerChris Banes <chrisbanes@google.com>2015-05-01 08:59:50 +0100
commit372e36e9014ff0d0ff478bd63c374c0068564be1 (patch)
tree97609bc4bf0c1e5fdbad94223a4e7da3197e465c
parent3061ae5673f1f6c3e028af037134fef09eb68ef8 (diff)
downloadandroid_external_doclava-372e36e9014ff0d0ff478bd63c374c0068564be1.tar.gz
android_external_doclava-372e36e9014ff0d0ff478bd63c374c0068564be1.tar.bz2
android_external_doclava-372e36e9014ff0d0ff478bd63c374c0068564be1.zip
Add wildcard support to stubpackages
Allows things like -stubpackages my.package.* which is really useful for the support lib API file generation. The alternative is keeping a list of each library's package, which is brittle to future changes. Change-Id: Ibd49cc0348e2767b2c0fe6f14e7253b6d8e04c7b
-rw-r--r--src/com/google/doclava/Stubs.java45
1 files changed, 44 insertions, 1 deletions
diff --git a/src/com/google/doclava/Stubs.java b/src/com/google/doclava/Stubs.java
index 44f1277..5ae1dd0 100644
--- a/src/com/google/doclava/Stubs.java
+++ b/src/com/google/doclava/Stubs.java
@@ -27,8 +27,10 @@ import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
+import java.util.Iterator;
import java.util.List;
import java.util.Set;
+import java.util.regex.Pattern;
public class Stubs {
public static void writeStubsAndApi(String stubsDir, String apiFile, String keepListFile,
@@ -161,9 +163,10 @@ public class Stubs {
// packages contains all the notStrippable classes mapped by their containing packages
HashMap<PackageInfo, List<ClassInfo>> packages = new HashMap<PackageInfo, List<ClassInfo>>();
+ final HashSet<Pattern> stubPackageWildcards = extractWildcards(stubPackages);
for (ClassInfo cl : notStrippable) {
if (!cl.isDocOnly()) {
- if (stubPackages == null || stubPackages.contains(cl.containingPackage().name())) {
+ if (shouldWriteStub(cl.containingPackage().name(), stubPackages, stubPackageWildcards)) {
// write out the stubs
if (stubsDir != null) {
writeClassFile(stubsDir, notStrippable, cl);
@@ -211,6 +214,46 @@ public class Stubs {
}
}
+ private static boolean shouldWriteStub(final String packageName,
+ final HashSet<String> stubPackages, final HashSet<Pattern> stubPackageWildcards) {
+ if (stubPackages == null) {
+ // There aren't any stub packages set, write all stubs
+ return true;
+ }
+ if (stubPackages.contains(packageName)) {
+ // Stub packages contains package, return true
+ return true;
+ }
+ if (stubPackageWildcards != null) {
+ // Else, we will iterate through the wildcards to see if there's a match
+ for (Pattern wildcard : stubPackageWildcards) {
+ if (wildcard.matcher(packageName).matches()) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ private static HashSet<Pattern> extractWildcards(HashSet<String> stubPackages) {
+ HashSet<Pattern> wildcards = null;
+ if (stubPackages != null) {
+ for (Iterator<String> i = stubPackages.iterator(); i.hasNext();) {
+ final String pkg = i.next();
+ if (pkg.indexOf('*') != -1) {
+ if (wildcards == null) {
+ wildcards = new HashSet<Pattern>();
+ }
+ // Add the compiled wildcard, replacing * with the regex equivalent
+ wildcards.add(Pattern.compile(pkg.replace("*", ".*?")));
+ // And remove the raw wildcard from the packages
+ i.remove();
+ }
+ }
+ }
+ return wildcards;
+ }
+
private static ClassInfo findHiddenClasses(TypeInfo ti) {
ClassInfo ci = ti.asClassInfo();
if (ci == null) return null;