hessiandebugstate.java

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

JAVA
1,772
字号
    State shift(Object object)    {      if (_state == TYPE) {	int def = (Integer) object;	_def = _objectDefList.get(def);	println("object " + _def.getType() + " (#" + _refId + ")");	_state = FIELD;	if (_def.getFields().size() == 0)	  return _next;      }      return this;    }    @Override    int depth()    {      if (_state <= TYPE)	return _next.depth();      else	return _fieldDepth;    }        State next(int ch)    {      switch (_state) {      case TYPE:	return nextObject(ch);	      case FIELD:	if (_def.getFields().size() <= _count)	  return _next.next(ch);	_fieldDepth = _next.depth() + 2;	println();	print(_def.getFields().get(_count++) + ": ");	_fieldDepth = _column;	_isObject = false;	return nextObject(ch);      default:	throw new IllegalStateException();      }    }  }    class ListState extends State {    private static final int TYPE = 0;    private static final int LENGTH = 1;    private static final int VALUE = 2;    private int _refId;    private int _state;    private boolean _hasData;    private int _count;    private int _valueDepth;    ListState(State next, int refId)    {      super(next);            _refId = refId;      _state = TYPE;    }    @Override    boolean isShift(Object value)    {      return _state == TYPE || _state == LENGTH;    }    @Override    State shift(Object object)    {      if (_state == TYPE) {	Object type = object;		if (type instanceof String) {	  _typeDefList.add((String) type);	}	else if (object instanceof Integer) {	  int index = (Integer) object;	  if (index >= 0 && index < _typeDefList.size())	    type = _typeDefList.get(index);	}		printObject("list " + type + "(#" + _refId + ")");      	_state = LENGTH;      	return this;      }      else if (_state == LENGTH) {	_state = VALUE;	return this;      }      else	return this;    }    @Override    int depth()    {      if (_state <= LENGTH)	return _next.depth();      else if (_state == VALUE)	return _valueDepth;      else	return _next.depth() + 2;    }        State next(int ch)    {      switch (_state) {      case TYPE:	if (ch == 't') {	  return new StringState(this, 't', true);	}	else if (ch == TYPE_REF) {	  return new IndirectState(this);	}	else if (ch == 'l') {	  printObject("list (#" + _refId + ")");	  _state = LENGTH;	  	  return new IntegerState(this, "length");	}	else if (ch == LENGTH_BYTE) {	  printObject("list (#" + _refId + ")");	  _state = LENGTH;	  	  return new IntegerState(this, "length", 0, 3);	}	else if (ch == 'z') {	  printObject("list (#" + _refId + ")");	  return _next;	}	else {	  printObject("list (#" + _refId + ")");	  	  _state = VALUE;	  _valueDepth = _next.depth() + 2;	  println();	  printObject(_count++ + ": ");	  _valueDepth = _column;	  _isObject = false;	  	  return nextObject(ch);	}	      case LENGTH:	if (ch == 'z') {	  return _next;	}	else if (ch == 'l') {	  return new IntegerState(this, "length");	}	else if (ch == LENGTH_BYTE) {	  return new IntegerState(this, "length", 0, 3);	}	else {	  _state = VALUE;	  	  _valueDepth = _next.depth() + 2;	  println();	  printObject(_count++ + ": ");	  _valueDepth = _column;	  _isObject = false;	  	  return nextObject(ch);	}	      case VALUE:	if (ch == 'z') {	  if (_count > 0)	    println();	  	  return _next;	}	else {	  _valueDepth = _next.depth() + 2;	  println();	  printObject(_count++ + ": ");	  _valueDepth = _column;	  _isObject = false;	  	  return nextObject(ch);	}      default:	throw new IllegalStateException();      }    }  }    class CompactListState extends State {    private static final int TYPE = 0;    private static final int LENGTH = 1;    private static final int VALUE = 2;    private int _refId;    private int _state;    private boolean _hasData;    private int _length;    private int _count;    private int _valueDepth;    CompactListState(State next, int refId)    {      super(next);            _refId = refId;      _state = TYPE;    }    @Override    boolean isShift(Object value)    {      return _state == TYPE || _state == LENGTH;    }    @Override    State shift(Object object)    {      if (_state == TYPE) {	Object type = object;		if (object instanceof Integer) {	  int index = (Integer) object;	  if (index >= 0 && index < _typeDefList.size())	    type = _typeDefList.get(index);	}		printObject("list " + type + "(#" + _refId + ")");      	_state = LENGTH;      	return this;      }      else if (_state == LENGTH) {	_length = (Integer) object;		_state = VALUE;	if (_length == 0)	  return _next;	else	  return this;      }      else	return this;    }    @Override    int depth()    {      if (_state <= LENGTH)	return _next.depth();      else if (_state == VALUE)	return _valueDepth;      else	return _next.depth() + 2;    }        State next(int ch)    {      switch (_state) {      case TYPE:	return nextObject(ch);	      case LENGTH:	return nextObject(ch);	      case VALUE:	if (_length <= _count)	  return _next.next(ch);	else {	  _valueDepth = _next.depth() + 2;	  println();	  printObject(_count++ + ": ");	  _valueDepth = _column;	  _isObject = false;	  	  return nextObject(ch);	}      default:	throw new IllegalStateException();      }    }  }    class CallState extends State {    private static final int MAJOR = 0;    private static final int MINOR = 1;    private static final int HEADER = 2;    private static final int METHOD = 3;    private static final int VALUE = 4;    private static final int ARG = 5;    private int _state;    private int _major;    private int _minor;    CallState(State next)    {      super(next);    }    int depth()    {      return _next.depth() + 2;    }        State next(int ch)    {      switch (_state) {      case MAJOR:	_major = ch;	_state = MINOR;	return this;	      case MINOR:	_minor = ch;	_state = HEADER;	println(-2, "call " + _major + "." + _minor);	return this;	      case HEADER:	if (ch == 'H') {	  println();	  print("header ");	  _isObject = false;	  _state = VALUE;	  return new StringState(this, 'H', true);	} 	else if (ch == 'm') {	  println();	  print("method ");	  _isObject = false;	  _state = ARG;	  return new StringState(this, 'm', true);	}	else {	  println((char) ch + ": unexpected char");	  return popStack();	}	      case VALUE:	print(" => ");	_isObject = false;	_state = HEADER;	return nextObject(ch);	      case ARG:	if (ch == 'z')	  return _next;	else	  return nextObject(ch);      default:	throw new IllegalStateException();      }    }  }    class ReplyState extends State {    private static final int MAJOR = 0;    private static final int MINOR = 1;    private static final int HEADER = 2;    private static final int VALUE = 3;    private static final int END = 4;    private int _state;    private int _major;    private int _minor;    ReplyState(State next)    {      _next = next;    }    int depth()    {      return _next.depth() + 2;    }        State next(int ch)    {      switch (_state) {      case MAJOR:	if (ch == 't' || ch == 'S')	  return new RemoteState(this).next(ch);		_major = ch;	_state = MINOR;	return this;	      case MINOR:	_minor = ch;	_state = HEADER;	println(-2, "reply " + _major + "." + _minor);	return this;	      case HEADER:	if (ch == 'H') {	  _state = VALUE;	  return new StringState(this, 'H', true);	}	else if (ch == 'f') {	  print("fault ");	  _isObject = false;	  _state = END;	  return new MapState(this, 0);	} 	else {	  _state = END;	  return nextObject(ch);	}	      case VALUE:	_state = HEADER;	return nextObject(ch);	      case END:	println();	if (ch == 'z') {	  return _next;	}	else	  return _next.next(ch);      default:	throw new IllegalStateException();      }    }  }    class IndirectState extends State {    IndirectState(State next)    {      super(next);    }    boolean isShift(Object object)    {      return _next.isShift(object);    }    State shift(Object object)    {      return _next.shift(object);    }        State next(int ch)    {      return nextObject(ch);    }  }    class RemoteState extends State {    private static final int TYPE = 0;    private static final int VALUE = 1;    private static final int END = 2;    private int _state;    private int _major;    private int _minor;    RemoteState(State next)    {      super(next);    }        State next(int ch)    {      switch (_state) {      case TYPE:	println(-1, "remote");	if (ch == 't') {	  _state = VALUE;	  return new StringState(this, 't', false);	}	else {	  _state = END;	  return nextObject(ch);	}      case VALUE:	_state = END;	return _next.nextObject(ch);      case END:	return _next.next(ch);      default:	throw new IllegalStateException();      }    }  }    class StreamingState extends State {    private int _digit;    private int _length;    private boolean _isLast;    private boolean _isFirst = true;    private State _childState;    StreamingState(State next, boolean isLast)    {      super(next);      _isLast = isLast;      _childState = new InitialState();    }        State next(int ch)    {      if (_digit < 2) {	_length = 256 * _length + ch;	_digit++;	if (_digit == 2 && _length == 0 && _isLast) {	  _refId = 0;	  return _next;	}	else {	  if (_digit == 2)	    println(-1, "packet-start(" + _length + ")");	  	  return this;	}      }      else if (_length == 0) {	_isLast = (ch == 'P');	_digit = 0;		return this;      }      _childState = _childState.next(ch);      _length--;      if (_length == 0 && _isLast) {	println(-1, "");	println(-1, "packet-end");	_refId = 0;	return _next;      }      else	return this;    }  }  static class ObjectDef {    private String _type;    private ArrayList<String> _fields;    ObjectDef(String type, ArrayList<String> fields)    {      _type = type;      _fields = fields;    }    String getType()    {      return _type;    }    ArrayList<String> getFields()    {      return _fields;    }  }}

⌨️ 快捷键说明

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