Search in sources :

Example 26 with CtConstructorCall

use of spoon.reflect.code.CtConstructorCall in project spoon by INRIA.

the class IntercessionScanner method avoidThrowUnsupportedOperationException.

protected boolean avoidThrowUnsupportedOperationException(CtMethod<?> candidate) {
    if (candidate.getBody().getStatements().size() != 1) {
        return true;
    }
    if (!(candidate.getBody().getStatement(0) instanceof CtThrow)) {
        return true;
    }
    CtThrow ctThrow = candidate.getBody().getStatement(0);
    if (!(ctThrow.getThrownExpression() instanceof CtConstructorCall)) {
        return true;
    }
    final CtConstructorCall<? extends Throwable> thrownExpression = (CtConstructorCall<? extends Throwable>) ctThrow.getThrownExpression();
    if (!thrownExpression.getType().equals(factory.Type().createReference(UnsupportedOperationException.class))) {
        return true;
    }
    return false;
}
Also used : CtThrow(spoon.reflect.code.CtThrow) CtConstructorCall(spoon.reflect.code.CtConstructorCall)

Aggregations

CtConstructorCall (spoon.reflect.code.CtConstructorCall)26 Test (org.junit.Test)20 Launcher (spoon.Launcher)14 Factory (spoon.reflect.factory.Factory)9 TypeFilter (spoon.reflect.visitor.filter.TypeFilter)9 CtClass (spoon.reflect.declaration.CtClass)6 CtReturn (spoon.reflect.code.CtReturn)5 CtElement (spoon.reflect.declaration.CtElement)4 CtMethod (spoon.reflect.declaration.CtMethod)4 MainTest (spoon.test.main.MainTest)4 ArrayList (java.util.ArrayList)3 CtComment (spoon.reflect.code.CtComment)3 CtExpression (spoon.reflect.code.CtExpression)3 CtIf (spoon.reflect.code.CtIf)3 CtInvocation (spoon.reflect.code.CtInvocation)3 CtLocalVariable (spoon.reflect.code.CtLocalVariable)3 CtStatement (spoon.reflect.code.CtStatement)3 CtConstructor (spoon.reflect.declaration.CtConstructor)3 CtParameter (spoon.reflect.declaration.CtParameter)3 CtTypeReference (spoon.reflect.reference.CtTypeReference)3