mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-08-26 03:13:40 +07:00
[java] adds support for Java 9's improved try-with-resources (IDEA-140266)
PSI, parser, highlighting, exception analysis, control flow, completion.
This commit is contained in:
+8
@@ -0,0 +1,8 @@
|
||||
import java.io.*;
|
||||
|
||||
class UnsupportedFeatures {
|
||||
void m() throws Exception {
|
||||
Reader r1 = new FileReader("/dev/null");
|
||||
try (<error descr="Resource references are not supported at this language level">r1</error>; Reader r2 = new FileReader("/dev/null")) { }
|
||||
}
|
||||
}
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
import java.io.IOException;
|
||||
|
||||
class TryWithResources {
|
||||
final AutoCloseable f1 = null;
|
||||
AutoCloseable f2 = null;
|
||||
|
||||
void testFields() throws Exception {
|
||||
try (f1; <error descr="Variable used as a try-with-resources resource should be final or effectively final">f2</error>) { }
|
||||
catch (Exception ignore) { }
|
||||
}
|
||||
|
||||
void testLocalVars() throws Exception {
|
||||
final AutoCloseable r1 = null;
|
||||
AutoCloseable r2 = null;
|
||||
AutoCloseable r3 = null;
|
||||
try (r1; r2; <error descr="Variable used as a try-with-resources resource should be final or effectively final">r3</error>) { }
|
||||
r3 = null;
|
||||
}
|
||||
|
||||
void testType() throws Exception {
|
||||
String s = "";
|
||||
try (<error descr="Incompatible types. Found: 'java.lang.String', required: 'java.lang.AutoCloseable'">s</error>;
|
||||
<error descr="Incompatible types. Found: 'TryWithResources', required: 'java.lang.AutoCloseable'">this</error>) { }
|
||||
}
|
||||
|
||||
void testUnhandled() {
|
||||
class Resource implements AutoCloseable {
|
||||
@Override public void close() throws IOException { }
|
||||
}
|
||||
Resource r = new Resource();
|
||||
try (<error descr="Unhandled exception from auto-closeable resource: java.io.IOException">r</error>) { }
|
||||
}
|
||||
|
||||
void testResolve() throws Exception {
|
||||
try (<error descr="Cannot resolve symbol 'r'">r</error>; AutoCloseable r = null) { }
|
||||
try (AutoCloseable r = null; r) { }
|
||||
}
|
||||
|
||||
void testUnassigned() throws Exception {
|
||||
AutoCloseable r;
|
||||
try (<error descr="Variable 'r' might not have been initialized">r</error>) {
|
||||
System.out.println(r);
|
||||
}
|
||||
}
|
||||
}
|
||||
-1
@@ -15,7 +15,6 @@ class C {
|
||||
@interface Anno { String f(Anno this); }
|
||||
|
||||
void m0() {
|
||||
try (Object <error descr="Receivers are not allowed outside of method parameter list">this</error>) { }
|
||||
Runnable r = (C <error descr="Receivers are not allowed outside of method parameter list">C.this</error>) -> { };
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user