Create muzzle references from ldc instructions
This commit is contained in:
parent
c06983ef34
commit
61aaebfc97
|
@ -347,5 +347,20 @@ public class ReferenceCreator extends ClassVisitor {
|
||||||
.build());
|
.build());
|
||||||
super.visitMethodInsn(opcode, owner, name, descriptor, isInterface);
|
super.visitMethodInsn(opcode, owner, name, descriptor, isInterface);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void visitLdcInsn(final Object value) {
|
||||||
|
if (value instanceof Type) {
|
||||||
|
final Type type = underlyingType((Type) value);
|
||||||
|
if (type.getSort() == Type.OBJECT) {
|
||||||
|
addReference(
|
||||||
|
new Reference.Builder(type.getInternalName())
|
||||||
|
.withSource(refSourceClassName, currentLineNumber)
|
||||||
|
.withFlag(computeMinimumClassAccess(refSourceType, type))
|
||||||
|
.build());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
super.visitLdcInsn(value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,6 +57,14 @@ class ReferenceCreatorTest extends AgentTestRunner {
|
||||||
findMethod(bMethods, "protectedMethod", "()V").getFlags().contains(Reference.Flag.PROTECTED_OR_HIGHER)
|
findMethod(bMethods, "protectedMethod", "()V").getFlags().contains(Reference.Flag.PROTECTED_OR_HIGHER)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def "ldc creates references" () {
|
||||||
|
setup:
|
||||||
|
Map<String, Reference> references = ReferenceCreator.createReferencesFrom(LdcAdvice.getName(), this.getClass().getClassLoader())
|
||||||
|
|
||||||
|
expect:
|
||||||
|
references.get('muzzle.TestClasses$MethodBodyAdvice$A') != null
|
||||||
|
}
|
||||||
|
|
||||||
private static Reference.Method findMethod(Set<Reference.Method> methods, String methodName, String methodDesc) {
|
private static Reference.Method findMethod(Set<Reference.Method> methods, String methodName, String methodDesc) {
|
||||||
for (Reference.Method method : methods) {
|
for (Reference.Method method : methods) {
|
||||||
if (method == new Reference.Method(methodName, methodDesc)) {
|
if (method == new Reference.Method(methodName, methodDesc)) {
|
||||||
|
|
|
@ -68,4 +68,10 @@ public class TestClasses {
|
||||||
|
|
||||||
public interface AnotherInterface extends SomeInterface {}
|
public interface AnotherInterface extends SomeInterface {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class LdcAdvice {
|
||||||
|
public static void ldcMethod() {
|
||||||
|
MethodBodyAdvice.A.class.getName();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue