highlight only method name on unhandled exception (IDEA-190912)

This commit is contained in:
Anna.Kozlova
2018-04-25 21:08:52 +02:00
parent 40af21eaeb
commit 51a2d549b2
25 changed files with 42 additions and 41 deletions

View File

@@ -369,7 +369,7 @@ public class HighlightMethodUtil {
if (resolved instanceof PsiMethod && resolveResult.isValidResult()) {
PsiElement nameElement = referenceToMethod.getReferenceNameElement();
TextRange fixRange = getFixRange(methodCall);
highlightInfo = HighlightUtil.checkUnhandledExceptions(methodCall, nameElement != null ? new TextRange(nameElement.getTextOffset(), fixRange.getEndOffset()) : fixRange);
highlightInfo = HighlightUtil.checkUnhandledExceptions(methodCall, nameElement != null ? nameElement.getTextRange() : fixRange);
if (highlightInfo == null && ((PsiMethod)resolved).hasModifierProperty(PsiModifier.STATIC)) {
PsiClass containingClass = ((PsiMethod)resolved).getContainingClass();

View File

@@ -521,7 +521,7 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh
super.visitEnumConstant(enumConstant);
if (!myHolder.hasErrorResults()) GenericsHighlightUtil.checkEnumConstantForConstructorProblems(enumConstant, myHolder, myJavaSdkVersion);
if (!myHolder.hasErrorResults()) registerConstructorCall(enumConstant);
if (!myHolder.hasErrorResults()) myHolder.add(HighlightUtil.checkUnhandledExceptions(enumConstant, null));
if (!myHolder.hasErrorResults()) myHolder.add(HighlightUtil.checkUnhandledExceptions(enumConstant, enumConstant.getNameIdentifier().getTextRange()));
}
@Override
@@ -997,7 +997,8 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh
public void visitNewExpression(PsiNewExpression expression) {
final PsiType type = expression.getType();
final PsiClass aClass = PsiUtil.resolveClassInType(type);
myHolder.add(HighlightUtil.checkUnhandledExceptions(expression, null));
PsiJavaCodeReferenceElement classReference = expression.getClassReference();
myHolder.add(HighlightUtil.checkUnhandledExceptions(expression, classReference != null ? classReference.getTextRange() : null));
if (!myHolder.hasErrorResults()) myHolder.add(HighlightClassUtil.checkAnonymousInheritFinal(expression));
if (!myHolder.hasErrorResults()) myHolder.add(HighlightClassUtil.checkQualifiedNew(expression, type, aClass));
if (!myHolder.hasErrorResults()) myHolder.add(HighlightClassUtil.checkCreateInnerClassFromStaticContext(expression, type, aClass));

View File

@@ -56,7 +56,7 @@ class a4 {
}
class a5 {
int i = <error descr="Unhandled exception: java.lang.ClassNotFoundException">f();</error>
int i = <error descr="Unhandled exception: java.lang.ClassNotFoundException">f</error>();
int f() throws ClassNotFoundException {
return 0;
@@ -110,7 +110,7 @@ class a9 {
public AnInterface getAnInterface() {
return new AnInterface() {
{
<error descr="Unhandled exception: java.io.FileNotFoundException">new java.io.FileInputStream("somefile")</error>;
new <error descr="Unhandled exception: java.io.FileNotFoundException">java.io.FileInputStream</error>("somefile");
}
};
}
@@ -121,7 +121,7 @@ class BadStatic {
static String f() throws ClassNotFoundException {
return null;
}
private static final String FOO = <error descr="Unhandled exception: java.lang.ClassNotFoundException">f();</error>
private static final String FOO = <error descr="Unhandled exception: java.lang.ClassNotFoundException">f</error>();
public BadStatic() throws ClassNotFoundException {
}

View File

@@ -54,7 +54,7 @@ class A3 {
// in initializer
class Test{
final String s = <error descr="Unhandled exception: java.lang.Exception">makeString();</error>
final String s = <error descr="Unhandled exception: java.lang.Exception">makeString</error>();
String makeString() throws Exception {throw new Exception();}
}

View File

@@ -13,7 +13,7 @@ class a {
void f2(int i) {
try {
<error descr="Unhandled exception: java.io.FileNotFoundException">new FileReader("")</error>;
new <error descr="Unhandled exception: java.io.FileNotFoundException">FileReader</error>("");
}
finally {
if (i==4) <error descr="Unhandled exception: java.lang.ClassNotFoundException">throw new ClassNotFoundException();</error>
@@ -22,7 +22,7 @@ class a {
void f3(int i) {
try {
<error descr="Unhandled exception: java.io.FileNotFoundException">new FileReader("")</error>;
new <error descr="Unhandled exception: java.io.FileNotFoundException">FileReader</error>("");
}
finally {
if (i==1) return;
@@ -31,7 +31,7 @@ class a {
void f4(int i) {
try {
<error descr="Unhandled exception: java.io.FileNotFoundException">new FileReader("")</error>;
new <error descr="Unhandled exception: java.io.FileNotFoundException">FileReader</error>("");
}
finally {
if (i==1) <error descr="Unhandled exception: java.io.FileNotFoundException">throw new FileNotFoundException();</error>

View File

@@ -1,6 +1,6 @@
enum ABC {
<error descr="Unhandled exception: java.io.IOException">A()</error>,
<error descr="Unhandled exception: java.io.IOException">A</error>(),
<error descr="Unhandled exception: java.io.IOException">B</error>,
<error descr="Unhandled exception: java.io.IOException">C</error>;
ABC() throws java.io.IOException {

View File

@@ -4,10 +4,10 @@ interface I<T extends Exception> {
class C {
void x(I<?> i) {
i.<error descr="Unhandled exception: java.lang.Exception">m();</error>
i.<error descr="Unhandled exception: java.lang.Exception">m</error>();
}
void y(I<? extends Exception> i) {
i.<error descr="Unhandled exception: java.lang.Exception">m();</error>
i.<error descr="Unhandled exception: java.lang.Exception">m</error>();
}
}

View File

@@ -48,7 +48,7 @@ abstract class C {
try { f(); } catch (E1 | E2 | <error descr="Exception 'C.E3' is never thrown in the corresponding try block">E3</error> e) { }
try { f(); } catch (<error descr="Exception 'C.E3' is never thrown in the corresponding try block">E3</error> | <error descr="Exception 'C.E4' is never thrown in the corresponding try block">E4</error> | RE e) { } catch (E e) { }
try { <error descr="Unhandled exceptions: C.E1, C.E2">f();</error> } catch (E3 | E4 | RE e) { }
try { <error descr="Unhandled exceptions: C.E1, C.E2">f</error>(); } catch (E3 | E4 | RE e) { }
try { f(); } catch (E e) { } catch (<error descr="Exception 'C.E1' has already been caught">E1</error> | <error descr="Exception 'C.E3' has already been caught">E3</error> e) { }
try { f(); } catch (E1 | E2 e) { } catch (<error descr="Exception 'C.E2' has already been caught">E2</error> e) { }

View File

@@ -32,10 +32,10 @@ class C {
try (<error descr="Unhandled exception from auto-closeable resource: C.E3">MyResource r = new MyResource()</error>) { }
catch (E1 e) { }
try (MyResource r = <error descr="Unhandled exception: C.E1">new MyResource()</error>) { }
try (MyResource r = new <error descr="Unhandled exception: C.E1">MyResource</error>()) { }
catch (E3 e) { }
try (MyResource r = <error descr="Unhandled exception: C.E1">new MyResource()</error>) { }
try (MyResource r = new <error descr="Unhandled exception: C.E1">MyResource</error>()) { }
try (<error descr="Unhandled exception from auto-closeable resource: java.lang.Exception">I r = null</error>) { System.out.println(r); }
}

View File

@@ -1,7 +1,7 @@
class C <T extends Exception> {
void foo () throws T {}
void bar () {
<error descr="Unhandled exception: T">foo ();</error>
<error descr="Unhandled exception: T">foo</error> ();
}
<T extends Error> void goo() {

View File

@@ -1,7 +1,7 @@
class C <T extends Exception> {
void foo () throws T {}
void bar () {
<error descr="Unhandled exception: T">foo ();</error>
<error descr="Unhandled exception: T">foo</error> ();
}
<T extends Error> void goo() {

View File

@@ -4,7 +4,7 @@ class MyTest<T> {
public MyTest() throws IOException {}
void m() {
MyTest<String> test = <error descr="Unhandled exception: java.io.IOException">new MyTest<>()</error>;
MyTest<String> test = new <error descr="Unhandled exception: java.io.IOException">MyTest<></error>();
}
{

View File

@@ -6,6 +6,6 @@ class Test {
{
foo((t)->{});
<error descr="Unhandled exception: java.lang.ClassNotFoundException">foo((ClassNotFoundException t)->{});</error>
<error descr="Unhandled exception: java.lang.ClassNotFoundException">foo</error>((ClassNotFoundException t)->{});
}
}

View File

@@ -16,7 +16,7 @@ class Test {
foo(this::m1);
foo(this::m2);
<error descr="Unhandled exception: java.io.IOException">foo(this::m3);</error>
<error descr="Unhandled exception: java.io.IOException">foo</error>(this::m3);
}
}

View File

@@ -5,6 +5,6 @@ class Test {
<K extends ClassNotFoundException> void foo(F<K> f) throws K { }
{
<error descr="Unhandled exception: java.lang.ClassNotFoundException">foo(() -> {});</error>
<error descr="Unhandled exception: java.lang.ClassNotFoundException">foo</error>(() -> {});
}
}

View File

@@ -12,18 +12,18 @@ class Test {
<K extends ClassNotFoundException> void foo2(F<K> f) throws K { }
{
<error descr="Unhandled exception: java.lang.ClassNotFoundException">foo2(()->{});</error>
<error descr="Unhandled exception: java.lang.ClassNotFoundException">foo2(()->{ throw new ClassNotFoundException(); });</error>
<error descr="Unhandled exception: java.lang.ClassNotFoundException">foo2</error>(()->{});
<error descr="Unhandled exception: java.lang.ClassNotFoundException">foo2</error>(()->{ throw new ClassNotFoundException(); });
<error descr="Unhandled exception: java.lang.ClassNotFoundException">foo2(this::m1);</error>
<error descr="Unhandled exception: java.lang.ClassNotFoundException">foo2(this::m2);</error>
<error descr="Unhandled exception: java.lang.ClassNotFoundException">foo2</error>(this::m1);
<error descr="Unhandled exception: java.lang.ClassNotFoundException">foo2</error>(this::m2);
<error descr="Unhandled exception: java.lang.ClassNotFoundException">foo1(()->{ throw new ClassNotFoundException(); });</error>
<error descr="Unhandled exception: java.lang.Exception">foo1(()->{ throw new Exception(); });</error>
<error descr="Unhandled exception: java.lang.ClassNotFoundException">foo1</error>(()->{ throw new ClassNotFoundException(); });
<error descr="Unhandled exception: java.lang.Exception">foo1</error>(()->{ throw new Exception(); });
<error descr="Unhandled exception: java.lang.ClassNotFoundException">foo1(this::m2);</error>
<error descr="Unhandled exception: java.lang.Exception">foo1(this::m3);</error>
<error descr="Unhandled exception: java.lang.ClassNotFoundException">foo1</error>(this::m2);
<error descr="Unhandled exception: java.lang.Exception">foo1</error>(this::m3);
}
}

View File

@@ -17,7 +17,7 @@ class Thing<T> {
public <X extends Throwable> void exceptionMethod(Supplier<X> xSupplier) throws X { }
void m(final Thing<Integer> integer){
integer.flatMap(s -> new Thing(s)).<error descr="Unhandled exception: java.lang.Throwable">exceptionMethod(IllegalStateException::new);</error>
integer.flatMap(s -> new Thing(s)).<error descr="Unhandled exception: java.lang.Throwable">exceptionMethod</error>(IllegalStateException::new);
integer.flatMap(Thing::new).exceptionMethod(IllegalStateException::new);
}
}

View File

@@ -4,7 +4,7 @@ public class ExTest {
}
{
Block<String> b = (t) -> ExTest.<error descr="Unhandled exception: ExTest.Ex">maybeThrow(t)</error>;
Block<String> b = (t) -> ExTest.<error descr="Unhandled exception: ExTest.Ex">maybeThrow</error>(t);
}

View File

@@ -5,7 +5,7 @@ import java.util.function.Consumer;
class Test {
public static void main(String[] args) {
Iterable<Consumer<Reader>> i = Arrays.asList((r) -> r.<error descr="Unhandled exception: java.io.IOException">read()</error>);
Iterable<Consumer<Reader>> i1 = Arrays.<Consumer<Reader>>asList((r) -> r.<error descr="Unhandled exception: java.io.IOException">read()</error>);
Iterable<Consumer<Reader>> i = Arrays.asList((r) -> r.<error descr="Unhandled exception: java.io.IOException">read</error>());
Iterable<Consumer<Reader>> i1 = Arrays.<Consumer<Reader>>asList((r) -> r.<error descr="Unhandled exception: java.io.IOException">read</error>());
}
}

View File

@@ -32,7 +32,7 @@ class Test1 {
}
{
bar(l -> <error descr="Unhandled exception: Test1.MyEx">baz(l)</error>);
bar(l -> <error descr="Unhandled exception: Test1.MyEx">baz</error>(l));
bar(<error descr="Unhandled exception: Test1.MyEx">this::baz</error>);
}
}

View File

@@ -1,7 +1,7 @@
class Test {
Test() {
foo(<error descr="Unhandled exception: java.lang.Exception">this::fs</error>);
foo((s) -> <error descr="Unhandled exception: java.lang.Exception">fs(s)</error>);
foo((s) -> <error descr="Unhandled exception: java.lang.Exception">fs</error>(s));
}
void foo(I<String, String> iss) {}

View File

@@ -9,6 +9,6 @@ class Test {
}
void m() {
try (MyResource r = <caret>new MyResource())
try (MyResource r = new My<caret>Resource())
}
}

View File

@@ -7,7 +7,7 @@ class CatchExceptions {
void bar() {
try {
foo();<caret>
fo<caret>o();
}
}
}

View File

@@ -265,7 +265,7 @@ void caught() {
}
void uncaught() {
foo.Foo.<error descr="Unhandled exception: java.lang.IllegalArgumentException">libraryMethod();</error>
foo.Foo.<error descr="Unhandled exception: java.lang.IllegalArgumentException">libraryMethod</error>();
}
}

View File

@@ -51,7 +51,7 @@ class Pogo {}
configureByText 'Main.java', '''\
class Main {
void foo() {
new Pogo().<error descr="Unhandled exception: java.lang.CloneNotSupportedException">clone();</error>;
new Pogo().<error descr="Unhandled exception: java.lang.CloneNotSupportedException">clone</error>();
try {
Pogo pogo = new Pogo().clone();
} catch (java.lang.CloneNotSupportedException e) {}
@@ -90,7 +90,7 @@ class Pogo {}
class Pojo extends Pogo {
void foo() {
Pogo pogo = new Pogo();
<error descr="Unhandled exception: java.lang.CloneNotSupportedException">cloneOrCopyMembers(pogo);</error>
<error descr="Unhandled exception: java.lang.CloneNotSupportedException">cloneOrCopyMembers</error>(pogo);
cloneOrCopyMembers<error descr="'cloneOrCopyMembers(Pogo)' in '' cannot be applied to '()'">()</error>;
}
}