c = Class.forName(AsmUtil.getFqn(type1), false, classLoader); d = Class.forName(AsmUtil.getFqn(type2), false, classLoader); } catch (Exception e) { throw new RuntimeException(e.toString(), e); c = c.getSuperclass(); } while (!c.isAssignableFrom(d)); return AsmUtil.getAsmInternalName(c.getName());
@Test public void protectedMod() { int mod = AsmUtil.getModifiers(Opcodes.ACC_PROTECTED); assertThat(Modifier.isProtected(mod), is(true)); }
int modifiers = AsmUtil.getModifiers(access); this.type = new AnnotationType(AsmUtil.getFqn(name), hash, modifiers); } else if ((Opcodes.ACC_INTERFACE & access) > 0) { InterfaceType interfaceType = new InterfaceType(AsmUtil.getFqn(name), hash, modifiers); interfaceType.addSuperInterface(new InterfaceType(AsmUtil.getFqn(interfaceName))); } else { ClassType classType = new ClassType(AsmUtil.getFqn(name), hash, modifiers); ClassType superClassType = new ClassType(AsmUtil.getFqn(superName)); classType.addSuperClass(superClassType); classType.addInterface(new InterfaceType(AsmUtil.getFqn(interfaceName)));
@Test public void fqn() { String asmInternal = "com/test/Example"; String fqn = AsmUtil.getFqn(asmInternal); assertThat(fqn, is("com.test.Example")); }
@Test public void defaultPackage() { String fqn = "Example"; String asmInternal = AsmUtil.getAsmInternalName(fqn); assertThat(asmInternal, is("Example")); } }
methodType.setModifiers(AsmUtil.getModifiers(access)); methodType.setName(name); methodType.addException(new ClassType(AsmUtil.getFqn(exceptionName)));
@Test public void defaultPackage() { String asmInternal = "Example"; String fqn = AsmUtil.getFqn(asmInternal); assertThat(fqn, is("Example")); } }
@Test public void asmInternalName() { String fqn = "com.test.Example"; String asmInternal = AsmUtil.getAsmInternalName(fqn); assertThat(asmInternal, is("com/test/Example")); }
@Test public void publicMod() { int mod = AsmUtil.getModifiers(Opcodes.ACC_PUBLIC); assertThat(Modifier.isPublic(mod), is(true)); }
/** * {@inheritDoc} */ @Override public AnnotationVisitor visitAnnotation(String desc, boolean visible) { // calling super to ensure the visitor pattern AnnotationVisitor annotationVisitor = super.visitAnnotation(desc, visible); // if we don't have correct type return if (!(type instanceof TypeWithAnnotations)) { LOG.error("Annotation visit failed as the analyzed type " + type + " is not implementing the TypeWithAnnotations interface."); return annotationVisitor; } String internalName = Type.getType(desc).getInternalName(); ((TypeWithAnnotations) type).addAnnotation(new AnnotationType(AsmUtil.getFqn(internalName))); return annotationVisitor; }
/** * {@inheritDoc} */ @Override public IProxyClassInfo createProxyClass(IProxyBuildPlan plan) { String internalName = AsmUtil.getAsmInternalName(plan.getProxyClassName()); Type proxyType = Type.getObjectType(internalName); String[] interfaces = getInternalNames(plan.getImplementedInterfaces()); String superClass = Type.getInternalName(plan.getSuperClass()); // generate a new class for the proxy with the defined interfaces and superclass ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS); cw.visit(V1_5, ACC_PUBLIC, internalName, null, superClass, interfaces); // create the subject field cw.visitField(ACC_PUBLIC, SUBJECT_FIELD, IInstrumenterConstant.OBJECT_TYPE.getDescriptor(), null, null).visitEnd(); // create the fields for the delegation-target methods // The result map maps the proxied methods to their generated field's names Map<IMethodBuildPlan, String> methodFields = generateDelegationMethodTargetFields(plan, cw); generateConstructor(plan, proxyType, cw); // create the proxied methods for (Entry<IMethodBuildPlan, String> entry : methodFields.entrySet()) { createDelegationMethod(proxyType, entry.getKey(), entry.getValue(), cw); } cw.visitEnd(); byte[] bytecode = cw.toByteArray(); Class<?> cl = loadClass(bytecode, plan.getProxyClassName(), plan.getTargetClassLoader()); // inject the method fields injectDelegationTargetFields(plan, methodFields, cl); return new ASMProxyClassInfo(cl); }
@Test public void finalMod() { int mod = AsmUtil.getModifiers(Opcodes.ACC_FINAL); assertThat(Modifier.isFinal(mod), is(true)); }
/** * {@inheritDoc} */ @Override public AnnotationVisitor visitAnnotation(String desc, boolean visible) { // calling super to ensure the visitor pattern AnnotationVisitor annotationVisitor = super.visitAnnotation(desc, visible); if (null == methodType) { return annotationVisitor; } String internalName = Type.getType(desc).getInternalName(); methodType.addAnnotation(new AnnotationType(AsmUtil.getFqn(internalName))); return annotationVisitor; }
@Test public void nativeMod() { int mod = AsmUtil.getModifiers(Opcodes.ACC_NATIVE); assertThat(Modifier.isNative(mod), is(true)); }
@Test public void privateMod() { int mod = AsmUtil.getModifiers(Opcodes.ACC_PRIVATE); assertThat(Modifier.isPrivate(mod), is(true)); }
@Test public void abstractMod() { int mod = AsmUtil.getModifiers(Opcodes.ACC_ABSTRACT); assertThat(Modifier.isAbstract(mod), is(true)); }
@Test public void staticMod() { int mod = AsmUtil.getModifiers(Opcodes.ACC_STATIC); assertThat(Modifier.isStatic(mod), is(true)); }
@Test public void volatileMod() { int mod = AsmUtil.getModifiers(Opcodes.ACC_VOLATILE); assertThat(Modifier.isVolatile(mod), is(true)); }
@Test public void transientMod() { int mod = AsmUtil.getModifiers(Opcodes.ACC_TRANSIENT); assertThat(Modifier.isTransient(mod), is(true)); }
@Test public void mixed() { int mod = AsmUtil.getModifiers(Opcodes.ACC_PUBLIC | Opcodes.ACC_ABSTRACT | Opcodes.ACC_FINAL); assertThat(Modifier.isPublic(mod), is(true)); assertThat(Modifier.isAbstract(mod), is(true)); assertThat(Modifier.isFinal(mod), is(true)); } }