Search in sources :

Example 1 with PsiThrowStatement

use of com.intellij.psi.PsiThrowStatement in project intellij-community by JetBrains.

the class ThrowsUsageTargetProvider method getTargets.

@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;
}
Also used : PsiThrowStatement(com.intellij.psi.PsiThrowStatement) PsiKeyword(com.intellij.psi.PsiKeyword) PsiElement(com.intellij.psi.PsiElement) UsageTarget(com.intellij.usages.UsageTarget) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with PsiThrowStatement

use of com.intellij.psi.PsiThrowStatement in project intellij-community by JetBrains.

the class MissingThrowExpressionFixer method apply.

@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());
    }
}
Also used : PsiThrowStatement(com.intellij.psi.PsiThrowStatement)

Aggregations

PsiThrowStatement (com.intellij.psi.PsiThrowStatement)2 PsiElement (com.intellij.psi.PsiElement)1 PsiKeyword (com.intellij.psi.PsiKeyword)1 UsageTarget (com.intellij.usages.UsageTarget)1 Nullable (org.jetbrains.annotations.Nullable)1