Skip to content

Commit

Permalink
Merge pull request #92 from badetitou/exception-parent-type
Browse files Browse the repository at this point in the history
Retrieve correctly the parentType of several exception
  • Loading branch information
badetitou authored Jun 12, 2023
2 parents d9a15e0 + bbe6a23 commit d7abf14
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 7 deletions.
Binary file modified lib/verveine.extractor.java.jar
Binary file not shown.
8 changes: 4 additions & 4 deletions src/fr/inria/verveine/extractor/java/EntityDictionary.java
Original file line number Diff line number Diff line change
Expand Up @@ -1005,11 +1005,11 @@ public Class ensureFamixClass(ITypeBinding bnd, String name, TNamedEntity owner,
// ---------------- create
if (fmx == null) {
if (isGeneric) {
fmx = ensureFamixParameterizableClass(bnd, name, (ContainerEntity) owner);
fmx = ensureFamixParameterizableClass(bnd, name, (TWithTypes) owner);
}
else {
fmx = ensureFamixEntity(Class.class, bnd, name);
fmx.setTypeContainer((ContainerEntity)owner);
fmx.setTypeContainer((TWithTypes)owner);
}
}

Expand All @@ -1028,7 +1028,7 @@ public Class ensureFamixClass(ITypeBinding bnd, String name, TNamedEntity owner,
else {
lastAssoc = ensureFamixInheritance((TWithInheritances) ensureFamixClassObject(null), fmx, lastAssoc);
}
ensureImplementedInterfaces(bnd, fmx, (ContainerEntity) owner, lastAssoc);
ensureImplementedInterfaces(bnd, fmx, (TWithTypes) owner, lastAssoc);
}
}

Expand Down Expand Up @@ -1299,7 +1299,7 @@ public Exception asException(TType excepFmx) {
/**
* helper method, we know the type exists, ensureFamixClass will recover it
*/
public Class getFamixClass(ITypeBinding bnd, String name, ContainerEntity owner) {
public Class getFamixClass(ITypeBinding bnd, String name, TNamedEntity owner) {
return ensureFamixClass(bnd, name, owner, /*isGeneric*/false, UNKNOWN_MODIFIERS);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ public TPackage popPckg() {
* @return the Famix class
*/
public TType popType() {
return this.popUpto(Type.class);
return this.popUpto(TType.class);

This comment has been minimized.

Copy link
@badetitou

badetitou Jun 12, 2023

Author Member

The import modification is here

}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.moosetechnology.model.famix.famixjavaentities.Exception;
import org.moosetechnology.model.famix.famixjavaentities.Package;
import org.moosetechnology.model.famix.famixtraits.TMethod;
import org.moosetechnology.model.famix.famixtraits.TNamedEntity;
import org.moosetechnology.model.famix.famixtraits.TType;
import org.moosetechnology.model.famix.famixtraits.TWithMethods;
import org.moosetechnology.model.famix.famixtraits.TWithTypes;
Expand Down Expand Up @@ -110,7 +111,7 @@ protected TType visitTypeDeclaration(TypeDeclaration node) {
} else if (dico.isThrowable(bnd)) {
fmx = dico.getFamixException(bnd, /*name*/node.getName().getIdentifier(), (TWithTypes) /*owner*/context.top());
} else {
fmx = dico.getFamixClass(bnd, /*name*/node.getName().getIdentifier(), (ContainerEntity) /*owner*/context.top());
fmx = dico.getFamixClass(bnd, /*name*/node.getName().getIdentifier(), (TNamedEntity) /*owner*/context.top());
}
if (fmx != null) {
this.context.pushType(fmx);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ public boolean visit(TypeDeclaration node) {
fmx = dico.ensureFamixClass(
bnd,
/*name*/node.getName().getIdentifier(),
(ContainerEntity)
/*owner*/context.top(),
/*isGeneric*/tparams.size()>0,
node.getModifiers());
Expand Down
32 changes: 32 additions & 0 deletions test_src/exceptions/MultipleSubException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package exceptions;

public class MultipleSubException {

public static class MInnerException extends java.lang.Exception {

public static class MRead extends MultipleSubException.MInnerException {

public MRead(final MultipleSubException el, final String details, final Throwable cause) {
super("Error : \n" + el.getName() + "\n> " + details, cause);
}

}

public static class MWrite extends MultipleSubException.MInnerException {

public MWrite(final MultipleSubException el, final String details, final Throwable cause) {
super("Error : \n" + el.getName() + "\n> " + details, cause);
}

}

public static class MReadWrite extends MultipleSubException.MInnerException {

public MReadWrite(final MultipleSubException el, final String details, final Throwable cause) {
super("Error : \n" + el.getName() + "\n> " + details, cause);
}

}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,21 @@ public void testExceptionInDefineMethodAfterInnerException() {
assertEquals(((TNamedEntity)methodAfterException.getParentType()).getName(), "DefineMethodAfterInnerException");
}


@Test
public void testSubException() {
org.moosetechnology.model.famix.famixjavaentities.Exception anException = detectFamixElement(org.moosetechnology.model.famix.famixjavaentities.Exception.class, "MInnerException");
org.moosetechnology.model.famix.famixjavaentities.Exception aReadException = detectFamixElement(org.moosetechnology.model.famix.famixjavaentities.Exception.class, "MRead");
org.moosetechnology.model.famix.famixjavaentities.Exception aWriteException = detectFamixElement(org.moosetechnology.model.famix.famixjavaentities.Exception.class, "MWrite");
org.moosetechnology.model.famix.famixjavaentities.Exception aReadWriteException = detectFamixElement(org.moosetechnology.model.famix.famixjavaentities.Exception.class, "MReadWrite");

assertNotNull(anException);
assertNotNull(aReadException);
assertNotNull(aWriteException);
assertNotNull(aReadWriteException);
assertEquals(aReadException.getTypeContainer(), anException);
assertEquals(aWriteException.getTypeContainer(), anException);
assertEquals(aReadWriteException.getTypeContainer(), anException);
}

}

0 comments on commit d7abf14

Please sign in to comment.