From 59e189bef2b5e6d129fb7c2c988ed0b2130e36ac Mon Sep 17 00:00:00 2001
From: lclc98
Date: Mon, 4 Jul 2016 18:14:22 +1000
Subject: Reformat
---
.../cuchaz/enigma/bytecode/CheckCastIterator.java | 113 ---------------------
.../cuchaz/enigma/bytecode/ConstPoolEditor.java | 26 -----
src/main/java/cuchaz/enigma/bytecode/InfoType.java | 62 +++--------
.../bytecode/accessors/ConstInfoAccessor.java | 47 +--------
4 files changed, 17 insertions(+), 231 deletions(-)
delete mode 100644 src/main/java/cuchaz/enigma/bytecode/CheckCastIterator.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
deleted file mode 100644
index c47a770..0000000
--- a/src/main/java/cuchaz/enigma/bytecode/CheckCastIterator.java
+++ /dev/null
@@ -1,113 +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;
-
-import java.util.Iterator;
-
-import cuchaz.enigma.bytecode.CheckCastIterator.CheckCast;
-import cuchaz.enigma.mapping.ClassEntry;
-import cuchaz.enigma.mapping.MethodEntry;
-import cuchaz.enigma.mapping.Signature;
-import javassist.bytecode.*;
-
-public class CheckCastIterator implements Iterator {
-
- public static class CheckCast {
-
- public final String className;
- public final MethodEntry prevMethodEntry;
-
- public CheckCast(String className, MethodEntry prevMethodEntry) {
- this.className = className;
- this.prevMethodEntry = prevMethodEntry;
- }
- }
-
- private final ConstPool constants;
- private final CodeAttribute attribute;
- private final CodeIterator iter;
- private CheckCast next;
-
- public CheckCastIterator(CodeAttribute codeAttribute) throws BadBytecode {
- this.constants = codeAttribute.getConstPool();
- this.attribute = codeAttribute;
- this.iter = this.attribute.iterator();
-
- this.next = getNext();
- }
-
- @Override
- public boolean hasNext() {
- return this.next != null;
- }
-
- @Override
- public CheckCast next() {
- CheckCast out = this.next;
- try {
- this.next = getNext();
- } catch (BadBytecode ex) {
- throw new Error(ex);
- }
- return out;
- }
-
- @Override
- public void remove() {
- throw new UnsupportedOperationException();
- }
-
- private CheckCast getNext() throws BadBytecode {
- int prevPos = 0;
- while (this.iter.hasNext()) {
- int pos = this.iter.next();
- int opcode = this.iter.byteAt(pos);
- switch (opcode) {
- case Opcode.CHECKCAST:
-
- // get the type of this op code (next two bytes are a classinfo index)
- MethodEntry prevMethodEntry = getMethodEntry(prevPos);
- if (prevMethodEntry != null) {
- return new CheckCast(this.constants.getClassInfo(this.iter.s16bitAt(pos + 1)), prevMethodEntry);
- }
- break;
- }
- prevPos = pos;
- }
- return null;
- }
-
- private MethodEntry getMethodEntry(int pos) {
- switch (this.iter.byteAt(pos)) {
- case Opcode.INVOKEVIRTUAL:
- case Opcode.INVOKESTATIC:
- case Opcode.INVOKEDYNAMIC:
- case Opcode.INVOKESPECIAL: {
- int index = this.iter.s16bitAt(pos + 1);
- return new MethodEntry(
- new ClassEntry(Descriptor.toJvmName(this.constants.getMethodrefClassName(index))),
- this.constants.getMethodrefName(index),
- new Signature(this.constants.getMethodrefType(index))
- );
- }
-
- case Opcode.INVOKEINTERFACE: {
- int index = this.iter.s16bitAt(pos + 1);
- return new MethodEntry(
- new ClassEntry(Descriptor.toJvmName(this.constants.getInterfaceMethodrefClassName(index))),
- this.constants.getInterfaceMethodrefName(index),
- new Signature(this.constants.getInterfaceMethodrefType(index))
- );
- }
- }
- return null;
- }
-}
diff --git a/src/main/java/cuchaz/enigma/bytecode/ConstPoolEditor.java b/src/main/java/cuchaz/enigma/bytecode/ConstPoolEditor.java
index e49ffdb..af8c79a 100644
--- a/src/main/java/cuchaz/enigma/bytecode/ConstPoolEditor.java
+++ b/src/main/java/cuchaz/enigma/bytecode/ConstPoolEditor.java
@@ -17,7 +17,6 @@ import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.HashMap;
-import cuchaz.enigma.bytecode.accessors.ClassInfoAccessor;
import cuchaz.enigma.bytecode.accessors.ConstInfoAccessor;
import cuchaz.enigma.bytecode.accessors.MemberRefInfoAccessor;
import javassist.bytecode.ConstPool;
@@ -101,32 +100,7 @@ public class ConstPoolEditor {
throw new Error(ex);
}
}
- @SuppressWarnings("rawtypes")
- public void removeLastItem() {
- try {
- // remove the item from the cache
- HashMap cache = getCache();
- if (cache != null) {
- Object item = getItem(this.pool.getSize() - 1);
- cache.remove(item);
- }
- // remove the actual item
- // based off of LongVector.addElement()
- Object item = items.get(this.pool);
- Object[][] object = (Object[][]) objects.get(items);
- int numElements = (Integer) elements.get(items) - 1;
- int nth = numElements >> 7;
- int offset = numElements & (128 - 1);
- object[nth][offset] = null;
-
- // decrement the number of items
- elements.set(item, numElements);
- numItems.set(this.pool, (Integer) numItems.get(this.pool) - 1);
- } catch (Exception ex) {
- throw new Error(ex);
- }
- }
@SuppressWarnings("rawtypes")
public HashMap getCache() {
diff --git a/src/main/java/cuchaz/enigma/bytecode/InfoType.java b/src/main/java/cuchaz/enigma/bytecode/InfoType.java
index bd9e7d1..21b0417 100644
--- a/src/main/java/cuchaz/enigma/bytecode/InfoType.java
+++ b/src/main/java/cuchaz/enigma/bytecode/InfoType.java
@@ -10,23 +10,21 @@
******************************************************************************/
package cuchaz.enigma.bytecode;
-import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import java.util.Collection;
-import java.util.List;
import java.util.Map;
import cuchaz.enigma.bytecode.accessors.*;
public enum InfoType {
- Utf8Info(1, 0),
- IntegerInfo(3, 0),
- FloatInfo(4, 0),
- LongInfo(5, 0),
- DoubleInfo(6, 0),
- ClassInfo(7, 1) {
+ Utf8Info(1),
+ IntegerInfo(3),
+ FloatInfo(4),
+ LongInfo(5),
+ DoubleInfo(6),
+ ClassInfo(7) {
@Override
public void gatherIndexTree(Collection indices, ConstPoolEditor editor, ConstInfoAccessor entry) {
ClassInfoAccessor accessor = new ClassInfoAccessor(entry.getItem());
@@ -46,7 +44,7 @@ public enum InfoType {
return nameEntry != null && nameEntry.getTag() == Utf8Info.getTag();
}
},
- StringInfo(8, 1) {
+ StringInfo(8) {
@Override
public void gatherIndexTree(Collection indices, ConstPoolEditor editor, ConstInfoAccessor entry) {
StringInfoAccessor accessor = new StringInfoAccessor(entry.getItem());
@@ -66,7 +64,7 @@ public enum InfoType {
return stringEntry != null && stringEntry.getTag() == Utf8Info.getTag();
}
},
- FieldRefInfo(9, 2) {
+ FieldRefInfo(9) {
@Override
public void gatherIndexTree(Collection indices, ConstPoolEditor editor, ConstInfoAccessor entry) {
MemberRefInfoAccessor accessor = new MemberRefInfoAccessor(entry.getItem());
@@ -90,7 +88,7 @@ public enum InfoType {
}
},
// same as FieldRefInfo
- MethodRefInfo(10, 2) {
+ MethodRefInfo(10) {
@Override
public void gatherIndexTree(Collection indices, ConstPoolEditor editor, ConstInfoAccessor entry) {
FieldRefInfo.gatherIndexTree(indices, editor, entry);
@@ -107,7 +105,7 @@ public enum InfoType {
}
},
// same as FieldRefInfo
- InterfaceMethodRefInfo(11, 2) {
+ InterfaceMethodRefInfo(11) {
@Override
public void gatherIndexTree(Collection indices, ConstPoolEditor editor, ConstInfoAccessor entry) {
FieldRefInfo.gatherIndexTree(indices, editor, entry);
@@ -123,7 +121,7 @@ public enum InfoType {
return FieldRefInfo.subIndicesAreValid(entry, pool);
}
},
- NameAndTypeInfo(12, 1) {
+ NameAndTypeInfo(12) {
@Override
public void gatherIndexTree(Collection indices, ConstPoolEditor editor, ConstInfoAccessor entry) {
NameAndTypeInfoAccessor accessor = new NameAndTypeInfoAccessor(entry.getItem());
@@ -146,7 +144,7 @@ public enum InfoType {
return nameEntry != null && nameEntry.getTag() == Utf8Info.getTag() && typeEntry != null && typeEntry.getTag() == Utf8Info.getTag();
}
},
- MethodHandleInfo(15, 3) {
+ MethodHandleInfo(15) {
@Override
public void gatherIndexTree(Collection indices, ConstPoolEditor editor, ConstInfoAccessor entry) {
MethodHandleInfoAccessor accessor = new MethodHandleInfoAccessor(entry.getItem());
@@ -169,7 +167,7 @@ public enum InfoType {
return typeEntry != null && typeEntry.getTag() == Utf8Info.getTag() && methodRefEntry != null && methodRefEntry.getTag() == MethodRefInfo.getTag();
}
},
- MethodTypeInfo(16, 1) {
+ MethodTypeInfo(16) {
@Override
public void gatherIndexTree(Collection indices, ConstPoolEditor editor, ConstInfoAccessor entry) {
MethodTypeInfoAccessor accessor = new MethodTypeInfoAccessor(entry.getItem());
@@ -189,7 +187,7 @@ public enum InfoType {
return typeEntry != null && typeEntry.getTag() == Utf8Info.getTag();
}
},
- InvokeDynamicInfo(18, 2) {
+ InvokeDynamicInfo(18) {
@Override
public void gatherIndexTree(Collection indices, ConstPoolEditor editor, ConstInfoAccessor entry) {
InvokeDynamicInfoAccessor accessor = new InvokeDynamicInfoAccessor(entry.getItem());
@@ -223,21 +221,15 @@ public enum InfoType {
}
private int tag;
- private int level;
- InfoType(int tag, int level) {
+ InfoType(int tag) {
this.tag = tag;
- this.level = level;
}
public int getTag() {
return this.tag;
}
- public int getLevel() {
- return this.level;
- }
-
public void gatherIndexTree(Collection indices, ConstPoolEditor editor, ConstInfoAccessor entry) {
// by default, do nothing
}
@@ -251,34 +243,10 @@ public enum InfoType {
return true;
}
- public boolean selfIndexIsValid(ConstInfoAccessor entry, ConstPoolEditor pool) {
- ConstInfoAccessor entryCheck = pool.getItem(entry.getIndex());
- return entryCheck != null && entryCheck.getItem().equals(entry.getItem());
- }
-
public static InfoType getByTag(int tag) {
return types.get(tag);
}
- public static List getByLevel(int level) {
- List types = Lists.newArrayList();
- for (InfoType type : values()) {
- if (type.getLevel() == level) {
- types.add(type);
- }
- }
- return types;
- }
-
- public static List getSortedByLevel() {
- List types = Lists.newArrayList();
- types.addAll(getByLevel(0));
- types.addAll(getByLevel(1));
- types.addAll(getByLevel(2));
- types.addAll(getByLevel(3));
- return types;
- }
-
public static void gatherIndexTree(Collection indices, ConstPoolEditor editor, int index) {
// add own index
indices.add(index);
diff --git a/src/main/java/cuchaz/enigma/bytecode/accessors/ConstInfoAccessor.java b/src/main/java/cuchaz/enigma/bytecode/accessors/ConstInfoAccessor.java
index 2ecda1d..0ea2d02 100644
--- a/src/main/java/cuchaz/enigma/bytecode/accessors/ConstInfoAccessor.java
+++ b/src/main/java/cuchaz/enigma/bytecode/accessors/ConstInfoAccessor.java
@@ -10,8 +10,8 @@
******************************************************************************/
package cuchaz.enigma.bytecode.accessors;
-import java.io.*;
-import java.lang.reflect.Constructor;
+import java.io.ByteArrayOutputStream;
+import java.io.PrintWriter;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
@@ -32,26 +32,6 @@ public class ConstInfoAccessor {
this.item = item;
}
- public ConstInfoAccessor(DataInputStream in) throws IOException {
- try {
- // read the entry
- String className = in.readUTF();
- int oldIndex = in.readInt();
-
- // NOTE: ConstInfo instances write a type id (a "tag"), but they don't read it back
- // so we have to read it here
- in.readByte();
-
- Constructor> constructor = Class.forName(className).getConstructor(DataInputStream.class, int.class);
- constructor.setAccessible(true);
- this.item = constructor.newInstance(in, oldIndex);
- } catch (IOException ex) {
- throw ex;
- } catch (Exception ex) {
- throw new Error(ex);
- }
- }
-
public Object getItem() {
return this.item;
}
@@ -64,14 +44,6 @@ public class ConstInfoAccessor {
}
}
- public void setIndex(int val) {
- try {
- index.set(this.item, val);
- } catch (Exception ex) {
- throw new Error(ex);
- }
- }
-
public int getTag() {
try {
return (Integer) getTag.invoke(this.item);
@@ -80,21 +52,6 @@ public class ConstInfoAccessor {
}
}
- public void write(DataOutputStream out) throws IOException {
- try {
- out.writeUTF(this.item.getClass().getName());
- out.writeInt(getIndex());
-
- Method method = this.item.getClass().getMethod("write", DataOutputStream.class);
- method.setAccessible(true);
- method.invoke(this.item, out);
- } catch (IOException ex) {
- throw ex;
- } catch (Exception ex) {
- throw new Error(ex);
- }
- }
-
@Override
public String toString() {
try {
--
cgit v1.2.3