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):nullcheck for resource is omitted when it is initialized usingnew- synthetic method
$closeResourcecontainingnullcheck of primaryExc and calls to methodsaddSuppressedandcloseis used when number of copies of closing logic reaches threshold,nullcheck of resource (if present) is done before call of this method
TryWithResourcesJavacFilter.Matcher.JavacPatterndefines all possible variants that will be tried sequentially.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classTryWithResourcesJavacFilter.Matcher.JavacPattern
-
Field Summary
Fields Modifier and Type Field Description private java.lang.StringexpectedOwnerprivate IFilterOutputoutputprivate org.objectweb.asm.tree.AbstractInsnNodestart-
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 booleanmatchJavac(TryWithResourcesJavacFilter.Matcher.JavacPattern p)private voidnextIsClose()private booleannextIsJavacClose(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 voidstart(org.objectweb.asm.tree.AbstractInsnNode start)-
Methods inherited from class org.jacoco.core.internal.analysis.filter.AbstractMatcher
firstIsALoad0, next, nextIs, nextIsField, nextIsInvoke, 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()
-
-