diff options
| author | 2015-01-13 23:25:04 -0500 | |
|---|---|---|
| committer | 2015-01-13 23:25:04 -0500 | |
| commit | 959cb5fd4f9586ec3bd265b452fe25fe1db82e3f (patch) | |
| tree | bdd8a2c52c2fe053ba3460614bde8542e5378dbe /src/cuchaz/enigma/bytecode/CheckCastIterator.java | |
| parent | got rid of gradle in favor of ivy+ssjb (diff) | |
| download | enigma-fork-959cb5fd4f9586ec3bd265b452fe25fe1db82e3f.tar.gz enigma-fork-959cb5fd4f9586ec3bd265b452fe25fe1db82e3f.tar.xz enigma-fork-959cb5fd4f9586ec3bd265b452fe25fe1db82e3f.zip | |
source format change
don't hate me too much if you were planning a big merge. =P
Diffstat (limited to 'src/cuchaz/enigma/bytecode/CheckCastIterator.java')
| -rw-r--r-- | src/cuchaz/enigma/bytecode/CheckCastIterator.java | 98 |
1 files changed, 37 insertions, 61 deletions
diff --git a/src/cuchaz/enigma/bytecode/CheckCastIterator.java b/src/cuchaz/enigma/bytecode/CheckCastIterator.java index 7ed5d7f..b6efbd4 100644 --- a/src/cuchaz/enigma/bytecode/CheckCastIterator.java +++ b/src/cuchaz/enigma/bytecode/CheckCastIterator.java | |||
| @@ -22,15 +22,14 @@ import cuchaz.enigma.bytecode.CheckCastIterator.CheckCast; | |||
| 22 | import cuchaz.enigma.mapping.ClassEntry; | 22 | import cuchaz.enigma.mapping.ClassEntry; |
| 23 | import cuchaz.enigma.mapping.MethodEntry; | 23 | import cuchaz.enigma.mapping.MethodEntry; |
| 24 | 24 | ||
| 25 | public class CheckCastIterator implements Iterator<CheckCast> | 25 | public class CheckCastIterator implements Iterator<CheckCast> { |
| 26 | { | 26 | |
| 27 | public static class CheckCast | 27 | public static class CheckCast { |
| 28 | { | 28 | |
| 29 | public String className; | 29 | public String className; |
| 30 | public MethodEntry prevMethodEntry; | 30 | public MethodEntry prevMethodEntry; |
| 31 | 31 | ||
| 32 | public CheckCast( String className, MethodEntry prevMethodEntry ) | 32 | public CheckCast(String className, MethodEntry prevMethodEntry) { |
| 33 | { | ||
| 34 | this.className = className; | 33 | this.className = className; |
| 35 | this.prevMethodEntry = prevMethodEntry; | 34 | this.prevMethodEntry = prevMethodEntry; |
| 36 | } | 35 | } |
| @@ -41,9 +40,7 @@ public class CheckCastIterator implements Iterator<CheckCast> | |||
| 41 | private CodeIterator m_iter; | 40 | private CodeIterator m_iter; |
| 42 | private CheckCast m_next; | 41 | private CheckCast m_next; |
| 43 | 42 | ||
| 44 | public CheckCastIterator( CodeAttribute codeAttribute ) | 43 | public CheckCastIterator(CodeAttribute codeAttribute) throws BadBytecode { |
| 45 | throws BadBytecode | ||
| 46 | { | ||
| 47 | m_constants = codeAttribute.getConstPool(); | 44 | m_constants = codeAttribute.getConstPool(); |
| 48 | m_attribute = codeAttribute; | 45 | m_attribute = codeAttribute; |
| 49 | m_iter = m_attribute.iterator(); | 46 | m_iter = m_attribute.iterator(); |
| @@ -52,52 +49,38 @@ public class CheckCastIterator implements Iterator<CheckCast> | |||
| 52 | } | 49 | } |
| 53 | 50 | ||
| 54 | @Override | 51 | @Override |
| 55 | public boolean hasNext( ) | 52 | public boolean hasNext() { |
| 56 | { | ||
| 57 | return m_next != null; | 53 | return m_next != null; |
| 58 | } | 54 | } |
| 59 | 55 | ||
| 60 | @Override | 56 | @Override |
| 61 | public CheckCast next( ) | 57 | public CheckCast next() { |
| 62 | { | ||
| 63 | CheckCast out = m_next; | 58 | CheckCast out = m_next; |
| 64 | try | 59 | try { |
| 65 | { | ||
| 66 | m_next = getNext(); | 60 | m_next = getNext(); |
| 67 | } | 61 | } catch (BadBytecode ex) { |
| 68 | catch( BadBytecode ex ) | 62 | throw new Error(ex); |
| 69 | { | ||
| 70 | throw new Error( ex ); | ||
| 71 | } | 63 | } |
| 72 | return out; | 64 | return out; |
| 73 | } | 65 | } |
| 74 | 66 | ||
| 75 | @Override | 67 | @Override |
| 76 | public void remove( ) | 68 | public void remove() { |
| 77 | { | ||
| 78 | throw new UnsupportedOperationException(); | 69 | throw new UnsupportedOperationException(); |
| 79 | } | 70 | } |
| 80 | 71 | ||
| 81 | private CheckCast getNext( ) | 72 | private CheckCast getNext() throws BadBytecode { |
| 82 | throws BadBytecode | ||
| 83 | { | ||
| 84 | int prevPos = 0; | 73 | int prevPos = 0; |
| 85 | while( m_iter.hasNext() ) | 74 | while (m_iter.hasNext()) { |
| 86 | { | ||
| 87 | int pos = m_iter.next(); | 75 | int pos = m_iter.next(); |
| 88 | int opcode = m_iter.byteAt( pos ); | 76 | int opcode = m_iter.byteAt(pos); |
| 89 | switch( opcode ) | 77 | switch (opcode) { |
| 90 | { | ||
| 91 | case Opcode.CHECKCAST: | 78 | case Opcode.CHECKCAST: |
| 92 | 79 | ||
| 93 | // get the type of this op code (next two bytes are a classinfo index) | 80 | // get the type of this op code (next two bytes are a classinfo index) |
| 94 | MethodEntry prevMethodEntry = getMethodEntry( prevPos ); | 81 | MethodEntry prevMethodEntry = getMethodEntry(prevPos); |
| 95 | if( prevMethodEntry != null ) | 82 | if (prevMethodEntry != null) { |
| 96 | { | 83 | return new CheckCast(m_constants.getClassInfo(m_iter.s16bitAt(pos + 1)), prevMethodEntry); |
| 97 | return new CheckCast( | ||
| 98 | m_constants.getClassInfo( m_iter.s16bitAt( pos + 1 ) ), | ||
| 99 | prevMethodEntry | ||
| 100 | ); | ||
| 101 | } | 84 | } |
| 102 | break; | 85 | break; |
| 103 | } | 86 | } |
| @@ -106,43 +89,36 @@ public class CheckCastIterator implements Iterator<CheckCast> | |||
| 106 | return null; | 89 | return null; |
| 107 | } | 90 | } |
| 108 | 91 | ||
| 109 | private MethodEntry getMethodEntry( int pos ) | 92 | private MethodEntry getMethodEntry(int pos) { |
| 110 | { | 93 | switch (m_iter.byteAt(pos)) { |
| 111 | switch( m_iter.byteAt( pos ) ) | ||
| 112 | { | ||
| 113 | case Opcode.INVOKEVIRTUAL: | 94 | case Opcode.INVOKEVIRTUAL: |
| 114 | case Opcode.INVOKESTATIC: | 95 | case Opcode.INVOKESTATIC: |
| 115 | case Opcode.INVOKEDYNAMIC: | 96 | case Opcode.INVOKEDYNAMIC: |
| 116 | case Opcode.INVOKESPECIAL: | 97 | case Opcode.INVOKESPECIAL: { |
| 117 | { | 98 | int index = m_iter.s16bitAt(pos + 1); |
| 118 | int index = m_iter.s16bitAt( pos + 1 ); | ||
| 119 | return new MethodEntry( | 99 | return new MethodEntry( |
| 120 | new ClassEntry( Descriptor.toJvmName( m_constants.getMethodrefClassName( index ) ) ), | 100 | new ClassEntry(Descriptor.toJvmName(m_constants.getMethodrefClassName(index))), |
| 121 | m_constants.getMethodrefName( index ), | 101 | m_constants.getMethodrefName(index), |
| 122 | m_constants.getMethodrefType( index ) | 102 | m_constants.getMethodrefType(index) |
| 123 | ); | 103 | ); |
| 124 | } | 104 | } |
| 125 | 105 | ||
| 126 | case Opcode.INVOKEINTERFACE: | 106 | case Opcode.INVOKEINTERFACE: { |
| 127 | { | 107 | int index = m_iter.s16bitAt(pos + 1); |
| 128 | int index = m_iter.s16bitAt( pos + 1 ); | ||
| 129 | return new MethodEntry( | 108 | return new MethodEntry( |
| 130 | new ClassEntry( Descriptor.toJvmName( m_constants.getInterfaceMethodrefClassName( index ) ) ), | 109 | new ClassEntry(Descriptor.toJvmName(m_constants.getInterfaceMethodrefClassName(index))), |
| 131 | m_constants.getInterfaceMethodrefName( index ), | 110 | m_constants.getInterfaceMethodrefName(index), |
| 132 | m_constants.getInterfaceMethodrefType( index ) | 111 | m_constants.getInterfaceMethodrefType(index) |
| 133 | ); | 112 | ); |
| 134 | } | 113 | } |
| 135 | } | 114 | } |
| 136 | return null; | 115 | return null; |
| 137 | } | 116 | } |
| 138 | 117 | ||
| 139 | public Iterable<CheckCast> casts( ) | 118 | public Iterable<CheckCast> casts() { |
| 140 | { | 119 | return new Iterable<CheckCast>() { |
| 141 | return new Iterable<CheckCast>( ) | ||
| 142 | { | ||
| 143 | @Override | 120 | @Override |
| 144 | public Iterator<CheckCast> iterator( ) | 121 | public Iterator<CheckCast> iterator() { |
| 145 | { | ||
| 146 | return CheckCastIterator.this; | 122 | return CheckCastIterator.this; |
| 147 | } | 123 | } |
| 148 | }; | 124 | }; |