KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > retrotranslator > transformer > SignatureListGenerator


1 /***
2  * Retrotranslator: a Java bytecode transformer that translates Java classes
3  * compiled with JDK 5.0 into classes that can be run on JVM 1.4.
4  *
5  * Copyright (c) 2005 - 2007 Taras Puchko
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  * notice, this list of conditions and the following disclaimer in the
15  * documentation and/or other materials provided with the distribution.
16  * 3. Neither the name of the copyright holders nor the names of its
17  * contributors may be used to endorse or promote products derived from
18  * this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
30  * THE POSSIBILITY OF SUCH DAMAGE.
31  */

32 package net.sf.retrotranslator.transformer;
33
34 import java.io.*;
35 import java.util.*;
36 import net.sf.retrotranslator.runtime.asm.ClassReader;
37 import net.sf.retrotranslator.runtime.impl.*;
38
39 /**
40  * @author Taras Puchko
41  */

42 public class SignatureListGenerator extends EmptyVisitor {
43
44     private static Object JavaDoc[][] CLASSES_14 = {
45             {java.util.Collection JavaDoc.class, "<E:Ljava/lang/Object;>Ljava/lang/Object;"},
46             {java.util.Set JavaDoc.class},
47             {java.util.List JavaDoc.class},
48             {java.util.Queue JavaDoc.class},
49             {java.util.Map JavaDoc.class},
50             {java.util.SortedSet JavaDoc.class},
51             {java.util.SortedMap JavaDoc.class},
52             {java.util.concurrent.BlockingQueue JavaDoc.class},
53             {java.util.concurrent.ConcurrentMap JavaDoc.class},
54             {java.util.HashSet JavaDoc.class},
55             {java.util.TreeSet JavaDoc.class,
56                     "<E:Ljava/lang/Object;>Ljava/util/AbstractSet<TE;>;Ljava/util/SortedSet<TE;>;" +
57                             "Ljava/lang/Cloneable;Ljava/io/Serializable;"},
58             {java.util.LinkedHashSet JavaDoc.class},
59             {java.util.ArrayList JavaDoc.class},
60             {java.util.LinkedList JavaDoc.class,
61                     "<E:Ljava/lang/Object;>Ljava/util/AbstractSequentialList<TE;>;" +
62                             "Ljava/util/List<TE;>;Ljava/lang/Cloneable;Ljava/io/Serializable;"},
63             {java.util.PriorityQueue JavaDoc.class},
64             {java.util.HashMap JavaDoc.class},
65             {java.util.TreeMap JavaDoc.class, "<K:Ljava/lang/Object;V:Ljava/lang/Object;>Ljava/util/AbstractMap<TK;TV;>;" +
66                     "Ljava/util/SortedMap<TK;TV;>;Ljava/lang/Cloneable;Ljava/io/Serializable;"},
67             {java.util.LinkedHashMap JavaDoc.class, "<K:Ljava/lang/Object;V:Ljava/lang/Object;>Ljava/util/HashMap<TK;TV;>;"},
68             {java.util.Vector JavaDoc.class},
69             {java.util.Hashtable JavaDoc.class},
70             {java.util.WeakHashMap JavaDoc.class},
71             {java.util.IdentityHashMap JavaDoc.class},
72             {java.util.concurrent.CopyOnWriteArrayList JavaDoc.class},
73             {java.util.concurrent.CopyOnWriteArraySet JavaDoc.class},
74             {java.util.EnumSet JavaDoc.class,
75                     "<E:Lnet/sf/retrotranslator/runtime/java/lang/Enum_<TE;>;>Ljava/util/HashSet<TE;>;"},
76             {java.util.EnumMap JavaDoc.class,
77                     "<K:Lnet/sf/retrotranslator/runtime/java/lang/Enum_<TK;>;V:Ljava/lang/Object;>" +
78                             "Ljava/util/TreeMap<TK;TV;>;"},
79             {java.util.concurrent.ConcurrentLinkedQueue JavaDoc.class},
80             {java.util.concurrent.LinkedBlockingQueue JavaDoc.class},
81             {java.util.concurrent.ArrayBlockingQueue JavaDoc.class},
82             {java.util.concurrent.PriorityBlockingQueue JavaDoc.class},
83             {java.util.concurrent.DelayQueue JavaDoc.class},
84             {java.util.concurrent.SynchronousQueue JavaDoc.class},
85             {java.util.concurrent.ConcurrentHashMap JavaDoc.class,
86                     "<K:Ljava/lang/Object;V:Ljava/lang/Object;>Ledu/emory/mathcs/backport/java/util/AbstractMap<TK;TV;>;" +
87                             "Ledu/emory/mathcs/backport/java/util/concurrent/ConcurrentMap<TK;TV;>;Ljava/io/Serializable;"},
88             {java.util.AbstractCollection JavaDoc.class},
89             {java.util.AbstractSet JavaDoc.class},
90             {java.util.AbstractList JavaDoc.class},
91             {java.util.AbstractSequentialList JavaDoc.class},
92             {java.util.AbstractQueue JavaDoc.class,
93                     "<E:Ljava/lang/Object;>Ledu/emory/mathcs/backport/java/util/AbstractCollection<TE;>;" +
94                             "Ledu/emory/mathcs/backport/java/util/Queue<TE;>;"},
95             {java.util.AbstractMap JavaDoc.class},
96             {java.util.Enumeration JavaDoc.class},
97             {java.lang.Iterable JavaDoc.class},
98             {java.util.Iterator JavaDoc.class},
99             {java.util.ListIterator JavaDoc.class},
100             {java.lang.Comparable JavaDoc.class},
101             {java.util.Comparator JavaDoc.class}
102     };
103
104     private Properties properties = new Properties();
105     private String JavaDoc specialSignature;
106
107     public static void main(String JavaDoc[] args) throws Exception JavaDoc {
108         new SignatureListGenerator().execute(args[0]);
109     }
110
111     private void execute(String JavaDoc fileName) throws Exception JavaDoc {
112         ClassTransformer classTransformer = new ClassTransformer(false, false, false, null, null,
113                 new ReplacementLocatorFactory(ClassVersion.VERSION_14, false, false, new ArrayList<Backport>()));
114         for (Object JavaDoc[] objects : CLASSES_14) {
115             Class JavaDoc aClass = (Class JavaDoc) objects[0];
116             specialSignature = objects.length > 1 ? (String JavaDoc) objects[1] : null;
117             byte[] bytes = RuntimeTools.getBytecode(aClass);
118             bytes = classTransformer.transform(bytes, 0, bytes.length);
119             new ClassReader(bytes).accept(this, true);
120         }
121         OutputStream outputStream = new FileOutputStream(fileName);
122         try {
123             properties.store(outputStream, null);
124         } finally {
125             outputStream.close();
126         }
127     }
128
129     public void visit(int version, int access, String JavaDoc name, String JavaDoc signature, String JavaDoc superName, String JavaDoc[] interfaces) {
130         if (specialSignature != null) {
131             signature = specialSignature;
132         }
133         if (signature != null) {
134             properties.setProperty(name, signature);
135         }
136     }
137 }
138
Popular Tags