/*
* Copyright 2000-2012 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
class C {
static class E extends Exception { }
static class E1 extends E { }
static class E2 extends E { }
static class E3 extends E { }
static class MyResource implements AutoCloseable {
public MyResource() throws E1 { }
public void doSomething() throws E2 { }
@Override public void close() throws E3 { }
}
static interface I extends AutoCloseable { }
void m1() {
try (MyResource r = new MyResource()) { r.doSomething(); }
catch (E1 | E2 | E3 ignore) { }
try (MyResource r = new MyResource()) { }
catch (E1 | E3 ignore) { }
try (MyResource r = new MyResource()) { }
catch (E1 e) { }
try (MyResource r = new MyResource()) { }
catch (E3 e) { }
try (MyResource r = new MyResource()) { }
try (I r = null) { System.out.println(r); }
}
void m2() throws Exception {
try (Object r = new MyResource()) { }
try (AutoCloseable r = "resource") { }
}
void m3(int p) throws Exception {
try (MyResource r = new MyResource()) {
r.doSomething();
r = null;
int r = 0;
}
catch (E e) {
r = null;
}
finally {
r = null;
}
r = null;
try (MyResource r = new MyResource(); MyResource r = new MyResource()) { }
try (MyResource r1 = new MyResource(); MyResource r2 = r1) { }
try (MyResource r1 = r2; MyResource r2 = r1) { }
MyResource r = null;
try (MyResource r = new MyResource()) { }
try (MyResource rr = r) { }
try (MyResource p = new MyResource()) { }
new Runnable() {
public void run() {
try (MyResource p = new MyResource()) { }
catch (E e) { }
}
}.run();
}
void m4() throws Exception {
try (MyResource r = r) { }
MyResource r;
try (MyResource r1 = r) { }
}
}