< prev index next >

src/java.xml/share/classes/com/sun/org/apache/bcel/internal/classfile/LineNumber.java

Print this page




  13  *      http://www.apache.org/licenses/LICENSE-2.0
  14  *
  15  * Unless required by applicable law or agreed to in writing, software
  16  * distributed under the License is distributed on an "AS IS" BASIS,
  17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  18  * See the License for the specific language governing permissions and
  19  * limitations under the License.
  20  */
  21 
  22 package com.sun.org.apache.bcel.internal.classfile;
  23 
  24 import java.io.DataInput;
  25 import java.io.DataOutputStream;
  26 import java.io.IOException;
  27 
  28 /**
  29  * This class represents a (PC offset, line number) pair, i.e., a line number in
  30  * the source that corresponds to a relative address in the byte code. This
  31  * is used for debugging purposes.
  32  *
  33  * @version $Id$
  34  * @see     LineNumberTable
  35  */
  36 public final class LineNumber implements Cloneable, Node {
  37 
  38     /** Program Counter (PC) corresponds to line */
  39     private short start_pc;
  40 
  41     /** number in source file */
  42     private short line_number;
  43 
  44     /**
  45      * Initialize from another object.
  46      *
  47      * @param c the object to copy
  48      */
  49     public LineNumber(final LineNumber c) {
  50         this(c.getStartPC(), c.getLineNumber());
  51     }
  52 
  53 
  54     /**
  55      * Construct object from file stream.
  56      *
  57      * @param file Input stream
  58      * @throws IOEXception if an I/O Exception occurs in readUnsignedShort
  59      */
  60     LineNumber(final DataInput file) throws IOException {
  61         this(file.readUnsignedShort(), file.readUnsignedShort());
  62     }
  63 
  64 
  65     /**
  66      * @param start_pc Program Counter (PC) corresponds to
  67      * @param line_number line number in source file
  68      */
  69     public LineNumber(final int start_pc, final int line_number) {
  70         this.start_pc = (short) start_pc;
  71         this.line_number = (short)line_number;
  72     }
  73 
  74 
  75     /**
  76      * Called by objects that are traversing the nodes of the tree implicitely
  77      * defined by the contents of a Java class. I.e., the hierarchy of methods,
  78      * fields, attributes, etc. spawns a tree of objects.
  79      *
  80      * @param v Visitor object
  81      */
  82     @Override
  83     public void accept( final Visitor v ) {
  84         v.visitLineNumber(this);
  85     }
  86 
  87 
  88     /**
  89      * Dump line number/pc pair to file stream in binary format.
  90      *
  91      * @param file Output file stream
  92      * @throws IOEXception if an I/O Exception occurs in writeShort
  93      */
  94     public final void dump( final DataOutputStream file ) throws IOException {
  95         file.writeShort(start_pc);
  96         file.writeShort(line_number);
  97     }
  98 
  99 
 100     /**
 101      * @return Corresponding source line
 102      */
 103     public final int getLineNumber() {
 104         return 0xffff & line_number;
 105     }
 106 
 107 
 108     /**
 109      * @return PC in code
 110      */
 111     public final int getStartPC() {
 112         return  0xffff & start_pc;
 113     }
 114 
 115 
 116     /**
 117      * @param line_number the source line number
 118      */
 119     public final void setLineNumber( final int line_number ) {
 120         this.line_number = (short) line_number;
 121     }
 122 
 123 
 124     /**
 125      * @param start_pc the pc for this line number
 126      */
 127     public final void setStartPC( final int start_pc ) {
 128         this.start_pc = (short) start_pc;
 129     }
 130 
 131 
 132     /**
 133      * @return String representation
 134      */
 135     @Override
 136     public final String toString() {
 137         return "LineNumber(" + start_pc + ", " + line_number + ")";
 138     }
 139 
 140 
 141     /**
 142      * @return deep copy of this object
 143      */
 144     public LineNumber copy() {
 145         try {
 146             return (LineNumber) clone();
 147         } catch (final CloneNotSupportedException e) {
 148             // TODO should this throw?
 149         }
 150         return null;
 151     }
 152 }


  13  *      http://www.apache.org/licenses/LICENSE-2.0
  14  *
  15  * Unless required by applicable law or agreed to in writing, software
  16  * distributed under the License is distributed on an "AS IS" BASIS,
  17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  18  * See the License for the specific language governing permissions and
  19  * limitations under the License.
  20  */
  21 
  22 package com.sun.org.apache.bcel.internal.classfile;
  23 
  24 import java.io.DataInput;
  25 import java.io.DataOutputStream;
  26 import java.io.IOException;
  27 
  28 /**
  29  * This class represents a (PC offset, line number) pair, i.e., a line number in
  30  * the source that corresponds to a relative address in the byte code. This
  31  * is used for debugging purposes.
  32  *

  33  * @see     LineNumberTable
  34  */
  35 public final class LineNumber implements Cloneable, Node {
  36 
  37     /** Program Counter (PC) corresponds to line */
  38     private short start_pc;
  39 
  40     /** number in source file */
  41     private short line_number;
  42 
  43     /**
  44      * Initialize from another object.
  45      *
  46      * @param c the object to copy
  47      */
  48     public LineNumber(final LineNumber c) {
  49         this(c.getStartPC(), c.getLineNumber());
  50     }
  51 
  52 
  53     /**
  54      * Construct object from file stream.
  55      *
  56      * @param file Input stream
  57      * @throws IOException if an I/O Exception occurs in readUnsignedShort
  58      */
  59     LineNumber(final DataInput file) throws IOException {
  60         this(file.readUnsignedShort(), file.readUnsignedShort());
  61     }
  62 
  63 
  64     /**
  65      * @param start_pc Program Counter (PC) corresponds to
  66      * @param line_number line number in source file
  67      */
  68     public LineNumber(final int start_pc, final int line_number) {
  69         this.start_pc = (short) start_pc;
  70         this.line_number = (short)line_number;
  71     }
  72 
  73 
  74     /**
  75      * Called by objects that are traversing the nodes of the tree implicitely
  76      * defined by the contents of a Java class. I.e., the hierarchy of methods,
  77      * fields, attributes, etc. spawns a tree of objects.
  78      *
  79      * @param v Visitor object
  80      */
  81     @Override
  82     public void accept( final Visitor v ) {
  83         v.visitLineNumber(this);
  84     }
  85 
  86 
  87     /**
  88      * Dump line number/pc pair to file stream in binary format.
  89      *
  90      * @param file Output file stream
  91      * @throws IOException if an I/O Exception occurs in writeShort
  92      */
  93     public void dump( final DataOutputStream file ) throws IOException {
  94         file.writeShort(start_pc);
  95         file.writeShort(line_number);
  96     }
  97 
  98 
  99     /**
 100      * @return Corresponding source line
 101      */
 102     public int getLineNumber() {
 103         return 0xffff & line_number;
 104     }
 105 
 106 
 107     /**
 108      * @return PC in code
 109      */
 110     public int getStartPC() {
 111         return  0xffff & start_pc;
 112     }
 113 
 114 
 115     /**
 116      * @param line_number the source line number
 117      */
 118     public void setLineNumber( final int line_number ) {
 119         this.line_number = (short) line_number;
 120     }
 121 
 122 
 123     /**
 124      * @param start_pc the pc for this line number
 125      */
 126     public void setStartPC( final int start_pc ) {
 127         this.start_pc = (short) start_pc;
 128     }
 129 
 130 
 131     /**
 132      * @return String representation
 133      */
 134     @Override
 135     public String toString() {
 136         return "LineNumber(" + start_pc + ", " + line_number + ")";
 137     }
 138 
 139 
 140     /**
 141      * @return deep copy of this object
 142      */
 143     public LineNumber copy() {
 144         try {
 145             return (LineNumber) clone();
 146         } catch (final CloneNotSupportedException e) {
 147             // TODO should this throw?
 148         }
 149         return null;
 150     }
 151 }
< prev index next >