Skip to content

Commit

Permalink
(WIP) add filter
Browse files Browse the repository at this point in the history
  • Loading branch information
Godin committed Jun 5, 2023
1 parent 0ca61db commit bc71921
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public static IFilter all() {
new PrivateEmptyNoArgConstructorFilter(), new AssertFilter(),
new StringSwitchJavacFilter(), new StringSwitchFilter(),
new EnumEmptyConstructorFilter(), new RecordsFilter(),
new RecordPatternFilter(), //
new AnnotationGeneratedFilter(), new KotlinGeneratedFilter(),
new KotlinLateinitFilter(), new KotlinWhenFilter(),
new KotlinWhenStringFilter(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,44 @@
*******************************************************************************/
package org.jacoco.core.internal.analysis.filter;

import org.objectweb.asm.Opcodes;
import org.objectweb.asm.tree.AbstractInsnNode;
import org.objectweb.asm.tree.MethodNode;
import org.objectweb.asm.tree.TryCatchBlockNode;

/**
* Filters code that is generated for record patterns.
*/
final class RecordPatternFilter implements IFilter {

public void filter(final MethodNode methodNode,
final IFilterContext context, final IFilterOutput output) {
// TODO
final Matcher matcher = new Matcher();
for (final TryCatchBlockNode t : methodNode.tryCatchBlocks) {
if ("java/lang/Throwable".equals(t.type)) {
matcher.match(t.handler, output);
}
}
}

private static class Matcher extends AbstractMatcher {
void match(final AbstractInsnNode start, final IFilterOutput output) {
cursor = start;
nextIsVar(Opcodes.ASTORE, "cause");
nextIsType(org.objectweb.asm.Opcodes.NEW,
"java/lang/MatchException");
nextIs(Opcodes.DUP);
nextIsVar(Opcodes.ALOAD, "cause");
nextIsInvoke(Opcodes.INVOKEVIRTUAL, "java/lang/Throwable",
"toString", "()Ljava/lang/String;");
nextIsVar(Opcodes.ALOAD, "cause");
nextIsInvoke(Opcodes.INVOKESPECIAL, "java/lang/MatchException",
"<init>", "(Ljava/lang/String;Ljava/lang/Throwable;)V");
nextIs(Opcodes.ATHROW);
if (cursor != null) {
output.ignore(start, cursor);
}
}
}

}

0 comments on commit bc71921

Please sign in to comment.