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

moosetechnology / VerveineJ / 15191557690

22 May 2025 04:10PM UTC coverage: 50.616% (+0.6%) from 49.972%
15191557690

push

github

web-flow
Merge pull request #127 from moosetechnology/new-generics-implementation

New generics implementation

1884 of 3956 branches covered (47.62%)

Branch coverage included in aggregate %.

513 of 1119 new or added lines in 53 files covered. (45.84%)

53 existing lines in 10 files now uncovered.

4277 of 8216 relevant lines covered (52.06%)

2.08 hits per line

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

40.21
/app/src/main/java/fr/inria/verveine/extractor/java/visitors/refvisitors/AbstractRefVisitor.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.visitors.GetVisitedEntityAbstractVisitor;
6
import org.eclipse.jdt.core.dom.*;
7
import org.moosetechnology.model.famix.famixjavaentities.ContainerEntity;
8
import org.moosetechnology.model.famix.famixjavaentities.ParametricClass;
9
import org.moosetechnology.model.famix.famixjavaentities.ParametricInterface;
10
import org.moosetechnology.model.famix.famixtraits.TNamedEntity;
11
import org.moosetechnology.model.famix.famixtraits.TType;
12
import org.moosetechnology.model.famix.famixtraits.TWithTypes;
13

14
/**
15
 * A collection of useful utility methods that are needed in various ref visitors
16
 */
17
public class AbstractRefVisitor extends GetVisitedEntityAbstractVisitor {
18

19
        public AbstractRefVisitor(EntityDictionary dico, VerveineJOptions options) {
20
                super(dico, options);
4✔
21
        }
1✔
22

23
        protected String findTypeName(org.eclipse.jdt.core.dom.Type t) {
24
                if (t == null) {
×
25
                        return null;
×
26
                }
27

28
                if (t.isPrimitiveType()) {
×
29
                        return t.toString();
×
30
                } else if (t.isSimpleType()) {
×
31
                        String fullName = ((SimpleType) t).getName().getFullyQualifiedName();
×
32
                        int i = fullName.lastIndexOf('.');
×
33
                        if (i > 0) {
×
34
                                return fullName.substring(i+1);
×
35
                        }
36
                        else {
37
                                return fullName;
×
38
                        }
39
                } else if (t.isQualifiedType()) {
×
40
                        return ((QualifiedType) t).getName().getIdentifier();
×
41
                } else if (t.isArrayType()) {
×
42
                        return findTypeName(((ArrayType) t).getElementType());
×
43
                } else if (t.isParameterizedType()) {
×
44
                        return findTypeName(((org.eclipse.jdt.core.dom.ParameterizedType) t).getType());
×
45
                } else { // it is a WildCardType
46
                        if (((org.eclipse.jdt.core.dom.WildcardType) t).isUpperBound()) {
×
47
                                return findTypeName(((org.eclipse.jdt.core.dom.WildcardType) t).getBound());
×
48
                        } else {
49
                                return EntityDictionary.OBJECT_NAME;
×
50
                        }
51
                }
52
        }
53

54
/**
55
         * Ensures the proper creation of a FamixType for JDT typ in the given context.
56
         * Useful for parameterizedTypes, or classInstance.
57
         *
58
         * @param isClass we are sure that the type is actually a class
59
         * @return a famix type or null
60
         */
61
        protected <T extends TWithTypes & TNamedEntity> TType referredType(Type typ, T ctxt, boolean isClass) {
62
                return referredType(typ, ctxt, isClass, /*isExcep*/false);
7✔
63
        }
64

65
        /**
66
         * Ensures the proper creation of a FamixType for JDT type in the given context.
67
         * Useful for parameterizedTypes, or classInstance.
68
         *
69
         * @param isClass we are sure that the type is actually a class
70
         * @return a famix type or null
71
         */
72
        protected <T extends TWithTypes & TNamedEntity> TType referredType(Type typ, T ctxt, boolean isClass, boolean isException) {
73
                if (typ == null) {
2✔
74
                        return null;
2✔
75
                } else if (typ.resolveBinding() != null) {
3!
76
                        return this.referredType(typ.resolveBinding(), ctxt, isClass);
8✔
77
                }
78
                // from here, we assume the owner is the context
NEW
79
                else if (isClass && !isException) {
×
80
                        return dico.ensureFamixClass(null, findTypeName(typ), /*owner*/ctxt, /*isGeneric*/false,
×
81
                                        EntityDictionary.UNKNOWN_MODIFIERS);
NEW
82
                } else if (isException) {
×
83
                        // return ensure FamixException
84
                        return dico.ensureFamixException(null, findTypeName(typ), (ContainerEntity) /*owner*/ctxt, /*isGeneric*/false,
×
85
                                        EntityDictionary.UNKNOWN_MODIFIERS);
86
                } else {
87
                        while (typ.isArrayType()) {
×
88
                                typ = ((ArrayType) typ).getElementType();
×
89
                        }
90

91
                        if (typ.isPrimitiveType()) {
×
92
                                return dico.ensureFamixPrimitiveType(null, findTypeName(typ));
×
93
                        } else {
94
                                return dico.ensureFamixType(null, findTypeName(typ), /*owner*/ctxt, /*container*/ctxt,
×
95
                                                EntityDictionary.UNKNOWN_MODIFIERS);
96
                        }
97
                }
98
        }
99

100
        protected TType referredType(ITypeBinding bnd, TNamedEntity ctxt, boolean isClass) {
101
                TType fmxTyp = null;
2✔
102

103
                if (bnd == null) {
2✔
104
                        return null;
2✔
105
                }
106

107
                String name;
108
                if (bnd.isArray()) {
3✔
109
                        bnd = bnd.getElementType();
3✔
110
                }
111
                name = bnd.getName();
3✔
112

113
                if ( bnd.isParameterizedType() ) {
3✔
114
                        
115
                        // remove type parameters from the name even for parameterized interfaces
116
                        int i = name.indexOf('<');
4✔
117
                        if (i > 0) {
2!
118
                                name = name.substring(0, i);
5✔
119
                        }
120

121
                        ITypeBinding parameterizableBnd = bnd.getErasure();
3✔
122
                        int modifiers = (parameterizableBnd != null) ? parameterizableBnd.getModifiers() : EntityDictionary.UNKNOWN_MODIFIERS;
6!
123
                        
124
                        if(parameterizableBnd != null && parameterizableBnd.isInterface()) {
5!
125
                                fmxTyp = (ParametricInterface) dico.ensureFamixInterface(parameterizableBnd, name, /*owner*/null, /*isGeneric*/true, modifiers);
11✔
126
                        } else {
127
                                fmxTyp = (ParametricClass) dico.ensureFamixClass(parameterizableBnd, name, /*owner*/null, /*isGeneric*/true, modifiers);
10✔
128
                        }
129
                } else {
1✔
130
                        fmxTyp = dico.ensureFamixType(bnd, name, /*owner*/null, (TWithTypes) ctxt, bnd.getModifiers());
11✔
131
                }
132

133
                return fmxTyp;
2✔
134
        }
135

136
}
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

© 2026 Coveralls, Inc