@Override public void apply(Editor editor, JavaSmartEnterProcessor processor, PsiElement psiElement) throws IncorrectOperationException { if (psiElement instanceof PsiSwitchLabelStatement && ((PsiSwitchLabelStatement)psiElement).getCaseValue() != null && !psiElement.getText().endsWith(":")) { editor.getDocument().insertString(psiElement.getTextRange().getEndOffset(), ":"); } }
@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 apply(Editor editor, JavaSmartEnterProcessor processor, PsiElement psiElement) throws IncorrectOperationException { if(psiElement instanceof PsiSwitchLabelStatement && !psiElement.getText().endsWith(":")) { PsiSwitchLabelStatement statement = (PsiSwitchLabelStatement) psiElement; if(statement.getCaseValue() != null || statement.isDefaultCase()) { editor.getDocument().insertString(psiElement.getTextRange().getEndOffset(), ":"); } } }
@Override public void visitSwitchLabelStatement(PsiSwitchLabelStatement statement) { mVisitor.report("PsiSwitchLabelStatement", statement.getText(), statement); super.visitStatement(statement); }