jaxp/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/classfile/ConstantMethodHandle.java
author joehw
Sun, 13 Aug 2017 21:10:40 -0700
changeset 46174 5611d2529b49
permissions -rw-r--r--
8163121: BCEL: update to the latest 6.0 release Reviewed-by: dfuchs, lancea
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
46174
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
     1
/*
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
     2
 * reserved comment block
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
     3
 * DO NOT REMOVE OR ALTER!
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
     4
 */
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
     5
/*
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
     6
 * Licensed to the Apache Software Foundation (ASF) under one or more
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
     7
 * contributor license agreements.  See the NOTICE file distributed with
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
     8
 * this work for additional information regarding copyright ownership.
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
     9
 * The ASF licenses this file to You under the Apache License, Version 2.0
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    10
 * (the "License"); you may not use this file except in compliance with
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    11
 * the License.  You may obtain a copy of the License at
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    12
 *
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    13
 *      http://www.apache.org/licenses/LICENSE-2.0
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    14
 *
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    15
 * Unless required by applicable law or agreed to in writing, software
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    16
 * distributed under the License is distributed on an "AS IS" BASIS,
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    17
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    18
 * See the License for the specific language governing permissions and
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    19
 * limitations under the License.
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    20
 */
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    21
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    22
package com.sun.org.apache.bcel.internal.classfile;
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    23
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    24
import java.io.DataInput;
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    25
import java.io.DataOutputStream;
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    26
import java.io.IOException;
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    27
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    28
import com.sun.org.apache.bcel.internal.Const;
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    29
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    30
/**
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    31
 * This class is derived from the abstract {@link Constant}
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    32
 * and represents a reference to a method handle.
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    33
 *
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    34
 * @see     Constant
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    35
 * @since 6.0
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    36
 */
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    37
public final class ConstantMethodHandle extends Constant {
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    38
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    39
    private int reference_kind;
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    40
    private int reference_index;
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    41
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    42
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    43
    /**
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    44
     * Initialize from another object.
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    45
     */
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    46
    public ConstantMethodHandle(final ConstantMethodHandle c) {
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    47
        this(c.getReferenceKind(), c.getReferenceIndex());
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    48
    }
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    49
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    50
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    51
    /**
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    52
     * Initialize instance from file data.
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    53
     *
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    54
     * @param file Input stream
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    55
     * @throws IOException
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    56
     */
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    57
    ConstantMethodHandle(final DataInput file) throws IOException {
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    58
        this(file.readUnsignedByte(), file.readUnsignedShort());
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    59
    }
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    60
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    61
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    62
    public ConstantMethodHandle(final int reference_kind, final int reference_index) {
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    63
        super(Const.CONSTANT_MethodHandle);
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    64
        this.reference_kind = reference_kind;
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    65
        this.reference_index = reference_index;
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    66
    }
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    67
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    68
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    69
    /**
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    70
     * Called by objects that are traversing the nodes of the tree implicitly
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    71
     * 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:
diff changeset
    72
     * fields, attributes, etc. spawns a tree of objects.
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    73
     *
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    74
     * @param v Visitor object
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    75
     */
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    76
    @Override
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    77
    public void accept( final Visitor v ) {
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    78
        v.visitConstantMethodHandle(this);
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    79
    }
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    80
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    81
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    82
    /**
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    83
     * Dump method kind and index to file stream in binary format.
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    84
     *
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    85
     * @param file Output file stream
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    86
     * @throws IOException
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    87
     */
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    88
    @Override
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    89
    public final void dump( final DataOutputStream file ) throws IOException {
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    90
        file.writeByte(super.getTag());
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    91
        file.writeByte(reference_kind);
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    92
        file.writeShort(reference_index);
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    93
    }
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    94
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    95
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    96
    public int getReferenceKind() {
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    97
        return reference_kind;
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    98
    }
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    99
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
   100
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
   101
    public void setReferenceKind(final int reference_kind) {
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
   102
        this.reference_kind = reference_kind;
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
   103
    }
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
   104
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
   105
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
   106
    public int getReferenceIndex() {
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
   107
        return reference_index;
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
   108
    }
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
   109
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
   110
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
   111
    public void setReferenceIndex(final int reference_index) {
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
   112
        this.reference_index = reference_index;
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
   113
    }
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
   114
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
   115
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
   116
    /**
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
   117
     * @return String representation
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
   118
     */
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
   119
    @Override
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
   120
    public final String toString() {
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
   121
        return super.toString() + "(reference_kind = " + reference_kind +
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
   122
                ", reference_index = " + reference_index + ")";
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
   123
    }
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
   124
}