Skip to content

Commit

Permalink
Merge pull request #6866 from robolectric/piper_410440888
Browse files Browse the repository at this point in the history
Limit instrumentation on interfaces
  • Loading branch information
hoisie committed Nov 17, 2021
2 parents 56cb74c + 0f1c9be commit 7ec9ef3
Showing 1 changed file with 12 additions and 12 deletions.
Expand Up @@ -143,18 +143,6 @@ private void recordPackageStats(PerfStatsCollector perfStats, MutableClass mutab

public void instrument(MutableClass mutableClass) {
try {
makeClassPublic(mutableClass.classNode);
if ((mutableClass.classNode.access & Opcodes.ACC_FINAL) == Opcodes.ACC_FINAL) {
mutableClass
.classNode
.visitAnnotation("Lcom/google/errorprone/annotations/DoNotMock;", true)
.visit(
"value",
"This class is final. Consider using the real thing, or "
+ "adding/enhancing a Robolectric shadow for it.");
}
mutableClass.classNode.access = mutableClass.classNode.access & ~Opcodes.ACC_FINAL;

// Need Java version >=7 to allow invokedynamic
mutableClass.classNode.version = Math.max(mutableClass.classNode.version, Opcodes.V1_7);

Expand All @@ -163,6 +151,18 @@ public void instrument(MutableClass mutableClass) {
if (mutableClass.isInterface()) {
mutableClass.addInterface(Type.getInternalName(InstrumentedInterface.class));
} else {
makeClassPublic(mutableClass.classNode);
if ((mutableClass.classNode.access & Opcodes.ACC_FINAL) == Opcodes.ACC_FINAL) {
mutableClass
.classNode
.visitAnnotation("Lcom/google/errorprone/annotations/DoNotMock;", true)
.visit(
"value",
"This class is final. Consider using the real thing, or "
+ "adding/enhancing a Robolectric shadow for it.");
}
mutableClass.classNode.access = mutableClass.classNode.access & ~Opcodes.ACC_FINAL;

// If there is no constructor, adds one
addNoArgsConstructor(mutableClass);

Expand Down

0 comments on commit 7ec9ef3

Please sign in to comment.