From 2505fc4cfa2af0f7621c86800e99d5a00a88b8a8 Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Thu, 8 Mar 2018 11:34:42 +0100 Subject: [PATCH] Cleanup (warnings; formatting) --- .../java/decompiler/main/ClassWriter.java | 23 ++++++-------- .../java/decompiler/main/Fernflower.java | 4 +-- .../decompiler/main/rels/ClassWrapper.java | 4 +-- .../main/rels/MethodProcessorRunnable.java | 31 ++++++------------- .../java/decompiler/IdeaDecompilerBundle.kt | 16 +--------- .../jetbrains/java/decompiler/IdeaLogger.kt | 24 +++----------- .../decompiler/ShowDecompiledClassAction.kt | 16 +--------- .../java/decompiler/IdeaDecompilerTest.kt | 2 +- 8 files changed, 30 insertions(+), 90 deletions(-) diff --git a/plugins/java-decompiler/engine/src/org/jetbrains/java/decompiler/main/ClassWriter.java b/plugins/java-decompiler/engine/src/org/jetbrains/java/decompiler/main/ClassWriter.java index 5d9066868869..a19bb3602174 100644 --- a/plugins/java-decompiler/engine/src/org/jetbrains/java/decompiler/main/ClassWriter.java +++ b/plugins/java-decompiler/engine/src/org/jetbrains/java/decompiler/main/ClassWriter.java @@ -1,6 +1,4 @@ -/* - * Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. - */ +// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package org.jetbrains.java.decompiler.main; import org.jetbrains.java.decompiler.code.CodeConstants; @@ -517,10 +515,9 @@ public class ClassWriter { try { buffer.append(root.toJava(indent, tracer)); } - catch (Throwable ex) { - DecompilerContext.getLogger().writeMessage("Method " + mt.getName() + " " + mt.getDescriptor() + " couldn't be written.", - IFernflowerLogger.Severity.WARN, - ex); + catch (Throwable t) { + String message = "Method " + mt.getName() + " " + mt.getDescriptor() + " couldn't be written."; + DecompilerContext.getLogger().writeMessage(message, IFernflowerLogger.Severity.WARN, t); methodWrapper.decompiledWithErrors = true; } } @@ -805,7 +802,6 @@ public class ClassWriter { buffer.append(';'); buffer.appendLineSeparator(); - tracer.incrementCurrentSourceLine(); } else { if (!clinit && !dinit) { @@ -831,11 +827,9 @@ public class ClassWriter { tracer.setCurrentSourceLine(codeTracer.getCurrentSourceLine()); tracer.addTracer(codeTracer); } - catch (Throwable ex) { - DecompilerContext.getLogger() - .writeMessage("Method " + mt.getName() + " " + mt.getDescriptor() + " couldn't be written.", - IFernflowerLogger.Severity.WARN, - ex); + catch (Throwable t) { + String message = "Method " + mt.getName() + " " + mt.getDescriptor() + " couldn't be written."; + DecompilerContext.getLogger().writeMessage(message, IFernflowerLogger.Severity.WARN, t); methodWrapper.decompiledWithErrors = true; } } @@ -850,8 +844,9 @@ public class ClassWriter { tracer.addMapping(root.getDummyExit().bytecode); } buffer.appendIndent(indent).append('}').appendLineSeparator(); - tracer.incrementCurrentSourceLine(); } + + tracer.incrementCurrentSourceLine(); } finally { DecompilerContext.setProperty(DecompilerContext.CURRENT_METHOD_WRAPPER, outerWrapper); diff --git a/plugins/java-decompiler/engine/src/org/jetbrains/java/decompiler/main/Fernflower.java b/plugins/java-decompiler/engine/src/org/jetbrains/java/decompiler/main/Fernflower.java index b7ca4a89ba0b..37a7db12bc33 100644 --- a/plugins/java-decompiler/engine/src/org/jetbrains/java/decompiler/main/Fernflower.java +++ b/plugins/java-decompiler/engine/src/org/jetbrains/java/decompiler/main/Fernflower.java @@ -114,8 +114,8 @@ public class Fernflower implements IDecompiledData { classProcessor.writeClass(cl, buffer); return buffer.toString(); } - catch (Throwable ex) { - DecompilerContext.getLogger().writeMessage("Class " + cl.qualifiedName + " couldn't be fully decompiled.", ex); + catch (Throwable t) { + DecompilerContext.getLogger().writeMessage("Class " + cl.qualifiedName + " couldn't be fully decompiled.", t); return null; } } diff --git a/plugins/java-decompiler/engine/src/org/jetbrains/java/decompiler/main/rels/ClassWrapper.java b/plugins/java-decompiler/engine/src/org/jetbrains/java/decompiler/main/rels/ClassWrapper.java index 9f41a3743368..15a4898b7f19 100644 --- a/plugins/java-decompiler/engine/src/org/jetbrains/java/decompiler/main/rels/ClassWrapper.java +++ b/plugins/java-decompiler/engine/src/org/jetbrains/java/decompiler/main/rels/ClassWrapper.java @@ -122,9 +122,9 @@ public class ClassWrapper { } } } - catch (Throwable ex) { + catch (Throwable t) { String message = "Method " + mt.getName() + " " + mt.getDescriptor() + " couldn't be decompiled."; - DecompilerContext.getLogger().writeMessage(message, IFernflowerLogger.Severity.WARN, ex); + DecompilerContext.getLogger().writeMessage(message, IFernflowerLogger.Severity.WARN, t); isError = true; } diff --git a/plugins/java-decompiler/engine/src/org/jetbrains/java/decompiler/main/rels/MethodProcessorRunnable.java b/plugins/java-decompiler/engine/src/org/jetbrains/java/decompiler/main/rels/MethodProcessorRunnable.java index 935589fb0a45..a639372e3f7b 100644 --- a/plugins/java-decompiler/engine/src/org/jetbrains/java/decompiler/main/rels/MethodProcessorRunnable.java +++ b/plugins/java-decompiler/engine/src/org/jetbrains/java/decompiler/main/rels/MethodProcessorRunnable.java @@ -129,39 +129,26 @@ public class MethodProcessorRunnable implements Runnable { SequenceHelper.condenseSequences(root); - while (true) { - StackVarsProcessor stackProc = new StackVarsProcessor(); + StackVarsProcessor stackProc = new StackVarsProcessor(); + + do { stackProc.simplifyStackVars(root, mt, cl); - varProc.setVarVersions(root); - - if (!new PPandMMHelper().findPPandMM(root)) { - break; - } } + while (new PPandMMHelper().findPPandMM(root)); while (true) { LabelHelper.cleanUpEdges(root); - while (true) { + do { MergeHelper.enhanceLoops(root); - - if (LoopExtractHelper.extractLoops(root)) { - continue; - } - - if (!IfHelper.mergeAllIfs(root)) { - break; - } } + while (LoopExtractHelper.extractLoops(root) || IfHelper.mergeAllIfs(root)); if (DecompilerContext.getOption(IFernflowerPreferences.IDEA_NOT_NULL_ANNOTATION)) { if (IdeaNotNullHelper.removeHardcodedChecks(root, mt)) { SequenceHelper.condenseSequences(root); - - StackVarsProcessor stackProc = new StackVarsProcessor(); stackProc.simplifyStackVars(root, mt, cl); - varProc.setVarVersions(root); } } @@ -178,9 +165,9 @@ public class MethodProcessorRunnable implements Runnable { } // FIXME: !! - // if(!EliminateLoopsHelper.eliminateLoops(root)) { - // break; - // } + //if(!EliminateLoopsHelper.eliminateLoops(root)) { + // break; + //} } ExitHelper.removeRedundantReturns(root); diff --git a/plugins/java-decompiler/plugin/src/org/jetbrains/java/decompiler/IdeaDecompilerBundle.kt b/plugins/java-decompiler/plugin/src/org/jetbrains/java/decompiler/IdeaDecompilerBundle.kt index 4920d6e34a51..3fb6d45f5c1a 100644 --- a/plugins/java-decompiler/plugin/src/org/jetbrains/java/decompiler/IdeaDecompilerBundle.kt +++ b/plugins/java-decompiler/plugin/src/org/jetbrains/java/decompiler/IdeaDecompilerBundle.kt @@ -1,18 +1,4 @@ -/* - * 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. - * 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. - */ +// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package org.jetbrains.java.decompiler import com.intellij.AbstractBundle diff --git a/plugins/java-decompiler/plugin/src/org/jetbrains/java/decompiler/IdeaLogger.kt b/plugins/java-decompiler/plugin/src/org/jetbrains/java/decompiler/IdeaLogger.kt index e005b5640835..76ab5a210175 100644 --- a/plugins/java-decompiler/plugin/src/org/jetbrains/java/decompiler/IdeaLogger.kt +++ b/plugins/java-decompiler/plugin/src/org/jetbrains/java/decompiler/IdeaLogger.kt @@ -1,18 +1,4 @@ -/* - * Copyright 2000-2017 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. - */ +// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package org.jetbrains.java.decompiler import com.intellij.openapi.diagnostic.Logger @@ -59,7 +45,7 @@ class IdeaLogger : IFernflowerLogger() { private fun extendMessage(message: String) = if (myClass != null) "$message [$myClass]" else message override fun startReadingClass(className: String) { - LOG.debug("decompiling class " + className) + LOG.debug("decompiling class $className") myClass = className } @@ -68,15 +54,15 @@ class IdeaLogger : IFernflowerLogger() { myClass = null } - override fun startClass(className: String) = LOG.debug("processing class " + className) + override fun startClass(className: String) = LOG.debug("processing class $className") override fun endClass() = LOG.debug("... class processed") - override fun startMethod(methodName: String) = LOG.debug("processing method " + methodName) + override fun startMethod(methodName: String) = LOG.debug("processing method $methodName") override fun endMethod() = LOG.debug("... method processed") - override fun startWriteClass(className: String) = LOG.debug("writing class " + className) + override fun startWriteClass(className: String) = LOG.debug("writing class $className") override fun endWriteClass() = LOG.debug("... class written") } \ No newline at end of file diff --git a/plugins/java-decompiler/plugin/src/org/jetbrains/java/decompiler/ShowDecompiledClassAction.kt b/plugins/java-decompiler/plugin/src/org/jetbrains/java/decompiler/ShowDecompiledClassAction.kt index 7da21573cb69..5d0ef7015cb6 100644 --- a/plugins/java-decompiler/plugin/src/org/jetbrains/java/decompiler/ShowDecompiledClassAction.kt +++ b/plugins/java-decompiler/plugin/src/org/jetbrains/java/decompiler/ShowDecompiledClassAction.kt @@ -1,18 +1,4 @@ -/* - * 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. - */ +// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package org.jetbrains.java.decompiler import com.intellij.ide.highlighter.JavaClassFileType diff --git a/plugins/java-decompiler/plugin/test/org/jetbrains/java/decompiler/IdeaDecompilerTest.kt b/plugins/java-decompiler/plugin/test/org/jetbrains/java/decompiler/IdeaDecompilerTest.kt index 4b0eed6e337d..463b330b29ac 100644 --- a/plugins/java-decompiler/plugin/test/org/jetbrains/java/decompiler/IdeaDecompilerTest.kt +++ b/plugins/java-decompiler/plugin/test/org/jetbrains/java/decompiler/IdeaDecompilerTest.kt @@ -170,7 +170,7 @@ class IdeaDecompilerTest : LightCodeInsightFixtureTestCase() { } else if (file.fileType === StdFileTypes.CLASS && !file.name.contains('$')) { val decompiled = (psiManager.findFile(file)!! as ClsFileImpl).mirror.text - assertTrue(file.path, decompiled.startsWith(IdeaDecompiler.BANNER) || file.name == "package-info.class") + assertTrue(file.path, decompiled.startsWith(IdeaDecompiler.BANNER) || file.name.endsWith("-info.class")) // check that no mapped line number is on an empty line val prefix = "// "