AddExceptionToExistingCatch: support language levels < 7

This commit is contained in:
Roman.Ivanov
2019-04-02 17:30:17 +07:00
parent 167df6aa4d
commit ed9d67604e
9 changed files with 152 additions and 14 deletions
@@ -0,0 +1,16 @@
// "Add exception to existing catch clause" "true"
import java.io.*;
public class c1 {
void f() {
FileInputStream fis = null;
try {
fis = new FileInputStream("");
DataInputStream dis = new DataInputStream(fis);
dis.<caret>readInt();
} catch (IOException e) {
e.printStackTrace();
}
}
}
@@ -0,0 +1,17 @@
// "Add exception to existing catch clause" "true"
class C {
static class E extends Exception { }
static class E1 extends E { }
static class MyResource implements AutoCloseable {
public MyResource() throws E1 { }
public void close() throws E { }
}
void f() {
try (MyResource r = new MyResource()) {
} catch (E e) {
e.printStackTrace();
}
}
}
@@ -0,0 +1,16 @@
// "Add exception to existing catch clause" "true"
import java.io.*;
public class c1 {
void f() {
FileInputStream fis = null;
try {
fis = new FileInputStream("");
DataInputStream dis = new DataInputStream(fis);
dis.<caret>readInt();
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
}
@@ -0,0 +1,16 @@
// "Add exception to existing catch clause" "false"
import java.io.*;
public class c1 {
void f() {
FileInputStream fis = null;
try {
fis = new FileInputStream("");
DataInputStream dis = new DataInputStream(fis);
<caret>throw new IllegalAccessException();
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
}
@@ -0,0 +1,17 @@
// "Add exception to existing catch clause" "true"
class C {
static class E extends Exception { }
static class E1 extends E { }
static class MyResource implements AutoCloseable {
public MyResource() throws E1 { }
public void close() throws E { }
}
void f() {
try (<caret>MyResource r = new MyResource()) {
} catch (E1 e) {
e.printStackTrace();
}
}
}
@@ -0,0 +1,16 @@
// "Add exception to existing catch clause" "false"
import java.util.function.Supplier;
class C {
static Object get() throws Exception {
return null;
}
void method() {
try {
Supplier<Object> lambda1 = () -> C.ge<caret>t();
} catch( Exception e) {
throw new RuntimeException(e);
}
}
}
@@ -0,0 +1,16 @@
// "Add exception to existing catch clause" "false"
import java.util.function.Supplier;
class C {
static Object get() throws Exception {
return null;
}
void method() {
try {
Supplier<Object> lambda1 = C::g<caret>et;
} catch( Exception e) {
throw new RuntimeException(e);
}
}
}