@Nullable private static NamespaceNameTree getThrownClassName(ThrowStatementTree tree) { if (tree.expression().is(Kind.NEW_EXPRESSION)) { NewExpressionTree newExpression = (NewExpressionTree) tree.expression(); if (newExpression.expression().is(Kind.FUNCTION_CALL)) { FunctionCallTree functionCall = (FunctionCallTree) newExpression.expression(); if (functionCall.callee().is(Kind.NAMESPACE_NAME)) { return (NamespaceNameTree) functionCall.callee(); } } } return null; }
@Nullable private static NamespaceNameTree getThrownClassName(ThrowStatementTree tree) { if (tree.expression().is(Kind.NEW_EXPRESSION)) { NewExpressionTree newExpression = (NewExpressionTree) tree.expression(); if (newExpression.expression().is(Kind.FUNCTION_CALL)) { FunctionCallTree functionCall = (FunctionCallTree) newExpression.expression(); if (functionCall.callee().is(Kind.NAMESPACE_NAME)) { return (NamespaceNameTree) functionCall.callee(); } } } return null; }
private static boolean isRetrowingException(CatchBlockTree catchBlock) { StatementTree statement = catchBlock.block().statements().get(0); if (!statement.is(Tree.Kind.THROW_STATEMENT)) { return false; } ExpressionTree thrownExpression = CheckUtils.skipParenthesis(((ThrowStatementTree) statement).expression()); return SyntacticEquivalence.areSyntacticallyEquivalent(catchBlock.variable(), thrownExpression); } }
private static boolean isRetrowingException(CatchBlockTree catchBlock) { StatementTree statement = catchBlock.block().statements().get(0); if (!statement.is(Tree.Kind.THROW_STATEMENT)) { return false; } ExpressionTree thrownExpression = CheckUtils.skipParenthesis(((ThrowStatementTree) statement).expression()); return SyntacticEquivalence.areSyntacticallyEquivalent(catchBlock.variable(), thrownExpression); } }
@Nullable private static String getReturnedOrThrownVariableName(StatementTree statement) { ExpressionTree returnedVariable = null; if (statement.is(Kind.RETURN_STATEMENT)) { returnedVariable = ((ReturnStatementTree) statement).expression(); } else if (statement.is(Kind.THROW_STATEMENT)) { returnedVariable = ((ThrowStatementTree) statement).expression(); } String returnedName = null; if (returnedVariable != null && returnedVariable.is(Kind.VARIABLE_IDENTIFIER)) { returnedName = ((VariableIdentifierTree) returnedVariable).variableExpression().text(); } return returnedName; }
@Nullable private static String getReturnedOrThrownVariableName(StatementTree statement) { ExpressionTree returnedVariable = null; if (statement.is(Kind.RETURN_STATEMENT)) { returnedVariable = ((ReturnStatementTree) statement).expression(); } else if (statement.is(Kind.THROW_STATEMENT)) { returnedVariable = ((ThrowStatementTree) statement).expression(); } String returnedName = null; if (returnedVariable != null && returnedVariable.is(Kind.VARIABLE_IDENTIFIER)) { returnedName = ((VariableIdentifierTree) returnedVariable).variableExpression().text(); } return returnedName; }
@Test public void test() throws Exception { ThrowStatementTree tree = parse("throw $a ;", PHPLexicalGrammar.THROW_STATEMENT); assertThat(tree.is(Kind.THROW_STATEMENT)).isTrue(); assertThat(tree.throwToken().text()).isEqualTo("throw"); assertThat(expressionToString(tree.expression())).isEqualTo("$a"); assertThat(tree.eosToken().text()).isEqualTo(";"); }