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

项目:intellij-ce-playground    文件:MissingThrowExpressionFixer.java   
@Override
public void apply(Editor editor, JavaSmartEnterProcessor processor, PsiElement psiElement)
    throws IncorrectOperationException {
  if (psiElement instanceof PsiThrowStatement) {
    PsiThrowStatement throwStatement = (PsiThrowStatement) psiElement;
    if (throwStatement.getException() != null &&
        startLine(editor, throwStatement) == startLine(editor, throwStatement.getException())) {
      return;
    }

    final int startOffset = throwStatement.getTextRange().getStartOffset();
    if (throwStatement.getException() != null) {
      editor.getDocument().insertString(startOffset + "throw".length(), ";");
    }
    processor.registerUnresolvedError(startOffset + "throw".length());
  }
}
项目:intellij-ce-playground    文件:ThrowsUsageTargetProvider.java   
@Override
@Nullable
public UsageTarget[] getTargets(Editor editor, final PsiFile file) {
  if (editor == null || file == null) return null;

  PsiElement element = file.findElementAt(TargetElementUtil.adjustOffset(file, editor.getDocument(), editor.getCaretModel().getOffset()));
  if (element == null) return null;

  if (element instanceof PsiKeyword && PsiKeyword.THROWS.equals(element.getText())) {
    return new UsageTarget[]{new PsiElement2UsageTargetAdapter(element)};
  }

  final PsiElement parent = element.getParent();
  if (parent instanceof PsiThrowStatement) {
    return new UsageTarget[] {new PsiElement2UsageTargetAdapter(parent)};
  }

  return null;
}
项目:intellij-ce-playground    文件:BadExceptionThrownInspectionBase.java   
@Override
public void visitThrowStatement(PsiThrowStatement statement) {
  super.visitThrowStatement(statement);
  final PsiExpression exception = statement.getException();
  if (exception == null) {
    return;
  }
  final PsiType type = exception.getType();
  if (type == null) {
    return;
  }
  final String text = type.getCanonicalText();
  if (exceptions.contains(text)) {
    registerStatementError(statement, type);
  }
}
项目:tools-idea    文件:MissingThrowExpressionFixer.java   
@Override
public void apply(Editor editor, JavaSmartEnterProcessor processor, PsiElement psiElement)
    throws IncorrectOperationException {
  if (psiElement instanceof PsiThrowStatement) {
    PsiThrowStatement throwStatement = (PsiThrowStatement) psiElement;
    if (throwStatement.getException() != null &&
        startLine(editor, throwStatement) == startLine(editor, throwStatement.getException())) {
      return;
    }

    final int startOffset = throwStatement.getTextRange().getStartOffset();
    if (throwStatement.getException() != null) {
      editor.getDocument().insertString(startOffset + "throw".length(), ";");
    }
    processor.registerUnresolvedError(startOffset + "throw".length());
  }
}
项目:tools-idea    文件:ThrowsUsageTargetProvider.java   
@Override
@Nullable
public UsageTarget[] getTargets(Editor editor, final PsiFile file) {
  if (editor == null || file == null) return null;

  PsiElement element = file.findElementAt(TargetElementUtilBase.adjustOffset(file, editor.getDocument(), editor.getCaretModel().getOffset()));
  if (element == null) return null;

  if (element instanceof PsiKeyword && PsiKeyword.THROWS.equals(element.getText())) {
    return new UsageTarget[]{new PsiElement2UsageTargetAdapter(element)};
  }

  final PsiElement parent = element.getParent();
  if (parent instanceof PsiThrowStatement) {
    return new UsageTarget[] {new PsiElement2UsageTargetAdapter(parent)};
  }

  return null;
}
项目:tools-idea    文件:BadExceptionThrownInspection.java   
@Override
public void visitThrowStatement(PsiThrowStatement statement) {
  super.visitThrowStatement(statement);
  final PsiExpression exception = statement.getException();
  if (exception == null) {
    return;
  }
  final PsiType type = exception.getType();
  if (type == null) {
    return;
  }
  final String text = type.getCanonicalText();
  if (exceptions.contains(text)) {
    registerStatementError(statement, type);
  }
}
项目:consulo-java    文件:MissingThrowExpressionFixer.java   
@Override
public void apply(Editor editor, JavaSmartEnterProcessor processor, PsiElement psiElement) throws IncorrectOperationException
{
    if(psiElement instanceof PsiThrowStatement)
    {
        PsiThrowStatement throwStatement = (PsiThrowStatement) psiElement;
        if(throwStatement.getException() != null && startLine(editor, throwStatement) == startLine(editor, throwStatement.getException()))
        {
            return;
        }

        final int startOffset = throwStatement.getTextRange().getStartOffset();
        if(throwStatement.getException() != null)
        {
            editor.getDocument().insertString(startOffset + "throw".length(), ";");
        }
        processor.registerUnresolvedError(startOffset + "throw".length());
    }
}
项目:consulo-java    文件:ThrowsUsageTargetProvider.java   
@Override
@Nullable
public UsageTarget[] getTargets(Editor editor, final PsiFile file) {
  if (editor == null || file == null) return null;

  PsiElement element = file.findElementAt(TargetElementUtil.adjustOffset(file, editor.getDocument(), editor.getCaretModel().getOffset()));
  if (element == null) return null;

  if (element instanceof PsiKeyword && PsiKeyword.THROWS.equals(element.getText())) {
    return new UsageTarget[]{new PsiElement2UsageTargetAdapter(element)};
  }

  final PsiElement parent = element.getParent();
  if (parent instanceof PsiThrowStatement) {
    return new UsageTarget[] {new PsiElement2UsageTargetAdapter(parent)};
  }

  return null;
}
项目:consulo-java    文件:BadExceptionThrownInspection.java   
@Override
public void visitThrowStatement(PsiThrowStatement statement) {
  super.visitThrowStatement(statement);
  final PsiExpression exception = statement.getException();
  if (exception == null) {
    return;
  }
  final PsiType type = exception.getType();
  if (type == null) {
    return;
  }
  final String text = type.getCanonicalText();
  if (exceptions.contains(text)) {
    registerStatementError(statement, type);
  }
}
项目:intellij-ce-playground    文件:ThrowFromFinallyBlockInspection.java   
@Override
public void visitThrowStatement(PsiThrowStatement statement) {
  super.visitThrowStatement(statement);
  if (!ControlFlowUtils.isInFinallyBlock(statement)) {
    return;
  }
  registerStatementError(statement);
}
项目:tools-idea    文件:ThrowFromFinallyBlockInspection.java   
@Override
public void visitThrowStatement(PsiThrowStatement statement) {
  super.visitThrowStatement(statement);
  if (!ControlFlowUtils.isInFinallyBlock(statement)) {
    return;
  }
  registerStatementError(statement);
}
项目:consulo-java    文件:AddRuntimeExceptionToThrowsAction.java   
private static PsiClassType getRuntimeExceptionAtCaret(Editor editor, PsiFile file) {
  PsiElement element = elementAtCaret(editor, file);
  if (element == null) return null;
  PsiThrowStatement expression = PsiTreeUtil.getParentOfType(element, PsiThrowStatement.class);
  if (expression == null) return null;
  PsiExpression exception = expression.getException();
  if (exception == null) return null;
  PsiType type = exception.getType();
  if (!(type instanceof PsiClassType)) return null;
  if (!ExceptionUtil.isUncheckedException((PsiClassType)type)) return null;
  return (PsiClassType)type;
}
项目:consulo-java    文件:ThrowFromFinallyBlockInspection.java   
@Override
public void visitThrowStatement(PsiThrowStatement statement) {
  super.visitThrowStatement(statement);
  if (!ControlFlowUtils.isInFinallyBlock(statement)) {
    return;
  }
  registerStatementError(statement);
}
项目:Android_Lint_SRP_Practice_Example    文件:PsiClassStructureDetector.java   
@Override
public void visitThrowStatement(PsiThrowStatement statement) {
    mVisitor.report("PsiThrowStatement", statement.getText(), statement);
    super.visitStatement(statement);
}
项目:intellij-ce-playground    文件:LeaveCodeBlockEnterProcessor.java   
/**
 * Handles situations like the one below:
 * <pre>
 *   void foo(int i) {
 *     if (i < 0) {
 *       return;[caret]
 *     }
 *   }
 * </pre>
 * 
 * <b>Output:</b>
 * <pre>
 *   void foo(int i) {
 *     if (i < 0) {
 *       return;
 *     }
 *     [caret]
 *   }
 * </pre>
 * 
 * @param element
 * @return
 */
