java-decompiler: post-import cleanup (code style issues)

This commit is contained in:
Roman Shevchenko
2014-08-29 14:31:45 +04:00
parent 076e4393f2
commit 84ea54eb1e
72 changed files with 567 additions and 600 deletions

View File

@@ -70,7 +70,7 @@ public class DeadCodeHelper {
cont = false;
for (int i = blocks.size() - 1; i >= 0; i--) {
BasicBlock block = (BasicBlock)blocks.get(i);
BasicBlock block = blocks.get(i);
if (removeEmptyBlock(graph, block, false)) {
cont = true;
@@ -197,7 +197,7 @@ public class DeadCodeHelper {
graph.removeBlock(block);
if (deletedRanges) {
DeadCodeHelper.removeDeadBlocks(graph);
removeDeadBlocks(graph);
}
}
}
@@ -219,7 +219,7 @@ public class DeadCodeHelper {
while (!lstNodes.isEmpty()) {
BasicBlock node = (BasicBlock)lstNodes.remove(0);
BasicBlock node = lstNodes.remove(0);
if (marked.contains(node)) {
continue;
}
@@ -232,14 +232,14 @@ public class DeadCodeHelper {
}
for (int i = 0; i < node.getPreds().size(); i++) {
BasicBlock pred = (BasicBlock)node.getPreds().get(i);
BasicBlock pred = node.getPreds().get(i);
if (!marked.contains(pred) && pred != dom) {
lstNodes.add(pred);
}
}
for (int i = 0; i < node.getPredExceptions().size(); i++) {
BasicBlock pred = (BasicBlock)node.getPredExceptions().get(i);
BasicBlock pred = node.getPredExceptions().get(i);
if (!marked.contains(pred) && pred != dom) {
lstNodes.add(pred);
}
@@ -259,7 +259,7 @@ public class DeadCodeHelper {
}
}
DeadCodeHelper.removeEmptyBlocks(graph);
removeEmptyBlocks(graph);
}
public static void connectDummyExitBlock(ControlFlowGraph graph) {
@@ -392,7 +392,7 @@ public class DeadCodeHelper {
public static void mergeBasicBlocks(ControlFlowGraph graph) {
for (; ; ) {
while (true) {
boolean merged = false;

View File

@@ -62,7 +62,7 @@ public class ConcatenationHelper {
// iterate in depth, collecting possible operands
List<Exprent> lstOperands = new ArrayList<Exprent>();
for (; ; ) {
while (true) {
int found = 0;

View File

@@ -76,7 +76,7 @@ public class DecHelper {
return false;
}
for (; ; ) {
while (true) {
lst.clear();

View File

@@ -254,7 +254,7 @@ public class DomHelper {
if (stat.type == Statement.TYPE_SEQUENCE) {
for (; ; ) {
while (true) {
boolean found = false;
@@ -371,7 +371,7 @@ public class DomHelper {
boolean forceall = i != 0;
for (; ; ) {
while (true) {
if (findSimpleStatements(general, mapExtPost)) {
reducibility = 0;
@@ -494,7 +494,7 @@ public class DomHelper {
// collect statement nodes
HashSet<Statement> setHandlers = new HashSet<Statement>();
setHandlers.add(head);
for (; ; ) {
while (true) {
boolean hdfound = false;
Iterator<Statement> itHandlers = setHandlers.iterator();

View File

@@ -91,7 +91,7 @@ public class ExitHelper {
if (stat.getExprents() == null) {
for (; ; ) {
while (true) {
int changed = 0;
@@ -160,7 +160,7 @@ public class ExitHelper {
bstat.addSuccessor(newexitedge);
oldexitedge.closure.addLabeledEdge(newexitedge);
SequenceStatement block = new SequenceStatement(Arrays.asList(new Statement[]{stat, bstat}));
SequenceStatement block = new SequenceStatement(Arrays.asList(stat, bstat));
block.setAllParent();
parent.replaceStatement(stat, block);
@@ -324,7 +324,7 @@ public class ExitHelper {
bstat.setExprents(new ArrayList<Exprent>(Arrays.asList(new Exprent[]{retexpr})));
// build sequence to replace the former top statement
SequenceStatement seq = new SequenceStatement(Arrays.asList(new Statement[]{top, bstat}));
SequenceStatement seq = new SequenceStatement(Arrays.asList(top, bstat));
top.setParent(seq);
bstat.setParent(seq);
seq.setParent(root);

View File

@@ -706,7 +706,7 @@ public class ExprProcessor implements CodeConstants {
return "void";
}
else if (tp == CodeConstants.TYPE_OBJECT) {
String ret = ExprProcessor.buildJavaClassName(type.value);
String ret = buildJavaClassName(type.value);
if (getShort) {
ret = DecompilerContext.getImpcollector().getShortName(ret);
}
@@ -761,7 +761,7 @@ public class ExprProcessor implements CodeConstants {
List<StatEdge> lstSuccs = stat.getSuccessorEdges(Statement.STATEDGE_DIRECT_ALL);
if (lstSuccs.size() == 1) {
StatEdge edge = lstSuccs.get(0);
if (edge.getType() != StatEdge.TYPE_REGULAR && edge.explicit == true && edge.getDestination().type != Statement.TYPE_DUMMYEXIT) {
if (edge.getType() != StatEdge.TYPE_REGULAR && edge.explicit && edge.getDestination().type != Statement.TYPE_DUMMYEXIT) {
buf.append(InterpreterUtil.getIndentString(indent));
switch (edge.getType()) {
@@ -820,7 +820,7 @@ public class ExprProcessor implements CodeConstants {
if (expr.type == Exprent.EXPRENT_MONITOR && ((MonitorExprent)expr).getMontype() == MonitorExprent.MONITOR_ENTER) {
buf.append("{}"); // empty synchronized block
}
if (ExprProcessor.endsWithSemikolon(expr)) {
if (endsWithSemikolon(expr)) {
buf.append(";");
}
buf.append(new_line_separator);
@@ -885,7 +885,7 @@ public class ExprProcessor implements CodeConstants {
res = "(" + res + ")";
}
res = "(" + ExprProcessor.getCastTypeName(leftType) + ")" + res;
res = "(" + getCastTypeName(leftType) + ")" + res;
ret = true;
}

View File

@@ -36,9 +36,7 @@ public class ExprentStack extends ListStack<Exprent> {
public Exprent pop() {
Exprent o = this.remove(--pointer);
return o;
return this.remove(--pointer);
}
public ExprentStack clone() {

View File

@@ -81,7 +81,7 @@ public class FinallyProcessor {
BasicBlock handler = fin.getHandler().getBasichead().getBlock();
if (catchallBlockIDs.containsKey(handler.id)) {
; // do nothing
// do nothing
}
else if (finallyBlockIDs.containsKey(handler.id)) {
@@ -465,8 +465,6 @@ public class FinallyProcessor {
range.getProtectedRange().remove(newheadinit);
}
}
return;
}
@@ -677,7 +675,7 @@ public class FinallyProcessor {
// exception successors
if (isLastBlock && blockSample.getSeq().isEmpty()) {
; // do nothing, blockSample will be removed anyway
// do nothing, blockSample will be removed anyway
}
else {
if (blockCatch.getSuccExceptions().size() == blockSample.getSuccExceptions().size()) {

View File

@@ -78,7 +78,7 @@ public class IdeaNotNullHelper {
Exprent second_param = func.getLstOperands().get(1);
if (second_param.type == Exprent.EXPRENT_CONST &&
((ConstExprent)second_param).getExprType().type == CodeConstants.TYPE_NULL) { // TODO: reversed parameter order
second_param.getExprType().type == CodeConstants.TYPE_NULL) { // TODO: reversed parameter order
if (first_param.type == Exprent.EXPRENT_VAR) {
VarExprent var = (VarExprent)first_param;
@@ -227,7 +227,7 @@ public class IdeaNotNullHelper {
Statement elsebranch = ifparent.getElsestat();
if (second_param.type == Exprent.EXPRENT_CONST &&
((ConstExprent)second_param).getExprType().type == CodeConstants.TYPE_NULL) { // TODO: reversed parameter order
second_param.getExprType().type == CodeConstants.TYPE_NULL) { // TODO: reversed parameter order
//if(first_param.type == Exprent.EXPRENT_VAR && ((VarExprent)first_param).getIndex() == var_value.getIndex()) {
if (first_param.equals(exprent_value)) { // TODO: check for absence of side effects like method invocations etc.
if (ifbranch.type == Statement.TYPE_BASICBLOCK &&
@@ -291,7 +291,7 @@ public class IdeaNotNullHelper {
Statement ifbranch = ifstat.getIfstat();
if (second_param.type == Exprent.EXPRENT_CONST &&
((ConstExprent)second_param).getExprType().type == CodeConstants.TYPE_NULL) { // TODO: reversed parameter order
second_param.getExprType().type == CodeConstants.TYPE_NULL) { // TODO: reversed parameter order
if (first_param.equals(exprent_value)) { // TODO: check for absence of side effects like method invocations etc.
if (ifbranch.type == Statement.TYPE_BASICBLOCK &&
ifbranch.getExprents().size() == 1 &&

View File

@@ -50,7 +50,7 @@ public class IfHelper {
if (stat.getExprents() == null) {
for (; ; ) {
while (true) {
boolean changed = false;
@@ -59,7 +59,7 @@ public class IfHelper {
res |= mergeAllIfsRec(st, setReorderedIfs);
// collapse composed if's
if (changed = IfHelper.mergeIfs(st, setReorderedIfs)) {
if (changed = mergeIfs(st, setReorderedIfs)) {
break;
}
}
@@ -84,7 +84,7 @@ public class IfHelper {
boolean res = false;
for (; ; ) {
while (true) {
boolean updated = false;
@@ -442,7 +442,6 @@ public class IfHelper {
}
boolean ifdirect = false, elsedirect = false;
;
boolean noifstat = false, noelsestat = false;
boolean ifdirectpath = false, elsedirectpath = false;
@@ -471,7 +470,7 @@ public class IfHelper {
}
}
Statement last = parent.type == Statement.TYPE_SEQUENCE ? ((SequenceStatement)parent).getStats().getLast() : ifstat;
Statement last = parent.type == Statement.TYPE_SEQUENCE ? parent.getStats().getLast() : ifstat;
noelsestat = (last == ifstat);
if (!last.getAllSuccessorEdges().isEmpty() && last.getAllSuccessorEdges().get(0).getType() == StatEdge.TYPE_FINALLYEXIT) {
@@ -575,7 +574,7 @@ public class IfHelper {
}
else {
Statement ifbranch = ifstat.getIfstat();
SequenceStatement newseq = new SequenceStatement(Arrays.asList(new Statement[]{ifstat, ifbranch}));
SequenceStatement newseq = new SequenceStatement(Arrays.asList(ifstat, ifbranch));
ifstat.getFirst().removeSuccessor(ifedge);
ifstat.getStats().removeWithKey(ifbranch.id);

View File

@@ -155,7 +155,7 @@ public class InlineSingleBlockHelper {
Statement from = edge.getSource();
Statement to = edge.getDestination();
for (; ; ) {
while (true) {
Statement parent = from.getParent();
if (parent.containsStatementStrict(to)) {

View File

@@ -65,7 +65,7 @@ public class LabelHelper {
List<Statement> lst = new ArrayList<Statement>();
if (parent.type == Statement.TYPE_SEQUENCE) {
lst.addAll(((SequenceStatement)parent).getStats());
lst.addAll(parent.getStats());
}
else if (parent.type == Statement.TYPE_SWITCH) {
lst.addAll(((SwitchStatement)parent).getCaseStatements());
@@ -489,7 +489,7 @@ public class LabelHelper {
private static Statement getMinContinueClosure(StatEdge edge) {
Statement closure = edge.closure;
for (; ; ) {
while (true) {
boolean found = false;

View File

@@ -44,7 +44,7 @@ public class LoopExtractHelper {
boolean res = false;
for (; ; ) {
while (true) {
boolean updated = false;
@@ -183,7 +183,7 @@ public class LoopExtractHelper {
loop.addLabeledEdge(ifedge);
SequenceStatement block = new SequenceStatement(Arrays.asList(new Statement[]{loop, target}));
SequenceStatement block = new SequenceStatement(Arrays.asList(loop, target));
loop.getParent().replaceStatement(loop, block);
block.setAllParent();

View File

@@ -32,7 +32,7 @@ public class LowBreakHelper {
private static void lowBreakLabelsRec(Statement stat) {
for (; ; ) {
while (true) {
boolean found = false;
@@ -79,7 +79,7 @@ public class LowBreakHelper {
public static Statement getMinClosure(Statement closure, Statement source) {
for (; ; ) {
while (true) {
Statement newclosure = null;
@@ -152,7 +152,7 @@ public class LowBreakHelper {
}
for (; ; ) {
while (true) {
boolean found = false;

View File

@@ -323,7 +323,7 @@ public class MergeHelper {
// search for an initializing exprent
Statement current = stat;
for (; ; ) {
while (true) {
Statement parent = current.getParent();
if (parent == null) {
break;

View File

@@ -142,7 +142,7 @@ public class SequenceHelper {
// replace flat statements with synthetic basic blocks
outer:
for (; ; ) {
while (true) {
for (Statement st : stat.getStats()) {
if ((st.getStats().isEmpty() || st.getExprents() != null) && st.type != Statement.TYPE_BASICBLOCK) {
destroyAndFlattenStatement(st);
@@ -185,7 +185,7 @@ public class SequenceHelper {
mergeFlatStatements(sequence);
for (; ; ) {
while (true) {
boolean found = false;
@@ -242,7 +242,7 @@ public class SequenceHelper {
private static void mergeFlatStatements(SequenceStatement sequence) {
for (; ; ) {
while (true) {
Statement next = null;
Statement current = null;

View File

@@ -45,7 +45,7 @@ public class SimplifyExprentsHelper {
if (stat.getExprents() == null) {
for (; ; ) {
while (true) {
boolean changed = false;
@@ -402,7 +402,7 @@ public class SimplifyExprentsHelper {
AssignmentExprent asf = (AssignmentExprent)first;
AssignmentExprent ass = (AssignmentExprent)second;
for (; ; ) {
while (true) {
if (asf.getRight().equals(ass.getRight())) {
if ((asf.getLeft().type == Exprent.EXPRENT_VAR && ((VarExprent)asf.getLeft()).isStack()) &&
(ass.getLeft().type != Exprent.EXPRENT_VAR || !((VarExprent)ass.getLeft()).isStack())) {
@@ -789,7 +789,7 @@ public class SimplifyExprentsHelper {
data.add(new AssignmentExprent(ifvar, new FunctionExprent(FunctionExprent.FUNCTION_IIF,
Arrays.asList(new Exprent[]{
((IfExprent)stif.getHeadexprent()).getCondition(),
stif.getHeadexprent().getCondition(),
ifas.getRight(),
elseas.getRight()}))));
stif.setExprents(data);
@@ -830,7 +830,7 @@ public class SimplifyExprentsHelper {
data.add(new ExitExprent(ifex.getExittype(), new FunctionExprent(FunctionExprent.FUNCTION_IIF,
Arrays.asList(new Exprent[]{
((IfExprent)stif.getHeadexprent()).getCondition(),
stif.getHeadexprent().getCondition(),
ifex.getValue(),
elseex.getValue()})), ifex.getRettype()));
stif.setExprents(data);

View File

@@ -43,7 +43,7 @@ public class StackVarsProcessor {
SSAUConstructorSparseEx ssau = null;
for (; ; ) {
while (true) {
boolean found = false;
@@ -287,7 +287,7 @@ public class StackVarsProcessor {
int changed = 0;
for (Exprent expr : exprent.getAllExprents()) {
for (; ; ) {
while (true) {
Object[] arr = iterateChildExprent(expr, exprent, next, mapVarValues, ssau);
Exprent retexpr = (Exprent)arr[0];
changed |= (Boolean)arr[1] ? 1 : 0;
@@ -464,7 +464,7 @@ public class StackVarsProcessor {
boolean changed = false;
for (Exprent expr : exprent.getAllExprents()) {
for (; ; ) {
while (true) {
Object[] arr = iterateChildExprent(expr, parent, next, mapVarValues, ssau);
Exprent retexpr = (Exprent)arr[0];
changed |= (Boolean)arr[1];

View File

@@ -78,7 +78,7 @@ public class DominatorEngine {
// exclude first statement
List<Integer> lstIds = colOrderedIDoms.getLstKeys().subList(1, colOrderedIDoms.getLstKeys().size());
for (; ; ) {
while (true) {
boolean changed = false;

View File

@@ -286,7 +286,7 @@ public class FastExtendedPostdominanceHelper {
private void iterateReachability(IReachabilityAction action, int edgetype) {
for (; ; ) {
while (true) {
boolean iterate = false;
@@ -350,6 +350,6 @@ public class FastExtendedPostdominanceHelper {
private interface IReachabilityAction {
public boolean action(Statement node, HashMap<Integer, FastFixedSet<Integer>> mapSets);
boolean action(Statement node, HashMap<Integer, FastFixedSet<Integer>> mapSets);
}
}

View File

@@ -91,7 +91,7 @@ public class GenericDominatorEngine {
List<IGraphNode> lstNodes = colOrderedIDoms.getLstKeys();
for (; ; ) {
while (true) {
boolean changed = false;

View File

@@ -20,7 +20,7 @@ import java.util.Set;
public interface IGraph {
public List<? extends IGraphNode> getReversePostOrderList();
List<? extends IGraphNode> getReversePostOrderList();
public Set<? extends IGraphNode> getRoots();
Set<? extends IGraphNode> getRoots();
}

View File

@@ -19,5 +19,5 @@ import java.util.List;
public interface IGraphNode {
public List<? extends IGraphNode> getPredecessors();
List<? extends IGraphNode> getPredecessors();
}

View File

@@ -63,7 +63,7 @@ public class IrreducibleCFGDeobfuscator {
}
// transforming and reducing the graph
for (; ; ) {
while (true) {
int ttype = 0;
Node node = null;

View File

@@ -108,7 +108,7 @@ public class Exprent {
lstAllExprents.add(this);
for (Exprent expr : lstAllExprents) {
if (expr.type == Exprent.EXPRENT_VAR) {
if (expr.type == EXPRENT_VAR) {
set.add(new VarVersionPaar((VarExprent)expr));
}
}

View File

@@ -292,10 +292,7 @@ public class FunctionExprent extends Exprent {
else if (functype == FUNCTION_STRCONCAT) {
exprType = VarType.VARTYPE_STRING;
}
else if (functype >= FUNCTION_EQ) {
exprType = VarType.VARTYPE_BOOLEAN;
}
else if (functype == FUNCTION_INSTANCEOF) {
else if (functype >= FUNCTION_EQ || functype == FUNCTION_INSTANCEOF) {
exprType = VarType.VARTYPE_BOOLEAN;
}
else if (functype >= FUNCTION_ARRAYLENGTH) {

View File

@@ -43,7 +43,6 @@ public class VarExprent extends Exprent {
private VarType vartype;
private boolean definition = false;
;
private VarProcessor processor;
@@ -52,7 +51,6 @@ public class VarExprent extends Exprent {
private boolean classdef = false;
private boolean stack = false;
;
{
this.type = EXPRENT_VAR;

View File

@@ -131,6 +131,6 @@ public class DirectGraph {
// 0 - success, do nothing
// 1 - cancel iteration
// 2 - success, delete exprent
public int processExprent(Exprent exprent);
int processExprent(Exprent exprent);
}
}

View File

@@ -321,7 +321,7 @@ public class FlattenStatementsHelper {
boolean isFinallyExit = false;
for (; ; ) {
while (true) {
StackEntry entry = null;
if (!stack.isEmpty()) {

View File

@@ -791,7 +791,7 @@ public class SSAUConstructorSparseEx {
private Integer getFirstProtectedRange(Statement stat) {
for (; ; ) {
while (true) {
Statement parent = stat.getParent();
if (parent == null) {

View File

@@ -49,8 +49,6 @@ public class CatchAllStatement extends Statement {
type = Statement.TYPE_CATCHALL;
}
;
private CatchAllStatement(Statement head, Statement handler) {
this();
@@ -102,7 +100,7 @@ public class CatchAllStatement extends Statement {
return null;
}
if (DecHelper.checkStatementExceptions(Arrays.asList(new Statement[]{head, exc}))) {
if (DecHelper.checkStatementExceptions(Arrays.asList(head, exc))) {
return new CatchAllStatement(head, exc);
}
}

View File

@@ -51,7 +51,7 @@ public class SequenceStatement extends Statement {
private SequenceStatement(Statement head, Statement tail) {
this(Arrays.asList(new Statement[]{head, tail}));
this(Arrays.asList(head, tail));
List<StatEdge> lstSuccs = tail.getSuccessorEdges(STATEDGE_DIRECT_ALL);
if (!lstSuccs.isEmpty()) {
@@ -88,7 +88,7 @@ public class SequenceStatement extends Statement {
&& !stat.isMonitorEnter()) {
if (stat.getLastBasicType() == Statement.LASTBASICTYPE_GENERAL) {
if (DecHelper.checkStatementExceptions(Arrays.asList(new Statement[]{head, stat}))) {
if (DecHelper.checkStatementExceptions(Arrays.asList(head, stat))) {
return new SequenceStatement(head, stat);
}
}

View File

@@ -124,7 +124,6 @@ public class Statement {
// FIXME: used in FlattenStatementsHelper.flattenStatement()! check and remove
//lastBasicType = LASTBASICTYPE_GENERAL;
isMonitorEnter = false;
;
containsMonitorExit = false;
for (Map<Integer, List<StatEdge>> map : new Map[]{mapSuccEdges, mapPredEdges}) {
@@ -234,7 +233,7 @@ public class Statement {
// monitorenter and monitorexit
stat.buildMonitorFlags();
if (stat.type == Statement.TYPE_SWITCH) {
if (stat.type == TYPE_SWITCH) {
// special case switch, sorting leaf nodes
((SwitchStatement)stat).sortEdgesAndNodes();
}
@@ -390,7 +389,7 @@ public class Statement {
continueSet.add(edge.getDestination().getBasichead());
}
if (type == Statement.TYPE_DO) {
if (type == TYPE_DO) {
continueSet.remove(first.getBasichead());
}
@@ -513,11 +512,11 @@ public class Statement {
}
public void initExprents() {
; // do nothing
// do nothing
}
public void replaceExprent(Exprent oldexpr, Exprent newexpr) {
; // do nothing
// do nothing
}
public Statement getSimpleCopy() {
@@ -804,7 +803,7 @@ public class Statement {
}
public BasicBlockStatement getBasichead() {
if (type == Statement.TYPE_BASICBLOCK) {
if (type == TYPE_BASICBLOCK) {
return (BasicBlockStatement)this;
}
else {
@@ -823,13 +822,12 @@ public class Statement {
}
public boolean hasBasicSuccEdge() {
boolean res = type == Statement.TYPE_BASICBLOCK || (type == Statement.TYPE_IF &&
((IfStatement)this).iftype == IfStatement.IFTYPE_IF) ||
(type == Statement.TYPE_DO && ((DoStatement)this).getLooptype() != DoStatement.LOOP_DO);
// FIXME: default switch
return res;
return type == TYPE_BASICBLOCK || (type == TYPE_IF &&
((IfStatement)this).iftype == IfStatement.IFTYPE_IF) ||
(type == TYPE_DO && ((DoStatement)this).getLooptype() != DoStatement.LOOP_DO);
}

View File

@@ -148,7 +148,7 @@ public class VarDefinitionHelper {
continue;
}
else {
List<Exprent> lstSpecial = Arrays.asList(new Exprent[]{dstat.getConditionExprent(), dstat.getIncExprent()});
List<Exprent> lstSpecial = Arrays.asList(dstat.getConditionExprent(), dstat.getIncExprent());
for (VarExprent var : getAllVars(lstSpecial)) {
if (var.getIndex() == index.intValue()) {
stat = stat.getParent();

View File

@@ -56,7 +56,7 @@ public class IdentifierConverter {
helper = (IIdentifierRenamer)IdentifierConverter.class.getClassLoader().loadClass(user_class).newInstance();
}
catch (Exception ex) {
; // ignore errors
// ignore errors
}
}