hessiandebugstate.java

来自「RESIN 3.2 最新源码」· Java 代码 · 共 1,772 行 · 第 1/3 页

JAVA
1,772
字号
    int _value;    RefState(State next, String typeCode)    {      super(next);      _typeCode = typeCode;    }    RefState(State next, String typeCode, int value, int length)    {      super(next);      _typeCode = typeCode;      _value = value;      _length = length;    }    State next(int ch)    {      _value = 256 * _value + (ch & 0xff);      if (++_length == 4) {	Integer value = new Integer(_value);		if (_next.isShift(value))	  return _next.shift(value);	else {	  printObject("ref(#" + value + ")");	  	  return _next;	}      }      else	return this;    }  }    class DateState extends State {    int _length;    long _value;    DateState(State next)    {      super(next);    }              State next(int ch)    {      _value = 256 * _value + (ch & 0xff);      if (++_length == 8) {	java.util.Date value = new java.util.Date(_value);	if (_next.isShift(value))	  return _next.shift(value);	else {	  printObject(value.toString());	  	  return _next;	}      }      else	return this;    }  }    class DoubleState extends State {    int _length;    long _value;    DoubleState(State next)    {      super(next);    }        State next(int ch)    {      _value = 256 * _value + (ch & 0xff);      if (++_length == 8) {	Double value = Double.longBitsToDouble(_value);	if (_next.isShift(value))	  return _next.shift(value);	else {	  printObject(value.toString());	  	  return _next;	}      }      else	return this;    }  }    class FloatState extends State {    int _length;    int _value;    FloatState(State next)    {      super(next);    }        State next(int ch)    {      _value = 256 * _value + (ch & 0xff);      if (++_length == 4) {	Double value = (double) Float.intBitsToFloat(_value);	if (_next.isShift(value))	  return _next.shift(value);	else {	  printObject(value.toString() + "F");	  	  return _next;	}      }      else	return this;    }  }    class StringState extends State {    private static final int TOP = 0;    private static final int UTF_2_1 = 1;    private static final int UTF_3_1 = 2;    private static final int UTF_3_2 = 3;    char _typeCode;        StringBuilder _value = new StringBuilder();    int _lengthIndex;    int _length;    boolean _isLastChunk;        int _utfState;    char _ch;    StringState(State next, char typeCode, boolean isLastChunk)    {      super(next);            _typeCode = typeCode;      _isLastChunk = isLastChunk;    }    StringState(State next, char typeCode, int length)    {      super(next);            _typeCode = typeCode;      _isLastChunk = true;      _length = length;      _lengthIndex = 2;    }        State next(int ch)    {      if (_lengthIndex < 2) {	_length = 256 * _length + (ch & 0xff);		if (++_lengthIndex == 2 && _length == 0 && _isLastChunk) {	  if (_next.isShift(_value.toString()))	    return _next.shift(_value.toString());	  else {	    printObject("\"" + _value + "\"");	    return _next;	  }	}	else	  return this;      }      else if (_length == 0) {	if (ch == 's' || ch == 'x') {	  _isLastChunk = false;	  _lengthIndex = 0;	  return this;	}	else if (ch == 'S' || ch == 'X') {	  _isLastChunk = true;	  _lengthIndex = 0;	  return this;	}	else if (ch == 0x00) {	  if (_next.isShift(_value.toString()))	    return _next.shift(_value.toString());	  else {	    printObject("\"" + _value + "\"");	    return _next;	  }	}	else if (0x00 <= ch && ch < 0x20) {	  _isLastChunk = true;	  _lengthIndex = 2;	  _length = ch & 0xff;	  return this;	}	else {	  println(String.valueOf((char) ch) + ": unexpected character");	  return _next;	}      }      switch (_utfState) {      case TOP:	if (ch < 0x80) {	  _length--;	  _value.append((char) ch);	}	else if (ch < 0xe0) {	  _ch = (char) ((ch & 0x1f) << 6);	  _utfState = UTF_2_1;	}	else {	  _ch = (char) ((ch & 0xf) << 12);	  _utfState = UTF_3_1;	}	break;      case UTF_2_1:      case UTF_3_2:	_ch += ch & 0x3f;	_value.append(_ch);	_length--;	_utfState = TOP;	break;      case UTF_3_1:	_ch += (char) ((ch & 0x3f) << 6);	_utfState = UTF_3_2;	break;      }      if (_length == 0 && _isLastChunk) {	if (_next.isShift(_value.toString()))	  return _next.shift(_value.toString());	else {	  printObject("\"" + _value + "\"");	  	  return _next;	}      }      else	return this;    }  }    class BinaryState extends State {    char _typeCode;        int _totalLength;        int _lengthIndex;    int _length;    boolean _isLastChunk;        BinaryState(State next, char typeCode, boolean isLastChunk)    {      super(next);      _typeCode = typeCode;      _isLastChunk = isLastChunk;    }    BinaryState(State next, char typeCode, int length)    {      super(next);      _typeCode = typeCode;      _isLastChunk = true;      _length = length;      _lengthIndex = 2;    }        State next(int ch)    {      if (_lengthIndex < 2) {	_length = 256 * _length + (ch & 0xff);		if (++_lengthIndex == 2 && _length == 0 && _isLastChunk) {	  String value = "binary(" + _totalLength + ")";	  	  if (_next.isShift(value))	    return _next.shift(value);	  else {	    printObject(value);	    return _next;	  }	}	else	  return this;      }      else if (_length == 0) {	if (ch == 'b') {	  _isLastChunk = false;	  _lengthIndex = 0;	  return this;	}	else if (ch == 'B') {	  _isLastChunk = true;	  _lengthIndex = 0;	  return this;	}	else if (ch == 0x20) {	  String value = "binary(" + _totalLength + ")";	  	  if (_next.isShift(value))	    return _next.shift(value);	  else {	    printObject(value);	    return _next;	  }	}	else if (0x20 <=ch && ch < 0x30) {	  _isLastChunk = true;	  _lengthIndex = 2;	  _length = (ch & 0xff) - 0x20;	  return this;	}	else {	  println(String.valueOf((char) ch) + ": unexpected character");	  return _next;	}      }            _length--;      _totalLength++;      if (_length == 0 && _isLastChunk) {	String value = "binary(" + _totalLength + ")";		if (_next.isShift(value))	  return _next.shift(value);	else {	  printObject(value);	  	  return _next;	}      }      else	return this;    }  }    class MapState extends State {    private static final int TYPE = 0;    private static final int KEY = 1;    private static final int VALUE = 2;    private int _refId;    private int _state;    private int _valueDepth;    private boolean _hasData;    MapState(State next, int refId)    {      super(next);            _refId = refId;      _state = TYPE;    }    @Override    boolean isShift(Object value)    {      return _state == TYPE;    }    @Override    State shift(Object type)    {      if (_state == TYPE) {	if (type instanceof String) {	  _typeDefList.add((String) type);	}	else if (type instanceof Integer) {	  int iValue = (Integer) type;	  if (iValue >= 0 && iValue < _typeDefList.size())	    type = _typeDefList.get(iValue);	}		printObject("map " + type + "(#" + _refId + ")");	_state = VALUE;      	return this;      }      else	throw new IllegalStateException();    }    @Override    int depth()    {      if (_state == TYPE)	return _next.depth();      else if (_state == KEY)	return _next.depth() + 2;      else	return _valueDepth;    }        State next(int ch)    {      switch (_state) {      case TYPE:	if (ch == 't') {	  return new StringState(this, 't', true);	}	else if (ch == 0x75) {	  return new IndirectState(this);	}	else if (ch == 'z') {	  printObject("map (#" + _refId + ")");	  return _next;	}	else {	  printObject("map (#" + _refId + ")");	  	  _state = KEY;	  	  return nextObject(ch);	}	      case VALUE:	if (ch == 'z') {	  if (_hasData)	    println();	  	  return _next;	}	else {	  if (_hasData)	    println();	  _hasData = true;	  _state = KEY;	  	  return nextObject(ch);	}	      case KEY:	print(" => ");	_isObject = false;	_valueDepth = _column;	_state = VALUE;		return nextObject(ch);      default:	throw new IllegalStateException();      }    }  }    class ObjectDefState extends State {    private static final int TYPE = 1;    private static final int COUNT = 2;    private static final int FIELD = 3;    private static final int COMPLETE = 4;    private int _refId;    private int _state;    private boolean _hasData;    private int _count;    private String _type;    private ArrayList<String> _fields = new ArrayList<String>();    ObjectDefState(State next)    {      super(next);            _state = TYPE;    }    @Override    boolean isShift(Object value)    {      return true;    }    @Override    State shift(Object object)    {      if (_state == TYPE) {	_type = (String) object;	print("/* defun " + _type + " [");	_objectDefList.add(new ObjectDef(_type, _fields));	_state = COUNT;      }      else if (_state == COUNT) {	_count = (Integer) object;	_state = FIELD;      }      else if (_state == FIELD) {	String field = (String) object;	_count--;	_fields.add(field);	if (_fields.size() == 1)	  print(field);	else	  print(", " + field);      }      else {	throw new UnsupportedOperationException();      }      return this;    }    @Override    int depth()    {      if (_state <= TYPE)	return _next.depth();      else	return _next.depth() + 2;    }        State next(int ch)    {      switch (_state) {      case TYPE:	return nextObject(ch);	      case COUNT:	return nextObject(ch);	      case FIELD:	if (_count == 0) {	  println("] */");	  _next.printIndent(0);	  return _next.nextObject(ch);	}	else	  return nextObject(ch);      default:	throw new IllegalStateException();      }    }  }    class ObjectState extends State {    private static final int TYPE = 0;    private static final int FIELD = 1;    private int _refId;    private int _state;    private ObjectDef _def;    private int _count;    private int _fieldDepth;    ObjectState(State next, int refId)    {      super(next);      _refId = refId;      _state = TYPE;    }    @Override    boolean isShift(Object value)    {      if (_state == TYPE)	return true;      else	return false;    }    @Override

⌨️ 快捷键说明

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