Search in sources :

Example 1 with PhpContinue

use of com.jetbrains.php.lang.psi.elements.PhpContinue in project phpinspectionsea by kalessil.

the class SwitchContinuationInLoopInspector method buildVisitor.

@Override
@NotNull
public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, boolean isOnTheFly) {
    return new BasePhpElementVisitor() {

        @Override
        public void visitPhpContinue(@NotNull PhpContinue continueStatement) {
            /* check if continue already defined with desired level */
            if (null != continueStatement.getFirstPsiChild()) {
                return;
            }
            boolean isSwitch = false;
            PsiElement objParent = continueStatement.getParent();
            while (null != objParent) {
                /* reached file or callable */
                if (objParent instanceof PhpFile || objParent instanceof Function) {
                    return;
                }
                /* check if should operate on loop-switch-continue analysis */
                if (!isSwitch && objParent instanceof PhpSwitch) {
                    isSwitch = true;
                }
                /* when met a loop, complete analysis */
                if (OpenapiTypesUtil.isLoop(objParent)) {
                    if (isSwitch) {
                        holder.registerProblem(continueStatement, MessagesPresentationUtil.prefixWithEa(message), ProblemHighlightType.GENERIC_ERROR, new UseContinue2LocalFix());
                    }
                    return;
                }
                objParent = objParent.getParent();
            }
        }
    };
}
Also used : BasePhpElementVisitor(com.kalessil.phpStorm.phpInspectionsEA.openApi.BasePhpElementVisitor) Function(com.jetbrains.php.lang.psi.elements.Function) PhpFile(com.jetbrains.php.lang.psi.PhpFile) PhpContinue(com.jetbrains.php.lang.psi.elements.PhpContinue) PhpSwitch(com.jetbrains.php.lang.psi.elements.PhpSwitch) NotNull(org.jetbrains.annotations.NotNull) PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

PsiElement (com.intellij.psi.PsiElement)1 PhpFile (com.jetbrains.php.lang.psi.PhpFile)1 Function (com.jetbrains.php.lang.psi.elements.Function)1 PhpContinue (com.jetbrains.php.lang.psi.elements.PhpContinue)1 PhpSwitch (com.jetbrains.php.lang.psi.elements.PhpSwitch)1 BasePhpElementVisitor (com.kalessil.phpStorm.phpInspectionsEA.openApi.BasePhpElementVisitor)1 NotNull (org.jetbrains.annotations.NotNull)1