Cleanup (duplicates extracted; formatting; typos)
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2000-2015 JetBrains s.r.o.
|
* Copyright 2000-2016 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.
|
||||||
@@ -20,16 +20,14 @@ 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;
|
||||||
import org.jetbrains.java.decompiler.modules.decompiler.exps.InvocationExprent;
|
import org.jetbrains.java.decompiler.modules.decompiler.exps.InvocationExprent;
|
||||||
import org.jetbrains.java.decompiler.modules.decompiler.exps.VarExprent;
|
|
||||||
import org.jetbrains.java.decompiler.modules.decompiler.stats.Statement;
|
import org.jetbrains.java.decompiler.modules.decompiler.stats.Statement;
|
||||||
import org.jetbrains.java.decompiler.modules.decompiler.vars.VarVersionPair;
|
import org.jetbrains.java.decompiler.modules.decompiler.stats.Statements;
|
||||||
import org.jetbrains.java.decompiler.struct.StructClass;
|
import org.jetbrains.java.decompiler.struct.StructClass;
|
||||||
import org.jetbrains.java.decompiler.struct.StructField;
|
import org.jetbrains.java.decompiler.struct.StructField;
|
||||||
import org.jetbrains.java.decompiler.struct.StructMethod;
|
import org.jetbrains.java.decompiler.struct.StructMethod;
|
||||||
import org.jetbrains.java.decompiler.util.InterpreterUtil;
|
import org.jetbrains.java.decompiler.util.InterpreterUtil;
|
||||||
|
|
||||||
public class EnumProcessor {
|
public class EnumProcessor {
|
||||||
|
|
||||||
public static void clearEnum(ClassWrapper wrapper) {
|
public static void clearEnum(ClassWrapper wrapper) {
|
||||||
StructClass cl = wrapper.getClassStruct();
|
StructClass cl = wrapper.getClassStruct();
|
||||||
|
|
||||||
@@ -50,12 +48,12 @@ public class EnumProcessor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (CodeConstants.INIT_NAME.equals(name)) {
|
else if (CodeConstants.INIT_NAME.equals(name)) {
|
||||||
Statement firstData = findFirstData(method.root);
|
Statement firstData = Statements.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);
|
||||||
if (exprent.type == Exprent.EXPRENT_INVOCATION) {
|
if (exprent.type == Exprent.EXPRENT_INVOCATION) {
|
||||||
InvocationExprent invexpr = (InvocationExprent)exprent;
|
InvocationExprent invExpr = (InvocationExprent)exprent;
|
||||||
if (isInvocationSuperConstructor(invexpr, method, wrapper)) {
|
if (Statements.isInvocationInitConstructor(invExpr, method, wrapper, false)) {
|
||||||
firstData.getExprents().remove(0);
|
firstData.getExprents().remove(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -71,49 +69,4 @@ public class EnumProcessor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// FIXME: move to a util class (see also InitializerProcessor)
|
|
||||||
private static Statement findFirstData(Statement stat) {
|
|
||||||
|
|
||||||
if (stat.getExprents() != null) {
|
|
||||||
return stat;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if (stat.isLabeled()) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (stat.type) {
|
|
||||||
case Statement.TYPE_SEQUENCE:
|
|
||||||
case Statement.TYPE_IF:
|
|
||||||
case Statement.TYPE_ROOT:
|
|
||||||
case Statement.TYPE_SWITCH:
|
|
||||||
case Statement.TYPE_SYNCRONIZED:
|
|
||||||
return findFirstData(stat.getFirst());
|
|
||||||
default:
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// FIXME: move to util class (see also InitializerProcessor)
|
|
||||||
private static boolean isInvocationSuperConstructor(InvocationExprent inv, MethodWrapper meth, ClassWrapper wrapper) {
|
|
||||||
|
|
||||||
if (inv.getFunctype() == InvocationExprent.TYP_INIT) {
|
|
||||||
if (inv.getInstance().type == Exprent.EXPRENT_VAR) {
|
|
||||||
VarExprent instvar = (VarExprent)inv.getInstance();
|
|
||||||
VarVersionPair varpaar = new VarVersionPair(instvar);
|
|
||||||
|
|
||||||
String classname = meth.varproc.getThisVars().get(varpaar);
|
|
||||||
|
|
||||||
if (classname != null) { // any this instance. TODO: Restrict to current class?
|
|
||||||
if (!wrapper.getClassStruct().qualifiedName.equals(inv.getClassname())) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2000-2015 JetBrains s.r.o.
|
* Copyright 2000-2016 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.
|
||||||
@@ -23,6 +23,7 @@ import org.jetbrains.java.decompiler.main.rels.MethodWrapper;
|
|||||||
import org.jetbrains.java.decompiler.modules.decompiler.exps.*;
|
import org.jetbrains.java.decompiler.modules.decompiler.exps.*;
|
||||||
import org.jetbrains.java.decompiler.modules.decompiler.stats.RootStatement;
|
import org.jetbrains.java.decompiler.modules.decompiler.stats.RootStatement;
|
||||||
import org.jetbrains.java.decompiler.modules.decompiler.stats.Statement;
|
import org.jetbrains.java.decompiler.modules.decompiler.stats.Statement;
|
||||||
|
import org.jetbrains.java.decompiler.modules.decompiler.stats.Statements;
|
||||||
import org.jetbrains.java.decompiler.modules.decompiler.vars.VarVersionPair;
|
import org.jetbrains.java.decompiler.modules.decompiler.vars.VarVersionPair;
|
||||||
import org.jetbrains.java.decompiler.struct.StructClass;
|
import org.jetbrains.java.decompiler.struct.StructClass;
|
||||||
import org.jetbrains.java.decompiler.struct.StructField;
|
import org.jetbrains.java.decompiler.struct.StructField;
|
||||||
@@ -31,14 +32,11 @@ import org.jetbrains.java.decompiler.util.InterpreterUtil;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
public class InitializerProcessor {
|
public class InitializerProcessor {
|
||||||
|
|
||||||
public static void extractInitializers(ClassWrapper wrapper) {
|
public static void extractInitializers(ClassWrapper wrapper) {
|
||||||
|
MethodWrapper method = wrapper.getMethodWrapper(CodeConstants.CLINIT_NAME, "()V");
|
||||||
MethodWrapper meth = wrapper.getMethodWrapper(CodeConstants.CLINIT_NAME, "()V");
|
if (method != null && method.root != null) { // successfully decompiled static constructor
|
||||||
if (meth != null && meth.root != null) { // successfully decompiled static constructor
|
extractStaticInitializers(wrapper, method);
|
||||||
extractStaticInitializers(wrapper, meth);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
extractDynamicInitializers(wrapper);
|
extractDynamicInitializers(wrapper);
|
||||||
@@ -52,30 +50,26 @@ public class InitializerProcessor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static void liftConstructor(ClassWrapper wrapper) {
|
private static void liftConstructor(ClassWrapper wrapper) {
|
||||||
|
for (MethodWrapper method : wrapper.getMethods()) {
|
||||||
for (MethodWrapper meth : wrapper.getMethods()) {
|
if (CodeConstants.INIT_NAME.equals(method.methodStruct.getName()) && method.root != null) {
|
||||||
if (CodeConstants.INIT_NAME.equals(meth.methodStruct.getName()) && meth.root != null) {
|
Statement firstData = Statements.findFirstData(method.root);
|
||||||
Statement firstdata = findFirstData(meth.root);
|
if (firstData == null) {
|
||||||
if (firstdata == null) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int index = 0;
|
int index = 0;
|
||||||
List<Exprent> lstExprents = firstdata.getExprents();
|
List<Exprent> lstExprents = firstData.getExprents();
|
||||||
|
|
||||||
for (Exprent exprent : lstExprents) {
|
for (Exprent exprent : lstExprents) {
|
||||||
|
|
||||||
int action = 0;
|
int action = 0;
|
||||||
|
|
||||||
if (exprent.type == Exprent.EXPRENT_ASSIGNMENT) {
|
if (exprent.type == Exprent.EXPRENT_ASSIGNMENT) {
|
||||||
AssignmentExprent asexpr = (AssignmentExprent)exprent;
|
AssignmentExprent assignExpr = (AssignmentExprent)exprent;
|
||||||
if (asexpr.getLeft().type == Exprent.EXPRENT_FIELD && asexpr.getRight().type == Exprent.EXPRENT_VAR) {
|
if (assignExpr.getLeft().type == Exprent.EXPRENT_FIELD && assignExpr.getRight().type == Exprent.EXPRENT_VAR) {
|
||||||
FieldExprent fexpr = (FieldExprent)asexpr.getLeft();
|
FieldExprent fExpr = (FieldExprent)assignExpr.getLeft();
|
||||||
if (fexpr.getClassname().equals(wrapper.getClassStruct().qualifiedName)) {
|
if (fExpr.getClassname().equals(wrapper.getClassStruct().qualifiedName)) {
|
||||||
StructField structField = wrapper.getClassStruct().getField(fexpr.getName(), fexpr.getDescriptor().descriptorString);
|
StructField structField = wrapper.getClassStruct().getField(fExpr.getName(), fExpr.getDescriptor().descriptorString);
|
||||||
if (structField != null && structField.hasModifier(CodeConstants.ACC_FINAL)) {
|
if (structField != null && structField.hasModifier(CodeConstants.ACC_FINAL)) {
|
||||||
action = 1;
|
action = 1;
|
||||||
}
|
}
|
||||||
@@ -83,7 +77,7 @@ public class InitializerProcessor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (index > 0 && exprent.type == Exprent.EXPRENT_INVOCATION &&
|
else if (index > 0 && exprent.type == Exprent.EXPRENT_INVOCATION &&
|
||||||
isInvocationInitConstructor((InvocationExprent)exprent, meth, wrapper, true)) {
|
Statements.isInvocationInitConstructor((InvocationExprent)exprent, method, wrapper, true)) {
|
||||||
// this() or super()
|
// this() or super()
|
||||||
lstExprents.add(0, lstExprents.remove(index));
|
lstExprents.add(0, lstExprents.remove(index));
|
||||||
action = 2;
|
action = 2;
|
||||||
@@ -99,53 +93,50 @@ public class InitializerProcessor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static void hideEmptySuper(ClassWrapper wrapper) {
|
private static void hideEmptySuper(ClassWrapper wrapper) {
|
||||||
|
for (MethodWrapper method : wrapper.getMethods()) {
|
||||||
for (MethodWrapper meth : wrapper.getMethods()) {
|
if (CodeConstants.INIT_NAME.equals(method.methodStruct.getName()) && method.root != null) {
|
||||||
if (CodeConstants.INIT_NAME.equals(meth.methodStruct.getName()) && meth.root != null) {
|
Statement firstData = Statements.findFirstData(method.root);
|
||||||
Statement firstdata = findFirstData(meth.root);
|
if (firstData == null || firstData.getExprents().isEmpty()) {
|
||||||
if (firstdata == null || firstdata.getExprents().isEmpty()) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Exprent exprent = firstdata.getExprents().get(0);
|
Exprent exprent = firstData.getExprents().get(0);
|
||||||
if (exprent.type == Exprent.EXPRENT_INVOCATION) {
|
if (exprent.type == Exprent.EXPRENT_INVOCATION) {
|
||||||
InvocationExprent invexpr = (InvocationExprent)exprent;
|
InvocationExprent invExpr = (InvocationExprent)exprent;
|
||||||
if (isInvocationInitConstructor(invexpr, meth, wrapper, false) && invexpr.getLstParameters().isEmpty()) {
|
if (Statements.isInvocationInitConstructor(invExpr, method, wrapper, false) && invExpr.getLstParameters().isEmpty()) {
|
||||||
firstdata.getExprents().remove(0);
|
firstData.getExprents().remove(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void extractStaticInitializers(ClassWrapper wrapper, MethodWrapper meth) {
|
private static void extractStaticInitializers(ClassWrapper wrapper, MethodWrapper method) {
|
||||||
|
RootStatement root = method.root;
|
||||||
RootStatement root = meth.root;
|
|
||||||
StructClass cl = wrapper.getClassStruct();
|
StructClass cl = wrapper.getClassStruct();
|
||||||
boolean isInterface = cl.hasModifier(CodeConstants.ACC_INTERFACE);
|
Statement firstData = Statements.findFirstData(root);
|
||||||
Statement firstdata = findFirstData(root);
|
if (firstData != null) {
|
||||||
if (firstdata != null) {
|
boolean isInterface = cl.hasModifier(CodeConstants.ACC_INTERFACE);
|
||||||
while (!firstdata.getExprents().isEmpty()) {
|
while (!firstData.getExprents().isEmpty()) {
|
||||||
Exprent exprent = firstdata.getExprents().get(0);
|
Exprent exprent = firstData.getExprents().get(0);
|
||||||
|
|
||||||
boolean found = false;
|
boolean found = false;
|
||||||
|
|
||||||
if (exprent.type == Exprent.EXPRENT_ASSIGNMENT) {
|
if (exprent.type == Exprent.EXPRENT_ASSIGNMENT) {
|
||||||
AssignmentExprent asexpr = (AssignmentExprent)exprent;
|
AssignmentExprent assignExpr = (AssignmentExprent)exprent;
|
||||||
if (asexpr.getLeft().type == Exprent.EXPRENT_FIELD) {
|
if (assignExpr.getLeft().type == Exprent.EXPRENT_FIELD) {
|
||||||
FieldExprent fexpr = (FieldExprent)asexpr.getLeft();
|
FieldExprent fExpr = (FieldExprent)assignExpr.getLeft();
|
||||||
if (fexpr.isStatic() && fexpr.getClassname().equals(cl.qualifiedName) &&
|
if (fExpr.isStatic() && fExpr.getClassname().equals(cl.qualifiedName) &&
|
||||||
cl.hasField(fexpr.getName(), fexpr.getDescriptor().descriptorString)) {
|
cl.hasField(fExpr.getName(), fExpr.getDescriptor().descriptorString)) {
|
||||||
|
|
||||||
// interfaces fields should always be initialized inline
|
// interfaces fields should always be initialized inline
|
||||||
if (isInterface || isExprentIndependent(asexpr.getRight(), meth)) {
|
if (isInterface || isExprentIndependent(assignExpr.getRight(), method)) {
|
||||||
|
|
||||||
String keyField = InterpreterUtil.makeUniqueKey(fexpr.getName(), fexpr.getDescriptor().descriptorString);
|
String keyField = InterpreterUtil.makeUniqueKey(fExpr.getName(), fExpr.getDescriptor().descriptorString);
|
||||||
if (!wrapper.getStaticFieldInitializers().containsKey(keyField)) {
|
if (!wrapper.getStaticFieldInitializers().containsKey(keyField)) {
|
||||||
wrapper.getStaticFieldInitializers().addWithKey(asexpr.getRight(), keyField);
|
wrapper.getStaticFieldInitializers().addWithKey(assignExpr.getRight(), keyField);
|
||||||
firstdata.getExprents().remove(0);
|
firstData.getExprents().remove(0);
|
||||||
found = true;
|
found = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -161,27 +152,26 @@ public class InitializerProcessor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static void extractDynamicInitializers(ClassWrapper wrapper) {
|
private static void extractDynamicInitializers(ClassWrapper wrapper) {
|
||||||
|
|
||||||
StructClass cl = wrapper.getClassStruct();
|
StructClass cl = wrapper.getClassStruct();
|
||||||
|
|
||||||
boolean isAnonymous = DecompilerContext.getClassProcessor().getMapRootClasses().get(cl.qualifiedName).type == ClassNode.CLASS_ANONYMOUS;
|
boolean isAnonymous = DecompilerContext.getClassProcessor().getMapRootClasses().get(cl.qualifiedName).type == ClassNode.CLASS_ANONYMOUS;
|
||||||
|
|
||||||
List<List<Exprent>> lstFirst = new ArrayList<List<Exprent>>();
|
List<List<Exprent>> lstFirst = new ArrayList<List<Exprent>>();
|
||||||
List<MethodWrapper> lstMethWrappers = new ArrayList<MethodWrapper>();
|
List<MethodWrapper> lstMethodWrappers = new ArrayList<MethodWrapper>();
|
||||||
|
|
||||||
for (MethodWrapper meth : wrapper.getMethods()) {
|
for (MethodWrapper method : wrapper.getMethods()) {
|
||||||
if (CodeConstants.INIT_NAME.equals(meth.methodStruct.getName()) && meth.root != null) { // successfully decompiled constructor
|
if (CodeConstants.INIT_NAME.equals(method.methodStruct.getName()) && method.root != null) { // successfully decompiled constructor
|
||||||
Statement firstdata = findFirstData(meth.root);
|
Statement firstData = Statements.findFirstData(method.root);
|
||||||
if (firstdata == null || firstdata.getExprents().isEmpty()) {
|
if (firstData == null || firstData.getExprents().isEmpty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
lstFirst.add(firstdata.getExprents());
|
lstFirst.add(firstData.getExprents());
|
||||||
lstMethWrappers.add(meth);
|
lstMethodWrappers.add(method);
|
||||||
|
|
||||||
Exprent exprent = firstdata.getExprents().get(0);
|
Exprent exprent = firstData.getExprents().get(0);
|
||||||
if (!isAnonymous) { // FIXME: doesn't make sense
|
if (!isAnonymous) { // FIXME: doesn't make sense
|
||||||
if (exprent.type != Exprent.EXPRENT_INVOCATION ||
|
if (exprent.type != Exprent.EXPRENT_INVOCATION ||
|
||||||
!isInvocationInitConstructor((InvocationExprent)exprent, meth, wrapper, false)) {
|
!Statements.isInvocationInitConstructor((InvocationExprent)exprent, method, wrapper, false)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -193,12 +183,10 @@ public class InitializerProcessor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
|
|
||||||
String fieldWithDescr = null;
|
String fieldWithDescr = null;
|
||||||
Exprent value = null;
|
Exprent value = null;
|
||||||
|
|
||||||
for (int i = 0; i < lstFirst.size(); i++) {
|
for (int i = 0; i < lstFirst.size(); i++) {
|
||||||
|
|
||||||
List<Exprent> lst = lstFirst.get(i);
|
List<Exprent> lst = lstFirst.get(i);
|
||||||
|
|
||||||
if (lst.size() < (isAnonymous ? 1 : 2)) {
|
if (lst.size() < (isAnonymous ? 1 : 2)) {
|
||||||
@@ -210,22 +198,21 @@ public class InitializerProcessor {
|
|||||||
boolean found = false;
|
boolean found = false;
|
||||||
|
|
||||||
if (exprent.type == Exprent.EXPRENT_ASSIGNMENT) {
|
if (exprent.type == Exprent.EXPRENT_ASSIGNMENT) {
|
||||||
AssignmentExprent asexpr = (AssignmentExprent)exprent;
|
AssignmentExprent assignExpr = (AssignmentExprent)exprent;
|
||||||
if (asexpr.getLeft().type == Exprent.EXPRENT_FIELD) {
|
if (assignExpr.getLeft().type == Exprent.EXPRENT_FIELD) {
|
||||||
FieldExprent fexpr = (FieldExprent)asexpr.getLeft();
|
FieldExprent fExpr = (FieldExprent)assignExpr.getLeft();
|
||||||
if (!fexpr.isStatic() && fexpr.getClassname().equals(cl.qualifiedName) &&
|
if (!fExpr.isStatic() && fExpr.getClassname().equals(cl.qualifiedName) &&
|
||||||
cl.hasField(fexpr.getName(), fexpr
|
cl.hasField(fExpr.getName(), fExpr.getDescriptor().descriptorString)) { // check for the physical existence of the field. Could be defined in a superclass.
|
||||||
.getDescriptor().descriptorString)) { // check for the physical existence of the field. Could be defined in a superclass.
|
|
||||||
|
|
||||||
if (isExprentIndependent(asexpr.getRight(), lstMethWrappers.get(i))) {
|
if (isExprentIndependent(assignExpr.getRight(), lstMethodWrappers.get(i))) {
|
||||||
String fieldKey = InterpreterUtil.makeUniqueKey(fexpr.getName(), fexpr.getDescriptor().descriptorString);
|
String fieldKey = InterpreterUtil.makeUniqueKey(fExpr.getName(), fExpr.getDescriptor().descriptorString);
|
||||||
if (fieldWithDescr == null) {
|
if (fieldWithDescr == null) {
|
||||||
fieldWithDescr = fieldKey;
|
fieldWithDescr = fieldKey;
|
||||||
value = asexpr.getRight();
|
value = assignExpr.getRight();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (!fieldWithDescr.equals(fieldKey) ||
|
if (!fieldWithDescr.equals(fieldKey) ||
|
||||||
!value.equals(asexpr.getRight())) {
|
!value.equals(assignExpr.getRight())) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -253,19 +240,17 @@ public class InitializerProcessor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isExprentIndependent(Exprent exprent, MethodWrapper meth) {
|
private static boolean isExprentIndependent(Exprent exprent, MethodWrapper method) {
|
||||||
|
|
||||||
List<Exprent> lst = exprent.getAllExprents(true);
|
List<Exprent> lst = exprent.getAllExprents(true);
|
||||||
lst.add(exprent);
|
lst.add(exprent);
|
||||||
|
|
||||||
for (Exprent expr : lst) {
|
for (Exprent expr : lst) {
|
||||||
switch (expr.type) {
|
switch (expr.type) {
|
||||||
case Exprent.EXPRENT_VAR:
|
case Exprent.EXPRENT_VAR:
|
||||||
VarVersionPair varpaar = new VarVersionPair((VarExprent)expr);
|
VarVersionPair varPair = new VarVersionPair((VarExprent)expr);
|
||||||
if (!meth.varproc.getExternalVars().contains(varpaar)) {
|
if (!method.varproc.getExternalVars().contains(varPair)) {
|
||||||
String varname = meth.varproc.getVarName(varpaar);
|
String varName = method.varproc.getVarName(varPair);
|
||||||
|
if (!varName.equals("this") && !varName.endsWith(".this")) { // FIXME: remove direct comparison with strings
|
||||||
if (!varname.equals("this") && !varname.endsWith(".this")) { // FIXME: remove direct comparison with strings
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -277,48 +262,4 @@ public class InitializerProcessor {
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static Statement findFirstData(Statement stat) {
|
|
||||||
|
|
||||||
if (stat.getExprents() != null) {
|
|
||||||
return stat;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if (stat.isLabeled()) { // FIXME: Why??
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (stat.type) {
|
|
||||||
case Statement.TYPE_SEQUENCE:
|
|
||||||
case Statement.TYPE_IF:
|
|
||||||
case Statement.TYPE_ROOT:
|
|
||||||
case Statement.TYPE_SWITCH:
|
|
||||||
case Statement.TYPE_SYNCRONIZED:
|
|
||||||
return findFirstData(stat.getFirst());
|
|
||||||
default:
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static boolean isInvocationInitConstructor(InvocationExprent inv, MethodWrapper meth, ClassWrapper wrapper, boolean withThis) {
|
|
||||||
|
|
||||||
if (inv.getFunctype() == InvocationExprent.TYP_INIT) {
|
|
||||||
if (inv.getInstance().type == Exprent.EXPRENT_VAR) {
|
|
||||||
VarExprent instvar = (VarExprent)inv.getInstance();
|
|
||||||
VarVersionPair varpaar = new VarVersionPair(instvar);
|
|
||||||
|
|
||||||
String classname = meth.varproc.getThisVars().get(varpaar);
|
|
||||||
|
|
||||||
if (classname != null) { // any this instance. TODO: Restrict to current class?
|
|
||||||
if (withThis || !wrapper.getClassStruct().qualifiedName.equals(inv.getClassname())) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2000-2016 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.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.jetbrains.java.decompiler.modules.decompiler.stats;
|
||||||
|
|
||||||
|
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;
|
||||||
|
import org.jetbrains.java.decompiler.modules.decompiler.exps.InvocationExprent;
|
||||||
|
import org.jetbrains.java.decompiler.modules.decompiler.exps.VarExprent;
|
||||||
|
import org.jetbrains.java.decompiler.modules.decompiler.vars.VarVersionPair;
|
||||||
|
|
||||||
|
public class Statements {
|
||||||
|
public static Statement findFirstData(Statement stat) {
|
||||||
|
if (stat.getExprents() != null) {
|
||||||
|
return stat;
|
||||||
|
}
|
||||||
|
else if (stat.isLabeled()) { // FIXME: Why??
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (stat.type) {
|
||||||
|
case Statement.TYPE_SEQUENCE:
|
||||||
|
case Statement.TYPE_IF:
|
||||||
|
case Statement.TYPE_ROOT:
|
||||||
|
case Statement.TYPE_SWITCH:
|
||||||
|
case Statement.TYPE_SYNCRONIZED:
|
||||||
|
return findFirstData(stat.getFirst());
|
||||||
|
default:
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isInvocationInitConstructor(InvocationExprent inv, MethodWrapper method, ClassWrapper wrapper, boolean withThis) {
|
||||||
|
if (inv.getFunctype() == InvocationExprent.TYP_INIT && inv.getInstance().type == Exprent.EXPRENT_VAR) {
|
||||||
|
VarExprent instVar = (VarExprent)inv.getInstance();
|
||||||
|
VarVersionPair varPair = new VarVersionPair(instVar);
|
||||||
|
String classname = method.varproc.getThisVars().get(varPair);
|
||||||
|
if (classname != null) { // any this instance. TODO: Restrict to current class?
|
||||||
|
if (withThis || !wrapper.getClassStruct().qualifiedName.equals(inv.getClassname())) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -33,19 +33,14 @@ import static org.jetbrains.java.decompiler.struct.attr.StructGeneralAttribute.A
|
|||||||
* @since March 07, 2016
|
* @since March 07, 2016
|
||||||
*/
|
*/
|
||||||
public final class StructUtils {
|
public final class StructUtils {
|
||||||
|
private StructUtils() { }
|
||||||
private StructUtils() {
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the local variables of the current method
|
* @return the local variables of the current method
|
||||||
*/
|
*/
|
||||||
public static List<String> getCurrentMethodLocalVariableNames() {
|
public static List<String> getCurrentMethodLocalVariableNames() {
|
||||||
final MethodWrapper method = (MethodWrapper) DecompilerContext.getProperty(CURRENT_METHOD_WRAPPER);
|
final MethodWrapper method = (MethodWrapper) DecompilerContext.getProperty(CURRENT_METHOD_WRAPPER);
|
||||||
if (null == method) {
|
return method == null ? Collections.emptyList() : getLocalVariables(method.methodStruct);
|
||||||
return Collections.emptyList();
|
|
||||||
}
|
|
||||||
return getLocalVariables(method.methodStruct);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -56,10 +51,9 @@ public final class StructUtils {
|
|||||||
final VBStyleCollection<StructGeneralAttribute, String> methodStruct = structMember.getAttributes();
|
final VBStyleCollection<StructGeneralAttribute, String> methodStruct = structMember.getAttributes();
|
||||||
final StructGeneralAttribute generalAttribute = methodStruct.getWithKey(ATTRIBUTE_LOCAL_VARIABLE_TABLE);
|
final StructGeneralAttribute generalAttribute = methodStruct.getWithKey(ATTRIBUTE_LOCAL_VARIABLE_TABLE);
|
||||||
if (generalAttribute instanceof StructLocalVariableTableAttribute) {
|
if (generalAttribute instanceof StructLocalVariableTableAttribute) {
|
||||||
final StructLocalVariableTableAttribute table = (StructLocalVariableTableAttribute) generalAttribute;
|
final StructLocalVariableTableAttribute table = (StructLocalVariableTableAttribute)generalAttribute;
|
||||||
return Collections.unmodifiableList(new ArrayList<>(table.getMapVarNames().values()));
|
return Collections.unmodifiableList(new ArrayList<>(table.getMapVarNames().values()));
|
||||||
}
|
}
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user