1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package com.tonicsystems.jarjar;
18
19 import com.tonicsystems.jarjar.util.*;
20 import java.io.*;
21 import java.util.*;
22 import java.util.zip.ZipEntry;
23 import java.util.zip.ZipFile;
24 import org.objectweb.asm.*;
25 import org.objectweb.asm.Type;
26 import org.objectweb.asm.commons.*;
27
28 class DepFindVisitor extends RemappingClassAdapter
29 {
30 public DepFindVisitor(Map<String, String> classes, String source, DepHandler handler) throws IOException {
31 super(null, new DepFindRemapper(classes, source, handler));
32 }
33
34 public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) {
35 ((DepFindRemapper)remapper).setClassName(name);
36 super.visit(version, access, name, signature, superName, interfaces);
37 }
38
39 private static class DepFindRemapper extends Remapper
40 {
41 private final Map<String, String> classes;
42 private final String source;
43 private final DepHandler handler;
44 private PathClass curPathClass;
45
46 public DepFindRemapper(Map<String, String> classes, String source, DepHandler handler) throws IOException {
47 this.classes = classes;
48 this.source = source;
49 this.handler = handler;
50 }
51
52 public void setClassName(String name) {
53 curPathClass = new PathClass(source, name);
54 }
55
56 public String map(String key) {
57 try {
58 if (classes.containsKey(key)) {
59 String otherSource = classes.get(key);
60 if (!source.equals(otherSource)) {
61
62 handler.handle(curPathClass, new PathClass(otherSource, key));
63 }
64 }
65 } catch (IOException e) {
66 throw new RuntimeIOException(e);
67 }
68 return null;
69 }
70 }
71 }