Cleanup (duplicates extracted; formatting; typos)

This commit is contained in:
Roman Shevchenko
2016-04-11 20:32:26 +02:00
parent 404783c874
commit a57e42690b
4 changed files with 134 additions and 186 deletions

View File

@@ -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");
* 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.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.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.StructField;
import org.jetbrains.java.decompiler.struct.StructMethod;
import org.jetbrains.java.decompiler.util.InterpreterUtil;
public class EnumProcessor {
public static void clearEnum(ClassWrapper wrapper) {
StructClass cl = wrapper.getClassStruct();
@@ -50,12 +48,12 @@ public class EnumProcessor {
}
}
else if (CodeConstants.INIT_NAME.equals(name)) {
Statement firstData = findFirstData(method.root);
Statement firstData = Statements.findFirstData(method.root);
if (firstData != null && !firstData.getExprents().isEmpty()) {
Exprent exprent = firstData.getExprents().get(0);
if (exprent.type == Exprent.EXPRENT_INVOCATION) {
InvocationExprent invexpr = (InvocationExprent)exprent;
if (isInvocationSuperConstructor(invexpr, method, wrapper)) {
InvocationExprent invExpr = (InvocationExprent)exprent;
if (Statements.isInvocationInitConstructor(invExpr, method, wrapper, false)) {
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;
}
}
}