1 21 22 package org.armedbear.j; 23 24 import java.util.ArrayList ; 25 import org.armedbear.lisp.ConditionThrowable; 26 import org.armedbear.lisp.LispError; 27 import org.armedbear.lisp.LispObject; 28 import org.armedbear.lisp.Symbol; 29 30 public final class JVar extends LispObject 31 { 32 private static final Symbol J_VARIABLE_VALUE = 33 LispAPI.PACKAGE_J_INTERNALS.addInternalSymbol("J-VARIABLE-VALUE"); 34 35 private final Property property; 36 37 private JVar(String name, Property property) 38 { 39 this.property = property; 40 Symbol symbol = LispAPI.PACKAGE_J.findAccessibleSymbol(name); 41 if (symbol == null) 42 symbol = LispAPI.PACKAGE_J.addExternalSymbol(name); 43 try { 44 put(symbol, J_VARIABLE_VALUE, this); 45 } 46 catch (Throwable t) { 47 Log.error(t); 48 } 49 } 50 51 public Property getProperty() 52 { 53 return property; 54 } 55 56 public static JVar getJVar(Symbol symbol) throws ConditionThrowable 57 { 58 LispObject obj = get(symbol, J_VARIABLE_VALUE, null); 59 if (obj instanceof JVar) 60 return (JVar) obj; 61 throw new ConditionThrowable(new LispError(String.valueOf(symbol) + 62 " is not defined as an editor variable")); 63 } 64 65 public static synchronized void addVariableForProperty(Property property) 66 { 67 new JVar(property.getLispName(), property); 68 } 69 70 public String toString() 71 { 72 FastStringBuffer sb = new FastStringBuffer("#<J-VARIABLE @ #x"); 73 sb.append(Integer.toHexString(hashCode())); 74 sb.append(">"); 75 return sb.toString(); 76 } 77 } 78 | Popular Tags |