decompiler: extracted <init> and <clinit> to constants
This commit is contained in:
@@ -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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -367,4 +367,8 @@ public interface CodeConstants {
|
|||||||
int opc_ifnonnull = 199;
|
int opc_ifnonnull = 199;
|
||||||
int opc_goto_w = 200;
|
int opc_goto_w = 200;
|
||||||
int opc_jsr_w = 201;
|
int opc_jsr_w = 201;
|
||||||
|
|
||||||
|
@SuppressWarnings("SpellCheckingInspection")
|
||||||
|
String CLINIT_NAME = "<clinit>";
|
||||||
|
String INIT_NAME = "<init>";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with 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);
|
VarType.VARTYPE_CLASS, null);
|
||||||
|
|
||||||
InvocationExprent constr = new InvocationExprent();
|
InvocationExprent constr = new InvocationExprent();
|
||||||
constr.setName("<init>");
|
constr.setName(CodeConstants.INIT_NAME);
|
||||||
constr.setClassname("java/lang/NoClassDefFoundError");
|
constr.setClassname("java/lang/NoClassDefFoundError");
|
||||||
constr.setStringDescriptor("()V");
|
constr.setStringDescriptor("()V");
|
||||||
constr.setFunctype(InvocationExprent.TYP_INIT);
|
constr.setFunctype(InvocationExprent.TYP_INIT);
|
||||||
|
|||||||
@@ -590,7 +590,7 @@ public class ClassWriter {
|
|||||||
if ((flags & CodeConstants.ACC_NATIVE) != 0) {
|
if ((flags & CodeConstants.ACC_NATIVE) != 0) {
|
||||||
flags &= ~CodeConstants.ACC_STRICT; // compiler bug: a strictfp class sets all methods to strictfp
|
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
|
flags &= CodeConstants.ACC_STATIC; // ignore all modifiers except 'static' in a static initializer
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -624,7 +624,7 @@ public class ClassWriter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
String name = mt.getName();
|
String name = mt.getName();
|
||||||
if ("<init>".equals(name)) {
|
if (CodeConstants.INIT_NAME.equals(name)) {
|
||||||
if (node.type == ClassNode.CLASS_ANONYMOUS) {
|
if (node.type == ClassNode.CLASS_ANONYMOUS) {
|
||||||
name = "";
|
name = "";
|
||||||
dinit = true;
|
dinit = true;
|
||||||
@@ -634,7 +634,7 @@ public class ClassWriter {
|
|||||||
init = true;
|
init = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if ("<clinit>".equals(name)) {
|
else if (CodeConstants.CLINIT_NAME.equals(name)) {
|
||||||
name = "";
|
name = "";
|
||||||
clinit = true;
|
clinit = true;
|
||||||
}
|
}
|
||||||
@@ -903,7 +903,7 @@ public class ClassWriter {
|
|||||||
|
|
||||||
int count = 0;
|
int count = 0;
|
||||||
for (StructMethod mt : wrapper.getClassStruct().getMethods()) {
|
for (StructMethod mt : wrapper.getClassStruct().getMethods()) {
|
||||||
if ("<init>".equals(mt.getName())) {
|
if (CodeConstants.INIT_NAME.equals(mt.getName())) {
|
||||||
if (++count > 1) {
|
if (++count > 1) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -15,6 +15,7 @@
|
|||||||
*/
|
*/
|
||||||
package org.jetbrains.java.decompiler.main;
|
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.ClassWrapper;
|
||||||
import org.jetbrains.java.decompiler.main.rels.MethodWrapper;
|
import org.jetbrains.java.decompiler.main.rels.MethodWrapper;
|
||||||
import org.jetbrains.java.decompiler.modules.decompiler.exps.Exprent;
|
import org.jetbrains.java.decompiler.modules.decompiler.exps.Exprent;
|
||||||
@@ -48,7 +49,7 @@ public class EnumProcessor {
|
|||||||
wrapper.getHiddenMembers().add(InterpreterUtil.makeUniqueKey(name, descriptor));
|
wrapper.getHiddenMembers().add(InterpreterUtil.makeUniqueKey(name, descriptor));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if ("<init>".equals(name)) {
|
else if (CodeConstants.INIT_NAME.equals(name)) {
|
||||||
Statement firstData = findFirstData(method.root);
|
Statement firstData = findFirstData(method.root);
|
||||||
if (firstData != null && !firstData.getExprents().isEmpty()) {
|
if (firstData != null && !firstData.getExprents().isEmpty()) {
|
||||||
Exprent exprent = firstData.getExprents().get(0);
|
Exprent exprent = firstData.getExprents().get(0);
|
||||||
|
|||||||
@@ -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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with 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) {
|
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
|
if (meth != null && meth.root != null) { // successfully decompiled static constructor
|
||||||
extractStaticInitializers(wrapper, meth);
|
extractStaticInitializers(wrapper, meth);
|
||||||
}
|
}
|
||||||
@@ -56,7 +56,7 @@ public class InitializerProcessor {
|
|||||||
private static void liftConstructor(ClassWrapper wrapper) {
|
private static void liftConstructor(ClassWrapper wrapper) {
|
||||||
|
|
||||||
for (MethodWrapper meth : wrapper.getMethods()) {
|
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);
|
Statement firstdata = findFirstData(meth.root);
|
||||||
if (firstdata == null) {
|
if (firstdata == null) {
|
||||||
return;
|
return;
|
||||||
@@ -103,7 +103,7 @@ public class InitializerProcessor {
|
|||||||
private static void hideEmptySuper(ClassWrapper wrapper) {
|
private static void hideEmptySuper(ClassWrapper wrapper) {
|
||||||
|
|
||||||
for (MethodWrapper meth : wrapper.getMethods()) {
|
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);
|
Statement firstdata = findFirstData(meth.root);
|
||||||
if (firstdata == null || firstdata.getExprents().isEmpty()) {
|
if (firstdata == null || firstdata.getExprents().isEmpty()) {
|
||||||
return;
|
return;
|
||||||
@@ -169,7 +169,7 @@ public class InitializerProcessor {
|
|||||||
List<MethodWrapper> lstMethWrappers = new ArrayList<MethodWrapper>();
|
List<MethodWrapper> lstMethWrappers = new ArrayList<MethodWrapper>();
|
||||||
|
|
||||||
for (MethodWrapper meth : wrapper.getMethods()) {
|
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);
|
Statement firstdata = findFirstData(meth.root);
|
||||||
if (firstdata == null || firstdata.getExprents().isEmpty()) {
|
if (firstdata == null || firstdata.getExprents().isEmpty()) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with 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;
|
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.InstructionSequence;
|
||||||
import org.jetbrains.java.decompiler.code.cfg.ControlFlowGraph;
|
import org.jetbrains.java.decompiler.code.cfg.ControlFlowGraph;
|
||||||
import org.jetbrains.java.decompiler.main.DecompilerContext;
|
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 {
|
public static RootStatement codeToJava(StructMethod mt, VarProcessor varProc) throws IOException {
|
||||||
StructClass cl = mt.getClassStruct();
|
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();
|
mt.expandData();
|
||||||
InstructionSequence seq = mt.getInstructionSequence();
|
InstructionSequence seq = mt.getInstructionSequence();
|
||||||
|
|||||||
@@ -427,7 +427,7 @@ public class NestedClassProcessor {
|
|||||||
for (Entry<String, List<VarFieldPair>> entmt : entcl.getValue().entrySet()) {
|
for (Entry<String, List<VarFieldPair>> entmt : entcl.getValue().entrySet()) {
|
||||||
mergeListSignatures(entmt.getValue(), intrPairMask, false);
|
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>();
|
meth.signatureFields = new ArrayList<VarVersionPair>();
|
||||||
|
|
||||||
for (VarFieldPair pair : entmt.getValue()) {
|
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) {
|
&& exprent.type == Exprent.EXPRENT_INVOCATION) {
|
||||||
InvocationExprent invexpr = (InvocationExprent)exprent;
|
InvocationExprent invexpr = (InvocationExprent)exprent;
|
||||||
if (invexpr.getFunctype() == InvocationExprent.TYP_INIT) {
|
if (invexpr.getFunctype() == InvocationExprent.TYP_INIT) {
|
||||||
@@ -646,11 +646,11 @@ public class NestedClassProcessor {
|
|||||||
|
|
||||||
// iterate over constructors
|
// iterate over constructors
|
||||||
for (StructMethod mt : cl.getMethods()) {
|
for (StructMethod mt : cl.getMethods()) {
|
||||||
if ("<init>".equals(mt.getName())) {
|
if (CodeConstants.INIT_NAME.equals(mt.getName())) {
|
||||||
|
|
||||||
MethodDescriptor md = MethodDescriptor.parseDescriptor(mt.getDescriptor());
|
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();
|
DirectGraph graph = meth.getOrBuildGraph();
|
||||||
|
|
||||||
if (graph != null) { // something gone wrong, should not be null
|
if (graph != null) { // something gone wrong, should not be null
|
||||||
|
|||||||
@@ -92,10 +92,10 @@ public class InvocationExprent extends Exprent {
|
|||||||
invokeDynamicClassSuffix = "##Lambda_" + cn.index1 + "_" + cn.index2;
|
invokeDynamicClassSuffix = "##Lambda_" + cn.index1 + "_" + cn.index2;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ("<init>".equals(name)) {
|
if (CodeConstants.INIT_NAME.equals(name)) {
|
||||||
functype = TYP_INIT;
|
functype = TYP_INIT;
|
||||||
}
|
}
|
||||||
else if ("<clinit>".equals(name)) {
|
else if (CodeConstants.CLINIT_NAME.equals(name)) {
|
||||||
functype = TYP_CLINIT;
|
functype = TYP_CLINIT;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -307,7 +307,7 @@ public class InvocationExprent extends Exprent {
|
|||||||
|
|
||||||
break;
|
break;
|
||||||
case TYP_CLINIT:
|
case TYP_CLINIT:
|
||||||
throw new RuntimeException("Explicit invocation of <clinit>");
|
throw new RuntimeException("Explicit invocation of " + CodeConstants.CLINIT_NAME);
|
||||||
case TYP_INIT:
|
case TYP_INIT:
|
||||||
if (super_qualifier != null) {
|
if (super_qualifier != null) {
|
||||||
buf.append("super(");
|
buf.append("super(");
|
||||||
@@ -316,7 +316,7 @@ public class InvocationExprent extends Exprent {
|
|||||||
buf.append("this(");
|
buf.append("this(");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
throw new RuntimeException("Unrecognized invocation of <init>");
|
throw new RuntimeException("Unrecognized invocation of " + CodeConstants.INIT_NAME);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -327,7 +327,7 @@ public class InvocationExprent extends Exprent {
|
|||||||
|
|
||||||
if (newNode != null) { // own class
|
if (newNode != null) { // own class
|
||||||
if (newNode.getWrapper() != null) {
|
if (newNode.getWrapper() != null) {
|
||||||
sigFields = newNode.getWrapper().getMethodWrapper("<init>", stringDescriptor).signatureFields;
|
sigFields = newNode.getWrapper().getMethodWrapper(CodeConstants.INIT_NAME, stringDescriptor).signatureFields;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (newNode.type == ClassNode.CLASS_MEMBER && (newNode.access & CodeConstants.ACC_STATIC) == 0) { // non-static member class
|
if (newNode.type == ClassNode.CLASS_MEMBER && (newNode.access & CodeConstants.ACC_STATIC) == 0) { // non-static member class
|
||||||
|
|||||||
@@ -177,7 +177,7 @@ public class NewExprent extends Exprent {
|
|||||||
List<VarVersionPair> sigFields = null;
|
List<VarVersionPair> sigFields = null;
|
||||||
if (newnode != null) { // own class
|
if (newnode != null) { // own class
|
||||||
if (newnode.getWrapper() != null) {
|
if (newnode.getWrapper() != null) {
|
||||||
sigFields = newnode.getWrapper().getMethodWrapper("<init>", invsuper.getStringDescriptor()).signatureFields;
|
sigFields = newnode.getWrapper().getMethodWrapper(CodeConstants.INIT_NAME, invsuper.getStringDescriptor()).signatureFields;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (newnode.type == ClassNode.CLASS_MEMBER && (newnode.access & CodeConstants.ACC_STATIC) == 0 &&
|
if (newnode.type == ClassNode.CLASS_MEMBER && (newnode.access & CodeConstants.ACC_STATIC) == 0 &&
|
||||||
@@ -287,7 +287,7 @@ public class NewExprent extends Exprent {
|
|||||||
List<VarVersionPair> sigFields = null;
|
List<VarVersionPair> sigFields = null;
|
||||||
if (newnode != null) { // own class
|
if (newnode != null) { // own class
|
||||||
if (newnode.getWrapper() != null) {
|
if (newnode.getWrapper() != null) {
|
||||||
sigFields = newnode.getWrapper().getMethodWrapper("<init>", constructor.getStringDescriptor()).signatureFields;
|
sigFields = newnode.getWrapper().getMethodWrapper(CodeConstants.INIT_NAME, constructor.getStringDescriptor()).signatureFields;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (newnode.type == ClassNode.CLASS_MEMBER && (newnode.access & CodeConstants.ACC_STATIC) == 0 &&
|
if (newnode.type == ClassNode.CLASS_MEMBER && (newnode.access & CodeConstants.ACC_STATIC) == 0 &&
|
||||||
|
|||||||
Reference in New Issue
Block a user