Made ClassReference14Processor static similar to how InitializerProcessor and EnumProcessor are setup. This gets rid of a lot of unnecessary InvocationExprent creation.

master
Christopher Carpenter 9 years ago committed by Roman Shevchenko
parent 35569de64f
commit f643b1c870
  1. 32
      src/org/jetbrains/java/decompiler/main/ClassReference14Processor.java
  2. 52
      src/org/jetbrains/java/decompiler/main/ClassWriter.java

@ -38,12 +38,11 @@ import java.util.Map.Entry;
public class ClassReference14Processor { public class ClassReference14Processor {
public final ExitExprent bodyexprent; public static final ExitExprent bodyexprent;
public final ExitExprent handlerexprent; public static final ExitExprent handlerexprent;
static {
public ClassReference14Processor() {
InvocationExprent invfor = new InvocationExprent(); InvocationExprent invfor = new InvocationExprent();
invfor.setName("forName"); invfor.setName("forName");
@ -65,7 +64,7 @@ public class ClassReference14Processor {
constr.setDescriptor(MethodDescriptor.parseDescriptor("()V")); constr.setDescriptor(MethodDescriptor.parseDescriptor("()V"));
NewExprent newexpr = NewExprent newexpr =
new NewExprent(new VarType(CodeConstants.TYPE_OBJECT, 0, "java/lang/NoClassDefFoundError"), new ArrayList<Exprent>(), null); new NewExprent(new VarType(CodeConstants.TYPE_OBJECT, 0, "java/lang/NoClassDefFoundError"), new ArrayList<>(), null);
newexpr.setConstructor(constr); newexpr.setConstructor(constr);
InvocationExprent invcause = new InvocationExprent(); InvocationExprent invcause = new InvocationExprent();
@ -82,32 +81,13 @@ public class ClassReference14Processor {
null, null); null, null);
} }
public static void processClassReferences(ClassNode node) {
public void processClassReferences(ClassNode node) {
ClassWrapper wrapper = node.getWrapper();
// int major_version = wrapper.getClassStruct().major_version;
// int minor_version = wrapper.getClassStruct().minor_version;
//
// if(major_version > 48 || (major_version == 48 && minor_version > 0)) {
// // version 1.5 or above
// return;
// }
if (wrapper.getClassStruct().isVersionGE_1_5()) {
// version 1.5 or above
return;
}
// find the synthetic method Class class$(String) if present // find the synthetic method Class class$(String) if present
HashMap<ClassWrapper, MethodWrapper> mapClassMeths = new HashMap<ClassWrapper, MethodWrapper>(); HashMap<ClassWrapper, MethodWrapper> mapClassMeths = new HashMap<ClassWrapper, MethodWrapper>();
mapClassMethods(node, mapClassMeths); mapClassMethods(node, mapClassMeths);
if (mapClassMeths.isEmpty()) { if (mapClassMeths.isEmpty()) {
return; return;
} }
HashSet<ClassWrapper> setFound = new HashSet<ClassWrapper>(); HashSet<ClassWrapper> setFound = new HashSet<ClassWrapper>();
processClassRec(node, mapClassMeths, setFound); processClassRec(node, mapClassMeths, setFound);
@ -173,7 +153,7 @@ public class ClassReference14Processor {
} }
} }
private void mapClassMethods(ClassNode node, Map<ClassWrapper, MethodWrapper> map) { private static void mapClassMethods(ClassNode node, Map<ClassWrapper, MethodWrapper> map) {
boolean noSynthFlag = DecompilerContext.getOption(IFernflowerPreferences.SYNTHETIC_NOT_SET); boolean noSynthFlag = DecompilerContext.getOption(IFernflowerPreferences.SYNTHETIC_NOT_SET);
ClassWrapper wrapper = node.getWrapper(); ClassWrapper wrapper = node.getWrapper();

@ -43,14 +43,14 @@ import org.jetbrains.java.decompiler.struct.gen.VarType;
import org.jetbrains.java.decompiler.struct.gen.generics.*; import org.jetbrains.java.decompiler.struct.gen.generics.*;
import org.jetbrains.java.decompiler.util.InterpreterUtil; import org.jetbrains.java.decompiler.util.InterpreterUtil;
import java.util.*; import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
public class ClassWriter { public class ClassWriter {
private final ClassReference14Processor ref14processor;
private final PoolInterceptor interceptor; private final PoolInterceptor interceptor;
public ClassWriter() { public ClassWriter() {
ref14processor = new ClassReference14Processor();
interceptor = DecompilerContext.getPoolInterceptor(); interceptor = DecompilerContext.getPoolInterceptor();
} }
@ -60,8 +60,10 @@ public class ClassWriter {
InitializerProcessor.extractInitializers(wrapper); InitializerProcessor.extractInitializers(wrapper);
if (node.type == ClassNode.CLASS_ROOT && DecompilerContext.getOption(IFernflowerPreferences.DECOMPILE_CLASS_1_4)) { if (node.type == ClassNode.CLASS_ROOT &&
ref14processor.processClassReferences(node); !cl.isVersionGE_1_5() &&
DecompilerContext.getOption(IFernflowerPreferences.DECOMPILE_CLASS_1_4)) {
ClassReference14Processor.processClassReferences(node);
} }
if (cl.hasModifier(CodeConstants.ACC_ENUM) && DecompilerContext.getOption(IFernflowerPreferences.DECOMPILE_ENUM)) { if (cl.hasModifier(CodeConstants.ACC_ENUM) && DecompilerContext.getOption(IFernflowerPreferences.DECOMPILE_ENUM)) {
@ -273,7 +275,8 @@ public class ClassWriter {
} }
private static void addTracer(StructClass cls, StructMethod method, BytecodeMappingTracer tracer) { private static void addTracer(StructClass cls, StructMethod method, BytecodeMappingTracer tracer) {
StructLineNumberTableAttribute table = (StructLineNumberTableAttribute)method.getAttributes().getWithKey(StructGeneralAttribute.ATTRIBUTE_LINE_NUMBER_TABLE); StructLineNumberTableAttribute table =
(StructLineNumberTableAttribute)method.getAttributes().getWithKey(StructGeneralAttribute.ATTRIBUTE_LINE_NUMBER_TABLE);
tracer.setLineNumberTable(table); tracer.setLineNumberTable(table);
String key = InterpreterUtil.makeUniqueKey(method.getName(), method.getDescriptor()); String key = InterpreterUtil.makeUniqueKey(method.getName(), method.getDescriptor());
DecompilerContext.getBytecodeSourceMapper().addTracer(cls.qualifiedName, key, tracer); DecompilerContext.getBytecodeSourceMapper().addTracer(cls.qualifiedName, key, tracer);
@ -385,7 +388,12 @@ public class ClassWriter {
buffer.append('{').appendLineSeparator(); buffer.append('{').appendLineSeparator();
} }
private void fieldToJava(ClassWrapper wrapper, StructClass cl, StructField fd, TextBuffer buffer, int indent, BytecodeMappingTracer tracer) { private void fieldToJava(ClassWrapper wrapper,
StructClass cl,
StructField fd,
TextBuffer buffer,
int indent,
BytecodeMappingTracer tracer) {
int start = buffer.length(); int start = buffer.length();
boolean isInterface = cl.hasModifier(CodeConstants.ACC_INTERFACE); boolean isInterface = cl.hasModifier(CodeConstants.ACC_INTERFACE);
boolean isDeprecated = fd.getAttributes().containsKey("Deprecated"); boolean isDeprecated = fd.getAttributes().containsKey("Deprecated");
@ -571,7 +579,9 @@ public class ClassWriter {
changed = true; changed = true;
res.append("_"); res.append("_");
} }
else res.append(c); else {
res.append(c);
}
} }
if (!changed) { if (!changed) {
return name; return name;
@ -661,7 +671,7 @@ public class ClassWriter {
int actualParams = md.params.length; int actualParams = md.params.length;
List<VarVersionPair> sigFields = methodWrapper.signatureFields; List<VarVersionPair> sigFields = methodWrapper.signatureFields;
if (sigFields != null) { if (sigFields != null) {
actualParams = 0; actualParams = 0;
for (VarVersionPair field : methodWrapper.signatureFields) { for (VarVersionPair field : methodWrapper.signatureFields) {
if (field == null) { if (field == null) {
actualParams++; actualParams++;
@ -670,7 +680,8 @@ public class ClassWriter {
} }
else if (isEnum && init) actualParams -= 2; else if (isEnum && init) actualParams -= 2;
if (actualParams != descriptor.params.size()) { if (actualParams != descriptor.params.size()) {
String message = "Inconsistent generic signature in method " + mt.getName() + " " + mt.getDescriptor() + " in " + cl.qualifiedName; String message =
"Inconsistent generic signature in method " + mt.getName() + " " + mt.getDescriptor() + " in " + cl.qualifiedName;
DecompilerContext.getLogger().writeMessage(message, IFernflowerLogger.Severity.WARN); DecompilerContext.getLogger().writeMessage(message, IFernflowerLogger.Severity.WARN);
descriptor = null; descriptor = null;
} }
@ -732,7 +743,8 @@ public class ClassWriter {
if (descriptor != null) { if (descriptor != null) {
GenericType parameterType = descriptor.params.get(i); GenericType parameterType = descriptor.params.get(i);
boolean isVarArg = (i == lastVisibleParameterIndex && mt.hasModifier(CodeConstants.ACC_VARARGS) && parameterType.arrayDim > 0); boolean isVarArg =
(i == lastVisibleParameterIndex && mt.hasModifier(CodeConstants.ACC_VARARGS) && parameterType.arrayDim > 0);
if (isVarArg) { if (isVarArg) {
parameterType = parameterType.decreaseArrayDim(); parameterType = parameterType.decreaseArrayDim();
} }
@ -752,7 +764,8 @@ public class ClassWriter {
else { else {
VarType parameterType = md.params[i]; VarType parameterType = md.params[i];
boolean isVarArg = (i == lastVisibleParameterIndex && mt.hasModifier(CodeConstants.ACC_VARARGS) && parameterType.arrayDim > 0); boolean isVarArg =
(i == lastVisibleParameterIndex && mt.hasModifier(CodeConstants.ACC_VARARGS) && parameterType.arrayDim > 0);
if (isVarArg) { if (isVarArg) {
parameterType = parameterType.decreaseArrayDim(); parameterType = parameterType.decreaseArrayDim();
} }
@ -961,7 +974,8 @@ public class ClassWriter {
} }
private static final String[] PARAMETER_ANNOTATION_ATTRIBUTES = { private static final String[] PARAMETER_ANNOTATION_ATTRIBUTES = {
StructGeneralAttribute.ATTRIBUTE_RUNTIME_VISIBLE_PARAMETER_ANNOTATIONS, StructGeneralAttribute.ATTRIBUTE_RUNTIME_INVISIBLE_PARAMETER_ANNOTATIONS}; StructGeneralAttribute.ATTRIBUTE_RUNTIME_VISIBLE_PARAMETER_ANNOTATIONS,
StructGeneralAttribute.ATTRIBUTE_RUNTIME_INVISIBLE_PARAMETER_ANNOTATIONS};
private static void appendParameterAnnotations(TextBuffer buffer, StructMethod mt, int param) { private static void appendParameterAnnotations(TextBuffer buffer, StructMethod mt, int param) {
@ -981,6 +995,7 @@ public class ClassWriter {
} }
private static final Map<Integer, String> MODIFIERS; private static final Map<Integer, String> MODIFIERS;
static { static {
MODIFIERS = new LinkedHashMap<>(); MODIFIERS = new LinkedHashMap<>();
MODIFIERS.put(CodeConstants.ACC_PUBLIC, "public"); MODIFIERS.put(CodeConstants.ACC_PUBLIC, "public");
@ -1003,8 +1018,15 @@ public class ClassWriter {
CodeConstants.ACC_PUBLIC | CodeConstants.ACC_PROTECTED | CodeConstants.ACC_PRIVATE | CodeConstants.ACC_STATIC | CodeConstants.ACC_PUBLIC | CodeConstants.ACC_PROTECTED | CodeConstants.ACC_PRIVATE | CodeConstants.ACC_STATIC |
CodeConstants.ACC_FINAL | CodeConstants.ACC_TRANSIENT | CodeConstants.ACC_VOLATILE; CodeConstants.ACC_FINAL | CodeConstants.ACC_TRANSIENT | CodeConstants.ACC_VOLATILE;
private static final int METHOD_ALLOWED = private static final int METHOD_ALLOWED =
CodeConstants.ACC_PUBLIC | CodeConstants.ACC_PROTECTED | CodeConstants.ACC_PRIVATE | CodeConstants.ACC_ABSTRACT | CodeConstants.ACC_PUBLIC |
CodeConstants.ACC_STATIC | CodeConstants.ACC_FINAL | CodeConstants.ACC_SYNCHRONIZED | CodeConstants.ACC_NATIVE | CodeConstants.ACC_STRICT; CodeConstants.ACC_PROTECTED |
CodeConstants.ACC_PRIVATE |
CodeConstants.ACC_ABSTRACT |
CodeConstants.ACC_STATIC |
CodeConstants.ACC_FINAL |
CodeConstants.ACC_SYNCHRONIZED |
CodeConstants.ACC_NATIVE |
CodeConstants.ACC_STRICT;
private static final int CLASS_EXCLUDED = CodeConstants.ACC_ABSTRACT | CodeConstants.ACC_STATIC; private static final int CLASS_EXCLUDED = CodeConstants.ACC_ABSTRACT | CodeConstants.ACC_STATIC;
private static final int FIELD_EXCLUDED = CodeConstants.ACC_PUBLIC | CodeConstants.ACC_STATIC | CodeConstants.ACC_FINAL; private static final int FIELD_EXCLUDED = CodeConstants.ACC_PUBLIC | CodeConstants.ACC_STATIC | CodeConstants.ACC_FINAL;

Loading…
Cancel
Save