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/struct/ContextUnit.java | 210 +++++++++++++++++++++ 1 file changed, 210 insertions(+) create mode 100644 src/org/jetbrains/java/decompiler/struct/ContextUnit.java (limited to 'src/org/jetbrains/java/decompiler/struct/ContextUnit.java') diff --git a/src/org/jetbrains/java/decompiler/struct/ContextUnit.java b/src/org/jetbrains/java/decompiler/struct/ContextUnit.java new file mode 100644 index 0000000..d859b29 --- /dev/null +++ b/src/org/jetbrains/java/decompiler/struct/ContextUnit.java @@ -0,0 +1,210 @@ +/* + * 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.struct; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.jar.Manifest; + +import org.jetbrains.java.decompiler.main.extern.IDecompilatSaver; +import org.jetbrains.java.decompiler.struct.lazy.LazyLoader; +import org.jetbrains.java.decompiler.struct.lazy.LazyLoader.Link; + +public class ContextUnit { + + public static final int TYPE_FOLDER = 0; + public static final int TYPE_JAR = 1; + public static final int TYPE_ZIP = 2; + + private static final String MANIFEST_ENTRY = "META-INF/MANIFEST.MF"; + + // ***************************************************************************** + // private fields + // ***************************************************************************** + + private int type; + + // relative path to jar/zip + private String archivepath; + + // folder: relative path + // archive: file name + private String filename; + + private List classes = new ArrayList(); + + // class file or jar/zip entry. Should, but doesn't have to be the same as qualifiedName of the class + private List classentries = new ArrayList(); + + private List direntries = new ArrayList(); + + private List otherentries = new ArrayList(); + + private Manifest manifest; + + private IDecompilatSaver decompilatSaver; + + private IDecompiledData decompiledData; + + private boolean own = true; + + // ***************************************************************************** + // constructors + // ***************************************************************************** + + public ContextUnit(int type, String archivepath, String filename, boolean own, + IDecompilatSaver decompilatSaver, IDecompiledData decompiledData) { + this.type = type; + this.own = own; + this.archivepath = archivepath; + this.filename = filename; + this.decompilatSaver = decompilatSaver; + this.decompiledData = decompiledData; + } + + // ***************************************************************************** + // public methods + // ***************************************************************************** + + public void addClass(StructClass cl, String entryname) { + classes.add(cl); + classentries.add(entryname); + } + + public void addDirEntry(String entry) { + direntries.add(entry); + } + + public void addOtherEntry(String fullpath, String entry) { + otherentries.add(new String[]{fullpath, entry}); + } + + public void reload(LazyLoader loader) throws IOException { + + List lstClasses = new ArrayList(); + for(StructClass cl : classes) { + String oldname = cl.qualifiedName; + StructClass newcl = new StructClass(loader.getClassStream(oldname), cl.isOwn(), loader); + + lstClasses.add(newcl); + + Link lnk = loader.getClassLink(oldname); + loader.removeClassLink(oldname); + loader.addClassLink(newcl.qualifiedName, lnk); + } + + classes = lstClasses; + } + + public void save() { + + switch(type) { + case TYPE_FOLDER: + + // create folder + decompilatSaver.saveFolder(filename); + + // non-class files + for(String[] arr: otherentries) { + decompilatSaver.copyFile(arr[0], filename, arr[0]); + } + + // classes + for(int i=0;i getClasses() { + return classes; + } + + public int getType() { + return type; + } + + public void setDecompilatSaver(IDecompilatSaver decompilatSaver) { + this.decompilatSaver = decompilatSaver; + } + + public void setDecompiledData(IDecompiledData decompiledData) { + this.decompiledData = decompiledData; + } + +} -- cgit v1.2.3