re PR libgcj/37636 (java tools are unable to find resource files)
[gcc.git] / libjava / classpath / tools / gnu / classpath / tools / doclets / DocletOptionPackageWildcard.java
1 /* gnu.classpath.tools.doclets.DocletOptionPackageWildcard
2 Copyright (C) 2004 Free Software Foundation, Inc.
3
4 This file is part of GNU Classpath.
5
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
10
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 02111-1307 USA. */
20
21 package gnu.classpath.tools.doclets;
22
23 import java.util.LinkedHashSet;
24 import java.util.Set;
25 import java.util.SortedSet;
26 import java.util.StringTokenizer;
27 import java.util.TreeSet;
28
29 import com.sun.javadoc.PackageDoc;
30
31 /**
32 * Processes a doclet option whose value consists of a
33 * colon-separated list of package wildcards, or - optionally -
34 * equals the string "all", denoting that all packages should match.
35 */
36 public class DocletOptionPackageWildcard
37 extends DocletOption
38 {
39 private PackageMatcher packageMatcher;
40 private boolean allowAll;
41 private boolean specified;
42
43 DocletOptionPackageWildcard(String optionName, boolean allowAll)
44 {
45 super(optionName);
46 this.allowAll = allowAll;
47 }
48
49 public int getLength()
50 {
51 return 2;
52 }
53
54 public boolean isSpecified()
55 {
56 return specified;
57 }
58
59 public boolean set(String[] optionArr)
60 {
61 this.specified = true;
62 try {
63 if (allowAll && "all".equals(optionArr[2])) {
64 packageMatcher = null;
65 }
66 else {
67 packageMatcher = new PackageMatcher();
68
69 StringTokenizer tokenizer = new StringTokenizer(optionArr[2], ":");
70 while (tokenizer.hasMoreTokens()) {
71 String packageWildcard = tokenizer.nextToken();
72 packageMatcher.addWildcard(packageWildcard);
73 }
74 }
75 return true;
76 }
77 catch (InvalidPackageWildcardException e) {
78 // FIXME: output problem description here, better throw
79 // DocletConfigurationException
80 return false;
81 }
82 }
83
84 public SortedSet filter(PackageDoc[] packages)
85 {
86 if (null != packageMatcher) {
87 return packageMatcher.filter(packages);
88 }
89 else {
90 SortedSet result = new TreeSet();
91 for (int i=0; i<packages.length; ++i) {
92 result.add(packages[i]);
93 }
94 return result;
95 }
96 }
97
98 public boolean match(PackageDoc packageDoc)
99 {
100 if (null != packageMatcher) {
101 return packageMatcher.match(packageDoc);
102 }
103 else {
104 return true;
105 }
106 }
107 }
108