use of act.asm.AnnotationVisitor in project actframework by actframework.
the class SingletonEnhancer method addAnnotationIfNeeded.
private void addAnnotationIfNeeded() {
if (shouldAddAnnotation) {
AnnotationVisitor av = super.visitAnnotation(Type.getType(Singleton.class).getDescriptor(), true);
av.visitEnd();
}
}
use of act.asm.AnnotationVisitor in project actframework by actframework.
the class GenieFactoryFinder method byteCodeVisitor.
@Override
public ByteCodeVisitor byteCodeVisitor() {
return new ByteCodeVisitor() {
private boolean isPublic;
@Override
public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) {
super.visit(version, access, name, signature, superName, interfaces);
isPublic = AsmTypes.isPublic(access);
isModule = Module.class.getName().equals(Type.getObjectType(superName).getClassName());
}
@Override
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
MethodVisitor mv = super.visitMethod(access, name, desc, signature, exceptions);
return !isPublic || isModule || isFactory ? mv : new MethodVisitor(ASM5, mv) {
@Override
public AnnotationVisitor visitAnnotation(String desc, boolean visible) {
Type annoType = Type.getType(desc);
if (AsmTypes.PROVIDES.asmType().equals(annoType)) {
isFactory = true;
}
return super.visitAnnotation(desc, visible);
}
};
}
};
}
use of act.asm.AnnotationVisitor in project actframework by actframework.
the class ClassDetector method of.
public static ClassDetector of(final ClassFilter... filters) {
E.illegalArgumentIf(filters.length == 0);
if (filters.length == 1) {
return new FilteredClassDetector(filters[0]);
}
return new ClassDetector() {
C.List<ClassDetector> detectors = C.listOf(filters).map(new $.F1<ClassFilter, ClassDetector>() {
@Override
public ClassDetector apply(ClassFilter classFilter) throws NotAppliedException, $.Break {
return new FilteredClassDetector(classFilter);
}
});
private List<ClassDetector> matches = new ArrayList<>();
@Override
public int hashCode() {
return $.hc(detectors);
}
@Override
public boolean equals(Object obj) {
return obj == this;
}
@Override
public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) {
super.visit(version, access, name, signature, superName, interfaces);
for (ClassDetector detector : detectors) {
detector.visit(version, access, name, signature, superName, interfaces);
if (detector.found()) {
matches.add(detector);
}
}
}
@Override
public AnnotationVisitor visitAnnotation(final String desc, final boolean visible) {
AnnotationVisitor av = super.visitAnnotation(desc, visible);
if (matches.size() == detectors.size() || !isExtendsAnnotation(desc)) {
return av;
}
final C.List<ClassDetector> unmatched = detectors.without(matches);
return new AnnotationVisitor(ASM5, av) {
@Override
public void visit(String name, Object value) {
for (ClassDetector detector : unmatched) {
AnnotationVisitor av0 = detector.visitAnnotation(desc, visible);
av0.visit(name, value);
if (detector.found()) {
matches.add(detector);
}
}
super.visit(name, value);
}
};
}
@Override
public boolean found() {
return !matches.isEmpty();
}
};
}
Aggregations