Java 类com.intellij.psi.PsiSwitchStatement 实例源码

项目:tools-idea    文件:NestedSwitchStatementInspection.java   
@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);
}
项目:consulo-java    文件:NestedSwitchStatementInspection.java   
@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);
}
项目:intellij-ce-playground    文件:SwitchStatementWithTooManyBranchesInspection.java   
@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));
}
项目:intellij-ce-playground    文件:DefaultNotLastCaseInSwitchInspection.java   
@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;
      }
    }
  }
}
项目:intellij-ce-playground    文件:NestedSwitchStatementInspection.java   
@Override
public void visitSwitchStatement(@NotNull PsiSwitchStatement statement) {
  super.visitSwitchStatement(statement);
  if (NestedSynchronizedStatementInspection.isNestedStatement(statement, PsiSwitchStatement.class)) {
    registerStatementError(statement);
  }
}
项目:intellij-ce-playground    文件:SwitchStatementWithTooFewBranchesInspection.java   
@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));
}
项目:tools-idea    文件:SwitchStatementWithTooManyBranchesInspection.java   
@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));
}
项目:tools-idea    文件:DefaultNotLastCaseInSwitchInspection.java   
@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;
      }
    }
  }
}
项目:tools-idea    文件:SwitchStatementWithTooFewBranchesInspection.java   
@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));
}
项目:consulo-java    文件:SwitchExpressionFixer.java   
@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(), ")");
        }
    }
}
项目:consulo-java    文件:SwitchStatementWithTooManyBranchesInspection.java   
@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));
}
项目:consulo-java    文件:DefaultNotLastCaseInSwitchInspection.java   
@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;
      }
    }
  }
}
项目:consulo-java    文件:SwitchStatementWithTooFewBranchesInspection.java   
@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));
}
项目:Android_Lint_SRP_Practice_Example    文件:PsiClassStructureDetector.java   
@Override
public void visitSwitchStatement(PsiSwitchStatement statement) {
    mVisitor.report("PsiSwitchStatement", statement.getText(), statement);
    super.visitStatement(statement);
}
项目:intellij-ce-playground    文件:SwitchStatementInspection.java   
@Override
public void visitSwitchStatement(
  @NotNull PsiSwitchStatement statement) {
  super.visitSwitchStatement(statement);
  registerStatementError(statement);
}
项目:tools-idea    文件:SwitchStatementInspection.java   
@Override
public void visitSwitchStatement(
  @NotNull PsiSwitchStatement statement) {
  super.visitSwitchStatement(statement);
  registerStatementError(statement);
}
项目:consulo-java    文件:SwitchStatementInspection.java   
@Override
public void visitSwitchStatement(
  @NotNull PsiSwitchStatement statement) {
  super.visitSwitchStatement(statement);
  registerStatementError(statement);
}