From 25bd28a290170260865e2ca07565cf096bc4e7d3 Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Mon, 26 May 2014 21:47:04 +0400 Subject: [PATCH] logging reworked - implementation-specific method removed from the API - internal exceptions handling incapsulated --- src/de/fernflower/main/ClassWriter.java | 12 ++---------- src/de/fernflower/main/Fernflower.java | 4 +--- .../decompiler/helper/PrintStreamLogger.java | 19 ++++++++----------- .../main/extern/IFernflowerLogger.java | 5 +---- src/de/fernflower/main/rels/ClassWrapper.java | 12 +++--------- 5 files changed, 15 insertions(+), 37 deletions(-) diff --git a/src/de/fernflower/main/ClassWriter.java b/src/de/fernflower/main/ClassWriter.java index e0684ba..9f52dda 100644 --- a/src/de/fernflower/main/ClassWriter.java +++ b/src/de/fernflower/main/ClassWriter.java @@ -637,11 +637,7 @@ public class ClassWriter { String code = root.toJava(indent+1); bufstrwriter.write(code); } catch(Throwable ex) { - if(DecompilerContext.getLogger().getShowStacktrace()) { - ex.printStackTrace(); - } - - DecompilerContext.getLogger().writeMessage("Method "+mt.getName()+" "+mt.getDescriptor()+" couldn't be written.", IFernflowerLogger.ERROR); + DecompilerContext.getLogger().writeMessage("Method "+mt.getName()+" "+mt.getDescriptor()+" couldn't be written.", ex); meth.decompiledWithErrors = true; } } @@ -978,11 +974,7 @@ public class ClassWriter { bufstrwriter.write(code); } catch(Throwable ex) { - if(DecompilerContext.getLogger().getShowStacktrace()) { - ex.printStackTrace(); - } - - DecompilerContext.getLogger().writeMessage("Method "+mt.getName()+" "+mt.getDescriptor()+" couldn't be written.", IFernflowerLogger.ERROR); + DecompilerContext.getLogger().writeMessage("Method "+mt.getName()+" "+mt.getDescriptor()+" couldn't be written.", ex); meth.decompiledWithErrors = true; } } diff --git a/src/de/fernflower/main/Fernflower.java b/src/de/fernflower/main/Fernflower.java index 2c594f0..a712450 100644 --- a/src/de/fernflower/main/Fernflower.java +++ b/src/de/fernflower/main/Fernflower.java @@ -22,7 +22,6 @@ import de.fernflower.main.ClassesProcessor.ClassNode; import de.fernflower.main.collectors.CounterContainer; import de.fernflower.main.extern.IBytecodeProvider; import de.fernflower.main.extern.IDecompilatSaver; -import de.fernflower.main.extern.IFernflowerLogger; import de.fernflower.main.extern.IFernflowerPreferences; import de.fernflower.modules.renamer.IdentifierConverter; import de.fernflower.struct.IDecompiledData; @@ -98,8 +97,7 @@ public class Fernflower implements IDecompiledData { } catch(ThreadDeath ex) { throw ex; } catch(Throwable ex) { - ex.printStackTrace(); - DecompilerContext.getLogger().writeMessage("Class "+cl.qualifiedName+" couldn't be fully decompiled." , IFernflowerLogger.ERROR); + DecompilerContext.getLogger().writeMessage("Class "+cl.qualifiedName+" couldn't be fully decompiled.", ex); } return res; diff --git a/src/de/fernflower/main/decompiler/helper/PrintStreamLogger.java b/src/de/fernflower/main/decompiler/helper/PrintStreamLogger.java index 6424b10..7d1de7d 100644 --- a/src/de/fernflower/main/decompiler/helper/PrintStreamLogger.java +++ b/src/de/fernflower/main/decompiler/helper/PrintStreamLogger.java @@ -35,15 +35,16 @@ public class PrintStreamLogger implements IFernflowerLogger { public void writeMessage(String message, int severity) { - writeMessage(message, severity, indent); + if(severity >= this.severity) { + stream.println(InterpreterUtil.getIndentString(indent)+names[severity]+": "+message); + } } - public void writeMessage(String message, int severity, int indent) { - if(severity >= this.severity) { - stream.println(InterpreterUtil.getIndentString(indent)+names[severity]+": "+message); - } - } - + public void writeMessage(String message, Throwable t) { + t.printStackTrace(stream); + writeMessage(message, ERROR); + } + public void startClass(String classname) { stream.println(InterpreterUtil.getIndentString(indent++)+"Processing class "+classname+" ..."); } @@ -79,8 +80,4 @@ public class PrintStreamLogger implements IFernflowerLogger { public void setSeverity(int severity) { this.severity = severity; } - - public boolean getShowStacktrace() { - return true; - } } diff --git a/src/de/fernflower/main/extern/IFernflowerLogger.java b/src/de/fernflower/main/extern/IFernflowerLogger.java index 3c5543e..c33ce50 100644 --- a/src/de/fernflower/main/extern/IFernflowerLogger.java +++ b/src/de/fernflower/main/extern/IFernflowerLogger.java @@ -36,7 +36,7 @@ public interface IFernflowerLogger { public void writeMessage(String message, int severity); - public void writeMessage(String message, int severity, int indent); + public void writeMessage(String message, Throwable t); public void startClass(String classname); @@ -53,7 +53,4 @@ public interface IFernflowerLogger { public int getSeverity(); public void setSeverity(int severity); - - public boolean getShowStacktrace(); - } diff --git a/src/de/fernflower/main/rels/ClassWrapper.java b/src/de/fernflower/main/rels/ClassWrapper.java index 80eb5c7..11adda0 100644 --- a/src/de/fernflower/main/rels/ClassWrapper.java +++ b/src/de/fernflower/main/rels/ClassWrapper.java @@ -110,7 +110,7 @@ public class ClassWrapper { if(maxsec > 0 && ++sec > maxsec) { DecompilerContext.getLogger().writeMessage("Processing time limit ("+maxsec+" sec.) for method " + - mt.getName()+" "+mt.getDescriptor()+ " exceeded, execution interrupted.", IFernflowerLogger.ERROR, 0); + mt.getName()+" "+mt.getDescriptor()+ " exceeded, execution interrupted.", IFernflowerLogger.ERROR); mtthread.stop(); isError = true; break; @@ -158,17 +158,11 @@ public class ClassWrapper { if(mtthread != null) { mtthread.stop(); } - } catch(Throwable e) { - ; - } + } catch(Throwable ignored) { } throw ex; } catch(Throwable ex) { - if(DecompilerContext.getLogger().getShowStacktrace()) { - ex.printStackTrace(); - } - - DecompilerContext.getLogger().writeMessage("Method "+mt.getName()+" "+mt.getDescriptor()+" couldn't be decompiled.", IFernflowerLogger.ERROR); + DecompilerContext.getLogger().writeMessage("Method "+mt.getName()+" "+mt.getDescriptor()+" couldn't be decompiled.", ex); isError = true; }