Mirror of the JODE repository
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
jode/jode/jode/decompiler/ImportHandler.java

96 lines
2.6 KiB

package jode;
import sun.tools.java.*;
import sun.tools.util.*;
import java.util.*;
public class JodeEnvironment extends LoadEnvironment {
Hashtable imports = new Hashtable();
BinaryClass main;
Identifier pkg;
boolean isVerbose = true;
JodeEnvironment() {
super(null);
path = new ClassPath(System.getProperty("java.class.path"));
}
public BinaryConstantPool getConstantPool() {
return main.getConstants();
}
public Object getConstant(int i) {
return main.getConstants().getConstant(i, this);
}
public Type getConstantType(int i)
throws ClassFormatError
{
int t = main.getConstants().getConstantType(i);
switch(t) {
case 3: return Type.tInt ;
case 4: return Type.tFloat ;
case 5: return Type.tLong ;
case 6: return Type.tDouble;
case 8: return Type.tString;
default:
throw new ClassFormatError("invalid constant type: "+t);
}
}
public String getNickName(String string) {
return string;
}
public ClassDefinition getClassDefinition() {
return main;
}
public void dumpHeader(TabbedPrintWriter writer)
throws java.io.IOException
{
writer.println("/* Decompiled by JoDe (Jochen's Decompiler) */");
if (pkg != null && pkg != Constants.idNull)
writer.println("package "+pkg+";");
Enumeration enum = imports.keys();
while (enum.hasMoreElements()) {
Identifier packageName = (Identifier) enum.nextElement();
Integer vote = (Integer) imports.get(packageName);
if (vote.intValue() > 3)
writer.println("import "+packageName+";");
}
writer.println("");
}
public void error(String message) {
System.err.println(message);
}
public void doClass(String className)
{
try {
Identifier ident = Identifier.lookup(className);
error(ident.toString());
if (!classExists(ident)) {
error("`"+ident+"' not found");
return;
}
pkg = ident.getQualifier();
main = (BinaryClass)getClassDefinition(ident);
ClassAnalyzer a = new ClassAnalyzer(main, this);
a.analyze();
TabbedPrintWriter writer =
new TabbedPrintWriter(System.out, " ");
a.dumpSource(writer);
} catch (ClassNotFound e) {
error(e.toString());
} catch (java.io.IOException e) {
error(e.toString());
}
}
protected int loadFileFlags()
{
return 1;
}
}