From 663631f0456fcc245dd835889f86541d75161c53 Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Thu, 28 Aug 2014 20:52:43 +0400 Subject: java-decompiler: post-import cleanup (classes moved) --- .../java/decompiler/main/rels/ClassWrapper.java | 216 +++++++++++++++++++++ 1 file changed, 216 insertions(+) create mode 100644 src/org/jetbrains/java/decompiler/main/rels/ClassWrapper.java (limited to 'src/org/jetbrains/java/decompiler/main/rels/ClassWrapper.java') diff --git a/src/org/jetbrains/java/decompiler/main/rels/ClassWrapper.java b/src/org/jetbrains/java/decompiler/main/rels/ClassWrapper.java new file mode 100644 index 0000000..dcbeaea --- /dev/null +++ b/src/org/jetbrains/java/decompiler/main/rels/ClassWrapper.java @@ -0,0 +1,216 @@ +/* + * Fernflower - The Analytical Java Decompiler + * http://www.reversed-java.com + * + * (C) 2008 - 2010, Stiver + * + * This software is NEITHER public domain NOR free software + * as per GNU License. See license.txt for more details. + * + * This software is distributed WITHOUT ANY WARRANTY; without + * even the implied warranty of MERCHANTABILITY or FITNESS FOR + * A PARTICULAR PURPOSE. + */ + +package org.jetbrains.java.decompiler.main.rels; + +import java.io.IOException; +import java.util.HashSet; + +import org.jetbrains.java.decompiler.code.CodeConstants; +import org.jetbrains.java.decompiler.main.DecompilerContext; +import org.jetbrains.java.decompiler.main.collectors.CounterContainer; +import org.jetbrains.java.decompiler.main.collectors.VarNamesCollector; +import org.jetbrains.java.decompiler.main.extern.IFernflowerLogger; +import org.jetbrains.java.decompiler.main.extern.IFernflowerPreferences; +import org.jetbrains.java.decompiler.modules.decompiler.exps.Exprent; +import org.jetbrains.java.decompiler.modules.decompiler.stats.RootStatement; +import org.jetbrains.java.decompiler.modules.decompiler.vars.VarProcessor; +import org.jetbrains.java.decompiler.modules.decompiler.vars.VarVersionPaar; +import org.jetbrains.java.decompiler.struct.StructClass; +import org.jetbrains.java.decompiler.struct.StructField; +import org.jetbrains.java.decompiler.struct.StructMethod; +import org.jetbrains.java.decompiler.struct.attr.StructGeneralAttribute; +import org.jetbrains.java.decompiler.struct.attr.StructLocalVariableTableAttribute; +import org.jetbrains.java.decompiler.struct.gen.MethodDescriptor; +import org.jetbrains.java.decompiler.util.InterpreterUtil; +import org.jetbrains.java.decompiler.util.VBStyleCollection; + +public class ClassWrapper { + + private StructClass classStruct; + + private HashSet hideMembers = new HashSet(); + + private VBStyleCollection staticFieldInitializers = new VBStyleCollection(); + + private VBStyleCollection dynamicFieldInitializers = new VBStyleCollection(); + + private VBStyleCollection methods = new VBStyleCollection(); + + + public ClassWrapper(StructClass classStruct) { + this.classStruct = classStruct; + } + + @SuppressWarnings("deprecation") + public void init() throws IOException { + + DecompilerContext.setProperty(DecompilerContext.CURRENT_CLASS, classStruct); + + DecompilerContext.getLogger().startClass(classStruct.qualifiedName); + + // collect field names + HashSet setFieldNames = new HashSet(); + for(StructField fd: classStruct.getFields()) { + setFieldNames.add(fd.getName()); + } + + for(StructMethod mt: classStruct.getMethods()) { + + DecompilerContext.getLogger().startMethod(mt.getName()+" "+mt.getDescriptor()); + + VarNamesCollector vc = new VarNamesCollector(); + DecompilerContext.setVarncollector(vc); + + CounterContainer counter = new CounterContainer(); + DecompilerContext.setCountercontainer(counter); + + DecompilerContext.setProperty(DecompilerContext.CURRENT_METHOD, mt); + DecompilerContext.setProperty(DecompilerContext.CURRENT_METHOD_DESCRIPTOR, MethodDescriptor.parseDescriptor(mt.getDescriptor())); + + VarProcessor varproc = new VarProcessor(); + DecompilerContext.setProperty(DecompilerContext.CURRENT_VAR_PROCESSOR, varproc); + + Thread mtthread = null; + RootStatement root = null; + + boolean isError = false; + + try { + if(mt.containsCode()) { + + int maxsec = 10 * Integer.parseInt(DecompilerContext.getProperty(IFernflowerPreferences.MAX_PROCESSING_METHOD).toString()); + + if(maxsec == 0) { // blocking wait + root = MethodProcessorThread.codeToJava(mt, varproc); + } else { + MethodProcessorThread mtproc = new MethodProcessorThread(mt, varproc, DecompilerContext.getCurrentContext()); + mtthread = new Thread(mtproc); + + mtthread.start(); + + int sec = 0; + while(mtthread.isAlive()) { + + synchronized(mtproc) { + mtproc.wait(100); + } + + if(maxsec > 0 && ++sec > maxsec) { + DecompilerContext.getLogger().writeMessage("Processing time limit ("+maxsec+" sec.) for method " + + mt.getName()+" "+mt.getDescriptor()+ " exceeded, execution interrupted.", IFernflowerLogger.ERROR); + mtthread.stop(); + isError = true; + break; + } + } + + if(!isError) { + if(mtproc.getError() != null) { + throw mtproc.getError(); + } else { + root = mtproc.getRoot(); + } + } + } + + } else { + boolean thisvar = (mt.getAccessFlags() & CodeConstants.ACC_STATIC) == 0; + MethodDescriptor md = MethodDescriptor.parseDescriptor(mt.getDescriptor()); + + int paramcount = 0; + if(thisvar) { + varproc.getThisvars().put(new VarVersionPaar(0,0), classStruct.qualifiedName); + paramcount = 1; + } + paramcount += md.params.length; + + int varindex = 0; + for(int i=0;i getMethods() { + return methods; + } + + public HashSet getHideMembers() { + return hideMembers; + } + + public VBStyleCollection getStaticFieldInitializers() { + return staticFieldInitializers; + } + + public VBStyleCollection getDynamicFieldInitializers() { + return dynamicFieldInitializers; + } + +} -- cgit v1.2.3