Class TryWithResourcesJavacFilter.Matcher
java.lang.Object
org.jacoco.core.internal.analysis.filter.AbstractMatcher
org.jacoco.core.internal.analysis.filter.TryWithResourcesJavacFilter.Matcher
- Enclosing class:
TryWithResourcesJavacFilter
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.JavacPattern defines all possible variants that
will be tried sequentially.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static enum -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate Stringprivate final IFilterOutputprivate org.objectweb.asm.tree.AbstractInsnNodeFields inherited from class AbstractMatcher
cursor, vars -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate booleanprivate voidprivate booleanOn 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 AbstractMatcher
firstIsALoad0, next, nextIs, nextIsField, nextIsInvoke, nextIsSwitch, nextIsType, nextIsVar, skipNonOpcodes, skipNonOpcodes
-
Field Details
-
output
-
expectedOwner
-
start
private org.objectweb.asm.tree.AbstractInsnNode start
-
-
Constructor Details
-
Matcher
Matcher(IFilterOutput output)
-
-
Method Details
-
start
private void start(org.objectweb.asm.tree.AbstractInsnNode start) -
matchJavac
-
nextIsJavacClose
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()
-