Skip to content

Commit aff2f5f

Browse files
committed
Fix exception comments when exceptions are detected afterwards
1 parent 6d6ebf0 commit aff2f5f

5 files changed

Lines changed: 60 additions & 6 deletions

File tree

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1340,6 +1340,7 @@ public TThrowable asException(TType fmxType) {
13401340
fmxException.addSuperInheritances( new ArrayList<>( ((TWithInheritances) fmxType).getSuperInheritances() ) );
13411341
fmxException.addSubInheritances( new ArrayList<>( ((TWithInheritances) fmxType).getSubInheritances() ) );
13421342
}
1343+
fmxException.setComments(new ArrayList<>( ((TWithComments) fmxType).getComments() ));
13431344
fmxException.setSourceAnchor(fmxType.getSourceAnchor());
13441345
fmxException.addIncomingTypings( new ArrayList<>( fmxType.getIncomingTypings() ) );
13451346
fmxException.addAnnotationInstances( new ArrayList<>( ((NamedEntity)fmxType).getAnnotationInstances() ) );

app/src/main/java/org/moosetechnology/model/famix/famixjavaentities/Class.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,8 +1021,6 @@ public Number getWeightedMethodCount() {
10211021
// TODO: this is a derived property, implement this method manually.
10221022
throw new UnsupportedOperationException("Not yet implemented!");
10231023
}
1024-
1025-
10261024

10271025
}
10281026

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

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,22 @@
22

33
import org.junit.Before;
44
import org.junit.Test;
5+
import org.moosetechnology.model.famix.famixjavaentities.Exception;
56
import org.moosetechnology.model.famix.famixjavaentities.Method;
7+
import org.moosetechnology.model.famix.famixjavaentities.Class;
68
import org.moosetechnology.model.famix.famixjavaentities.TypeParameter;
79
import org.moosetechnology.model.famix.famixtraits.TNamedEntity;
810

911

1012
import static org.junit.Assert.*;
1113

12-
import org.eclipse.jdt.core.dom.ThrowStatement;
13-
1414
public class VerveineJTest_Exceptions extends VerveineJTest_Basic {
1515

1616
/**
1717
* @throws java.lang.Exception
1818
*/
1919
@Before
20-
public void setUp() throws Exception {
20+
public void setUp() throws java.lang.Exception {
2121
parser = new VerveineJParser();
2222
repo = parser.getFamixRepo();
2323
parser.configure( new String[] {"src/test/resources/exceptions"});
@@ -163,5 +163,41 @@ public void testThrowingUnionTypeException() {
163163
assertEquals(1,throwerMethod.getThrownExceptions().size());
164164
assertEquals("Throwable", ((TNamedEntity)firstElt(throwerMethod.getThrownExceptions())).getName() );
165165
}
166-
166+
167+
@Test
168+
public void testLoadExceptionWithoutThrow() {
169+
parser = new VerveineJParser();
170+
repo = parser.getFamixRepo();
171+
172+
//If we load in JDK mode, RuntimeException is not available and we do not realize that this is an exception!
173+
parser.configure( new String[] { "-jdkMode", "-1.7",
174+
"src/test/resources/exceptions/OurRuntimeException.java" });
175+
parser.parse();
176+
177+
//The exception is not throwable!
178+
assertNull(detectFamixElement(Exception.class, "OurRuntimeException"));
179+
//But a normal class
180+
assertNotNull(detectFamixElement(Class.class, "OurRuntimeException"));
181+
}
182+
183+
@Test
184+
public void testTransformNormalClassToException() {
185+
parser = new VerveineJParser();
186+
repo = parser.getFamixRepo();
187+
188+
//We parse first the exception, then the client.
189+
parser.configure( new String[] {
190+
"-jdkMode", "-1.7",
191+
"src/test/resources/exceptions/OurRuntimeException.java",
192+
"src/test/resources/exceptions/OurRuntimeExceptionThrower.java" });
193+
parser.parse();
194+
195+
Exception e = detectFamixElement(Exception.class, "OurRuntimeException");
196+
//Now the exception should be a throwable!
197+
assertNotNull(e);
198+
199+
//And the comments should be transferred
200+
assertTrue(e.hasComments());
201+
assertEquals(e, e.getComments().iterator().next().getCommentedEntity());
202+
}
167203
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/**
2+
* Package Comment!!
3+
*/
4+
package exceptions;
5+
6+
/**
7+
* With Comment!!
8+
*/
9+
public class OurRuntimeException extends RuntimeException { }
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package exceptions;
2+
3+
4+
public class OurRuntimeExceptionThrower {
5+
6+
public static OurRuntimeExceptionThrower method() {
7+
throw new OurRuntimeException();
8+
}
9+
10+
}

0 commit comments

Comments
 (0)