File: Filter.pm

package info (click to toggle)
josm 0.0.svn17428%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 204,760 kB
  • sloc: java: 360,765; xml: 198,972; perl: 10,138; jsp: 250; sh: 123; makefile: 112; javascript: 74; python: 29
file content (336 lines) | stat: -rw-r--r-- 7,654 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
###########################################################################
# A module to filter API symbols
#
# Copyright (C) 2016-2018 Andrey Ponomarenko's ABI Laboratory
#
# Written by Andrey Ponomarenko
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA  02110-1301  USA.
###########################################################################
use strict;

my %SkippedPackage;

sub classFilter($$$)
{
    my ($Class, $LVer, $ClassContext) = @_;
    
    if(defined $Class->{"Dep"}) {
        return 0;
    }
    
    my $CName = $Class->{"Name"};
    my $Package = $Class->{"Package"};
    
    if(defined $In::Opt{"ClassListPath"}
    and not defined $In::Opt{"ClassList_User"}{$CName})
    { # user defined classes
        return 0;
    }
    
    if(defined $In::Opt{"SkipClassesList"})
    { # user defined classes
        if(defined $In::Opt{"SkipClasses"}{$CName}) {
            return 0;
        }
        else
        {
            my $SClass = $CName;
            
            while($SClass=~s/\.[^\.]+?\Z//)
            {
                if(defined $In::Opt{"SkipClasses"}{$SClass}) {
                    return 0;
                }
            }
        }
    }
    
    if(skipPackage($Package, $LVer))
    { # internal packages
        return 0;
    }
    
    if(skipType($CName))
    { # internal types
        return 0;
    }
    
    if($ClassContext)
    {
        my @Ann = ();
        
        if(defined $Class->{"Annotations"}) {
            @Ann = keys(%{$Class->{"Annotations"}});
        }
        
        if(not annotationFilter(\@Ann, $LVer)) {
            return 0;
        }
        
        if($In::Opt{"ClientPath"})
        {
            if(not defined $In::Opt{"UsedClasses_Client"}{$CName}) {
                return 0;
            }
        }
    }
    
    return 1;
}

sub nonImplClass($)
{
    my $Class = $_[0];
    
    if(defined $In::Opt{"NonImplAll"}) {
        return 1;
    }
    
    if(defined $In::Opt{"NonImplClassesList"})
    { # user defined classes
        if(defined $In::Opt{"NonImplClasses"}{$Class->{"Name"}}) {
            return 1;
        }
    }
    
    return 0;
}

sub methodFilter($$)
{
    my ($Method, $LVer) = @_;
    
    my $MAttr = $In::API{$LVer}{"MethodInfo"}{$Method};
    my $MName = $MAttr->{"Name"};
    
    if(defined $MAttr->{"Dep"}) {
        return 0;
    }
    
    if($MAttr->{"Access"}=~/private/)
    { # non-public
        return 0;
    }
    
    my $ClassId = $MAttr->{"Class"};
    my $Class = getType($ClassId, $LVer);
    
    if($Class->{"Access"}=~/private/)
    { # skip private classes
        return 0;
    }
    
    my $Package = $MAttr->{"Package"};
    
    my @Ann = ();
    
    if(defined $Class->{"Annotations"}) {
        @Ann = (@Ann, keys(%{$Class->{"Annotations"}}));
    }
    
    if(defined $MAttr->{"Annotations"}) {
        @Ann = (@Ann, keys(%{$MAttr->{"Annotations"}}));
    }
    
    if(not annotationFilter(\@Ann, $LVer)) {
        return 0;
    }
    
    if($In::Opt{"ClientPath"})
    { # user defined application
        if(not defined $In::Opt{"UsedMethods_Client"}{$MName}
        and not defined $In::Opt{"UsedClasses_Client"}{$Class->{"Name"}}) {
            return 0;
        }
    }
    
    if(skipPackage($Package, $LVer))
    { # internal packages
        return 0;
    }
    
    if(not classFilter($Class, $LVer, 0)) {
        return 0;
    }
    
    if(defined $In::Opt{"SkipDeprecated"})
    {
        if($Class->{"Deprecated"})
        { # deprecated class
            return 0;
        }
        if($MAttr->{"Deprecated"})
        { # deprecated method
            return 0;
        }
    }
    
    return 1;
}

sub annotationFilter($$)
{
    my ($Ann, $LVer) = @_;
    
    if(not defined $In::Opt{"CountMethods"})
    {
        if(defined $In::Opt{"AddedAnnotations"} and $LVer==1) {
            return 1;
        }
        
        if(defined $In::Opt{"RemovedAnnotations"} and $LVer==2) {
            return 1;
        }
    }
    
    if($In::Opt{"SkipAnnotationsListPath"})
    {
        foreach my $Aid (@{$Ann})
        {
            my $AName = $In::API{$LVer}{"TypeInfo"}{$Aid}{"Name"};
            
            if(defined $In::Opt{"SkipAnnotationList_User"}{$AName}) {
                return 0;
            }
        }
    }
    
    if($In::Opt{"AnnotationsListPath"})
    {
        my $Annotated = 0;
        
        foreach my $Aid (@{$Ann})
        {
            my $AName = $In::API{$LVer}{"TypeInfo"}{$Aid}{"Name"};
            
            if(defined $In::Opt{"AnnotationList_User"}{$AName})
            {
                $Annotated = 1;
                last;
            }
        }
        
        if(not $Annotated) {
            return 0;
        }
    }
    
    return 1;
}

sub skipType($)
{
    my $TName = $_[0];
    
    if(my $SkipInternalTypes = $In::Opt{"SkipInternalTypes"})
    {
        if($TName=~/($SkipInternalTypes)/) {
            return 1;
        }
    }
    
    return 0;
}

sub skipPackage($$)
{
    my ($Package, $LVer) = @_;
    
    if(my $SkipInternalPackages = $In::Opt{"SkipInternalPackages"})
    {
        if($Package=~/($SkipInternalPackages)/) {
            return 1;
        }
    }
    
    if(defined $In::Desc{$LVer}{"SkipPackages"})
    {
        foreach my $P (keys(%{$In::Desc{$LVer}{"SkipPackages"}}))
        {
            if($Package=~/\A\Q$P\E(\.|\Z)/)
            { # user skipped packages
                return 1;
            }
        }
    }
    
    if(not defined $In::Opt{"KeepInternal"})
    {
        my $Note = (not keys(%SkippedPackage));
        
        if($Package=~/(\A|\.)(internal|impl|examples)(\.|\Z)/)
        { # internal packages
            my $P = $2;
            if(not $SkippedPackage{$LVer}{$P})
            {
                $SkippedPackage{$LVer}{$P} = 1;
                printMsg("WARNING", "skipping \"$P\" packages");
                
                if($Note) {
                    printMsg("NOTE", "use --keep-internal option to check them");
                }
            }
            return 1;
        }
    }
    
    if(defined $In::Desc{$LVer}{"KeepPackages"}
    and my @Keeped = keys(%{$In::Desc{$LVer}{"KeepPackages"}}))
    {
        my $UserKeeped = 0;
        foreach my $P (@Keeped)
        {
            if($Package=~/\A\Q$P\E(\.|\Z)/)
            { # user keeped packages
                $UserKeeped = 1;
                last;
            }
        }
        if(not $UserKeeped) {
            return 1;
        }
    }
    
    if(my $Check = $In::Opt{"CheckPackages"})
    {
        if($Package!~/$Check/) {
            return 1;
        }
    }
    
    return 0;
}

sub ignorePath($$)
{
    my ($Path, $Prefix) = @_;
    
    if($Path=~/\~\Z/)
    { # skipping system backup files
        return 1;
    }
    
    # skipping hidden .svn, .git, .bzr, .hg and CVS directories
    if(cutPrefix($Path, $Prefix)=~/(\A|[\/\\]+)(\.(svn|git|bzr|hg)|CVS)([\/\\]+|\Z)/)
    {
        return 1;
    }
    
    return 0;
}

return 1;