From a8403429efcc52bf9aa8b5c0f2bcddadc6702248 Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Thu, 21 Apr 2016 21:18:37 +0200 Subject: [PATCH] Cleanup (minor optimization) --- .../collectors/BytecodeMappingTracer.java | 6 +- .../modules/decompiler/exps/Exprent.java | 64 ++++++++----------- .../modules/decompiler/stats/Statement.java | 7 +- 3 files changed, 32 insertions(+), 45 deletions(-) diff --git a/src/org/jetbrains/java/decompiler/main/collectors/BytecodeMappingTracer.java b/src/org/jetbrains/java/decompiler/main/collectors/BytecodeMappingTracer.java index 94c2993..a72f988 100644 --- a/src/org/jetbrains/java/decompiler/main/collectors/BytecodeMappingTracer.java +++ b/src/org/jetbrains/java/decompiler/main/collectors/BytecodeMappingTracer.java @@ -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. @@ -21,6 +21,8 @@ import java.util.*; import java.util.Map.Entry; public class BytecodeMappingTracer { + public static final BytecodeMappingTracer DUMMY = new BytecodeMappingTracer(); + private int currentSourceLine; private StructLineNumberTableAttribute lineNumberTable = null; private final Map mapping = new HashMap(); // bytecode offset, source line @@ -116,4 +118,4 @@ public class BytecodeMappingTracer { } return res; } -} +} \ No newline at end of file diff --git a/src/org/jetbrains/java/decompiler/modules/decompiler/exps/Exprent.java b/src/org/jetbrains/java/decompiler/modules/decompiler/exps/Exprent.java index 42abbb2..77b35b3 100644 --- a/src/org/jetbrains/java/decompiler/modules/decompiler/exps/Exprent.java +++ b/src/org/jetbrains/java/decompiler/modules/decompiler/exps/Exprent.java @@ -15,13 +15,6 @@ */ package org.jetbrains.java.decompiler.modules.decompiler.exps; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashSet; -import java.util.List; -import java.util.Map.Entry; -import java.util.Set; - import org.jetbrains.java.decompiler.main.DecompilerContext; import org.jetbrains.java.decompiler.main.TextBuffer; import org.jetbrains.java.decompiler.main.collectors.BytecodeMappingTracer; @@ -34,8 +27,10 @@ import org.jetbrains.java.decompiler.struct.match.MatchEngine; import org.jetbrains.java.decompiler.struct.match.MatchNode; import org.jetbrains.java.decompiler.struct.match.MatchNode.RuleValue; -public class Exprent implements IMatchable { +import java.util.*; +import java.util.Map.Entry; +public class Exprent implements IMatchable { public static final int MULTIPLE_USES = 1; public static final int SIDE_EFFECTS_FREE = 2; public static final int BOTH_FLAGS = 3; @@ -144,58 +139,53 @@ public class Exprent implements IMatchable { // ***************************************************************************** // IMatchable implementation // ***************************************************************************** - + + @Override public IMatchable findObject(MatchNode matchNode, int index) { - - if(matchNode.getType() != MatchNode.MATCHNODE_EXPRENT) { + if (matchNode.getType() != MatchNode.MATCHNODE_EXPRENT) { return null; } List lstAllExprents = getAllExprents(); - - if(lstAllExprents == null || lstAllExprents.isEmpty()) { + if (lstAllExprents == null || lstAllExprents.isEmpty()) { return null; } - + String position = (String)matchNode.getRuleValue(MatchProperties.EXPRENT_POSITION); - if(position != null) { - if(position.matches("-?\\d+")) { - return lstAllExprents.get((lstAllExprents.size() + Integer.parseInt(position)) % lstAllExprents.size()); // care for negative positions + if (position != null) { + if (position.matches("-?\\d+")) { + return lstAllExprents + .get((lstAllExprents.size() + Integer.parseInt(position)) % lstAllExprents.size()); // care for negative positions } - } else if(index < lstAllExprents.size()) { // use 'index' parameter + } + else if (index < lstAllExprents.size()) { // use 'index' parameter return lstAllExprents.get(index); } return null; } + @Override public boolean match(MatchNode matchNode, MatchEngine engine) { - - if(matchNode.getType() != MatchNode.MATCHNODE_EXPRENT) { + if (matchNode.getType() != MatchNode.MATCHNODE_EXPRENT) { return false; } - - for(Entry rule : matchNode.getRules().entrySet()) { - switch(rule.getKey()) { - case EXPRENT_TYPE: - if(this.type != ((Integer)rule.getValue().value).intValue()) { - return false; - } - break; - case EXPRENT_RET: - if(!engine.checkAndSetVariableValue((String)rule.getValue().value, this)) { - return false; - } - break; + + for (Entry rule : matchNode.getRules().entrySet()) { + MatchProperties key = rule.getKey(); + if (key == MatchProperties.EXPRENT_TYPE && this.type != ((Integer)rule.getValue().value).intValue()) { + return false; + } + if (key == MatchProperties.EXPRENT_RET && !engine.checkAndSetVariableValue((String)rule.getValue().value, this)) { + return false; } - } - + return true; } @Override public String toString() { - return toJava(0, new BytecodeMappingTracer()).toString(); + return toJava(0, BytecodeMappingTracer.DUMMY).toString(); } -} +} \ No newline at end of file diff --git a/src/org/jetbrains/java/decompiler/modules/decompiler/stats/Statement.java b/src/org/jetbrains/java/decompiler/modules/decompiler/stats/Statement.java index ced701f..5efa6cf 100644 --- a/src/org/jetbrains/java/decompiler/modules/decompiler/stats/Statement.java +++ b/src/org/jetbrains/java/decompiler/modules/decompiler/stats/Statement.java @@ -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. @@ -494,11 +494,6 @@ public class Statement implements IMatchable { return false; } - // to be overwritten - public TextBuffer toJava() { - return toJava(0, new BytecodeMappingTracer()); - } - public TextBuffer toJava(int indent, BytecodeMappingTracer tracer) { throw new RuntimeException("not implemented"); }