1 /* 2 * reserved comment block 3 * DO NOT REMOVE OR ALTER! 4 */ 5 /* 6 * Licensed to the Apache Software Foundation (ASF) under one or more 7 * contributor license agreements. See the NOTICE file distributed with 8 * this work for additional information regarding copyright ownership. 9 * The ASF licenses this file to You under the Apache License, Version 2.0 10 * (the "License"); you may not use this file except in compliance with 11 * the License. You may obtain a copy of the License at 12 * 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.generic; 23 24 25 import com.sun.org.apache.bcel.internal.classfile.*; 26 27 /** 28 * This class represents a line number within a method, i.e., give an instruction 29 * a line number corresponding to the source code line. 30 * 31 * @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A> 32 * @see LineNumber 33 * @see MethodGen 34 */ 35 public class LineNumberGen 36 implements InstructionTargeter, Cloneable, java.io.Serializable 37 { 38 private InstructionHandle ih; 39 private int src_line; 40 41 /** 42 * Create a line number. 43 * 44 * @param ih instruction handle to reference 45 */ 46 public LineNumberGen(InstructionHandle ih, int src_line) { 47 setInstruction(ih); 48 setSourceLine(src_line); 49 } 50 51 /** 52 * @return true, if ih is target of this line number 53 */ 54 @Override 55 public boolean containsTarget(InstructionHandle ih) { 56 return this.ih == ih; 57 } 58 59 /** 60 * @param old_ih old target 61 * @param new_ih new target 62 */ 63 @Override 64 public void updateTarget(InstructionHandle old_ih, InstructionHandle new_ih) { 65 if(old_ih != ih) 66 throw new ClassGenException("Not targeting " + old_ih + ", but " + ih + "}"); 67 else 68 setInstruction(new_ih); 69 } 70 71 /** 72 * Get LineNumber attribute . 73 * 74 * This relies on that the instruction list has already been dumped to byte code or 75 * or that the `setPositions' methods has been called for the instruction list. 76 */ 77 public LineNumber getLineNumber() { 78 return new LineNumber(ih.getPosition(), src_line); 79 } 80 81 public final void setInstruction(InstructionHandle ih) { 82 BranchInstruction.notifyTargetChanging(this.ih, this); 83 this.ih = ih; 84 BranchInstruction.notifyTargetChanged(this.ih, this); 85 } 86 87 @Override 88 public Object clone() { 89 try { 90 return super.clone(); 91 } catch(CloneNotSupportedException e) { 92 System.err.println(e); 93 return null; 94 } 95 } 96 97 public InstructionHandle getInstruction() { return ih; } 98 public void setSourceLine(int src_line) { this.src_line = src_line; } 99 public int getSourceLine() { return src_line; } 100 }