From 1742190f784d0d62e7cc869eebafdfe1927e448f Mon Sep 17 00:00:00 2001 From: lclc98 Date: Sat, 2 Jul 2016 21:57:31 +1000 Subject: Removed unused methods --- .../cuchaz/enigma/bytecode/CheckCastIterator.java | 14 ++-- .../java/cuchaz/enigma/bytecode/ClassRenamer.java | 10 --- .../cuchaz/enigma/bytecode/ConstPoolEditor.java | 96 ---------------------- .../bytecode/accessors/ClassInfoAccessor.java | 4 - .../bytecode/accessors/ConstInfoAccessor.java | 23 ------ .../accessors/InvokeDynamicInfoAccessor.java | 4 - .../bytecode/accessors/MemberRefInfoAccessor.java | 4 - .../accessors/MethodHandleInfoAccessor.java | 4 - .../bytecode/accessors/MethodTypeInfoAccessor.java | 4 - .../accessors/NameAndTypeInfoAccessor.java | 4 - .../bytecode/accessors/StringInfoAccessor.java | 4 - .../bytecode/accessors/Utf8InfoAccessor.java | 28 ------- 12 files changed, 5 insertions(+), 194 deletions(-) delete mode 100644 src/main/java/cuchaz/enigma/bytecode/accessors/Utf8InfoAccessor.java (limited to 'src/main/java/cuchaz/enigma/bytecode') diff --git a/src/main/java/cuchaz/enigma/bytecode/CheckCastIterator.java b/src/main/java/cuchaz/enigma/bytecode/CheckCastIterator.java index 19c39d3..c47a770 100644 --- a/src/main/java/cuchaz/enigma/bytecode/CheckCastIterator.java +++ b/src/main/java/cuchaz/enigma/bytecode/CheckCastIterator.java @@ -22,8 +22,8 @@ public class CheckCastIterator implements Iterator { public static class CheckCast { - public String className; - public MethodEntry prevMethodEntry; + public final String className; + public final MethodEntry prevMethodEntry; public CheckCast(String className, MethodEntry prevMethodEntry) { this.className = className; @@ -31,9 +31,9 @@ public class CheckCastIterator implements Iterator { } } - private ConstPool constants; - private CodeAttribute attribute; - private CodeIterator iter; + private final ConstPool constants; + private final CodeAttribute attribute; + private final CodeIterator iter; private CheckCast next; public CheckCastIterator(CodeAttribute codeAttribute) throws BadBytecode { @@ -110,8 +110,4 @@ public class CheckCastIterator implements Iterator { } return null; } - - public Iterable casts() { - return () -> CheckCastIterator.this; - } } diff --git a/src/main/java/cuchaz/enigma/bytecode/ClassRenamer.java b/src/main/java/cuchaz/enigma/bytecode/ClassRenamer.java index d8e7971..944e486 100644 --- a/src/main/java/cuchaz/enigma/bytecode/ClassRenamer.java +++ b/src/main/java/cuchaz/enigma/bytecode/ClassRenamer.java @@ -90,16 +90,6 @@ public class ClassRenamer { }); } - public static void moveAllClassesIntoDefaultPackage(CtClass c, final String oldPackageName) { - renameClasses(c, className -> { - ClassEntry entry = new ClassEntry(className); - if (entry.getPackageName().equals(oldPackageName)) { - return entry.getSimpleName(); - } - return null; - }); - } - @SuppressWarnings("unchecked") public static void renameClasses(CtClass c, ClassNameReplacer replacer) { diff --git a/src/main/java/cuchaz/enigma/bytecode/ConstPoolEditor.java b/src/main/java/cuchaz/enigma/bytecode/ConstPoolEditor.java index 256df61..e49ffdb 100644 --- a/src/main/java/cuchaz/enigma/bytecode/ConstPoolEditor.java +++ b/src/main/java/cuchaz/enigma/bytecode/ConstPoolEditor.java @@ -78,22 +78,6 @@ public class ConstPoolEditor { this.pool = pool; } - public void writePool(DataOutputStream out) { - try { - methodWritePool.invoke(this.pool, out); - } catch (Exception ex) { - throw new Error(ex); - } - } - - public static ConstPool readPool(DataInputStream in) { - try { - return constructorPool.newInstance(in); - } catch (Exception ex) { - throw new Error(ex); - } - } - public String getMemberrefClassname(int memberrefIndex) { return Descriptor.toJvmName(this.pool.getClassInfo(this.pool.getMemberClass(memberrefIndex))); } @@ -117,23 +101,6 @@ public class ConstPoolEditor { throw new Error(ex); } } - - public int addItem(Object item) { - try { - return (Integer) addItem.invoke(this.pool, item); - } catch (Exception ex) { - throw new Error(ex); - } - } - - public int addItemForceNew(Object item) { - try { - return (Integer) addItem0.invoke(this.pool, item); - } catch (Exception ex) { - throw new Error(ex); - } - } - @SuppressWarnings("rawtypes") public void removeLastItem() { try { @@ -197,67 +164,4 @@ public class ConstPoolEditor { assert (newName.equals(getMemberrefName(memberrefIndex))); assert (newType.equals(getMemberrefType(memberrefIndex))); } - - @SuppressWarnings({"rawtypes", "unchecked"}) - public void changeClassName(int classNameIndex, String newName) { - // NOTE: when changing values, we always need to copy-on-write - try { - // get the class item - Object item = getItem(classNameIndex).getItem(); - - // update the cache - HashMap cache = getCache(); - if (cache != null) { - cache.remove(item); - } - - // add the new name and repoint the name-and-type to it - new ClassInfoAccessor(item).setNameIndex(this.pool.addUtf8Info(newName)); - - // update the cache - if (cache != null) { - cache.put(item, item); - } - } catch (Exception ex) { - throw new Error(ex); - } - } - - public static ConstPool newConstPool() { - // const pool expects the name of a class to initialize itself - // but we want an empty pool - // so give it a bogus name, and then clear the entries afterwards - ConstPool pool = new ConstPool("a"); - - ConstPoolEditor editor = new ConstPoolEditor(pool); - int size = pool.getSize(); - for (int i = 0; i < size - 1; i++) { - editor.removeLastItem(); - } - - // make sure the pool is actually empty - // although, in this case "empty" means one thing in it - // the JVM spec says index 0 should be reserved - assert (pool.getSize() == 1); - assert (editor.getItem(0) == null); - assert (editor.getItem(1) == null); - assert (editor.getItem(2) == null); - assert (editor.getItem(3) == null); - - // also, clear the cache - editor.getCache().clear(); - - return pool; - } - - public String dump() { - StringBuilder buf = new StringBuilder(); - for (int i = 1; i < this.pool.getSize(); i++) { - buf.append(String.format("%4d", i)); - buf.append(" "); - buf.append(getItem(i).toString()); - buf.append("\n"); - } - return buf.toString(); - } } diff --git a/src/main/java/cuchaz/enigma/bytecode/accessors/ClassInfoAccessor.java b/src/main/java/cuchaz/enigma/bytecode/accessors/ClassInfoAccessor.java index 66f2283..316bb5e 100644 --- a/src/main/java/cuchaz/enigma/bytecode/accessors/ClassInfoAccessor.java +++ b/src/main/java/cuchaz/enigma/bytecode/accessors/ClassInfoAccessor.java @@ -39,10 +39,6 @@ public class ClassInfoAccessor { } } - public static boolean isType(ConstInfoAccessor accessor) { - return clazz.isAssignableFrom(accessor.getItem().getClass()); - } - static { try { clazz = Class.forName("javassist.bytecode.ClassInfo"); diff --git a/src/main/java/cuchaz/enigma/bytecode/accessors/ConstInfoAccessor.java b/src/main/java/cuchaz/enigma/bytecode/accessors/ConstInfoAccessor.java index ea775e9..2ecda1d 100644 --- a/src/main/java/cuchaz/enigma/bytecode/accessors/ConstInfoAccessor.java +++ b/src/main/java/cuchaz/enigma/bytecode/accessors/ConstInfoAccessor.java @@ -80,29 +80,6 @@ public class ConstInfoAccessor { } } - public ConstInfoAccessor copy() { - return new ConstInfoAccessor(copyItem()); - } - - public Object copyItem() { - // I don't know of a simpler way to copy one of these silly things... - try { - // serialize the item - ByteArrayOutputStream buf = new ByteArrayOutputStream(); - DataOutputStream out = new DataOutputStream(buf); - write(out); - - // deserialize the item - DataInputStream in = new DataInputStream(new ByteArrayInputStream(buf.toByteArray())); - Object item = new ConstInfoAccessor(in).getItem(); - in.close(); - - return item; - } catch (Exception ex) { - throw new Error(ex); - } - } - public void write(DataOutputStream out) throws IOException { try { out.writeUTF(this.item.getClass().getName()); diff --git a/src/main/java/cuchaz/enigma/bytecode/accessors/InvokeDynamicInfoAccessor.java b/src/main/java/cuchaz/enigma/bytecode/accessors/InvokeDynamicInfoAccessor.java index 69aee16..a158394 100644 --- a/src/main/java/cuchaz/enigma/bytecode/accessors/InvokeDynamicInfoAccessor.java +++ b/src/main/java/cuchaz/enigma/bytecode/accessors/InvokeDynamicInfoAccessor.java @@ -57,10 +57,6 @@ public class InvokeDynamicInfoAccessor { } } - public static boolean isType(ConstInfoAccessor accessor) { - return clazz.isAssignableFrom(accessor.getItem().getClass()); - } - static { try { clazz = Class.forName("javassist.bytecode.InvokeDynamicInfo"); diff --git a/src/main/java/cuchaz/enigma/bytecode/accessors/MemberRefInfoAccessor.java b/src/main/java/cuchaz/enigma/bytecode/accessors/MemberRefInfoAccessor.java index 0e0297b..2835508 100644 --- a/src/main/java/cuchaz/enigma/bytecode/accessors/MemberRefInfoAccessor.java +++ b/src/main/java/cuchaz/enigma/bytecode/accessors/MemberRefInfoAccessor.java @@ -56,10 +56,6 @@ public class MemberRefInfoAccessor { } } - public static boolean isType(ConstInfoAccessor accessor) { - return clazz.isAssignableFrom(accessor.getItem().getClass()); - } - static { try { clazz = Class.forName("javassist.bytecode.MemberrefInfo"); diff --git a/src/main/java/cuchaz/enigma/bytecode/accessors/MethodHandleInfoAccessor.java b/src/main/java/cuchaz/enigma/bytecode/accessors/MethodHandleInfoAccessor.java index 9a7dd69..a203b43 100644 --- a/src/main/java/cuchaz/enigma/bytecode/accessors/MethodHandleInfoAccessor.java +++ b/src/main/java/cuchaz/enigma/bytecode/accessors/MethodHandleInfoAccessor.java @@ -56,10 +56,6 @@ public class MethodHandleInfoAccessor { } } - public static boolean isType(ConstInfoAccessor accessor) { - return clazz.isAssignableFrom(accessor.getItem().getClass()); - } - static { try { clazz = Class.forName("javassist.bytecode.MethodHandleInfo"); diff --git a/src/main/java/cuchaz/enigma/bytecode/accessors/MethodTypeInfoAccessor.java b/src/main/java/cuchaz/enigma/bytecode/accessors/MethodTypeInfoAccessor.java index 5ec9c3b..993c79b 100644 --- a/src/main/java/cuchaz/enigma/bytecode/accessors/MethodTypeInfoAccessor.java +++ b/src/main/java/cuchaz/enigma/bytecode/accessors/MethodTypeInfoAccessor.java @@ -39,10 +39,6 @@ public class MethodTypeInfoAccessor { } } - public static boolean isType(ConstInfoAccessor accessor) { - return clazz.isAssignableFrom(accessor.getItem().getClass()); - } - static { try { clazz = Class.forName("javassist.bytecode.MethodTypeInfo"); diff --git a/src/main/java/cuchaz/enigma/bytecode/accessors/NameAndTypeInfoAccessor.java b/src/main/java/cuchaz/enigma/bytecode/accessors/NameAndTypeInfoAccessor.java index 95df37c..d6c2531 100644 --- a/src/main/java/cuchaz/enigma/bytecode/accessors/NameAndTypeInfoAccessor.java +++ b/src/main/java/cuchaz/enigma/bytecode/accessors/NameAndTypeInfoAccessor.java @@ -56,10 +56,6 @@ public class NameAndTypeInfoAccessor { } } - public static boolean isType(ConstInfoAccessor accessor) { - return clazz.isAssignableFrom(accessor.getItem().getClass()); - } - static { try { clazz = Class.forName("javassist.bytecode.NameAndTypeInfo"); diff --git a/src/main/java/cuchaz/enigma/bytecode/accessors/StringInfoAccessor.java b/src/main/java/cuchaz/enigma/bytecode/accessors/StringInfoAccessor.java index 1c55a44..e211381 100644 --- a/src/main/java/cuchaz/enigma/bytecode/accessors/StringInfoAccessor.java +++ b/src/main/java/cuchaz/enigma/bytecode/accessors/StringInfoAccessor.java @@ -39,10 +39,6 @@ public class StringInfoAccessor { } } - public static boolean isType(ConstInfoAccessor accessor) { - return clazz.isAssignableFrom(accessor.getItem().getClass()); - } - static { try { clazz = Class.forName("javassist.bytecode.StringInfo"); diff --git a/src/main/java/cuchaz/enigma/bytecode/accessors/Utf8InfoAccessor.java b/src/main/java/cuchaz/enigma/bytecode/accessors/Utf8InfoAccessor.java deleted file mode 100644 index 7a2cb66..0000000 --- a/src/main/java/cuchaz/enigma/bytecode/accessors/Utf8InfoAccessor.java +++ /dev/null @@ -1,28 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2015 Jeff Martin. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the GNU Lesser General Public - * License v3.0 which accompanies this distribution, and is available at - * http://www.gnu.org/licenses/lgpl.html - *

- * Contributors: - * Jeff Martin - initial API and implementation - ******************************************************************************/ -package cuchaz.enigma.bytecode.accessors; - -public class Utf8InfoAccessor { - - private static Class clazz; - - static { - try { - clazz = Class.forName("javassist.bytecode.Utf8Info"); - } catch (Exception ex) { - throw new Error(ex); - } - } - - public static boolean isType(ConstInfoAccessor accessor) { - return clazz.isAssignableFrom(accessor.getItem().getClass()); - } -} -- cgit v1.2.3