Search in sources :

Example 1 with MaybeReturnInstruction

use of org.jetbrains.plugins.groovy.lang.psi.controlFlow.impl.MaybeReturnInstruction in project intellij-community by JetBrains.

the class ControlFlowUtils method visitAllExitPointsInner.

private static boolean visitAllExitPointsInner(Instruction last, Instruction first, boolean[] visited, ExitPointVisitor visitor) {
    if (first == last)
        return true;
    if (last instanceof AfterCallInstruction) {
        visited[last.num()] = true;
        return visitAllExitPointsInner(((AfterCallInstruction) last).myCall, first, visited, visitor);
    }
    if (last instanceof MaybeReturnInstruction) {
        return visitor.visitExitPoint(last, (GrExpression) last.getElement());
    } else if (last instanceof IfEndInstruction) {
        visited[last.num()] = true;
        for (Instruction instruction : last.allPredecessors()) {
            if (!visitAllExitPointsInner(instruction, first, visited, visitor))
                return false;
        }
        return true;
    } else if (last instanceof ThrowingInstruction) {
        PsiElement element = last.getElement();
        if (!(element instanceof GrThrowStatement || element instanceof GrAssertStatement))
            return true;
    }
    PsiElement element = last.getElement();
    if (element != null) {
        final GrExpression returnValue;
        if (element instanceof GrReturnStatement) {
            returnValue = ((GrReturnStatement) element).getReturnValue();
        } else if (element instanceof GrExpression && PsiUtil.isExpressionStatement(element)) {
            returnValue = (GrExpression) element;
        } else {
            returnValue = null;
        }
        return visitor.visitExitPoint(last, returnValue);
    }
    visited[last.num()] = true;
    for (Instruction pred : last.allPredecessors()) {
        if (!visited[pred.num()]) {
            if (!visitAllExitPointsInner(pred, first, visited, visitor))
                return false;
        }
    }
    return true;
}
Also used : MaybeReturnInstruction(org.jetbrains.plugins.groovy.lang.psi.controlFlow.impl.MaybeReturnInstruction) GrExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression) AfterCallInstruction(org.jetbrains.plugins.groovy.lang.psi.controlFlow.AfterCallInstruction) Instruction(org.jetbrains.plugins.groovy.lang.psi.controlFlow.Instruction) MaybeReturnInstruction(org.jetbrains.plugins.groovy.lang.psi.controlFlow.impl.MaybeReturnInstruction) AfterCallInstruction(org.jetbrains.plugins.groovy.lang.psi.controlFlow.AfterCallInstruction) ThrowingInstruction(org.jetbrains.plugins.groovy.lang.psi.controlFlow.impl.ThrowingInstruction) IfEndInstruction(org.jetbrains.plugins.groovy.lang.psi.controlFlow.impl.IfEndInstruction) ReadWriteVariableInstruction(org.jetbrains.plugins.groovy.lang.psi.controlFlow.ReadWriteVariableInstruction) ThrowingInstruction(org.jetbrains.plugins.groovy.lang.psi.controlFlow.impl.ThrowingInstruction) PsiElement(com.intellij.psi.PsiElement) GroovyPsiElement(org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement) IfEndInstruction(org.jetbrains.plugins.groovy.lang.psi.controlFlow.impl.IfEndInstruction)

Aggregations

PsiElement (com.intellij.psi.PsiElement)1 GroovyPsiElement (org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement)1 GrExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression)1 AfterCallInstruction (org.jetbrains.plugins.groovy.lang.psi.controlFlow.AfterCallInstruction)1 Instruction (org.jetbrains.plugins.groovy.lang.psi.controlFlow.Instruction)1 ReadWriteVariableInstruction (org.jetbrains.plugins.groovy.lang.psi.controlFlow.ReadWriteVariableInstruction)1 IfEndInstruction (org.jetbrains.plugins.groovy.lang.psi.controlFlow.impl.IfEndInstruction)1 MaybeReturnInstruction (org.jetbrains.plugins.groovy.lang.psi.controlFlow.impl.MaybeReturnInstruction)1 ThrowingInstruction (org.jetbrains.plugins.groovy.lang.psi.controlFlow.impl.ThrowingInstruction)1