diff --git a/app/src/main/java/fr/inria/verveine/extractor/java/EntityDictionary.java b/app/src/main/java/fr/inria/verveine/extractor/java/EntityDictionary.java index e5909a40..f3ac5cb3 100644 --- a/app/src/main/java/fr/inria/verveine/extractor/java/EntityDictionary.java +++ b/app/src/main/java/fr/inria/verveine/extractor/java/EntityDictionary.java @@ -1340,6 +1340,7 @@ public TThrowable asException(TType fmxType) { fmxException.addSuperInheritances( new ArrayList<>( ((TWithInheritances) fmxType).getSuperInheritances() ) ); fmxException.addSubInheritances( new ArrayList<>( ((TWithInheritances) fmxType).getSubInheritances() ) ); } + fmxException.setComments(new ArrayList<>( ((TWithComments) fmxType).getComments() )); fmxException.setSourceAnchor(fmxType.getSourceAnchor()); fmxException.addIncomingTypings( new ArrayList<>( fmxType.getIncomingTypings() ) ); fmxException.addAnnotationInstances( new ArrayList<>( ((NamedEntity)fmxType).getAnnotationInstances() ) ); diff --git a/app/src/test/java/fr/inria/verveine/extractor/java/VerveineJTest_Exceptions.java b/app/src/test/java/fr/inria/verveine/extractor/java/VerveineJTest_Exceptions.java index 004dcb17..5b4b59f5 100644 --- a/app/src/test/java/fr/inria/verveine/extractor/java/VerveineJTest_Exceptions.java +++ b/app/src/test/java/fr/inria/verveine/extractor/java/VerveineJTest_Exceptions.java @@ -2,22 +2,22 @@ import org.junit.Before; import org.junit.Test; +import org.moosetechnology.model.famix.famixjavaentities.Exception; import org.moosetechnology.model.famix.famixjavaentities.Method; +import org.moosetechnology.model.famix.famixjavaentities.Class; import org.moosetechnology.model.famix.famixjavaentities.TypeParameter; import org.moosetechnology.model.famix.famixtraits.TNamedEntity; import static org.junit.Assert.*; -import org.eclipse.jdt.core.dom.ThrowStatement; - public class VerveineJTest_Exceptions extends VerveineJTest_Basic { /** * @throws java.lang.Exception */ @Before - public void setUp() throws Exception { + public void setUp() throws java.lang.Exception { parser = new VerveineJParser(); repo = parser.getFamixRepo(); parser.configure( new String[] {"src/test/resources/exceptions"}); @@ -163,5 +163,41 @@ public void testThrowingUnionTypeException() { assertEquals(1,throwerMethod.getThrownExceptions().size()); assertEquals("Throwable", ((TNamedEntity)firstElt(throwerMethod.getThrownExceptions())).getName() ); } - + + @Test + public void testLoadExceptionWithoutThrow() { + parser = new VerveineJParser(); + repo = parser.getFamixRepo(); + + //If we load in JDK mode, RuntimeException is not available and we do not realize that this is an exception! + parser.configure( new String[] { "-jdkMode", "-1.7", + "src/test/resources/exceptions/OurRuntimeException.java" }); + parser.parse(); + + //The exception is not throwable! + assertNull(detectFamixElement(Exception.class, "OurRuntimeException")); + //But a normal class + assertNotNull(detectFamixElement(Class.class, "OurRuntimeException")); + } + + @Test + public void testTransformNormalClassToException() { + parser = new VerveineJParser(); + repo = parser.getFamixRepo(); + + //We parse first the exception, then the client. + parser.configure( new String[] { + "-jdkMode", "-1.7", + "src/test/resources/exceptions/OurRuntimeException.java", + "src/test/resources/exceptions/OurRuntimeExceptionThrower.java" }); + parser.parse(); + + Exception e = detectFamixElement(Exception.class, "OurRuntimeException"); + //Now the exception should be a throwable! + assertNotNull(e); + + //And the comments should be transferred + assertTrue(e.hasComments()); + assertEquals(e, e.getComments().iterator().next().getCommentedEntity()); + } } diff --git a/app/src/test/resources/exceptions/OurRuntimeException.java b/app/src/test/resources/exceptions/OurRuntimeException.java new file mode 100644 index 00000000..22dffe1c --- /dev/null +++ b/app/src/test/resources/exceptions/OurRuntimeException.java @@ -0,0 +1,9 @@ +/** + * Package Comment!! + */ +package exceptions; + +/** + * With Comment!! + */ +public class OurRuntimeException extends RuntimeException { } diff --git a/app/src/test/resources/exceptions/OurRuntimeExceptionThrower.java b/app/src/test/resources/exceptions/OurRuntimeExceptionThrower.java new file mode 100644 index 00000000..6ce388e3 --- /dev/null +++ b/app/src/test/resources/exceptions/OurRuntimeExceptionThrower.java @@ -0,0 +1,10 @@ +package exceptions; + + +public class OurRuntimeExceptionThrower { + + public static OurRuntimeExceptionThrower method() { + throw new OurRuntimeException(); + } + +}