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

项目:intellij-ce-playground    文件:PopFrameAction.java   
private static List<PsiStatement> getFinallyStatements(@Nullable SourcePosition position) {
  if (position == null) {
    return Collections.emptyList();
  }
  List<PsiStatement> res = new ArrayList<PsiStatement>();
  PsiElement element = position.getFile().findElementAt(position.getOffset());
  PsiTryStatement tryStatement = PsiTreeUtil.getParentOfType(element, PsiTryStatement.class);
  while (tryStatement != null) {
    PsiCodeBlock finallyBlock = tryStatement.getFinallyBlock();
    if (finallyBlock != null) {
      ContainerUtil.addAll(res, finallyBlock.getStatements());
    }
    tryStatement = PsiTreeUtil.getParentOfType(tryStatement, PsiTryStatement.class);
  }
  return res;
}
项目:intellij-ce-playground    文件:NestedTryStatementInspection.java   
@Override
public void visitTryStatement(@NotNull PsiTryStatement statement) {
  super.visitTryStatement(statement);
  final PsiTryStatement parentTry = PsiTreeUtil.getParentOfType(statement, PsiTryStatement.class);
  if (parentTry == null) {
    return;
  }
  final PsiCodeBlock tryBlock = parentTry.getTryBlock();
  if (tryBlock == null) {
    return;
  }
  if (!PsiTreeUtil.isAncestor(tryBlock, statement, true)) {
    return;
  }
  if (NestedSynchronizedStatementInspection.isNestedStatement(statement, PsiTryStatement.class)) {
    registerStatementError(statement);
  }
}
项目:intellij-ce-playground    文件:FinallyBlockCannotCompleteNormallyInspection.java   
@Override
public void visitTryStatement(@NotNull PsiTryStatement statement) {
  super.visitTryStatement(statement);
  final PsiCodeBlock finallyBlock = statement.getFinallyBlock();
  if (finallyBlock == null) {
    return;
  }
  if (ControlFlowUtils.codeBlockMayCompleteNormally(finallyBlock)) {
    return;
  }
  final PsiElement[] children = statement.getChildren();
  for (final PsiElement child : children) {
    final String childText = child.getText();
    if (PsiKeyword.FINALLY.equals(childText)) {
      registerError(child);
      return;
    }
  }
}
项目:tools-idea    文件:FinallyBlockCannotCompleteNormallyInspection.java   
@Override
public void visitTryStatement(@NotNull PsiTryStatement statement) {
  super.visitTryStatement(statement);
  final PsiCodeBlock finallyBlock = statement.getFinallyBlock();
  if (finallyBlock == null) {
    return;
  }
  if (ControlFlowUtils.codeBlockMayCompleteNormally(finallyBlock)) {
    return;
  }
  final PsiElement[] children = statement.getChildren();
  for (final PsiElement child : children) {
    final String childText = child.getText();
    if (PsiKeyword.FINALLY.equals(childText)) {
      registerError(child);
      return;
    }
  }
}
项目:consulo-java    文件:MissingTryBodyFixer.java   
@Override
public void apply(Editor editor, JavaSmartEnterProcessor processor, PsiElement psiElement) throws IncorrectOperationException
{
    if(!(psiElement instanceof PsiTryStatement))
    {
        return;
    }
    PsiTryStatement tryStatement = (PsiTryStatement) psiElement;

    final Document doc = editor.getDocument();

    PsiElement body = tryStatement.getTryBlock();
    if(body != null)
    {
        return;
    }

    doc.insertString(tryStatement.getTextRange().getEndOffset(), "{}");
}
项目:consulo-java    文件:FinallyBlockCannotCompleteNormallyInspection.java   
@Override
public void visitTryStatement(@NotNull PsiTryStatement statement) {
  super.visitTryStatement(statement);
  final PsiCodeBlock finallyBlock = statement.getFinallyBlock();
  if (finallyBlock == null) {
    return;
  }
  if (ControlFlowUtils.codeBlockMayCompleteNormally(finallyBlock)) {
    return;
  }
  final PsiElement[] children = statement.getChildren();
  for (final PsiElement child : children) {
    final String childText = child.getText();
    if (PsiKeyword.FINALLY.equals(childText)) {
      registerError(child);
      return;
    }
  }
}
项目:intellij-ce-playground    文件:MoveCatchUpFix.java   
@Override
public void invoke(@NotNull Project project, Editor editor, PsiFile file) {
  if (!FileModificationService.getInstance().prepareFileForWrite(myCatchSection.getContainingFile())) return;
  try {
    PsiTryStatement statement = myCatchSection.getTryStatement();
    statement.addBefore(myCatchSection, myMoveBeforeSection);
    myCatchSection.delete();
  }
  catch (IncorrectOperationException e) {
    LOG.error(e);
  }
}
项目:intellij-ce-playground    文件:JavaTryUnwrapper.java   
@Override
protected void doUnwrap(final PsiElement element, final Context context) throws IncorrectOperationException {
  final PsiTryStatement trySt = (PsiTryStatement)element;

  context.extractFromCodeBlock(trySt.getTryBlock(), trySt);
  context.extractFromCodeBlock(trySt.getFinallyBlock(), trySt);

  context.delete(trySt);
}
项目:intellij-ce-playground    文件:FinallyBlockSelectioner.java   
@Override
public List<TextRange> select(PsiElement e, CharSequence editorText, int cursorOffset, Editor editor) {
  List<TextRange> result = new ArrayList<TextRange>();

  final PsiElement parent = e.getParent();
  if (parent instanceof PsiTryStatement) {
    final PsiTryStatement tryStatement = (PsiTryStatement)parent;
    final PsiCodeBlock finallyBlock = tryStatement.getFinallyBlock();
    if (finallyBlock != null) {
      result.add(new TextRange(e.getTextRange().getStartOffset(), finallyBlock.getTextRange().getEndOffset()));
    }
  }

  return result;
}
项目:intellij-ce-playground    文件:EmptyTryBlockInspection.java   
@Override
public void visitTryStatement(@NotNull PsiTryStatement statement) {
  super.visitTryStatement(statement);
  final PsiCodeBlock finallyBlock = statement.getTryBlock();
  if (finallyBlock == null) {
    return;
  }
  if (finallyBlock.getStatements().length != 0) {
    return;
  }
  registerStatementError(statement);
}
项目:tools-idea    文件:MoveCatchUpFix.java   
@Override
public void invoke(@NotNull Project project, Editor editor, PsiFile file) {
  if (!FileModificationService.getInstance().prepareFileForWrite(myCatchSection.getContainingFile())) return;
  try {
    PsiTryStatement statement = myCatchSection.getTryStatement();
    statement.addBefore(myCatchSection, myMoveBeforeSection);
    myCatchSection.delete();
  }
  catch (IncorrectOperationException e) {
    LOG.error(e);
  }
}
项目:tools-idea    文件:JavaTryUnwrapper.java   
@Override
protected void doUnwrap(final PsiElement element, final Context context) throws IncorrectOperationException {
  final PsiTryStatement trySt = (PsiTryStatement)element;

  context.extractFromCodeBlock(trySt.getTryBlock(), trySt);
  context.extractFromCodeBlock(trySt.getFinallyBlock(), trySt);

  context.delete(trySt);
}
项目:tools-idea    文件:FinallyBlockSelectioner.java   
@Override
public List<TextRange> select(PsiElement e, CharSequence editorText, int cursorOffset, Editor editor) {
  List<TextRange> result = new ArrayList<TextRange>();

  final PsiElement parent = e.getParent();
  if (parent instanceof PsiTryStatement) {
    final PsiTryStatement tryStatement = (PsiTryStatement)parent;
    final PsiCodeBlock finallyBlock = tryStatement.getFinallyBlock();
    if (finallyBlock != null) {
      result.add(new TextRange(e.getTextRange().getStartOffset(), finallyBlock.getTextRange().getEndOffset()));
    }
  }

  return result;
}
项目:tools-idea    文件:EmptyTryBlockInspection.java   
@Override
public void visitTryStatement(@NotNull PsiTryStatement statement) {
  super.visitTryStatement(statement);
  if (FileTypeUtils.isInJsp(statement.getContainingFile())) {
    return;
  }
  final PsiCodeBlock finallyBlock = statement.getTryBlock();
  if (finallyBlock == null) {
    return;
  }
  if (finallyBlock.getStatements().length != 0) {
    return;
  }
  registerStatementError(statement);
}
项目:tools-idea    文件:NestedTryStatementInspection.java   
@Override
public void visitTryStatement(@NotNull PsiTryStatement statement) {
  super.visitTryStatement(statement);
  final PsiTryStatement parentTry =
    PsiTreeUtil.getParentOfType(statement,
                                PsiTryStatement.class);
  if (parentTry == null) {
    return;
  }
  final PsiCodeBlock tryBlock = parentTry.getTryBlock();
  if (tryBlock == null) {
    return;
  }
  if (!PsiTreeUtil.isAncestor(tryBlock, statement, true)) {
    return;
  }
  final PsiMethod containingMethod =
    PsiTreeUtil.getParentOfType(statement, PsiMethod.class);
  final PsiMethod containingContainingMethod =
    PsiTreeUtil.getParentOfType(parentTry, PsiMethod.class);
  if (containingMethod == null ||
      containingContainingMethod == null ||
      !containingMethod.equals(containingContainingMethod)) {
    return;
  }
  registerStatementError(statement);
}
项目:consulo-java    文件:MoveCatchUpFix.java   
@Override
public void invoke(@NotNull Project project, Editor editor, PsiFile file) {
  if (!FileModificationService.getInstance().prepareFileForWrite(myCatchSection.getContainingFile())) return;
  try {
    PsiTryStatement statement = myCatchSection.getTryStatement();
    statement.addBefore(myCatchSection, myMoveBeforeSection);
    myCatchSection.delete();
  }
  catch (IncorrectOperationException e) {
    LOG.error(e);
  }
}
项目:consulo-java    文件:JavaTryUnwrapper.java   
@Override
protected void doUnwrap(final PsiElement element, final Context context) throws IncorrectOperationException {
  final PsiTryStatement trySt = (PsiTryStatement)element;

  context.extractFromCodeBlock(trySt.getTryBlock(), trySt);
  context.extractFromCodeBlock(trySt.getFinallyBlock(), trySt);

  context.delete(trySt);
}
项目:consulo-java    文件:FinallyBlockSelectioner.java   
@Override
public List<TextRange> select(PsiElement e, CharSequence editorText, int cursorOffset, Editor editor) {
  List<TextRange> result = new ArrayList<TextRange>();

  final PsiElement parent = e.getParent();
  if (parent instanceof PsiTryStatement) {
    final PsiTryStatement tryStatement = (PsiTryStatement)parent;
    final PsiCodeBlock finallyBlock = tryStatement.getFinallyBlock();
    if (finallyBlock != null) {
      result.add(new TextRange(e.getTextRange().getStartOffset(), finallyBlock.getTextRange().getEndOffset()));
    }
  }

  return result;
}
项目:consulo-java    文件:UnusedCatchParameterInspection.java   
@Override
public void visitTryStatement(@NotNull PsiTryStatement statement) {
  super.visitTryStatement(statement);
  if (m_ignoreTestCases && TestUtils.isInTestCode(statement)) {
    return;
  }
  final PsiCatchSection[] catchSections = statement.getCatchSections();
  for (PsiCatchSection catchSection : catchSections) {
    checkCatchSection(catchSection);
  }
}
项目:consulo-java    文件:EmptyTryBlockInspection.java   
@Override
public void visitTryStatement(@NotNull PsiTryStatement statement) {
  super.visitTryStatement(statement);
  /*if (JspPsiUtil.isInJspFile(statement.getContainingFile())) {
    return;
  } */
  final PsiCodeBlock finallyBlock = statement.getTryBlock();
  if (finallyBlock == null) {
    return;
  }
  if (finallyBlock.getStatements().length != 0) {
    return;
  }
  registerStatementError(statement);
}
项目:consulo-java    文件:NestedTryStatementInspection.java   
@Override
public void visitTryStatement(@NotNull PsiTryStatement statement) {
  super.visitTryStatement(statement);
  final PsiTryStatement parentTry =
    PsiTreeUtil.getParentOfType(statement,
                                PsiTryStatement.class);
  if (parentTry == null) {
    return;
  }
  final PsiCodeBlock tryBlock = parentTry.getTryBlock();
  if (tryBlock == null) {
    return;
  }
  if (!PsiTreeUtil.isAncestor(tryBlock, statement, true)) {
    return;
  }
  final PsiMethod containingMethod =
    PsiTreeUtil.getParentOfType(statement, PsiMethod.class);
  final PsiMethod containingContainingMethod =
    PsiTreeUtil.getParentOfType(parentTry, PsiMethod.class);
  if (containingMethod == null ||
      containingContainingMethod == null ||
      !containingMethod.equals(containingContainingMethod)) {
    return;
  }
  registerStatementError(statement);
}
项目:Android_Lint_SRP_Practice_Example    文件:PsiClassStructureDetector.java   
@Override
public void visitTryStatement(PsiTryStatement statement) {
    mVisitor.report("PsiTryStatement", statement.getText(), statement);
    super.visitStatement(statement);
}
项目:intellij-ce-playground    文件:JavaTryUnwrapper.java   
@Override
public boolean isApplicableTo(PsiElement e) {
  return e instanceof PsiTryStatement;
}
项目:intellij-ce-playground    文件:JavaCatchRemover.java   
private static boolean tryHasSeveralCatchesOrResourcesDefined(PsiElement el) {
  PsiTryStatement tryStatement = (PsiTryStatement)el.getParent();
  return tryStatement.getCatchBlocks().length > 1 || tryStatement.getResourceList() != null;
}
项目:tools-idea    文件:JavaTryUnwrapper.java   
@Override
public boolean isApplicableTo(PsiElement e) {
  return e instanceof PsiTryStatement;
}
项目:tools-idea    文件:JavaCatchRemover.java   
private boolean tryHasSeveralCatches(PsiElement el) {
  return ((PsiTryStatement)el.getParent()).getCatchBlocks().length > 1;
}
项目:consulo-java    文件:Trap.java   
TryCatch(PsiTryStatement tryStatement, Map<PsiCatchSection, ControlFlow.ControlFlowOffset> clauses)
{
    super(tryStatement);
    myTryStatement = tryStatement;
    myClauses = clauses;
}
项目:consulo-java    文件:Trap.java   
public PsiTryStatement getTryStatement()
{
    return myTryStatement;
}
项目:consulo-java    文件:JavaTryUnwrapper.java   
@Override
public boolean isApplicableTo(PsiElement e) {
  return e instanceof PsiTryStatement;
}
项目:consulo-java    文件:JavaCatchRemover.java   
private boolean tryHasSeveralCatches(PsiElement el) {
  return ((PsiTryStatement)el.getParent()).getCatchBlocks().length > 1;
}