decompiler: extracted <init> and <clinit> to constants

This commit is contained in:
Egor.Ushakov
2015-01-22 12:30:12 +03:00
parent 9ba9af5425
commit effbed6727
9 changed files with 33 additions and 27 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
* Copyright 2000-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -58,7 +58,7 @@ public class ClassReference14Processor {
VarType.VARTYPE_CLASS, null);
InvocationExprent constr = new InvocationExprent();
constr.setName("<init>");
constr.setName(CodeConstants.INIT_NAME);
constr.setClassname("java/lang/NoClassDefFoundError");
constr.setStringDescriptor("()V");
constr.setFunctype(InvocationExprent.TYP_INIT);

View File

@@ -590,7 +590,7 @@ public class ClassWriter {
if ((flags & CodeConstants.ACC_NATIVE) != 0) {
flags &= ~CodeConstants.ACC_STRICT; // compiler bug: a strictfp class sets all methods to strictfp
}
if ("<clinit>".equals(mt.getName())) {
if (CodeConstants.CLINIT_NAME.equals(mt.getName())) {
flags &= CodeConstants.ACC_STATIC; // ignore all modifiers except 'static' in a static initializer
}
@@ -624,7 +624,7 @@ public class ClassWriter {
}
String name = mt.getName();
if ("<init>".equals(name)) {
if (CodeConstants.INIT_NAME.equals(name)) {
if (node.type == ClassNode.CLASS_ANONYMOUS) {
name = "";
dinit = true;
@@ -634,7 +634,7 @@ public class ClassWriter {
init = true;
}
}
else if ("<clinit>".equals(name)) {
else if (CodeConstants.CLINIT_NAME.equals(name)) {
name = "";
clinit = true;
}
@@ -903,7 +903,7 @@ public class ClassWriter {
int count = 0;
for (StructMethod mt : wrapper.getClassStruct().getMethods()) {
if ("<init>".equals(mt.getName())) {
if (CodeConstants.INIT_NAME.equals(mt.getName())) {
if (++count > 1) {
return false;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
* Copyright 2000-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,6 +15,7 @@
*/
package org.jetbrains.java.decompiler.main;
import org.jetbrains.java.decompiler.code.CodeConstants;
import org.jetbrains.java.decompiler.main.rels.ClassWrapper;
import org.jetbrains.java.decompiler.main.rels.MethodWrapper;
import org.jetbrains.java.decompiler.modules.decompiler.exps.Exprent;
@@ -48,7 +49,7 @@ public class EnumProcessor {
wrapper.getHiddenMembers().add(InterpreterUtil.makeUniqueKey(name, descriptor));
}
}
else if ("<init>".equals(name)) {
else if (CodeConstants.INIT_NAME.equals(name)) {
Statement firstData = findFirstData(method.root);
if (firstData != null && !firstData.getExprents().isEmpty()) {
Exprent exprent = firstData.getExprents().get(0);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
* Copyright 2000-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -36,7 +36,7 @@ public class InitializerProcessor {
public static void extractInitializers(ClassWrapper wrapper) {
MethodWrapper meth = wrapper.getMethodWrapper("<clinit>", "()V");
MethodWrapper meth = wrapper.getMethodWrapper(CodeConstants.CLINIT_NAME, "()V");
if (meth != null && meth.root != null) { // successfully decompiled static constructor
extractStaticInitializers(wrapper, meth);
}
@@ -56,7 +56,7 @@ public class InitializerProcessor {
private static void liftConstructor(ClassWrapper wrapper) {
for (MethodWrapper meth : wrapper.getMethods()) {
if ("<init>".equals(meth.methodStruct.getName()) && meth.root != null) {
if (CodeConstants.INIT_NAME.equals(meth.methodStruct.getName()) && meth.root != null) {
Statement firstdata = findFirstData(meth.root);
if (firstdata == null) {
return;
@@ -103,7 +103,7 @@ public class InitializerProcessor {
private static void hideEmptySuper(ClassWrapper wrapper) {
for (MethodWrapper meth : wrapper.getMethods()) {
if ("<init>".equals(meth.methodStruct.getName()) && meth.root != null) {
if (CodeConstants.INIT_NAME.equals(meth.methodStruct.getName()) && meth.root != null) {
Statement firstdata = findFirstData(meth.root);
if (firstdata == null || firstdata.getExprents().isEmpty()) {
return;
@@ -169,7 +169,7 @@ public class InitializerProcessor {
List<MethodWrapper> lstMethWrappers = new ArrayList<MethodWrapper>();
for (MethodWrapper meth : wrapper.getMethods()) {
if ("<init>".equals(meth.methodStruct.getName()) && meth.root != null) { // successfully decompiled constructor
if (CodeConstants.INIT_NAME.equals(meth.methodStruct.getName()) && meth.root != null) { // successfully decompiled constructor
Statement firstdata = findFirstData(meth.root);
if (firstdata == null || firstdata.getExprents().isEmpty()) {
return;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
* Copyright 2000-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,6 +15,7 @@
*/
package org.jetbrains.java.decompiler.main.rels;
import org.jetbrains.java.decompiler.code.CodeConstants;
import org.jetbrains.java.decompiler.code.InstructionSequence;
import org.jetbrains.java.decompiler.code.cfg.ControlFlowGraph;
import org.jetbrains.java.decompiler.main.DecompilerContext;
@@ -78,7 +79,7 @@ public class MethodProcessorRunnable implements Runnable {
public static RootStatement codeToJava(StructMethod mt, VarProcessor varProc) throws IOException {
StructClass cl = mt.getClassStruct();
boolean isInitializer = "<clinit>".equals(mt.getName()); // for now static initializer only
boolean isInitializer = CodeConstants.CLINIT_NAME.equals(mt.getName()); // for now static initializer only
mt.expandData();
InstructionSequence seq = mt.getInstructionSequence();

View File

@@ -427,7 +427,7 @@ public class NestedClassProcessor {
for (Entry<String, List<VarFieldPair>> entmt : entcl.getValue().entrySet()) {
mergeListSignatures(entmt.getValue(), intrPairMask, false);
MethodWrapper meth = nestedNode.getWrapper().getMethodWrapper("<init>", entmt.getKey());
MethodWrapper meth = nestedNode.getWrapper().getMethodWrapper(CodeConstants.INIT_NAME, entmt.getKey());
meth.signatureFields = new ArrayList<VarVersionPair>();
for (VarFieldPair pair : entmt.getValue()) {
@@ -577,7 +577,7 @@ public class NestedClassProcessor {
}
}
if (child.type == ClassNode.CLASS_ANONYMOUS && "<init>".equals(meth.methodStruct.getName())
if (child.type == ClassNode.CLASS_ANONYMOUS && CodeConstants.INIT_NAME.equals(meth.methodStruct.getName())
&& exprent.type == Exprent.EXPRENT_INVOCATION) {
InvocationExprent invexpr = (InvocationExprent)exprent;
if (invexpr.getFunctype() == InvocationExprent.TYP_INIT) {
@@ -646,11 +646,11 @@ public class NestedClassProcessor {
// iterate over constructors
for (StructMethod mt : cl.getMethods()) {
if ("<init>".equals(mt.getName())) {
if (CodeConstants.INIT_NAME.equals(mt.getName())) {
MethodDescriptor md = MethodDescriptor.parseDescriptor(mt.getDescriptor());
MethodWrapper meth = wrapper.getMethodWrapper("<init>", mt.getDescriptor());
MethodWrapper meth = wrapper.getMethodWrapper(CodeConstants.INIT_NAME, mt.getDescriptor());
DirectGraph graph = meth.getOrBuildGraph();
if (graph != null) { // something gone wrong, should not be null