@Override public void visitSwitchStatement( @NotNull PsiSwitchStatement statement) { super.visitSwitchStatement(statement); final PsiElement containingSwitchStatement = PsiTreeUtil.getParentOfType(statement, PsiSwitchStatement.class); if (containingSwitchStatement == null) { return; } final PsiMethod containingMethod = PsiTreeUtil.getParentOfType(statement, PsiMethod.class); final PsiMethod containingContainingMethod = PsiTreeUtil.getParentOfType(containingSwitchStatement, PsiMethod.class); if (containingMethod == null || containingContainingMethod == null || !containingMethod.equals(containingContainingMethod)) { return; } registerStatementError(statement); }
@Override public void visitSwitchStatement( @NotNull PsiSwitchStatement statement) { final PsiCodeBlock body = statement.getBody(); if (body == null) { return; } final int branchCount = SwitchUtils.calculateBranchCount(statement); if (branchCount <= m_limit) { return; } registerStatementError(statement, Integer.valueOf(branchCount)); }
@Override public void visitSwitchStatement( @NotNull PsiSwitchStatement statement) { super.visitSwitchStatement(statement); final PsiCodeBlock body = statement.getBody(); if (body == null) { return; } final PsiStatement[] statements = body.getStatements(); boolean labelSeen = false; for (int i = statements.length - 1; i >= 0; i--) { final PsiStatement child = statements[i]; if (child instanceof PsiSwitchLabelStatement) { final PsiSwitchLabelStatement label = (PsiSwitchLabelStatement)child; if (label.isDefaultCase()) { if (labelSeen) { registerStatementError(label); } return; } else { labelSeen = true; } } } }
@Override public void visitSwitchStatement(@NotNull PsiSwitchStatement statement) { super.visitSwitchStatement(statement); if (NestedSynchronizedStatementInspection.isNestedStatement(statement, PsiSwitchStatement.class)) { registerStatementError(statement); } }
@Override public void visitSwitchStatement(@NotNull PsiSwitchStatement statement) { final PsiCodeBlock body = statement.getBody(); if (body == null) { return; } final int branchCount = SwitchUtils.calculateBranchCount(statement); if (branchCount == 0) { return; // // do not warn when no switch branches are present at all } if (branchCount >= m_limit) { return; } registerStatementError(statement, Integer.valueOf(branchCount)); }
@Override public void apply(Editor editor, JavaSmartEnterProcessor processor, PsiElement psiElement) throws IncorrectOperationException { if(psiElement instanceof PsiSwitchStatement) { final Document doc = editor.getDocument(); final PsiSwitchStatement switchStatement = (PsiSwitchStatement) psiElement; final PsiJavaToken rParenth = switchStatement.getRParenth(); final PsiJavaToken lParenth = switchStatement.getLParenth(); final PsiExpression condition = switchStatement.getExpression(); if(condition == null) { if(lParenth == null || rParenth == null) { int stopOffset = doc.getLineEndOffset(doc.getLineNumber(switchStatement.getTextRange().getStartOffset())); final PsiCodeBlock block = switchStatement.getBody(); if(block != null) { stopOffset = Math.min(stopOffset, block.getTextRange().getStartOffset()); } doc.replaceString(switchStatement.getTextRange().getStartOffset(), stopOffset, "switch ()"); } else { processor.registerUnresolvedError(lParenth.getTextRange().getEndOffset()); } } else if(rParenth == null) { doc.insertString(condition.getTextRange().getEndOffset(), ")"); } } }
@Override public void visitSwitchStatement(PsiSwitchStatement statement) { mVisitor.report("PsiSwitchStatement", statement.getText(), statement); super.visitStatement(statement); }
@Override public void visitSwitchStatement( @NotNull PsiSwitchStatement statement) { super.visitSwitchStatement(statement); registerStatementError(statement); }