source: josm/trunk/tools/japicc/modules/Internals/Filter.pm@ 12872

Last change on this file since 12872 was 12872, checked in by Don-vip, 7 years ago

update to JAPICC 2.3

File size: 7.1 KB
Line 
1###########################################################################
2# A module to filter API symbols
3#
4# Copyright (C) 2016-2017 Andrey Ponomarenko's ABI Laboratory
5#
6# Written by Andrey Ponomarenko
7#
8# This program is free software: you can redistribute it and/or modify
9# it under the terms of the GNU General Public License or the GNU Lesser
10# General Public License as published by the Free Software Foundation.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU General Public License for more details.
16#
17# You should have received a copy of the GNU General Public License
18# and the GNU Lesser General Public License along with this program.
19# If not, see <http://www.gnu.org/licenses/>.
20###########################################################################
21use strict;
22
23my %SkippedPackage;
24
25sub classFilter($$$)
26{
27 my ($Class, $LVer, $ClassContext) = @_;
28
29 if(defined $Class->{"Dep"}) {
30 return 0;
31 }
32
33 my $CName = $Class->{"Name"};
34 my $Package = $Class->{"Package"};
35
36 if(defined $In::Opt{"ClassListPath"}
37 and not defined $In::Opt{"ClassList_User"}{$CName})
38 { # user defined classes
39 return 0;
40 }
41
42 if(defined $In::Opt{"SkipClassesList"})
43 { # user defined classes
44 if(defined $In::Opt{"SkipClasses"}{$CName}) {
45 return 0;
46 }
47 else
48 {
49 my $SClass = $CName;
50
51 while($SClass=~s/\.[^\.]+?\Z//)
52 {
53 if(defined $In::Opt{"SkipClasses"}{$SClass}) {
54 return 0;
55 }
56 }
57 }
58 }
59
60 if(skipPackage($Package, $LVer))
61 { # internal packages
62 return 0;
63 }
64
65 if(skipType($CName))
66 { # internal types
67 return 0;
68 }
69
70 if($ClassContext)
71 {
72 my @Ann = ();
73
74 if(defined $Class->{"Annotations"}) {
75 @Ann = keys(%{$Class->{"Annotations"}});
76 }
77
78 if(not annotationFilter(\@Ann, $LVer)) {
79 return 0;
80 }
81
82 if($In::Opt{"ClientPath"})
83 {
84 if(not defined $In::Opt{"UsedClasses_Client"}{$CName}) {
85 return 0;
86 }
87 }
88 }
89
90 return 1;
91}
92
93sub methodFilter($$)
94{
95 my ($Method, $LVer) = @_;
96
97 my $MAttr = $In::API{$LVer}{"MethodInfo"}{$Method};
98 my $MName = $MAttr->{"Name"};
99
100 if(defined $MAttr->{"Dep"}) {
101 return 0;
102 }
103
104 if($MAttr->{"Access"}=~/private/)
105 { # non-public
106 return 0;
107 }
108
109 my $ClassId = $MAttr->{"Class"};
110 my $Class = getType($ClassId, $LVer);
111
112 if($Class->{"Access"}=~/private/)
113 { # skip private classes
114 return 0;
115 }
116
117 my $Package = $MAttr->{"Package"};
118
119 my @Ann = ();
120
121 if(defined $Class->{"Annotations"}) {
122 @Ann = (@Ann, keys(%{$Class->{"Annotations"}}));
123 }
124
125 if(defined $MAttr->{"Annotations"}) {
126 @Ann = (@Ann, keys(%{$MAttr->{"Annotations"}}));
127 }
128
129 if(not annotationFilter(\@Ann, $LVer)) {
130 return 0;
131 }
132
133 if($In::Opt{"ClientPath"})
134 { # user defined application
135 if(not defined $In::Opt{"UsedMethods_Client"}{$MName}
136 and not defined $In::Opt{"UsedClasses_Client"}{$Class->{"Name"}}) {
137 return 0;
138 }
139 }
140
141 if(skipPackage($Package, $LVer))
142 { # internal packages
143 return 0;
144 }
145
146 if(not classFilter($Class, $LVer, 0)) {
147 return 0;
148 }
149
150 if(defined $In::Opt{"SkipDeprecated"})
151 {
152 if($Class->{"Deprecated"})
153 { # deprecated class
154 return 0;
155 }
156 if($MAttr->{"Deprecated"})
157 { # deprecated method
158 return 0;
159 }
160 }
161
162 return 1;
163}
164
165sub annotationFilter($$)
166{
167 my ($Ann, $LVer) = @_;
168
169 if(not defined $In::Opt{"CountMethods"})
170 {
171 if(defined $In::Opt{"AddedAnnotations"} and $LVer==1) {
172 return 1;
173 }
174
175 if(defined $In::Opt{"RemovedAnnotations"} and $LVer==2) {
176 return 1;
177 }
178 }
179
180 if($In::Opt{"SkipAnnotationsListPath"})
181 {
182 foreach my $Aid (@{$Ann})
183 {
184 my $AName = $In::API{$LVer}{"TypeInfo"}{$Aid}{"Name"};
185
186 if(defined $In::Opt{"SkipAnnotationList_User"}{$AName}) {
187 return 0;
188 }
189 }
190 }
191
192 if($In::Opt{"AnnotationsListPath"})
193 {
194 my $Annotated = 0;
195
196 foreach my $Aid (@{$Ann})
197 {
198 my $AName = $In::API{$LVer}{"TypeInfo"}{$Aid}{"Name"};
199
200 if(defined $In::Opt{"AnnotationList_User"}{$AName})
201 {
202 $Annotated = 1;
203 last;
204 }
205 }
206
207 if(not $Annotated) {
208 return 0;
209 }
210 }
211
212 return 1;
213}
214
215sub skipType($)
216{
217 my $TName = $_[0];
218
219 if(my $SkipInternalTypes = $In::Opt{"SkipInternalTypes"})
220 {
221 if($TName=~/($SkipInternalTypes)/) {
222 return 1;
223 }
224 }
225
226 return 0;
227}
228
229sub skipPackage($$)
230{
231 my ($Package, $LVer) = @_;
232
233 if(my $SkipInternalPackages = $In::Opt{"SkipInternalPackages"})
234 {
235 if($Package=~/($SkipInternalPackages)/) {
236 return 1;
237 }
238 }
239
240 if(defined $In::Desc{$LVer}{"SkipPackages"})
241 {
242 foreach my $P (keys(%{$In::Desc{$LVer}{"SkipPackages"}}))
243 {
244 if($Package=~/\A\Q$P\E(\.|\Z)/)
245 { # user skipped packages
246 return 1;
247 }
248 }
249 }
250
251 if(not defined $In::Opt{"KeepInternal"})
252 {
253 my $Note = (not keys(%SkippedPackage));
254
255 if($Package=~/(\A|\.)(internal|impl|examples)(\.|\Z)/)
256 { # internal packages
257 my $P = $2;
258 if(not $SkippedPackage{$LVer}{$P})
259 {
260 $SkippedPackage{$LVer}{$P} = 1;
261 printMsg("WARNING", "skipping \"$P\" packages");
262
263 if($Note) {
264 printMsg("NOTE", "use --keep-internal option to check them");
265 }
266 }
267 return 1;
268 }
269 }
270
271 if(defined $In::Desc{$LVer}{"KeepPackages"}
272 and my @Keeped = keys(%{$In::Desc{$LVer}{"KeepPackages"}}))
273 {
274 my $UserKeeped = 0;
275 foreach my $P (@Keeped)
276 {
277 if($Package=~/\A\Q$P\E(\.|\Z)/)
278 { # user keeped packages
279 $UserKeeped = 1;
280 last;
281 }
282 }
283 if(not $UserKeeped) {
284 return 1;
285 }
286 }
287
288 if(my $Check = $In::Opt{"CheckPackages"})
289 {
290 if($Package!~/$Check/) {
291 return 1;
292 }
293 }
294
295 return 0;
296}
297
298sub ignorePath($$)
299{
300 my ($Path, $Prefix) = @_;
301
302 if($Path=~/\~\Z/)
303 { # skipping system backup files
304 return 1;
305 }
306
307 # skipping hidden .svn, .git, .bzr, .hg and CVS directories
308 if(cutPrefix($Path, $Prefix)=~/(\A|[\/\\]+)(\.(svn|git|bzr|hg)|CVS)([\/\\]+|\Z)/)
309 {
310 return 1;
311 }
312
313 return 0;
314}
315
316return 1;
Note: See TracBrowser for help on using the repository browser.