24 */ |
24 */ |
25 |
25 |
26 package com.sun.tools.doclint; |
26 package com.sun.tools.doclint; |
27 |
27 |
28 |
28 |
|
29 import java.util.Arrays; |
|
30 import java.util.HashSet; |
|
31 import java.util.LinkedHashSet; |
|
32 import java.util.List; |
29 import java.util.Set; |
33 import java.util.Set; |
30 import java.util.LinkedHashSet; |
34 import java.util.regex.Pattern; |
31 |
35 |
32 import javax.lang.model.element.Element; |
36 import javax.lang.model.element.Element; |
33 import javax.lang.model.element.ElementKind; |
37 import javax.lang.model.element.ElementKind; |
34 import javax.lang.model.element.ExecutableElement; |
38 import javax.lang.model.element.ExecutableElement; |
35 import javax.lang.model.element.Modifier; |
39 import javax.lang.model.element.Modifier; |
36 import javax.lang.model.type.TypeMirror; |
40 import javax.lang.model.type.TypeMirror; |
37 import javax.lang.model.util.Elements; |
41 import javax.lang.model.util.Elements; |
38 import javax.lang.model.util.Types; |
42 import javax.lang.model.util.Types; |
|
43 import javax.tools.Diagnostic.Kind; |
39 |
44 |
40 import com.sun.source.doctree.DocCommentTree; |
45 import com.sun.source.doctree.DocCommentTree; |
41 import com.sun.source.util.DocTrees; |
46 import com.sun.source.util.DocTrees; |
42 import com.sun.source.util.JavacTask; |
47 import com.sun.source.util.JavacTask; |
43 import com.sun.source.util.SourcePositions; |
48 import com.sun.source.util.SourcePositions; |
44 import com.sun.source.util.TreePath; |
49 import com.sun.source.util.TreePath; |
45 import com.sun.tools.javac.model.JavacTypes; |
50 import com.sun.tools.javac.model.JavacTypes; |
46 import com.sun.tools.javac.tree.JCTree; |
51 import com.sun.tools.javac.tree.JCTree; |
|
52 import com.sun.tools.javac.util.MatchingUtils; |
47 import com.sun.tools.javac.util.StringUtils; |
53 import com.sun.tools.javac.util.StringUtils; |
48 |
54 |
49 /** |
55 /** |
50 * Utility container for current execution environment, |
56 * Utility container for current execution environment, |
51 * providing the current declaration and its doc comment. |
57 * providing the current declaration and its doc comment. |
127 |
136 |
128 void init(DocTrees trees, Elements elements, Types types) { |
137 void init(DocTrees trees, Elements elements, Types types) { |
129 this.trees = trees; |
138 this.trees = trees; |
130 this.elements = elements; |
139 this.elements = elements; |
131 this.types = types; |
140 this.types = types; |
|
141 } |
|
142 |
|
143 void initTypes() { |
|
144 if (java_lang_Error != null) |
|
145 return ; |
|
146 |
132 java_lang_Error = elements.getTypeElement("java.lang.Error").asType(); |
147 java_lang_Error = elements.getTypeElement("java.lang.Error").asType(); |
133 java_lang_RuntimeException = elements.getTypeElement("java.lang.RuntimeException").asType(); |
148 java_lang_RuntimeException = elements.getTypeElement("java.lang.RuntimeException").asType(); |
134 java_lang_Throwable = elements.getTypeElement("java.lang.Throwable").asType(); |
149 java_lang_Throwable = elements.getTypeElement("java.lang.Throwable").asType(); |
135 java_lang_Void = elements.getTypeElement("java.lang.Void").asType(); |
150 java_lang_Void = elements.getTypeElement("java.lang.Void").asType(); |
136 } |
151 } |
139 implicitHeaderLevel = n; |
154 implicitHeaderLevel = n; |
140 } |
155 } |
141 |
156 |
142 void setCustomTags(String cTags) { |
157 void setCustomTags(String cTags) { |
143 customTags = new LinkedHashSet<>(); |
158 customTags = new LinkedHashSet<>(); |
144 for (String s : cTags.split(DocLint.TAGS_SEPARATOR)) { |
159 for (String s : cTags.split(DocLint.SEPARATOR)) { |
145 if (!s.isEmpty()) |
160 if (!s.isEmpty()) |
146 customTags.add(s); |
161 customTags.add(s); |
147 } |
162 } |
|
163 } |
|
164 |
|
165 void setCheckPackages(String packages) { |
|
166 includePackages = new HashSet<>(); |
|
167 excludePackages = new HashSet<>(); |
|
168 for (String pack : packages.split(DocLint.SEPARATOR)) { |
|
169 boolean excluded = false; |
|
170 if (pack.startsWith("-")) { |
|
171 pack = pack.substring(1); |
|
172 excluded = true; |
|
173 } |
|
174 if (pack.isEmpty()) |
|
175 continue; |
|
176 Pattern pattern = MatchingUtils.validImportStringToPattern(pack); |
|
177 if (excluded) { |
|
178 excludePackages.add(pattern); |
|
179 } else { |
|
180 includePackages.add(pattern); |
|
181 } |
|
182 } |
|
183 } |
|
184 |
|
185 static boolean validatePackages(String packages) { |
|
186 for (String pack : packages.split(DocLint.SEPARATOR)) { |
|
187 if (pack.startsWith("-")) { |
|
188 pack = pack.substring(1); |
|
189 } |
|
190 if (!pack.isEmpty() && !MatchingUtils.isValidImportString(pack)) |
|
191 return false; |
|
192 } |
|
193 return true; |
148 } |
194 } |
149 |
195 |
150 /** Set the current declaration and its doc comment. */ |
196 /** Set the current declaration and its doc comment. */ |
151 void setCurrent(TreePath path, DocCommentTree comment) { |
197 void setCurrent(TreePath path, DocCommentTree comment) { |
152 currPath = path; |
198 currPath = path; |