mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Postfix completion: apply throw template on Throwable only
This commit is contained in:
+3
-1
@@ -19,6 +19,7 @@ import com.intellij.codeInsight.template.postfix.util.PostfixTemplatesUtils;
|
||||
import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiExpression;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class ThrowExceptionPostfixTemplate extends PostfixTemplate {
|
||||
@@ -28,7 +29,8 @@ public class ThrowExceptionPostfixTemplate extends PostfixTemplate {
|
||||
|
||||
@Override
|
||||
public boolean isApplicable(@NotNull PsiElement context, @NotNull Document copyDocument, int newOffset) {
|
||||
return getTopmostExpression(context) != null;
|
||||
PsiExpression expression = getTopmostExpression(context);
|
||||
return expression != null && PostfixTemplatesUtils.isThrowable(expression.getType());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+5
@@ -56,6 +56,11 @@ public abstract class PostfixTemplatesUtils {
|
||||
return type != null && InheritanceUtil.isInheritor(type, CommonClassNames.JAVA_LANG_ITERABLE);
|
||||
}
|
||||
|
||||
@Contract("null -> false")
|
||||
public static boolean isThrowable(@Nullable PsiType type) {
|
||||
return type != null && InheritanceUtil.isInheritor(type, CommonClassNames.JAVA_LANG_THROWABLE);
|
||||
}
|
||||
|
||||
@Contract("null -> false")
|
||||
public static boolean isArray(@Nullable PsiType type) {
|
||||
return type != null && type instanceof PsiArrayType;
|
||||
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
public class Foo {
|
||||
void m(Object o) {
|
||||
o.throw<caret>
|
||||
}
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
public class Foo {
|
||||
void m(Object o) {
|
||||
throw o;<caret>
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
import java.lang.RuntimeException;
|
||||
|
||||
public class Foo {
|
||||
void m(Object o) {
|
||||
o.throw<caret>
|
||||
void m() {
|
||||
new RuntimeException("error").throw<caret>
|
||||
}
|
||||
}
|
||||
+4
-2
@@ -1,5 +1,7 @@
|
||||
import java.lang.RuntimeException;
|
||||
|
||||
public class Foo {
|
||||
void m(Object o) {
|
||||
throw o;<caret>
|
||||
void m() {
|
||||
throw new RuntimeException("error");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user