Skip to content

Commit

Permalink
StringSwitchEcjFilter and KotlinWhenStringFilter should use correct V…
Browse files Browse the repository at this point in the history
…arInsnNode (#746)
  • Loading branch information
Godin authored and marchof committed Aug 20, 2018
1 parent 6bbb012 commit 964778b
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,12 @@ public void should_filter() {
final Label case3 = new Label();
final Label defaultCase = new Label();

// filter should not remember this unrelated slot
m.visitLdcInsn("");
m.visitVarInsn(Opcodes.ASTORE, 1);
m.visitVarInsn(Opcodes.ALOAD, 1);

// switch (...)
m.visitVarInsn(Opcodes.ASTORE, 2);
m.visitVarInsn(Opcodes.ALOAD, 2);
m.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/String", "hashCode",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,13 @@ public void should_filter() {
final Label h1 = new Label();
final Label h2 = new Label();

// filter should not remember this unrelated slot
m.visitLdcInsn("");
m.visitVarInsn(Opcodes.ASTORE, 1);
m.visitVarInsn(Opcodes.ALOAD, 1);

// switch (...)
m.visitInsn(Opcodes.DUP);
m.visitVarInsn(Opcodes.ASTORE, 2);
m.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/String", "hashCode",
"()I", false);
Expand Down Expand Up @@ -112,8 +117,13 @@ public void should_filter_when_default_is_first() {
final Label caseDefault = new Label();
final Label h1 = new Label();

// filter should not remember this unrelated slot
m.visitLdcInsn("");
m.visitVarInsn(Opcodes.ASTORE, 1);
m.visitVarInsn(Opcodes.ALOAD, 1);

// switch (...)
m.visitInsn(Opcodes.DUP);
m.visitVarInsn(Opcodes.ASTORE, 2);
m.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/String", "hashCode",
"()I", false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.objectweb.asm.tree.LookupSwitchInsnNode;
import org.objectweb.asm.tree.MethodNode;
import org.objectweb.asm.tree.TableSwitchInsnNode;
import org.objectweb.asm.tree.VarInsnNode;

/**
* Filters bytecode that Kotlin compiler generates for <code>when</code>
Expand All @@ -41,15 +42,16 @@ private static class Matcher extends AbstractMatcher {
public void match(final AbstractInsnNode start,
final IFilterOutput output) {

if (Opcodes.ALOAD != start.getOpcode()) {
return;
}
cursor = start;

nextIsVar(Opcodes.ASTORE, "s");
nextIsVar(Opcodes.ALOAD, "s");
nextIsInvokeVirtual("java/lang/String", "hashCode");
nextIsSwitch();
if (cursor == null) {
return;
}
vars.put("s", (VarInsnNode) start);

final AbstractInsnNode s = cursor;
final int hashCodes;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.objectweb.asm.tree.LookupSwitchInsnNode;
import org.objectweb.asm.tree.MethodNode;
import org.objectweb.asm.tree.TableSwitchInsnNode;
import org.objectweb.asm.tree.VarInsnNode;

/**
* Filters code that is generated by ECJ for a <code>switch</code> statement
Expand All @@ -41,14 +42,16 @@ private static class Matcher extends AbstractMatcher {
public void match(final AbstractInsnNode start,
final IFilterOutput output) {

if (Opcodes.ASTORE != start.getOpcode()) {
return;
}
cursor = start;

nextIsVar(Opcodes.ASTORE, "s");
nextIsInvokeVirtual("java/lang/String", "hashCode");
nextIsSwitch();
if (cursor == null) {
return;
}
vars.put("s", (VarInsnNode) start);

final AbstractInsnNode s = cursor;
final int hashCodes;
Expand Down
6 changes: 4 additions & 2 deletions org.jacoco.doc/docroot/doc/changes.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ <h3>New Features</h3>
<code>java.lang.String</code> values is filtered out during generation of
report
(GitHub <a href="https://github.com/jacoco/jacoco/issues/735">#735</a>,
<a href="https://github.com/jacoco/jacoco/issues/741">#741</a>).</li>
<a href="https://github.com/jacoco/jacoco/issues/741">#741</a>,
<a href="https://github.com/jacoco/jacoco/issues/746">#746</a>).</li>
<li>Methods added by the Kotlin compiler are filtered out during generation
of report. Idea and implementation by Nikolay Krasko
(GitHub <a href="https://github.com/jacoco/jacoco/issues/689">#689</a>).</li>
Expand All @@ -52,7 +53,8 @@ <h3>New Features</h3>
<li>Additional bytecode generated by Kotlin compiler for <code>when</code>
expressions on <code>kotlin.String</code> values is filtered out during
generation of report
(GitHub <a href="https://github.com/jacoco/jacoco/issues/737">#737</a>).</li>
(GitHub <a href="https://github.com/jacoco/jacoco/issues/737">#737</a>,
<a href="https://github.com/jacoco/jacoco/issues/746">#746</a>).</li>
<li>Classes and methods annotated with runtime visible and invisible annotation
whose simple name is <code>Generated</code> are filtered out during
generation of report
Expand Down

0 comments on commit 964778b

Please sign in to comment.