1 9 package com.vladium.jcd.cls; 10 11 import java.io.IOException ; 12 import java.util.ArrayList ; 13 import java.util.List ; 14 15 import com.vladium.jcd.lib.UDataOutputStream; 16 import com.vladium.util.IntVector; 17 18 22 final class MethodCollection implements IMethodCollection 23 { 24 26 28 public Method_info get (final int offset) 29 { 30 return (Method_info) m_methods.get (offset); 31 } 32 33 public int [] get (final ClassDef cls, final String name) 34 { 35 if (cls == null) throw new IllegalArgumentException ("null input: cls"); 36 37 39 final int count = m_methods.size (); final IntVector result = new IntVector (count); 41 42 for (int m = 0; m < count; ++ m) 43 { 44 final Method_info method = (Method_info) m_methods.get (m); 45 46 if (method.getName (cls).equals (name)) 47 result.add (m); 48 } 49 50 return result.values (); } 52 53 public int size () 54 { 55 return m_methods.size (); 56 } 57 58 60 63 public Object clone () 64 { 65 try 66 { 67 final MethodCollection _clone = (MethodCollection) super.clone (); 68 69 final int methods_count = m_methods.size (); _clone.m_methods = new ArrayList (methods_count); 72 for (int m = 0; m < methods_count; ++ m) 73 { 74 _clone.m_methods.add (((Method_info) m_methods.get (m)).clone ()); 75 } 76 77 return _clone; 78 } 79 catch (CloneNotSupportedException e) 80 { 81 throw new InternalError (e.toString ()); 82 } 83 } 84 85 87 public void writeInClassFormat (final UDataOutputStream out) throws IOException 88 { 89 final int methods_count = m_methods.size (); out.writeU2 (methods_count); 91 92 for (int i = 0; i < methods_count; i++) 93 { 94 get (i).writeInClassFormat (out); 95 } 96 } 97 98 100 public void accept (final IClassDefVisitor visitor, final Object ctx) 101 { 102 visitor.visit (this, ctx); 103 } 104 105 106 108 public int add (final Method_info method) 109 { 110 final int newoffset = m_methods.size (); m_methods.add (method); 112 113 return newoffset; 114 } 115 116 public Method_info set (final int offset, final Method_info method) 117 { 118 return (Method_info) m_methods.set (offset, method); 119 } 120 121 public Method_info remove (final int offset) 122 { 123 return (Method_info) m_methods.remove (offset); 124 } 125 126 128 130 131 MethodCollection (final int capacity) 132 { 133 m_methods = capacity < 0 ? new ArrayList () : new ArrayList (capacity); 134 } 135 136 138 139 private List m_methods; 141 } 144 | Popular Tags |