-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSimpleVisitAcceptingExample.java
55 lines (35 loc) · 1.23 KB
/
SimpleVisitAcceptingExample.java
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
package com.apploidxxx.classvisitor;
import com.apploidxxx.parse.ClassParserExample;
import org.apache.bcel.classfile.ClassParser;
import org.apache.bcel.classfile.JavaClass;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
/**
* @author Arthur Kupriyanov
*/
public class SimpleVisitAcceptingExample {
public static void main(String[] args) throws IOException {
InputStream inputStream = ClassParserExample.class.getResourceAsStream("/compiled/ClassA.class");
if (inputStream == null) throw new FileNotFoundException();
ClassParser parser = new ClassParser(inputStream, "ClassA.class");
JavaClass clazz = parser.parse();
clazz.accept(new SimpleVisitor());
// Visited JavClass with name: com.apploidxxx.parse.ClassA
clazz.getMethods()[0].accept(new SimpleVisitor());
// Visited method with name: <init>
// And with return type: void
clazz.getMethods()[1].accept(new SimpleVisitor());
// Visited method with name: main
// And with return type: void
}
}
/*
public class ClassA {
public ClassA() {
}
public static void main(String[] args) {
System.out.println("Hello world");
}
}
*/