@Override
 public void visitBreakStatement(@NotNull PsiBreakStatement statement) {
   final PsiIdentifier labelIdentifier = statement.getLabelIdentifier();
   if (labelIdentifier == null) {
     return;
   }
   final String labelText = labelIdentifier.getText();
   if (labelText == null || labelText.length() == 0) {
     return;
   }
   final PsiStatement exitedStatement = statement.findExitedStatement();
   if (exitedStatement == null) {
     return;
   }
   final PsiStatement labelEnabledParent =
       PsiTreeUtil.getParentOfType(
           statement,
           PsiForStatement.class,
           PsiDoWhileStatement.class,
           PsiForeachStatement.class,
           PsiWhileStatement.class,
           PsiSwitchStatement.class);
   if (labelEnabledParent == null) {
     return;
   }
   if (exitedStatement.equals(labelEnabledParent)) {
     registerStatementError(statement);
   }
 }
コード例 #2
0
 public void visitBreakStatement(PsiBreakStatement statement) {
   super.visitBreakStatement(statement);
   if (statement.getLabelIdentifier() != null) {
     elementCount++;
   } else if (!(statement.findExitedStatement() instanceof PsiSwitchStatement)) {
     elementCount++;
   }
 }
 public void doFix(Project project, ProblemDescriptor descriptor)
     throws IncorrectOperationException {
   final PsiElement breakKeywordElement = descriptor.getPsiElement();
   final PsiBreakStatement breakStatement = (PsiBreakStatement) breakKeywordElement.getParent();
   final PsiIdentifier identifier = breakStatement.getLabelIdentifier();
   if (identifier == null) {
     return;
   }
   identifier.delete();
 }
コード例 #4
0
 private static boolean breakStatementsAreEquivalent(
     @NotNull PsiBreakStatement statement1, @NotNull PsiBreakStatement statement2) {
   final PsiIdentifier identifier1 = statement1.getLabelIdentifier();
   final PsiIdentifier identifier2 = statement2.getLabelIdentifier();
   if (identifier1 == null) {
     return identifier2 == null;
   }
   if (identifier2 == null) {
     return false;
   }
   final String text1 = identifier1.getText();
   final String text2 = identifier2.getText();
   return text1.equals(text2);
 }