Skip to content

Commit 4823e9a

Browse files
Merge pull request #148 from moosetechnology/issue/146
fix issue #146
2 parents c9bd393 + 307520e commit 4823e9a

3 files changed

Lines changed: 27 additions & 5 deletions

File tree

app/src/main/java/fr/inria/verveine/extractor/java/EntityDictionary.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -560,20 +560,24 @@ public void ensureImplementedInterfaces(ITypeBinding bnd, TType fmx, TWithTypes
560560
* @return the FamixReference
561561
*/
562562
public Reference addFamixReference(Method src, TType tgt, TAssociation prev, ITypeBinding referredTypeBnd) {
563+
Reference ref;
564+
563565
if ( (src == null) || (tgt == null) ) {
564566
return null;
565567
}
566568

567569
if (prev == null) {
568-
for (TReference ref : src.getOutgoingReferences()) {
569-
if (ref.getReferredEntity() == tgt) {
570-
return (Reference) ref;
570+
for (TReference existingRef : src.getOutgoingReferences()) {
571+
if (existingRef.getReferredEntity() == tgt) {
572+
return (Reference) existingRef;
571573
}
572574
}
573575
}
574576

575-
Reference ref;
576-
if (referredTypeBnd != null && referredTypeBnd.isParameterizedType()) { // Needs checks and tests.
577+
/* issue <href="https://github.com/moosetechnology/VerveineJ/issues/146">146</href> an expression like <code>char[].class</code> is a <code>Class</code>
578+
* gives referredTypeBnd.isParameterizedType() == true.
579+
* We test <code>tgt instanceof PrimitiveType</code> to avoid this case */
580+
if (referredTypeBnd != null && referredTypeBnd.isParameterizedType() && ! (tgt instanceof PrimitiveType)) { // Needs checks and tests.
577581
ref = (ParametricReference)buildFamixParametricAssociation(new ParametricReference(), referredTypeBnd.getErasure().getTypeParameters(), referredTypeBnd.getTypeArguments());
578582
} else {
579583
ref = new Reference();

app/src/test/java/fr/inria/verveine/extractor/java/VerveineJTest_AdHoc.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,16 @@ public void testSeveralFieldsOneInit() {
8080
}
8181

8282

83+
@Test
84+
public void testCharTypeReference() {
85+
parse(new String[] {"src/test/resources/ad_hoc/CharTypeReference.java"});
86+
87+
assertEquals(1, entitiesOfType(Reference.class).size());
88+
Reference ref = firstElt(entitiesOfType(Reference.class));
89+
assertEquals("char", ((TNamedEntity) ref.getReferredEntity()).getName());
90+
}
91+
92+
8393
@Test
8494
public void testJunit5Bug1() {
8595
File generatedMSE = new File(DEFAULT_OUTPUT_FILE);
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package ad_hoc;
2+
3+
public class CharTypeReference {
4+
5+
public static void main(String[] args) {
6+
Class<?> c = char[].class;
7+
}
8+
}

0 commit comments

Comments
 (0)