-
Notifications
You must be signed in to change notification settings - Fork 226
Expand file tree
/
Copy pathExposedTypeVisitor.java
More file actions
65 lines (53 loc) · 1.83 KB
/
ExposedTypeVisitor.java
File metadata and controls
65 lines (53 loc) · 1.83 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
package org.python.expose.generate;
import org.objectweb.asm.AnnotationVisitor;
import org.objectweb.asm.Type;
/**
* Visits an ExposedType annotation and passes the values it gathers to handleResult.
*/
public abstract class ExposedTypeVisitor extends RestrictiveAnnotationVisitor {
private String typeName;
private Type onType;
private Type base = Type.getType(Object.class);
private boolean isBaseType = true;
private String doc;
private final AnnotationVisitor passthrough;
public ExposedTypeVisitor(Type onType, AnnotationVisitor passthrough) {
this.onType = onType;
this.passthrough = passthrough;
}
@Override
public void visit(String name, Object value) {
if (name.equals("name")) {
typeName = (String)value;
} else if (name.equals("base")) {
base = (Type)value;
} else if (name.equals("isBaseType")) {
isBaseType = (Boolean)value;
} else if (name.equals("doc")) {
doc = (String)value;
} else {
super.visit(name, value);
}
if (passthrough != null) {
passthrough.visit(name, value);
}
}
@Override
public void visitEnd() {
if (typeName == null) {
String name = onType.getClassName();
typeName = name.substring(name.lastIndexOf(".") + 1);
}
handleResult(typeName, base, isBaseType, doc);
if (passthrough != null) {
passthrough.visitEnd();
}
}
/**
* @param name the name the type should be exposed as from the annotation
* @param base the specified base type
* @param isBaseType the value of the isBaseType flag
* @param doc the type's docstring
*/
public abstract void handleResult(String name, Type base, boolean isBaseType, String doc);
}