DNode.java

  1. package org.jruby.ast;

  2. import org.jcodings.Encoding;
  3. import org.jcodings.specific.ASCIIEncoding;
  4. import org.jruby.lexer.yacc.ISourcePosition;

  5. /**
  6.  * Base class for all D (e.g. Dynamic) node types like DStrNode, DSymbolNode, etc...
  7.  */
  8. public abstract class DNode extends ListNode {
  9.     protected Encoding encoding;

  10.     public DNode(ISourcePosition position) {
  11.         // FIXME: I believe this possibly should be default parsed encoding but this is
  12.         // what we currently default to if we happen to receive a null encoding.  This is
  13.         // an attempt to at least always have a valid encoding set to something.
  14.         this(position, ASCIIEncoding.INSTANCE);
  15.     }

  16.     public DNode(ISourcePosition position, Encoding encoding) {
  17.         super(position);

  18.         assert encoding != null: "" + getClass().getName() + " passed in a null encoding";

  19.         this.encoding = encoding;
  20.     }

  21.     public Encoding getEncoding() {
  22.         return encoding;
  23.     }
  24. }