Search in sources :

Example 1 with PhpGotoLabel

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

the class UnusedGotoLabelInspector method buildVisitor.

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

        @Override
        public void visitPhpGotoLabel(@NotNull PhpGotoLabel label) {
            final Function function = ExpressionSemanticUtil.getScope(label);
            final GroupStatement body = null == function ? null : ExpressionSemanticUtil.getGroupStatement(function);
            if (body != null && ExpressionSemanticUtil.countExpressionsInGroup(body) > 0) {
                /* process goto statements and drop used from existing */
                final Collection<PhpGoto> references = PsiTreeUtil.findChildrenOfType(body, PhpGoto.class);
                if (!references.isEmpty()) {
                    final String labelName = label.getName();
                    for (final PhpGoto gotoExpression : references) {
                        final String labelUsed = gotoExpression.getName();
                        if (null != labelUsed && labelUsed.equals(labelName)) {
                            references.clear();
                            return;
                        }
                    }
                    references.clear();
                }
                /* TODO: marks as unused instead, see https://youtrack.jetbrains.com/issue/WI-34508 */
                holder.registerProblem(label, MessagesPresentationUtil.prefixWithEa(message), ProblemHighlightType.LIKE_DEPRECATED, new TheLocalFix());
            }
        }
    };
}
Also used : BasePhpElementVisitor(com.kalessil.phpStorm.phpInspectionsEA.openApi.BasePhpElementVisitor) Function(com.jetbrains.php.lang.psi.elements.Function) GroupStatement(com.jetbrains.php.lang.psi.elements.GroupStatement) NotNull(org.jetbrains.annotations.NotNull) PhpGotoLabel(com.jetbrains.php.lang.psi.elements.PhpGotoLabel) PhpGoto(com.jetbrains.php.lang.psi.elements.PhpGoto) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

Function (com.jetbrains.php.lang.psi.elements.Function)1 GroupStatement (com.jetbrains.php.lang.psi.elements.GroupStatement)1 PhpGoto (com.jetbrains.php.lang.psi.elements.PhpGoto)1 PhpGotoLabel (com.jetbrains.php.lang.psi.elements.PhpGotoLabel)1 BasePhpElementVisitor (com.kalessil.phpStorm.phpInspectionsEA.openApi.BasePhpElementVisitor)1 NotNull (org.jetbrains.annotations.NotNull)1