jaxp/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/LineNumberGen.java
author joehw
Mon, 17 Apr 2017 16:24:10 -0700
changeset 44797 8b3b3b911b8a
parent 25868 686eef1e7a79
child 46174 5611d2529b49
permissions -rw-r--r--
8162572: Update License Header for all JAXP sources Reviewed-by: lancea
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6
7f561c08de6b Initial load
duke
parents:
diff changeset
     1
/*
7f561c08de6b Initial load
duke
parents:
diff changeset
     2
 * reserved comment block
7f561c08de6b Initial load
duke
parents:
diff changeset
     3
 * DO NOT REMOVE OR ALTER!
7f561c08de6b Initial load
duke
parents:
diff changeset
     4
 */
44797
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
     5
/*
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
     6
 * Licensed to the Apache Software Foundation (ASF) under one or more
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
     7
 * contributor license agreements.  See the NOTICE file distributed with
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
     8
 * this work for additional information regarding copyright ownership.
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
     9
 * The ASF licenses this file to You under the Apache License, Version 2.0
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
    10
 * (the "License"); you may not use this file except in compliance with
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
    11
 * the License.  You may obtain a copy of the License at
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
    12
 *
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
    13
 *      http://www.apache.org/licenses/LICENSE-2.0
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
    14
 *
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
    15
 * Unless required by applicable law or agreed to in writing, software
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
    16
 * distributed under the License is distributed on an "AS IS" BASIS,
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
    17
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
    18
 * See the License for the specific language governing permissions and
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
    19
 * limitations under the License.
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
    20
 */
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
    21
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    22
package com.sun.org.apache.bcel.internal.generic;
7f561c08de6b Initial load
duke
parents:
diff changeset
    23
7f561c08de6b Initial load
duke
parents:
diff changeset
    24
7f561c08de6b Initial load
duke
parents:
diff changeset
    25
import com.sun.org.apache.bcel.internal.classfile.*;
7f561c08de6b Initial load
duke
parents:
diff changeset
    26
7f561c08de6b Initial load
duke
parents:
diff changeset
    27
/**
7f561c08de6b Initial load
duke
parents:
diff changeset
    28
 * This class represents a line number within a method, i.e., give an instruction
7f561c08de6b Initial load
duke
parents:
diff changeset
    29
 * a line number corresponding to the source code line.
7f561c08de6b Initial load
duke
parents:
diff changeset
    30
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    31
 * @author  <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
7f561c08de6b Initial load
duke
parents:
diff changeset
    32
 * @see     LineNumber
7f561c08de6b Initial load
duke
parents:
diff changeset
    33
 * @see     MethodGen
7f561c08de6b Initial load
duke
parents:
diff changeset
    34
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    35
public class LineNumberGen
7f561c08de6b Initial load
duke
parents:
diff changeset
    36
  implements InstructionTargeter, Cloneable, java.io.Serializable
7f561c08de6b Initial load
duke
parents:
diff changeset
    37
{
7f561c08de6b Initial load
duke
parents:
diff changeset
    38
  private InstructionHandle ih;
7f561c08de6b Initial load
duke
parents:
diff changeset
    39
  private int               src_line;
7f561c08de6b Initial load
duke
parents:
diff changeset
    40
7f561c08de6b Initial load
duke
parents:
diff changeset
    41
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    42
   * Create a line number.
7f561c08de6b Initial load
duke
parents:
diff changeset
    43
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
    44
   * @param ih instruction handle to reference
7f561c08de6b Initial load
duke
parents:
diff changeset
    45
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
    46
  public LineNumberGen(InstructionHandle ih, int src_line) {
7f561c08de6b Initial load
duke
parents:
diff changeset
    47
    setInstruction(ih);
7f561c08de6b Initial load
duke
parents:
diff changeset
    48
    setSourceLine(src_line);
7f561c08de6b Initial load
duke
parents:
diff changeset
    49
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
    50
7f561c08de6b Initial load
duke
parents:
diff changeset
    51
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    52
   * @return true, if ih is target of this line number
7f561c08de6b Initial load
duke
parents:
diff changeset
    53
   */
17538
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12457
diff changeset
    54
  @Override
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    55
  public boolean containsTarget(InstructionHandle ih) {
7f561c08de6b Initial load
duke
parents:
diff changeset
    56
    return this.ih == ih;
7f561c08de6b Initial load
duke
parents:
diff changeset
    57
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
    58
7f561c08de6b Initial load
duke
parents:
diff changeset
    59
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    60
   * @param old_ih old target
7f561c08de6b Initial load
duke
parents:
diff changeset
    61
   * @param new_ih new target
7f561c08de6b Initial load
duke
parents:
diff changeset
    62
   */
17538
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12457
diff changeset
    63
  @Override
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    64
  public void updateTarget(InstructionHandle old_ih, InstructionHandle new_ih) {
7f561c08de6b Initial load
duke
parents:
diff changeset
    65
    if(old_ih != ih)
7f561c08de6b Initial load
duke
parents:
diff changeset
    66
      throw new ClassGenException("Not targeting " + old_ih + ", but " + ih + "}");
7f561c08de6b Initial load
duke
parents:
diff changeset
    67
    else
7f561c08de6b Initial load
duke
parents:
diff changeset
    68
      setInstruction(new_ih);
7f561c08de6b Initial load
duke
parents:
diff changeset
    69
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
    70
7f561c08de6b Initial load
duke
parents:
diff changeset
    71
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    72
   * Get LineNumber attribute .
7f561c08de6b Initial load
duke
parents:
diff changeset
    73
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
    74
   * This relies on that the instruction list has already been dumped to byte code or
7f561c08de6b Initial load
duke
parents:
diff changeset
    75
   * or that the `setPositions' methods has been called for the instruction list.
7f561c08de6b Initial load
duke
parents:
diff changeset
    76
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
    77
  public LineNumber getLineNumber() {
7f561c08de6b Initial load
duke
parents:
diff changeset
    78
    return new LineNumber(ih.getPosition(), src_line);
7f561c08de6b Initial load
duke
parents:
diff changeset
    79
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
    80
17538
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12457
diff changeset
    81
  public final void setInstruction(InstructionHandle ih) {
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12457
diff changeset
    82
    BranchInstruction.notifyTargetChanging(this.ih, this);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    83
    this.ih = ih;
17538
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12457
diff changeset
    84
    BranchInstruction.notifyTargetChanged(this.ih, this);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    85
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
    86
17538
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12457
diff changeset
    87
  @Override
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    88
  public Object clone() {
7f561c08de6b Initial load
duke
parents:
diff changeset
    89
    try {
7f561c08de6b Initial load
duke
parents:
diff changeset
    90
      return super.clone();
7f561c08de6b Initial load
duke
parents:
diff changeset
    91
    } catch(CloneNotSupportedException e) {
7f561c08de6b Initial load
duke
parents:
diff changeset
    92
      System.err.println(e);
7f561c08de6b Initial load
duke
parents:
diff changeset
    93
      return null;
7f561c08de6b Initial load
duke
parents:
diff changeset
    94
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
    95
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
    96
7f561c08de6b Initial load
duke
parents:
diff changeset
    97
  public InstructionHandle getInstruction()               { return ih; }
7f561c08de6b Initial load
duke
parents:
diff changeset
    98
  public void              setSourceLine(int src_line)    { this.src_line = src_line; }
7f561c08de6b Initial load
duke
parents:
diff changeset
    99
  public int               getSourceLine()                { return src_line; }
7f561c08de6b Initial load
duke
parents:
diff changeset
   100
}