1 33 package org.jruby.runtime; 34 35 import org.jruby.RubyModule; 36 import org.jruby.lexer.yacc.ISourcePosition; 37 import org.jruby.runtime.builtin.IRubyObject; 38 39 51 public class Frame { 52 56 private RubyModule klazz; 57 58 61 private IRubyObject self; 62 63 67 private String name; 68 69 73 private IRubyObject[] args; 74 75 81 private Block block; 82 83 86 private Visibility visibility = Visibility.PUBLIC; 87 88 91 private final ISourcePosition position; 92 93 public Frame(ISourcePosition position) { 94 this(null, null, null, IRubyObject.NULL_ARRAY, Block.NULL_BLOCK, position); 95 } 96 97 public Frame(RubyModule klazz, IRubyObject self, String name, 98 IRubyObject[] args, Block block, ISourcePosition position) { 99 assert block != null : "Block uses null object pattern. It should NEVER be null"; 100 101 this.self = self; 102 this.args = args; 103 this.name = name; 104 this.klazz = klazz; 105 this.position = position; 106 this.block = block; 107 } 108 109 112 IRubyObject[] getArgs() { 113 return args; 114 } 115 116 119 void setArgs(IRubyObject[] args) { 120 this.args = args; 121 } 122 123 126 ISourcePosition getPosition() { 127 return position; 128 } 129 130 135 RubyModule getKlazz() { 136 return klazz; 137 } 138 139 145 public void setKlazz(RubyModule klazz) { 146 this.klazz = klazz; 147 } 148 149 154 public void setName(String name) { 155 this.name = name; 156 } 157 158 163 String getName() { 164 return name; 165 } 166 167 172 IRubyObject getSelf() { 173 return self; 174 } 175 176 181 void setSelf(IRubyObject self) { 182 this.self = self; 183 } 184 185 190 public Visibility getVisibility() { 191 return visibility; 192 } 193 194 199 public void setVisibility(Visibility visibility) { 200 this.visibility = visibility; 201 } 202 203 208 public Block getBlock() { 209 return block; 210 } 211 212 public Frame duplicate() { 213 IRubyObject[] newArgs; 214 if (args.length != 0) { 215 newArgs = new IRubyObject[args.length]; 216 System.arraycopy(args, 0, newArgs, 0, args.length); 217 } else { 218 newArgs = args; 219 } 220 221 return new Frame(klazz, self, name, newArgs, block, position); 222 } 223 224 227 public String toString() { 228 StringBuffer sb = new StringBuffer (50); 229 sb.append(position != null ? position.toString() : "-1"); 230 sb.append(':'); 231 sb.append(klazz + " " + name); 232 if (name != null) { 233 sb.append("in "); 234 sb.append(name); 235 } 236 return sb.toString(); 237 } 238 } 239 | Popular Tags |