⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 singletontype.java

📁 A framework written in Java for implementing high-level and dynamic languages, compiling them into J
💻 JAVA
字号:
// Copyright (c) 2006  Per M.A. Bothner.// This is free software;  for terms and warranty disclaimer see ./COPYING.package gnu.kawa.reflect;import gnu.bytecode.*;import gnu.mapping.*;import gnu.expr.*;public class SingletonType extends ObjectType // implements TypeValue{  static final SingletonType instance = new SingletonType("singleton");  public SingletonType (String name)  {    super(name);  }  public static final SingletonType getInstance () { return instance; }  public java.lang.Class getReflectClass()  {    return getImplementationType().getReflectClass();  }  public Type getImplementationType ()  {    return Type.pointer_type;  }  public int compare(Type other)  {    int otherRange = OccurrenceType.itemCountRange(other);    int otherMin = otherRange & 0xfff;    int otherMax = otherRange >> 12;    if (otherMax == 0 || otherMin > 1)      return -3;    if (otherMin == 1 && otherMax == 1)      return Type.pointer_type.compare(other);    int cmp = Type.pointer_type.compare(other);    if (cmp == 0 || cmp == -1)      return -1;    return -2;  }  public static Object coerceToSingleton (Object obj)  {    if (obj instanceof Values)      obj = ((Values) obj).canonicalize();    if (obj == null || obj instanceof Values)      throw new ClassCastException("value is not a singleton");    return obj;  }  public Object coerceFromObject (Object obj)  {    return coerceToSingleton(obj);  }  public void emitCoerceFromObject (CodeAttr code)  {    code.emitInvokeStatic(ClassType.make("gnu.kawa.reflect.SingletonType")                          .getDeclaredMethod("coerceToSingleton", 1));  }  public boolean isInstance (Object obj)  {    return obj != null && ! (obj instanceof Values);  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -