Class TryWithResourcesJavacFilter.Matcher
- java.lang.Object
-
- org.jacoco.core.internal.analysis.filter.AbstractMatcher
-
- org.jacoco.core.internal.analysis.filter.TryWithResourcesJavacFilter.Matcher
-
- Enclosing class:
- TryWithResourcesJavacFilter
static class TryWithResourcesJavacFilter.Matcher extends AbstractMatcher
javac from JDK 7 and 8 generates bytecode that is equivalent to the compilation of source code that is described in JLS 14.20.3. try-with-resources:Resource r = ...; Throwable primaryExc = null; try { ... } finally { if (r != null) { if (primaryExc != null) { try { r.close(); } catch (Throwable suppressedExc) { primaryExc.addSuppressed(suppressedExc); } } else { r.close(); } } }
Case of multiple resources looks like multiple nested try-with-resources statements. javac from JDK 9 EA b160 does the same, but with some optimizations (see JDK-7020499):null
check for resource is omitted when it is initialized usingnew
- synthetic method
$closeResource
containingnull
check of primaryExc and calls to methodsaddSuppressed
andclose
is used when number of copies of closing logic reaches threshold,null
check of resource (if present) is done before call of this method
TryWithResourcesJavacFilter.Matcher.JavacPattern
defines all possible variants that will be tried sequentially.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
TryWithResourcesJavacFilter.Matcher.JavacPattern
-
Field Summary
Fields Modifier and Type Field Description private java.lang.String
expectedOwner
private IFilterOutput
output
private org.objectweb.asm.tree.AbstractInsnNode
start
-
Fields inherited from class org.jacoco.core.internal.analysis.filter.AbstractMatcher
cursor, vars
-
-
Constructor Summary
Constructors Constructor Description Matcher(IFilterOutput output)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private boolean
matchJavac(TryWithResourcesJavacFilter.Matcher.JavacPattern p)
private void
nextIsClose()
private boolean
nextIsJavacClose(TryWithResourcesJavacFilter.Matcher.JavacPattern p, java.lang.String ctx)
On a first invocation will associate variables with names "r" and "primaryExc", on subsequent invocations will use those associations for checks.private void
start(org.objectweb.asm.tree.AbstractInsnNode start)
-
Methods inherited from class org.jacoco.core.internal.analysis.filter.AbstractMatcher
firstIsALoad0, next, nextIs, nextIsInvokeStatic, nextIsInvokeSuper, nextIsInvokeVirtual, nextIsSwitch, nextIsType, nextIsVar, skipNonOpcodes, skipNonOpcodes
-
-
-
-
Field Detail
-
output
private final IFilterOutput output
-
expectedOwner
private java.lang.String expectedOwner
-
start
private org.objectweb.asm.tree.AbstractInsnNode start
-
-
Constructor Detail
-
Matcher
Matcher(IFilterOutput output)
-
-
Method Detail
-
start
private void start(org.objectweb.asm.tree.AbstractInsnNode start)
-
matchJavac
private boolean matchJavac(TryWithResourcesJavacFilter.Matcher.JavacPattern p)
-
nextIsJavacClose
private boolean nextIsJavacClose(TryWithResourcesJavacFilter.Matcher.JavacPattern p, java.lang.String ctx)
On a first invocation will associate variables with names "r" and "primaryExc", on subsequent invocations will use those associations for checks.
-
nextIsClose
private void nextIsClose()
-
-