Change ast parser behavior

I’m trying to develop custom rule for javacard.

In javacard its common to use ISOExeption.throwIt() method rather than throw new ISOException().

Is there anyway to change ast parser behavior so that the ISOExeption.throwIt() returning ThrowStatementTree instead of MethodInvocationTree?

This would make little sense : ISOExeption.throwIt() is a MethodInvocationTree and NOT a ThrowStatementTree even though in your case those are semantically equivalent.

could you be more specific about what you are trying to achieve here ? If it is about determining returned type of that method invocation then you should rely on semantic and detect such calls that you know are going to throw.

Hope that helps,

Cheers,

Thank you for the answer nicolas…
So what I’m to do here is extending JC003 rule from SwitchCaseWithoutBreakRule class to perform test like following:

  public process(APDU apdu)
        {
            byte[] apduBuffer = apdu.getBuffer();
            byte ins = apduBuffer[ISO7816.OFFSET_INS];
            switch(ins)
            {
                //...
                case INS_7:
                    ISOException.throwIt(ISO7816.SW_NO_ERROR);
                case INS_8:         // Noncompliant {39=[{MESSAGE=End this switch case with an unconditional break, return or throw statement.}}
                    doSomethingElse();
                    if(apduBuffer[ISO7816.OFFSET_CLA]==0x80)
                        return;
                case INS_10:      // Noncompliant {43=[{MESSAGE=End this switch case with an unconditional break, return or throw statement.}}
                    doSomethingElse();
                    if(apduBuffer[ISO7816.OFFSET_CLA]==0x80)
                        ISOException.throwIt(ISO7816.SW_NO_ERROR);
                case INS_9:
                    doSomething();
                    break;
                default:
                    doSomethingElse();
                    break;
            }
        }

If I understand correctly, you want to remove some false positives for those method throwIt which you know are always going to throw so you don’t need break.
In order to do that you should rely on semantic to recognize that xxx.throwIt() method invocations are of some specific methods (defined by type and the method name) by retrieving the symbol on the MethodInvocationTree and testing it appropriately.

Thank you for your idea Nicolas. Solution is work, what I did is filter the issue before reporting the issue by checking the semantics.