-
Notifications
You must be signed in to change notification settings - Fork 60
Expand file tree
/
Copy pathExposedFieldFinder.java
More file actions
69 lines (56 loc) · 2.14 KB
/
Copy pathExposedFieldFinder.java
File metadata and controls
69 lines (56 loc) · 2.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package org.python.expose.generate;
import org.objectweb.asm.AnnotationVisitor;
import org.objectweb.asm.Attribute;
import org.objectweb.asm.FieldVisitor;
import org.objectweb.asm.Opcodes;
import static org.objectweb.asm.Opcodes.ACC_FINAL;
import static org.objectweb.asm.Opcodes.ACC_STATIC;
public abstract class ExposedFieldFinder extends FieldVisitor implements PyTypes {
private int access;
private String fieldName;
private FieldVisitor delegate;
public ExposedFieldFinder(int access, String name, FieldVisitor delegate) {
super(Opcodes.ASM5);
this.access = access;
this.fieldName = name;
this.delegate = delegate;
}
public AnnotationVisitor visitAnnotation(String desc, boolean visible) {
if(EXPOSED_GET.getDescriptor().equals(desc)) {
return new DescriptorVisitor(fieldName) {
@Override
public void handleResult(String name, String doc) {
exposeAsGet(name, doc);
}
};
} else if(EXPOSED_SET.getDescriptor().equals(desc)) {
return new DescriptorVisitor(fieldName) {
@Override
public void handleResult(String name, String doc) {
exposeAsSet(name);
}
};
} else if(EXPOSED_CONST.getDescriptor().equals(desc)) {
if ((access & (ACC_STATIC | ACC_FINAL)) == 0) {
throw new InvalidExposingException("Exposed constant must be static final");
}
return new ConstantVisitor(fieldName) {
@Override
public void handleResult(String name) {
exposeAsConstant(name);
}
};
} else {
return delegate.visitAnnotation(desc, visible);
}
}
public abstract void exposeAsGet(String name, String doc);
public abstract void exposeAsSet(String name);
public abstract void exposeAsConstant(String name);
public void visitAttribute(Attribute attr) {
delegate.visitAttribute(attr);
}
public void visitEnd() {
delegate.visitEnd();
}
}