private static boolean isControlFlowBreak(@Nullable PsiElement element) {
  return element instanceof PsiReturnStatement || element instanceof PsiThrowStatement;
}
项目:tools-idea    文件:LeaveCodeBlockEnterProcessor.java   
/**
 * Handles situations like the one below:
 * <pre>
 *   void foo(int i) {
 *     if (i < 0) {
 *       return;[caret]
 *     }
 *   }
 * </pre>
 * 
 * <b>Output:</b>
 * <pre>
 *   void foo(int i) {
 *     if (i < 0) {
 *       return;
 *     }
 *     [caret]
 *   }
 * </pre>
 * 
 * @param element
 * @return
 */
private static boolean isControlFlowBreak(@Nullable PsiElement element) {
  return element instanceof PsiReturnStatement || element instanceof PsiThrowStatement;
}
项目:consulo-java    文件:LeaveCodeBlockEnterProcessor.java   
/**
 * Handles situations like the one below:
 * <pre>
 *   void foo(int i) {
 *     if (i < 0) {
 *       return;[caret]
 *     }
 *   }
 * </pre>
 * <p>
 * <b>Output:</b>
 * <pre>
 *   void foo(int i) {
 *     if (i < 0) {
 *       return;
 *     }
 *     [caret]
 *   }
 * </pre>
 *
 * @param element
 * @return
 */
private static boolean isControlFlowBreak(@Nullable PsiElement element)
{
    return element instanceof PsiReturnStatement || element instanceof PsiThrowStatement;
}