src/java.xml/share/classes/com/sun/org/apache/bcel/internal/classfile/ConstantNameAndType.java
author joehw
Wed, 26 Jun 2019 05:49:59 +0000
changeset 55496 8e0ae3830fca
parent 47216 71c04702a3d5
permissions -rw-r--r--
8224157: BCEL: update to version 6.3.1 Reviewed-by: dfuchs, 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.classfile;
7f561c08de6b Initial load
duke
parents:
diff changeset
    23
46174
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    24
import java.io.DataInput;
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    25
import java.io.DataOutputStream;
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    26
import java.io.IOException;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    27
46174
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    28
import com.sun.org.apache.bcel.internal.Const;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    29
7f561c08de6b Initial load
duke
parents:
diff changeset
    30
/**
46174
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    31
 * This class is derived from the abstract {@link Constant}
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    32
 * and represents a reference to the name and signature
7f561c08de6b Initial load
duke
parents:
diff changeset
    33
 * of a field or method.
7f561c08de6b Initial load
duke
parents:
diff changeset
    34
 *
55496
8e0ae3830fca 8224157: BCEL: update to version 6.3.1
joehw
parents: 47216
diff changeset
    35
 * @version $Id$
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    36
 * @see     Constant
7f561c08de6b Initial load
duke
parents:
diff changeset
    37
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    38
public final class ConstantNameAndType extends Constant {
46174
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    39
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    40
    private int name_index; // Name of field/method
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    41
    private int signature_index; // and its signature.
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    42
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    43
46174
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    44
    /**
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    45
     * Initialize from another object.
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    46
     */
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    47
    public ConstantNameAndType(final ConstantNameAndType c) {
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    48
        this(c.getNameIndex(), c.getSignatureIndex());
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    49
    }
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    50
46174
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    51
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    52
    /**
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    53
     * Initialize instance from file data.
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    54
     *
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    55
     * @param file Input stream
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    56
     * @throws IOException
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    57
     */
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    58
    ConstantNameAndType(final DataInput file) throws IOException {
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    59
        this(file.readUnsignedShort(), file.readUnsignedShort());
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    60
    }
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    61
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    62
46174
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    63
    /**
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    64
     * @param name_index Name of field/method
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    65
     * @param signature_index and its signature
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    66
     */
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    67
    public ConstantNameAndType(final int name_index, final int signature_index) {
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    68
        super(Const.CONSTANT_NameAndType);
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    69
        this.name_index = name_index;
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    70
        this.signature_index = signature_index;
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    71
    }
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    72
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    73
46174
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    74
    /**
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    75
     * Called by objects that are traversing the nodes of the tree implicitely
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    76
     * defined by the contents of a Java class. I.e., the hierarchy of methods,
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    77
     * fields, attributes, etc. spawns a tree of objects.
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    78
     *
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    79
     * @param v Visitor object
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    80
     */
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    81
    @Override
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    82
    public void accept( final Visitor v ) {
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    83
        v.visitConstantNameAndType(this);
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    84
    }
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    85
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    86
46174
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    87
    /**
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    88
     * Dump name and signature index to file stream in binary format.
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    89
     *
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    90
     * @param file Output file stream
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    91
     * @throws IOException
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    92
     */
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    93
    @Override
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    94
    public final void dump( final DataOutputStream file ) throws IOException {
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    95
        file.writeByte(super.getTag());
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    96
        file.writeShort(name_index);
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    97
        file.writeShort(signature_index);
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    98
    }
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    99
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   100
46174
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
   101
    /**
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
   102
     * @return Name index in constant pool of field/method name.
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
   103
     */
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
   104
    public final int getNameIndex() {
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
   105
        return name_index;
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
   106
    }
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   107
7f561c08de6b Initial load
duke
parents:
diff changeset
   108
46174
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
   109
    /** @return name
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
   110
     */
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
   111
    public final String getName( final ConstantPool cp ) {
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
   112
        return cp.constantToString(getNameIndex(), Const.CONSTANT_Utf8);
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
   113
    }
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
   114
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   115
46174
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
   116
    /**
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
   117
     * @return Index in constant pool of field/method signature.
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
   118
     */
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
   119
    public final int getSignatureIndex() {
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
   120
        return signature_index;
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
   121
    }
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   122
46174
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
   123
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
   124
    /** @return signature
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
   125
     */
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
   126
    public final String getSignature( final ConstantPool cp ) {
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
   127
        return cp.constantToString(getSignatureIndex(), Const.CONSTANT_Utf8);
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
   128
    }
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
   129
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   130
46174
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
   131
    /**
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
   132
     * @param name_index the name index of this constant
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
   133
     */
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
   134
    public final void setNameIndex( final int name_index ) {
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
   135
        this.name_index = name_index;
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
   136
    }
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
   137
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   138
46174
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
   139
    /**
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
   140
     * @param signature_index the signature index in the constant pool of this type
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
   141
     */
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
   142
    public final void setSignatureIndex( final int signature_index ) {
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
   143
        this.signature_index = signature_index;
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
   144
    }
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
   145
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
   146
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
   147
    /**
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
   148
     * @return String representation
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
   149
     */
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
   150
    @Override
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
   151
    public final String toString() {
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
   152
        return super.toString() + "(name_index = " + name_index + ", signature_index = "
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
   153
                + signature_index + ")";
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
   154
    }
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   155
}