From 768f82b7986daab840c6cbfe77cff4acf3d57091 Mon Sep 17 00:00:00 2001 From: "Egor.Ushakov" Date: Wed, 14 Jan 2015 21:15:17 +0300 Subject: [PATCH] avoid using Arrays.asList for a single element --- .../java/decompiler/code/cfg/ControlFlowGraph.java | 4 ++-- .../java/decompiler/main/AssertProcessor.java | 5 ++--- .../decompiler/modules/decompiler/ExprProcessor.java | 2 +- .../java/decompiler/modules/decompiler/IfHelper.java | 12 +++++------- .../decompiler/modules/decompiler/PPandMMHelper.java | 5 ++--- .../modules/decompiler/SecondaryFunctionsHelper.java | 7 +++---- .../modules/decompiler/SimplifyExprentsHelper.java | 4 ++-- .../modules/decompiler/exps/FunctionExprent.java | 6 +++++- .../modules/decompiler/exps/IfExprent.java | 4 ++-- 9 files changed, 24 insertions(+), 25 deletions(-) diff --git a/src/org/jetbrains/java/decompiler/code/cfg/ControlFlowGraph.java b/src/org/jetbrains/java/decompiler/code/cfg/ControlFlowGraph.java index 1365858..8e66fdd 100644 --- a/src/org/jetbrains/java/decompiler/code/cfg/ControlFlowGraph.java +++ b/src/org/jetbrains/java/decompiler/code/cfg/ControlFlowGraph.java @@ -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. @@ -397,7 +397,7 @@ public class ControlFlowGraph implements CodeConstants { ExceptionRangeCFG range = new ExceptionRangeCFG(protectedRange, handle, handler.exceptionClass == null ? null - : Arrays.asList(handler.exceptionClass)); + : Collections.singletonList(handler.exceptionClass)); mapRanges.put(key, range); exceptions.add(range); diff --git a/src/org/jetbrains/java/decompiler/main/AssertProcessor.java b/src/org/jetbrains/java/decompiler/main/AssertProcessor.java index 5b204d4..abb51ce 100644 --- a/src/org/jetbrains/java/decompiler/main/AssertProcessor.java +++ b/src/org/jetbrains/java/decompiler/main/AssertProcessor.java @@ -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. @@ -173,8 +173,7 @@ public class AssertProcessor { Exprent ascond = null, retcond = null; if (exprres[0] != null) { - ascond = new FunctionExprent(FunctionExprent.FUNCTION_BOOL_NOT, - Arrays.asList((Exprent)exprres[0]), throwError.bytecode); + ascond = new FunctionExprent(FunctionExprent.FUNCTION_BOOL_NOT, (Exprent)exprres[0], throwError.bytecode); retcond = SecondaryFunctionsHelper.propagateBoolNot(ascond); } diff --git a/src/org/jetbrains/java/decompiler/modules/decompiler/ExprProcessor.java b/src/org/jetbrains/java/decompiler/modules/decompiler/ExprProcessor.java index 292d865..efb1e0a 100644 --- a/src/org/jetbrains/java/decompiler/modules/decompiler/ExprProcessor.java +++ b/src/org/jetbrains/java/decompiler/modules/decompiler/ExprProcessor.java @@ -336,7 +336,7 @@ public class ExprProcessor implements CodeConstants { Instruction instr = seq.getInstr(i); Integer bytecode_offset = block.getOldOffset(i); - Set bytecode_offsets = bytecode_offset >= 0 ? new HashSet(Arrays.asList(bytecode_offset)) : null; + Set bytecode_offsets = bytecode_offset >= 0 ? Collections.singleton(bytecode_offset) : null; switch (instr.opcode) { case opc_aconst_null: diff --git a/src/org/jetbrains/java/decompiler/modules/decompiler/IfHelper.java b/src/org/jetbrains/java/decompiler/modules/decompiler/IfHelper.java index 14b72e0..97c4f8d 100644 --- a/src/org/jetbrains/java/decompiler/modules/decompiler/IfHelper.java +++ b/src/org/jetbrains/java/decompiler/modules/decompiler/IfHelper.java @@ -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. @@ -252,8 +252,7 @@ public class IfHelper { List lstOperands = new ArrayList(); lstOperands.add(statexpr.getCondition()); - lstOperands.add(new FunctionExprent(FunctionExprent.FUNCTION_BOOL_NOT, - Arrays.asList(ifchild.getHeadexprent().getCondition()), null)); + lstOperands.add(new FunctionExprent(FunctionExprent.FUNCTION_BOOL_NOT, ifchild.getHeadexprent().getCondition(), null)); statexpr.setCondition(new FunctionExprent(FunctionExprent.FUNCTION_CADD, lstOperands, null)); statexpr.addBytecodeOffsets(ifchild.getHeadexprent().bytecode); @@ -310,8 +309,7 @@ public class IfHelper { lstOperands.add(firstif.getHeadexprent().getCondition()); if (path == 2) { - lstOperands.set(0, new FunctionExprent(FunctionExprent.FUNCTION_BOOL_NOT, - Arrays.asList(lstOperands.get(0)), null)); + lstOperands.set(0, new FunctionExprent(FunctionExprent.FUNCTION_BOOL_NOT, lstOperands.get(0), null)); } lstOperands.add(statexpr.getCondition()); @@ -361,7 +359,7 @@ public class IfHelper { // negate the if condition IfExprent statexpr = firstif.getHeadexprent(); statexpr - .setCondition(new FunctionExprent(FunctionExprent.FUNCTION_BOOL_NOT, Arrays.asList(statexpr.getCondition()), null)); + .setCondition(new FunctionExprent(FunctionExprent.FUNCTION_BOOL_NOT, statexpr.getCondition(), null)); return true; } @@ -556,7 +554,7 @@ public class IfHelper { // negate the if condition IfExprent statexpr = ifstat.getHeadexprent(); - statexpr.setCondition(new FunctionExprent(FunctionExprent.FUNCTION_BOOL_NOT, Arrays.asList(statexpr.getCondition()), null)); + statexpr.setCondition(new FunctionExprent(FunctionExprent.FUNCTION_BOOL_NOT, statexpr.getCondition(), null)); if (noelsestat) { StatEdge ifedge = ifstat.getIfEdge(); diff --git a/src/org/jetbrains/java/decompiler/modules/decompiler/PPandMMHelper.java b/src/org/jetbrains/java/decompiler/modules/decompiler/PPandMMHelper.java index ceed2b8..4eb366b 100644 --- a/src/org/jetbrains/java/decompiler/modules/decompiler/PPandMMHelper.java +++ b/src/org/jetbrains/java/decompiler/modules/decompiler/PPandMMHelper.java @@ -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. @@ -25,7 +25,6 @@ import org.jetbrains.java.decompiler.modules.decompiler.sforms.FlattenStatements import org.jetbrains.java.decompiler.modules.decompiler.stats.RootStatement; import org.jetbrains.java.decompiler.struct.gen.VarType; -import java.util.Arrays; import java.util.HashSet; import java.util.LinkedList; import java.util.List; @@ -138,7 +137,7 @@ public class PPandMMHelper { if (left.equals(econd) && (midlayer == null || midlayer.equals(condtype))) { FunctionExprent ret = new FunctionExprent( func.getFuncType() == FunctionExprent.FUNCTION_ADD ? FunctionExprent.FUNCTION_PPI : FunctionExprent.FUNCTION_MMI, - Arrays.asList(econd), func.bytecode); + econd, func.bytecode); ret.setImplicitType(condtype); exprentReplaced = true; diff --git a/src/org/jetbrains/java/decompiler/modules/decompiler/SecondaryFunctionsHelper.java b/src/org/jetbrains/java/decompiler/modules/decompiler/SecondaryFunctionsHelper.java index 356b7e7..f57457c 100644 --- a/src/org/jetbrains/java/decompiler/modules/decompiler/SecondaryFunctionsHelper.java +++ b/src/org/jetbrains/java/decompiler/modules/decompiler/SecondaryFunctionsHelper.java @@ -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. @@ -286,7 +286,7 @@ public class SecondaryFunctionsHelper { cexpr2.getExprType().type == CodeConstants.TYPE_BOOLEAN) { if (cexpr1.getIntValue() == 0 && cexpr2.getIntValue() != 0) { - return new FunctionExprent(FunctionExprent.FUNCTION_BOOL_NOT, Arrays.asList(lstOperands.get(0)), fexpr.bytecode); + return new FunctionExprent(FunctionExprent.FUNCTION_BOOL_NOT, lstOperands.get(0), fexpr.bytecode); } else if (cexpr1.getIntValue() != 0 && cexpr2.getIntValue() == 0) { return lstOperands.get(0); @@ -407,8 +407,7 @@ public class SecondaryFunctionsHelper { case FunctionExprent.FUNCTION_COR: List operands = fparam.getLstOperands(); for (int i = 0; i < operands.size(); i++) { - Exprent newparam = new FunctionExprent(FunctionExprent.FUNCTION_BOOL_NOT, - Arrays.asList(operands.get(i)), operands.get(i).bytecode); + Exprent newparam = new FunctionExprent(FunctionExprent.FUNCTION_BOOL_NOT, operands.get(i), operands.get(i).bytecode); Exprent retparam = propagateBoolNot(newparam); operands.set(i, retparam == null ? newparam : retparam); diff --git a/src/org/jetbrains/java/decompiler/modules/decompiler/SimplifyExprentsHelper.java b/src/org/jetbrains/java/decompiler/modules/decompiler/SimplifyExprentsHelper.java index f78be6b..dffb657 100644 --- a/src/org/jetbrains/java/decompiler/modules/decompiler/SimplifyExprentsHelper.java +++ b/src/org/jetbrains/java/decompiler/modules/decompiler/SimplifyExprentsHelper.java @@ -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. @@ -448,7 +448,7 @@ public class SimplifyExprentsHelper { if (left.type != Exprent.EXPRENT_VAR && left.equals(econd)) { FunctionExprent ret = new FunctionExprent( func.getFuncType() == FunctionExprent.FUNCTION_ADD ? FunctionExprent.FUNCTION_PPI : FunctionExprent.FUNCTION_MMI, - Arrays.asList(econd), func.bytecode); + econd, func.bytecode); ret.setImplicitType(VarType.VARTYPE_INT); return ret; } diff --git a/src/org/jetbrains/java/decompiler/modules/decompiler/exps/FunctionExprent.java b/src/org/jetbrains/java/decompiler/modules/decompiler/exps/FunctionExprent.java index 178e126..7fde2f5 100644 --- a/src/org/jetbrains/java/decompiler/modules/decompiler/exps/FunctionExprent.java +++ b/src/org/jetbrains/java/decompiler/modules/decompiler/exps/FunctionExprent.java @@ -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. @@ -220,6 +220,10 @@ public class FunctionExprent extends Exprent { addBytecodeOffsets(bytecodeOffsets); } + public FunctionExprent(int funcType, Exprent operand, Set bytecodeOffsets) { + this(funcType, Collections.singletonList(operand), bytecodeOffsets); + } + @Override public VarType getExprType() { VarType exprType = null; diff --git a/src/org/jetbrains/java/decompiler/modules/decompiler/exps/IfExprent.java b/src/org/jetbrains/java/decompiler/modules/decompiler/exps/IfExprent.java index e5dd625..f471d45 100644 --- a/src/org/jetbrains/java/decompiler/modules/decompiler/exps/IfExprent.java +++ b/src/org/jetbrains/java/decompiler/modules/decompiler/exps/IfExprent.java @@ -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. @@ -135,7 +135,7 @@ public class IfExprent extends Exprent { } public IfExprent negateIf() { - condition = new FunctionExprent(FunctionExprent.FUNCTION_BOOL_NOT, Collections.singletonList(condition), condition.bytecode); + condition = new FunctionExprent(FunctionExprent.FUNCTION_BOOL_NOT, condition, condition.bytecode); return this; }