Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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() ) );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"});
Expand Down Expand Up @@ -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());
}
}
9 changes: 9 additions & 0 deletions app/src/test/resources/exceptions/OurRuntimeException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* Package Comment!!
*/
package exceptions;

/**
* With Comment!!
*/
public class OurRuntimeException extends RuntimeException { }
10 changes: 10 additions & 0 deletions app/src/test/resources/exceptions/OurRuntimeExceptionThrower.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package exceptions;


public class OurRuntimeExceptionThrower {

public static OurRuntimeExceptionThrower method() {
throw new OurRuntimeException();
}

}
Loading