-
Notifications
You must be signed in to change notification settings - Fork 354
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Avoid instrumenting synthetic methods
Coverage was being generated for synthetic methods, artificially inflating the number of covered lines for some kotlin classes. This change prevents probes from being inserting into them, duplicating the logic use elsewhere to ensure that lambda implementations still have probes, despite their synthetic flag.
- Loading branch information
Showing
4 changed files
with
41 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
pitest/src/main/java/org/pitest/classinfo/SyntheticMethodFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package org.pitest.classinfo; | ||
|
||
import org.objectweb.asm.Opcodes; | ||
import org.pitest.functional.F5; | ||
|
||
/** | ||
* Filters out synthetic and bridge methods, but allows synthetic | ||
* lambdas. This logic is duplicated in org.pitest.bytecode.analysis.MethodTree | ||
* when identifying code lines. | ||
*/ | ||
public enum SyntheticMethodFilter implements | ||
F5<Integer, String, String, String, String[], Boolean> { | ||
|
||
INSTANCE; | ||
|
||
@Override | ||
public Boolean apply(final Integer access, final String name, | ||
final String desc, final String signature, final String[] exceptions) { | ||
return (!isSynthetic(access, name) && !isBridge(access)); | ||
} | ||
|
||
private static boolean isSynthetic(final int access, String name) { | ||
return (access & Opcodes.ACC_SYNTHETIC) != 0 && !name.startsWith("lambda$"); | ||
} | ||
|
||
private static boolean isBridge(final Integer access) { | ||
return (access & Opcodes.ACC_BRIDGE) != 0; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters