- console decompiler: resource closing, lookup instead of scan, error reporting - logger interface reworked - saver interface renamed - bytecode provider returns byte array (to reduce stream leakage) - extra level of context unit avoided - unneeded exceptions, dead code, formattingmaster
parent
4e79d160ca
commit
ff382a6fdf
@ -0,0 +1,80 @@ |
|||||||
|
/* |
||||||
|
* Copyright 2000-2014 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. |
||||||
|
*/ |
||||||
|
package org.jetbrains.java.decompiler.main.decompiler; |
||||||
|
|
||||||
|
import org.jetbrains.java.decompiler.main.extern.IFernflowerLogger; |
||||||
|
import org.jetbrains.java.decompiler.util.InterpreterUtil; |
||||||
|
|
||||||
|
import java.io.PrintStream; |
||||||
|
|
||||||
|
public class PrintStreamLogger extends IFernflowerLogger { |
||||||
|
|
||||||
|
private final PrintStream stream; |
||||||
|
private int indent; |
||||||
|
|
||||||
|
public PrintStreamLogger(PrintStream printStream) { |
||||||
|
stream = printStream; |
||||||
|
indent = 0; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void writeMessage(String message, Severity severity) { |
||||||
|
if (accepts(severity)) { |
||||||
|
stream.println(InterpreterUtil.getIndentString(indent) + severity.name() + ": " + message); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void writeMessage(String message, Throwable t) { |
||||||
|
writeMessage(message, Severity.ERROR); |
||||||
|
if (accepts(Severity.ERROR)) { |
||||||
|
t.printStackTrace(stream); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void startClass(String className) { |
||||||
|
writeMessage("Processing class " + className + " ...", Severity.INFO); |
||||||
|
++indent; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void endClass() { |
||||||
|
--indent; |
||||||
|
writeMessage("... proceeded.", Severity.INFO); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void startWriteClass(String className) { |
||||||
|
writeMessage("Writing class " + className + " ...", Severity.INFO); |
||||||
|
++indent; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void endWriteClass() { |
||||||
|
--indent; |
||||||
|
writeMessage("... written.", Severity.INFO); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void startMethod(String methodName) { |
||||||
|
writeMessage("Processing method " + methodName + " ...", Severity.INFO); |
||||||
|
} |
||||||
|
|
||||||
|
public void endMethod() { |
||||||
|
writeMessage("... proceeded.", Severity.INFO); |
||||||
|
} |
||||||
|
} |
@ -1,78 +0,0 @@ |
|||||||
/* |
|
||||||
* Copyright 2000-2014 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. |
|
||||||
*/ |
|
||||||
package org.jetbrains.java.decompiler.main.decompiler; |
|
||||||
|
|
||||||
import org.jetbrains.java.decompiler.main.extern.IFernflowerLogger; |
|
||||||
|
|
||||||
import java.io.File; |
|
||||||
import java.util.HashMap; |
|
||||||
import java.util.HashSet; |
|
||||||
|
|
||||||
|
|
||||||
public class WebDecompiler extends ConsoleDecompiler { |
|
||||||
|
|
||||||
private HashMap<String, File> mapInputFilenames = new HashMap<String, File>(); |
|
||||||
|
|
||||||
private HashSet<String> setClassFiles = new HashSet<String>(); |
|
||||||
|
|
||||||
private File root; |
|
||||||
|
|
||||||
public WebDecompiler(IFernflowerLogger logger, HashMap<String, Object> propertiesCustom) { |
|
||||||
super(logger, propertiesCustom); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void decompileContext(File root) { |
|
||||||
this.root = root; |
|
||||||
super.decompileContext(root); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void copyFile(String source, String destpath, String destfilename) { |
|
||||||
super.copyFile(source, destpath, destfilename); |
|
||||||
mapInputFilenames.put(destfilename, new File(getAbsolutePath(destpath), destfilename)); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void saveFile(String path, String filename, String content) { |
|
||||||
super.saveFile(path, filename, content); |
|
||||||
|
|
||||||
mapInputFilenames.put(setClassFiles.contains(filename) ? |
|
||||||
filename.substring(0, filename.lastIndexOf(".java")) + ".class" : |
|
||||||
filename, new File(getAbsolutePath(path), filename)); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void saveClassFile(String path, String qualifiedName, String entryName, String content) { |
|
||||||
setClassFiles.add(entryName); |
|
||||||
saveFile(path, entryName, content); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void closeArchive(String path, String archivename) { |
|
||||||
super.closeArchive(path, archivename); |
|
||||||
mapInputFilenames.put(archivename, new File(getAbsolutePath(path), archivename)); |
|
||||||
} |
|
||||||
|
|
||||||
private String getAbsolutePath(String path) { |
|
||||||
return new File(root, path).getAbsolutePath(); |
|
||||||
} |
|
||||||
|
|
||||||
public HashMap<String, File> getMapInputFilenames() { |
|
||||||
return mapInputFilenames; |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
@ -1,84 +0,0 @@ |
|||||||
/* |
|
||||||
* Copyright 2000-2014 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. |
|
||||||
*/ |
|
||||||
package org.jetbrains.java.decompiler.main.decompiler.helper; |
|
||||||
|
|
||||||
import org.jetbrains.java.decompiler.main.extern.IFernflowerLogger; |
|
||||||
import org.jetbrains.java.decompiler.util.InterpreterUtil; |
|
||||||
|
|
||||||
import java.io.PrintStream; |
|
||||||
|
|
||||||
public class PrintStreamLogger implements IFernflowerLogger { |
|
||||||
|
|
||||||
private int severity; |
|
||||||
|
|
||||||
private int indent; |
|
||||||
|
|
||||||
private PrintStream stream; |
|
||||||
|
|
||||||
public PrintStreamLogger(int severity, PrintStream stream) { |
|
||||||
this.severity = severity; |
|
||||||
this.indent = 0; |
|
||||||
this.stream = stream; |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
public void writeMessage(String message, int severity) { |
|
||||||
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 + " ..."); |
|
||||||
} |
|
||||||
|
|
||||||
public void endClass() { |
|
||||||
stream.println(InterpreterUtil.getIndentString(--indent) + "... proceeded."); |
|
||||||
} |
|
||||||
|
|
||||||
public void startWriteClass(String classname) { |
|
||||||
stream.println(InterpreterUtil.getIndentString(indent++) + "Writing class " + classname + " ..."); |
|
||||||
} |
|
||||||
|
|
||||||
public void endWriteClass() { |
|
||||||
stream.println(InterpreterUtil.getIndentString(--indent) + "... written."); |
|
||||||
} |
|
||||||
|
|
||||||
public void startMethod(String method) { |
|
||||||
if (severity <= INFO) { |
|
||||||
stream.println(InterpreterUtil.getIndentString(indent) + "Processing method " + method + " ..."); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
public void endMethod() { |
|
||||||
if (severity <= INFO) { |
|
||||||
stream.println(InterpreterUtil.getIndentString(indent) + "... proceeded."); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
public int getSeverity() { |
|
||||||
return severity; |
|
||||||
} |
|
||||||
|
|
||||||
public void setSeverity(int severity) { |
|
||||||
this.severity = severity; |
|
||||||
} |
|
||||||
} |
|
Loading…
Reference in new issue