• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

moosetechnology / MooseIDE / 19293949353

12 Nov 2025 10:15AM UTC coverage: 65.543% (-0.3%) from 65.828%
19293949353

push

github

web-flow
Merge pull request #1516 from moosetechnology/dead-code-java-rules

Dead code java rules

142 of 325 new or added lines in 10 files covered. (43.69%)

21293 of 32487 relevant lines covered (65.54%)

1.31 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

18.0
/src/MooseIDE-DeadCode/MiDeadCodeJavaInitializerHeuristic.class.st
1
"
2
In Java, the default constructor is invoked by any other constructor, and the initialization block is invoked by all constructors.
3

4
So if any of the other constructors is not dead, then these ones are not-dead either.
5
But rules cannot model this, so we just assume they are not-dead by default
6
"
7
Class {
8
        #name : 'MiDeadCodeJavaInitializerHeuristic',
9
        #superclass : 'MiDeadCodeAbstractJavaHeuristic',
10
        #category : 'MooseIDE-DeadCode-Rules',
11
        #package : 'MooseIDE-DeadCode',
12
        #tag : 'Rules'
13
}
14

15
{ #category : 'visiting' }
NEW
16
MiDeadCodeJavaInitializerHeuristic >> accept: aTMethod [
×
NEW
17

×
NEW
18
        ^self notDead: aTMethod 
×
NEW
19
]
×
20

21
{ #category : 'testing' }
22
MiDeadCodeJavaInitializerHeuristic >> classHasNonDefaultConstructor: aClass [
×
23

×
24
        aClass methods
×
25
                detect: [ :m | m isConstructor and: [ m parameters isNotEmpty ] ]
×
26
                ifOne: [ :nonDefaultConstructor | ^true ]
×
27
                ifNone: [ ^false ]
×
28

×
29
]
×
30

31
{ #category : 'accessing' }
32
MiDeadCodeJavaInitializerHeuristic >> description [
2✔
33

2✔
34
        ^super description ,
2✔
35
        'Default constructor and initialization block are assumed not-dead'
2✔
36
]
2✔
37

38
{ #category : 'testing' }
39
MiDeadCodeJavaInitializerHeuristic >> isDefaultConstructorWithOtherConstructors: aTMethod [
×
40
        "the default constructor (no parameter) is always called by any other constructor
×
41
         Note: assumes but does not check that the other constructor is itself called"
×
42

×
43
        aTMethod isConstructor ifFalse: [ ^false ].
×
44
        aTMethod parameters isEmpty ifFalse: [ ^false ].
×
45
        ^self classHasNonDefaultConstructor: aTMethod parentType
×
46

×
47
]
×
48

49
{ #category : 'accessing' }
NEW
50
MiDeadCodeJavaInitializerHeuristic >> isForEntryPoint [
×
NEW
51

×
NEW
52
        ^true
×
NEW
53
]
×
54

55
{ #category : 'testing' }
56
MiDeadCodeJavaInitializerHeuristic >> isInitializerBlock: aTMethod [
×
57

×
58
        ^aTMethod name = '<Initializer>'
×
59
]
×
60

61
{ #category : 'accessing' }
62
MiDeadCodeJavaInitializerHeuristic >> name [
2✔
63

2✔
64
        ^super name , 'Defautl constructor/Initialization block'
2✔
65
]
2✔
66

67
{ #category : 'testing' }
68
MiDeadCodeJavaInitializerHeuristic >> notDead: aTMethod [
×
69

×
70
        | parentType |
×
71
        parentType := aTMethod parentType.
×
72

×
73
        ^(self isInitializerBlock: aTMethod ) or:
×
74
        [  self isDefaultConstructorWithOtherConstructors: aTMethod ]
×
75
        "[ (aTMethod name = parentType name) and:
×
76
                [ (aTMethod parameters isEmpty) and: 
×
77
                 [parentType methods count: [ :m | m name = aTMethod parentType name ]] ]]
×
78
"
×
79
]
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc