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

moosetechnology / VerveineJ / 19989916441

06 Dec 2025 02:34PM UTC coverage: 50.978% (+0.003%) from 50.975%
19989916441

Pull #177

github

web-flow
Merge 27220d346 into 67bcff346
Pull Request #177: Fix object inheriting from object if parsing the JDK

1925 of 3988 branches covered (48.27%)

Branch coverage included in aggregate %.

6 of 8 new or added lines in 1 file covered. (75.0%)

9 existing lines in 1 file now uncovered.

4303 of 8229 relevant lines covered (52.29%)

2.1 hits per line

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

77.55
/app/src/main/java/fr/inria/verveine/extractor/java/visitors/refvisitors/VisitorInheritanceRef.java
1
package fr.inria.verveine.extractor.java.visitors.refvisitors;
2

3
import fr.inria.verveine.extractor.java.EntityDictionary;
4
import fr.inria.verveine.extractor.java.VerveineJOptions;
5
import fr.inria.verveine.extractor.java.utils.StubBinding;
6
import fr.inria.verveine.extractor.java.utils.Util;
7
import fr.inria.verveine.extractor.java.visitors.GetVisitedEntityAbstractVisitor;
8
import org.eclipse.jdt.core.dom.*;
9
import org.moosetechnology.model.famix.famixjavaentities.Class;
10
import org.moosetechnology.model.famix.famixjavaentities.ContainerEntity;
11
import org.moosetechnology.model.famix.famixjavaentities.Package;
12
import org.moosetechnology.model.famix.famixtraits.TAssociation;
13
import org.moosetechnology.model.famix.famixtraits.TNamedEntity;
14
import org.moosetechnology.model.famix.famixtraits.TType;
15
import org.moosetechnology.model.famix.famixtraits.TWithInheritances;
16
import org.moosetechnology.model.famix.famixtraits.TWithTypes;
17

18
/** A visitor to record inheritance relationships.<br>
19
 * It is simpler than the other ref visitors
20
 * @author anquetil
21
 */
22
public class VisitorInheritanceRef extends GetVisitedEntityAbstractVisitor {
23

24
        public VisitorInheritanceRef(EntityDictionary dico, VerveineJOptions options) {
25
                super(dico, options);
4✔
26
        }
1✔
27

28
        public boolean visit(TypeDeclaration node) {
29
                TWithInheritances fmx = (TWithInheritances) visitTypeDeclaration(node);
5✔
30
                ITypeBinding bnd = node.resolveBinding();
3✔
31
                if ((fmx != null) && (bnd != null)) {
4!
32
                        ensureInheritances(bnd, fmx);
4✔
33

34
                        return super.visit(node);
4✔
35
                } else {
UNCOV
36
                        return false;
×
37
                }
38
        }
39

40
        public void endVisit(TypeDeclaration node) {
41
                endVisitTypeDeclaration(node);
3✔
42
                super.endVisit(node);
3✔
43
        }
1✔
44

45
        public boolean visit(ClassInstanceCreation node) {
46
                // used to get the name of the super type of the anonymous class
47
                possiblyAnonymousClassDeclaration(node);
3✔
48
                return super.visit(node);
4✔
49
        }
50

51
        public boolean visit(AnonymousClassDeclaration node) {
52

53
                // ITypeBinding bnd = node.resolveBinding();
54
                ITypeBinding bnd = (ITypeBinding) StubBinding.getDeclarationBinding(node);
4✔
55
                org.moosetechnology.model.famix.famixjavaentities.Class fmx = this.dico.getFamixClass(bnd, Util.stringForAnonymousName(getAnonymousSuperTypeName(), context), /*owner*/(ContainerEntity) context.top());
14✔
56

57
                if ((fmx != null) && (bnd != null)) {
4!
58
                        ensureInheritances(bnd, fmx);
4✔
59

60
                        this.context.pushType(fmx);
4✔
61
                        return super.visit(node);
4✔
62
                } else {
UNCOV
63
                        return false;
×
64
                }
65
        }
66

67
        public void endVisit(AnonymousClassDeclaration node) {
68
                visitAnonymousClassDeclaration(node);
4✔
69
                super.endVisit(node);
3✔
70
        }
1✔
71

72
        public boolean visit(EnumDeclaration node) {
73
                ITypeBinding bnd = node.resolveBinding();
3✔
74
                org.moosetechnology.model.famix.famixjavaentities.Enum fmx = dico.getFamixEnum(bnd, node.getName().getIdentifier(), (TWithTypes) context.top());
12✔
75

76
                if ((fmx != null) && (bnd != null)) {
4!
77
                        // --------------- implicit superclass java.lang.Enum<> cannot use ensureInheritances(bnd,fmx)
78
                        TType superclass;
79
                        ITypeBinding supbnd = null;
2✔
80
                        supbnd = bnd.getSuperclass();
3✔
81
                        if (supbnd != null) {
2!
82
                                superclass = dico.ensureFamixType(supbnd);
6✔
83
                        } else {
UNCOV
84
                                Package javaLang = dico.ensureFamixPackageJavaLang(null);
×
UNCOV
85
                                superclass = dico.ensureFamixClass(/*bnd*/null, /*name*/"Enum", /*owner*/javaLang, /*isGeneric*/true, /*modifiers*/Modifier.ABSTRACT & Modifier.PUBLIC);
×
86
                        }
87
                        dico.ensureFamixInheritance((TWithInheritances) superclass, fmx, /*lastInheritance*/null, supbnd);
9✔
88

89
                        this.context.pushType(fmx);
4✔
90
                        return super.visit(node);
4✔
91
                }
92
                else {
UNCOV
93
                        return false;
×
94
                }
95
        }
96

97
        public void endVisit(EnumDeclaration node) {
98
                endVisitEnumDeclaration( node);
3✔
99
                super.endVisit(node);
3✔
100
        }
1✔
101

102
        public boolean visit(AnnotationTypeDeclaration node) {
103
                if (visitAnnotationTypeDeclaration( node) != null) {
4!
104
                        return super.visit(node);
4✔
105
                }
106
                else {
UNCOV
107
                        return false;
×
108
                }
109
        }
110

111
        public void endVisit(AnnotationTypeDeclaration node) {
112
                endVisitAnnotationTypeDeclaration( node);
3✔
113
                super.endVisit(node);
3✔
114
        }
1✔
115

116
        public boolean visit(MethodDeclaration node) {
117
                if (visitMethodDeclaration( node) != null) {
4!
118
                        return super.visit(node);
4✔
119
                } else {
UNCOV
120
                        return false;
×
121
                }
122
        }
123

124
        @Override
125
        public void endVisit(MethodDeclaration node) {
126
                endVisitMethodDeclaration(node);
3✔
127
        }
1✔
128

129
        @Override
130
        public boolean visit(Initializer node) {
131
                if (visitInitializer(node) != null) {
4!
132
                        return super.visit(node);
4✔
133
                }
134
                else {
UNCOV
135
                        return false;
×
136
                }
137
        }
138

139
        @Override
140
        public void endVisit(Initializer node) {
141
                endVisitInitializer(node);
3✔
142
        }
1✔
143

144
        // UTILITY METHODS
145

146
        protected void ensureInheritances(ITypeBinding bnd, TWithInheritances fmx) {
147
                TAssociation lastInheritance = null;
2✔
148

149
                if (bnd.isInterface()) {
3✔
150
                        return;
1✔
151
                }
152

153
                // --------------- superclass
154
                ITypeBinding supbnd = bnd.getSuperclass();
3✔
155

156
        TType type;
157
                if (supbnd != null) {
2✔
158
                        type = dico.ensureFamixType(supbnd);
6✔
159
                } else {
160

161
            if(this.isObjectClassFromJavaLang((Class) fmx)){
5!
162
                // Edge case: If we are parsing java.lang.Object, then we should not have an inheritance at all
NEW
163
                return;
×
164
            }
165

166
                        type = dico.ensureFamixClassObject(null);
5✔
167
                }
168
                lastInheritance = dico.ensureFamixInheritance((TWithInheritances) type, fmx, lastInheritance, supbnd);
9✔
169

170
                // --------------- interfaces
171
                dico.ensureImplementedInterfaces(bnd, (TType)fmx, null, lastInheritance);
8✔
172
        }
1✔
173

174
    /**
175
     * @param famixClass A famix class
176
     * @return Return true if the parameter is a representation of java.lang.Object. Else return false
177
     */
178
    public boolean isObjectClassFromJavaLang(Class famixClass) {
179
        if (famixClass.getName().equals(EntityDictionary.OBJECT_NAME)) {
5!
NEW
UNCOV
180
            return ((TNamedEntity) famixClass.getTypeContainer()).getName().equals(EntityDictionary.OBJECT_PACKAGE_NAME);
×
181
        }
182
        return false;
2✔
183
    }
184

185
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc