• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright 2007 Google Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
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 {
DepFindVisitor(Map<String, String> classes, String source, DepHandler handler)30     public DepFindVisitor(Map<String, String> classes, String source, DepHandler handler) throws IOException {
31         super(null, new DepFindRemapper(classes, source, handler));
32     }
33 
visit(int version, int access, String name, String signature, String superName, String[] interfaces)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 
DepFindRemapper(Map<String, String> classes, String source, DepHandler handler)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 
setClassName(String name)52         public void setClassName(String name) {
53             curPathClass = new PathClass(source, name);
54         }
55 
map(String key)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                         // TODO: some escape mechanism?
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 }
72