Syntax patterns: more statistics.
Ruslan Shevchenko
rssh at gradsoft.com.ua
Fri Apr 24 08:20:17 PDT 2009
> Ruslan,
> I believe that the Elvis check isn't checking for the right thing
>
> ConditionalExpression(
> EqualityExpression($x,"==",NullLiteral()),
> $ifNull, MethodCall($x,$method,$args)) -> true
> [ violationDiscovered(Elvis, "elvis", $method) ],
>
> This would at first glance appear to match:
>
> (a == null ? null : a.xxx())
>
This is (a==null ? b : a.xxx())
Also note, that check elvis contains 4 rules
(starting fromn line 112, end from line 131 in )
http://redmine.gradsoft.ua/repositories/entry/javachecker/trunk/JavaChecker/etc/checkers_coin.def
You cite only one.
(Under elvis I understand
http://mail.openjdk.java.net/pipermail/coin-dev/2009-March/000047.html)
where the most generic is conditional expression.
What you guess:
(a == null ? null : a.xxx()) is
ConditionalExpression(
EqualityExpression($x,"==",NullLiteral()),
NullLiteral(), MethodCall($x,$method,$args)) -> true
[ violationDiscovered(Elvis, "elvis", $method) ],
> which isn't Elvis.
>
> Elvis is:
>
> (a == null ? b : a)
> (a != null ? a : b)
> (null == a ? b : a)
> (null != a ? a : b)
>
//
Let's create this version.
> Unfortunately, my attempts to encode this failed:
> ConditionalExpression(
> EqualityExpression($x,"==",NullLiteral()),
> $y, $x) -> true
> [ violationDiscovered(Elvis, "elvis", $x) ],
>
>
> On a separate item, the following finds all conditionals:
> define(AllConditionals,coin,"all conditionals",
> BT_TYPE_RULESET,
> ruleset(
> ConditionalExpression($x,$y,$z)
> -> true [ violationDiscovered(AllConditionals, "all
> conditionals",$x) ]
> ),
> true
> ),
>
Sorry, can you attach modified checkers_coin.def ?
(or diff)
> ConditionalExpression(
> EqualityExpression($x,"==",NullLiteral()),
> $y, $x) -> true
> [ violationDiscovered(Elvis, "elvis", $x) ],
is correct (in first look), but not complete
//Probably, you can place rule inside ruleset of AllConditional to achieve
such effect, or may be write AllConditionals instead Elvis in violation
discovered
To say something concrete, I need to see full define term.
I. e. starts from define( .... and up to ,)
//btw, If you agree, I can give you write access to svn, create file
checkers_elvis.def, than will able see you changes and point on errors
automatically after commits.
> Stephen
>
>
> 2009/4/20 Ruslan Shevchenko <Ruslan at shevchenko.kiev.ua>:
>> Good day, community !
>>
>> ═I want to share some statistics about java usage patterns, related to
>> some of coin-dev proposals.
>>
>> Main changes from previous post are:
>> ═- added counts for 'if' syntax constructions, so we can say, hom many
>> ═percents of if's can be eliminated by elvis operator ( [4-5]%)
>> ═- added counts for 'catch' syntax constructions, so we can say that
>> multicath eliminate 6-8% of all catch clauses.
>> ═- added count for big integers integers (where undescore can be
>> applicable, I guess this is x: x > 100000 || x < -10000) and for all
>> integer literals.
>> ═ (underscore can be applicable to near 1%)
>> ═- added count for object-switch proposal by Ulf Zibis (refining, that
>> Left/Right part of expressions are first operand in equalirty expression
>> or object in method call)
>> ═- added count for rethrow proposal by Mark Mahieu (near 50% of all
>> catches in some packages (!) ).
>> ═- added count for catches inside finally block. (Is this is a real
>> problem [?]).
>>
>> If anybody whant run checks on own dataset or/and add own check
>> definitions: all ═procedure is the same as in my previous letter (see
>> http://mail.openjdk.java.net/pipermail/coin-dev/2009-April/001442.html)
>> except URL for last version
>> ═is
>> http://datacenter.gradsoft.ua/public.repository/ua.gradsoft/javachecker/installations/JavaCheckerSourceInstaller-2.5.0p1.jar
>>
>> Now summary statistics for some well-known packages:
>> jetty (web server)
>> all catchs ═ ═ ═: ═ ═ ═ 281
>> all ifs : ═ ═ ═ 764
>> all integer literals ═ ═: ═ ═ ═ 2903
>> big integer literals(undescores) ═ ═ ═ ═: ═ ═ ═ 25
>> byte literal ═ ═: ═ ═ ═ 52
>> catch in finally ═ ═ ═ ═: ═ ═ ═ 3
>> elvis ═ : ═ ═ ═ 43
>> instanceof switch ═ ═ ═ : ═ ═ ═ 8
>> loop with remove ═ ═ ═ ═: ═ ═ ═ 0
>> multi catch ═ ═ : ═ ═ ═ 22
>> object switch ═ : ═ ═ ═ 31
>> rethrow clause ═: ═ ═ ═ 34
>> string in switch ═ ═ ═ ═: ═ ═ ═ 19
>> Files:187
>>
>> gwt-users (google java ajax client library)
>> all catchs ═ ═ ═: ═ ═ ═ 171
>> all ifs : ═ ═ ═ 735
>> all integer literals ═ ═: ═ ═ ═ 2282
>> big integer literals(undescores) ═ ═ ═ ═: ═ ═ ═ 24
>> byte literal ═ ═: ═ ═ ═ 2
>> catch in finally ═ ═ ═ ═: ═ ═ ═ 2
>> elvis ═ : ═ ═ ═ 30
>> instanceof switch ═ ═ ═ : ═ ═ ═ 6
>> loop with remove ═ ═ ═ ═: ═ ═ ═ 5
>> multi catch ═ ═ : ═ ═ ═ 9
>> object switch ═ : ═ ═ ═ 27
>> rethrow clause ═: ═ ═ ═ 84
>> string in switch ═ ═ ═ ═: ═ ═ ═ 10
>> Files:920
>>
>> hibernate (ORM toolkit)
>> all catchs ═ ═ ═: ═ ═ ═ 650
>> all ifs : ═ ═ ═ 2410
>> all integer literals ═ ═: ═ ═ ═ 3240
>> big integer literals(undescores) ═ ═ ═ ═: ═ ═ ═ 12
>> byte literal ═ ═: ═ ═ ═ 1
>> catch in finally ═ ═ ═ ═: ═ ═ ═ 27
>> elvis ═ : ═ ═ ═ 182
>> instanceof switch ═ ═ ═ : ═ ═ ═ 28
>> loop with remove ═ ═ ═ ═: ═ ═ ═ 12
>> multi catch ═ ═ : ═ ═ ═ 25
>> object switch ═ : ═ ═ ═ 94
>> rethrow clause ═: ═ ═ ═ 450
>> string in switch ═ ═ ═ ═: ═ ═ ═ 86
>> Files:1372
>>
>> openjdk7 (standard java library)
>> all catchs ═ ═ ═: ═ ═ ═ 8404
>> all ifs : ═ ═ ═ 28494
>> all integer literals ═ ═: ═ ═ ═ 124356
>> big integer literals(undescores) ═ ═ ═ ═: ═ ═ ═ 4066
>> byte literal ═ ═: ═ ═ ═ 1454
>> catch in finally ═ ═ ═ ═: ═ ═ ═ 103
>> elvis ═ : ═ ═ ═ 877
>> instanceof switch ═ ═ ═ : ═ ═ ═ 318
>> loop with remove ═ ═ ═ ═: ═ ═ ═ 62
>> multi catch ═ ═ : ═ ═ ═ 411
>> object switch ═ : ═ ═ ═ 1363
>> rethrow clause ═: ═ ═ ═ 3264
>> string in switch ═ ═ ═ ═: ═ ═ ═ 445
>> Files:9252
>>
>> Hope, this data will be useful in some cases.
>> Regards !
>>
>>
>>
>>
>
>
More information about the coin-dev
mailing list