diff options
Diffstat (limited to 'src/cuchaz/enigma/bytecode/accessors/InvokeDynamicInfoAccessor.java')
| -rw-r--r-- | src/cuchaz/enigma/bytecode/accessors/InvokeDynamicInfoAccessor.java | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/src/cuchaz/enigma/bytecode/accessors/InvokeDynamicInfoAccessor.java b/src/cuchaz/enigma/bytecode/accessors/InvokeDynamicInfoAccessor.java new file mode 100644 index 00000000..0d780ea6 --- /dev/null +++ b/src/cuchaz/enigma/bytecode/accessors/InvokeDynamicInfoAccessor.java | |||
| @@ -0,0 +1,74 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2014 Jeff Martin. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the GNU Public License v3.0 | ||
| 5 | * which accompanies this distribution, and is available at | ||
| 6 | * http://www.gnu.org/licenses/gpl.html | ||
| 7 | * | ||
| 8 | * Contributors: | ||
| 9 | * Jeff Martin - initial API and implementation | ||
| 10 | ******************************************************************************/ | ||
| 11 | package cuchaz.enigma.bytecode.accessors; | ||
| 12 | |||
| 13 | import java.lang.reflect.Field; | ||
| 14 | |||
| 15 | public class InvokeDynamicInfoAccessor { | ||
| 16 | |||
| 17 | private static Class<?> m_class; | ||
| 18 | private static Field m_bootstrapIndex; | ||
| 19 | private static Field m_nameAndTypeIndex; | ||
| 20 | |||
| 21 | static { | ||
| 22 | try { | ||
| 23 | m_class = Class.forName("javassist.bytecode.InvokeDynamicInfo"); | ||
| 24 | m_bootstrapIndex = m_class.getDeclaredField("bootstrap"); | ||
| 25 | m_bootstrapIndex.setAccessible(true); | ||
| 26 | m_nameAndTypeIndex = m_class.getDeclaredField("nameAndType"); | ||
| 27 | m_nameAndTypeIndex.setAccessible(true); | ||
| 28 | } catch (Exception ex) { | ||
| 29 | throw new Error(ex); | ||
| 30 | } | ||
| 31 | } | ||
| 32 | |||
| 33 | public static boolean isType(ConstInfoAccessor accessor) { | ||
| 34 | return m_class.isAssignableFrom(accessor.getItem().getClass()); | ||
| 35 | } | ||
| 36 | |||
| 37 | private Object m_item; | ||
| 38 | |||
| 39 | public InvokeDynamicInfoAccessor(Object item) { | ||
| 40 | m_item = item; | ||
| 41 | } | ||
| 42 | |||
| 43 | public int getBootstrapIndex() { | ||
| 44 | try { | ||
| 45 | return (Integer)m_bootstrapIndex.get(m_item); | ||
| 46 | } catch (Exception ex) { | ||
| 47 | throw new Error(ex); | ||
| 48 | } | ||
| 49 | } | ||
| 50 | |||
| 51 | public void setBootstrapIndex(int val) { | ||
| 52 | try { | ||
| 53 | m_bootstrapIndex.set(m_item, val); | ||
| 54 | } catch (Exception ex) { | ||
| 55 | throw new Error(ex); | ||
| 56 | } | ||
| 57 | } | ||
| 58 | |||
| 59 | public int getNameAndTypeIndex() { | ||
| 60 | try { | ||
| 61 | return (Integer)m_nameAndTypeIndex.get(m_item); | ||
| 62 | } catch (Exception ex) { | ||
| 63 | throw new Error(ex); | ||
| 64 | } | ||
| 65 | } | ||
| 66 | |||
| 67 | public void setNameAndTypeIndex(int val) { | ||
| 68 | try { | ||
| 69 | m_nameAndTypeIndex.set(m_item, val); | ||
| 70 | } catch (Exception ex) { | ||
| 71 | throw new Error(ex); | ||
| 72 | } | ||
| 73 | } | ||
| 74 | } | ||