src/java.xml/share/classes/com/sun/org/apache/bcel/internal/classfile/Constant.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
/*
55496
8e0ae3830fca 8224157: BCEL: update to version 6.3.1
joehw
parents: 47216
diff changeset
     2
 * Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
6
7f561c08de6b Initial load
duke
parents:
diff changeset
     3
 */
44797
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
     4
/*
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
     5
 * 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
     6
 * contributor license agreements.  See the NOTICE file distributed with
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
     7
 * this work for additional information regarding copyright ownership.
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
     8
 * 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
     9
 * (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
    10
 * 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
    11
 *
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
    12
 *      http://www.apache.org/licenses/LICENSE-2.0
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
    13
 *
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
    14
 * 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
    15
 * 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
    16
 * 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
    17
 * See the License for the specific language governing permissions and
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
    18
 * limitations under the License.
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
    19
 */
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    20
package com.sun.org.apache.bcel.internal.classfile;
7f561c08de6b Initial load
duke
parents:
diff changeset
    21
46174
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    22
import java.io.DataInput;
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    23
import java.io.DataOutputStream;
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    24
import java.io.IOException;
55496
8e0ae3830fca 8224157: BCEL: update to version 6.3.1
joehw
parents: 47216
diff changeset
    25
import java.util.Objects;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    26
46174
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    27
import com.sun.org.apache.bcel.internal.Const;
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    28
import com.sun.org.apache.bcel.internal.util.BCELComparator;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    29
7f561c08de6b Initial load
duke
parents:
diff changeset
    30
/**
55496
8e0ae3830fca 8224157: BCEL: update to version 6.3.1
joehw
parents: 47216
diff changeset
    31
 * Abstract superclass for classes to represent the different constant types
8e0ae3830fca 8224157: BCEL: update to version 6.3.1
joehw
parents: 47216
diff changeset
    32
 * in the constant pool of a class file. The classes keep closely to
8e0ae3830fca 8224157: BCEL: update to version 6.3.1
joehw
parents: 47216
diff changeset
    33
 * the JVM specification.
6
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$
8e0ae3830fca 8224157: BCEL: update to version 6.3.1
joehw
parents: 47216
diff changeset
    36
 * @LastModified: Jun 2019
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    37
 */
46174
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    38
public abstract class Constant implements Cloneable, Node {
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 static BCELComparator bcelComparator = new BCELComparator() {
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    41
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    42
        @Override
55496
8e0ae3830fca 8224157: BCEL: update to version 6.3.1
joehw
parents: 47216
diff changeset
    43
        public boolean equals( final Object o1, final Object o2 ) {
46174
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    44
            final Constant THIS = (Constant) o1;
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    45
            final Constant THAT = (Constant) o2;
55496
8e0ae3830fca 8224157: BCEL: update to version 6.3.1
joehw
parents: 47216
diff changeset
    46
            return Objects.equals(THIS.toString(), THAT.toString());
46174
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    47
        }
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    48
55496
8e0ae3830fca 8224157: BCEL: update to version 6.3.1
joehw
parents: 47216
diff changeset
    49
46174
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    50
        @Override
55496
8e0ae3830fca 8224157: BCEL: update to version 6.3.1
joehw
parents: 47216
diff changeset
    51
        public int hashCode( final Object o ) {
46174
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    52
            final Constant THIS = (Constant) o;
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    53
            return THIS.toString().hashCode();
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
    };
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    56
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    57
    /* In fact this tag is redundant since we can distinguish different
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    58
     * `Constant' objects by their type, i.e., via `instanceof'. In some
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    59
     * places we will use the tag for switch()es anyway.
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
     * First, we want match the specification as closely as possible. Second we
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    62
     * need the tag as an index to select the corresponding class name from the
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    63
     * `CONSTANT_NAMES' array.
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    64
     */
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    65
    private byte tag;
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    66
55496
8e0ae3830fca 8224157: BCEL: update to version 6.3.1
joehw
parents: 47216
diff changeset
    67
46174
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    68
    Constant(final byte tag) {
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    69
        this.tag = tag;
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    70
    }
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    71
55496
8e0ae3830fca 8224157: BCEL: update to version 6.3.1
joehw
parents: 47216
diff changeset
    72
46174
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    73
    /**
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    74
     * 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
    75
     * 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
    76
     * fields, attributes, etc. spawns a tree of objects.
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    77
     *
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    78
     * @param v Visitor object
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    79
     */
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    80
    @Override
55496
8e0ae3830fca 8224157: BCEL: update to version 6.3.1
joehw
parents: 47216
diff changeset
    81
    public abstract void accept( Visitor v );
8e0ae3830fca 8224157: BCEL: update to version 6.3.1
joehw
parents: 47216
diff changeset
    82
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    83
55496
8e0ae3830fca 8224157: BCEL: update to version 6.3.1
joehw
parents: 47216
diff changeset
    84
    public abstract void dump( DataOutputStream file ) throws IOException;
8e0ae3830fca 8224157: BCEL: update to version 6.3.1
joehw
parents: 47216
diff changeset
    85
46174
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    86
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
     * @return Tag of constant, i.e., its type. No setTag() method to avoid
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    89
     * confusion.
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    90
     */
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    91
    public final byte getTag() {
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    92
        return tag;
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    93
    }
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    94
55496
8e0ae3830fca 8224157: BCEL: update to version 6.3.1
joehw
parents: 47216
diff changeset
    95
46174
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    96
    /**
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    97
     * @return String representation.
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
    @Override
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
   100
    public String toString() {
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
   101
        return Const.getConstantName(tag) + "[" + tag + "]";
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
   102
    }
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   103
55496
8e0ae3830fca 8224157: BCEL: update to version 6.3.1
joehw
parents: 47216
diff changeset
   104
46174
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
   105
    /**
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
   106
     * @return deep copy of this constant
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
   107
     */
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
   108
    public Constant copy() {
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
   109
        try {
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
   110
            return (Constant) super.clone();
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
   111
        } catch (final CloneNotSupportedException e) {
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
   112
            // TODO should this throw?
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
        return null;
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
   115
    }
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   116
55496
8e0ae3830fca 8224157: BCEL: update to version 6.3.1
joehw
parents: 47216
diff changeset
   117
46174
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
   118
    @Override
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
   119
    public Object clone() {
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
   120
        try {
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
   121
            return super.clone();
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
   122
        } catch (final CloneNotSupportedException e) {
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
   123
            throw new Error("Clone Not Supported"); // never happens
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
   124
        }
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
   125
    }
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   126
55496
8e0ae3830fca 8224157: BCEL: update to version 6.3.1
joehw
parents: 47216
diff changeset
   127
46174
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
     * Read one constant from the given input, the type depends on a tag byte.
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
   130
     *
55496
8e0ae3830fca 8224157: BCEL: update to version 6.3.1
joehw
parents: 47216
diff changeset
   131
     * @param dataInput Input stream
46174
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
   132
     * @return Constant object
55496
8e0ae3830fca 8224157: BCEL: update to version 6.3.1
joehw
parents: 47216
diff changeset
   133
     * @throws IOException if an I/O error occurs reading from the given {@code dataInput}.
8e0ae3830fca 8224157: BCEL: update to version 6.3.1
joehw
parents: 47216
diff changeset
   134
     * @throws ClassFormatException if the next byte is not recognized
46174
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
   135
     * @since 6.0 made public
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
   136
     */
55496
8e0ae3830fca 8224157: BCEL: update to version 6.3.1
joehw
parents: 47216
diff changeset
   137
    public static Constant readConstant(final DataInput dataInput) throws IOException, ClassFormatException {
8e0ae3830fca 8224157: BCEL: update to version 6.3.1
joehw
parents: 47216
diff changeset
   138
        final byte b = dataInput.readByte(); // Read tag byte
46174
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
   139
        switch (b) {
55496
8e0ae3830fca 8224157: BCEL: update to version 6.3.1
joehw
parents: 47216
diff changeset
   140
        case Const.CONSTANT_Class:
8e0ae3830fca 8224157: BCEL: update to version 6.3.1
joehw
parents: 47216
diff changeset
   141
            return new ConstantClass(dataInput);
8e0ae3830fca 8224157: BCEL: update to version 6.3.1
joehw
parents: 47216
diff changeset
   142
        case Const.CONSTANT_Fieldref:
8e0ae3830fca 8224157: BCEL: update to version 6.3.1
joehw
parents: 47216
diff changeset
   143
            return new ConstantFieldref(dataInput);
8e0ae3830fca 8224157: BCEL: update to version 6.3.1
joehw
parents: 47216
diff changeset
   144
        case Const.CONSTANT_Methodref:
8e0ae3830fca 8224157: BCEL: update to version 6.3.1
joehw
parents: 47216
diff changeset
   145
            return new ConstantMethodref(dataInput);
8e0ae3830fca 8224157: BCEL: update to version 6.3.1
joehw
parents: 47216
diff changeset
   146
        case Const.CONSTANT_InterfaceMethodref:
8e0ae3830fca 8224157: BCEL: update to version 6.3.1
joehw
parents: 47216
diff changeset
   147
            return new ConstantInterfaceMethodref(dataInput);
8e0ae3830fca 8224157: BCEL: update to version 6.3.1
joehw
parents: 47216
diff changeset
   148
        case Const.CONSTANT_String:
8e0ae3830fca 8224157: BCEL: update to version 6.3.1
joehw
parents: 47216
diff changeset
   149
            return new ConstantString(dataInput);
8e0ae3830fca 8224157: BCEL: update to version 6.3.1
joehw
parents: 47216
diff changeset
   150
        case Const.CONSTANT_Integer:
8e0ae3830fca 8224157: BCEL: update to version 6.3.1
joehw
parents: 47216
diff changeset
   151
            return new ConstantInteger(dataInput);
8e0ae3830fca 8224157: BCEL: update to version 6.3.1
joehw
parents: 47216
diff changeset
   152
        case Const.CONSTANT_Float:
8e0ae3830fca 8224157: BCEL: update to version 6.3.1
joehw
parents: 47216
diff changeset
   153
            return new ConstantFloat(dataInput);
8e0ae3830fca 8224157: BCEL: update to version 6.3.1
joehw
parents: 47216
diff changeset
   154
        case Const.CONSTANT_Long:
8e0ae3830fca 8224157: BCEL: update to version 6.3.1
joehw
parents: 47216
diff changeset
   155
            return new ConstantLong(dataInput);
8e0ae3830fca 8224157: BCEL: update to version 6.3.1
joehw
parents: 47216
diff changeset
   156
        case Const.CONSTANT_Double:
8e0ae3830fca 8224157: BCEL: update to version 6.3.1
joehw
parents: 47216
diff changeset
   157
            return new ConstantDouble(dataInput);
8e0ae3830fca 8224157: BCEL: update to version 6.3.1
joehw
parents: 47216
diff changeset
   158
        case Const.CONSTANT_NameAndType:
8e0ae3830fca 8224157: BCEL: update to version 6.3.1
joehw
parents: 47216
diff changeset
   159
            return new ConstantNameAndType(dataInput);
8e0ae3830fca 8224157: BCEL: update to version 6.3.1
joehw
parents: 47216
diff changeset
   160
        case Const.CONSTANT_Utf8:
8e0ae3830fca 8224157: BCEL: update to version 6.3.1
joehw
parents: 47216
diff changeset
   161
            return ConstantUtf8.getInstance(dataInput);
8e0ae3830fca 8224157: BCEL: update to version 6.3.1
joehw
parents: 47216
diff changeset
   162
        case Const.CONSTANT_MethodHandle:
8e0ae3830fca 8224157: BCEL: update to version 6.3.1
joehw
parents: 47216
diff changeset
   163
            return new ConstantMethodHandle(dataInput);
8e0ae3830fca 8224157: BCEL: update to version 6.3.1
joehw
parents: 47216
diff changeset
   164
        case Const.CONSTANT_MethodType:
8e0ae3830fca 8224157: BCEL: update to version 6.3.1
joehw
parents: 47216
diff changeset
   165
            return new ConstantMethodType(dataInput);
8e0ae3830fca 8224157: BCEL: update to version 6.3.1
joehw
parents: 47216
diff changeset
   166
        case Const.CONSTANT_Dynamic:
8e0ae3830fca 8224157: BCEL: update to version 6.3.1
joehw
parents: 47216
diff changeset
   167
            return new ConstantDynamic(dataInput);
8e0ae3830fca 8224157: BCEL: update to version 6.3.1
joehw
parents: 47216
diff changeset
   168
        case Const.CONSTANT_InvokeDynamic:
8e0ae3830fca 8224157: BCEL: update to version 6.3.1
joehw
parents: 47216
diff changeset
   169
            return new ConstantInvokeDynamic(dataInput);
8e0ae3830fca 8224157: BCEL: update to version 6.3.1
joehw
parents: 47216
diff changeset
   170
        case Const.CONSTANT_Module:
8e0ae3830fca 8224157: BCEL: update to version 6.3.1
joehw
parents: 47216
diff changeset
   171
            return new ConstantModule(dataInput);
8e0ae3830fca 8224157: BCEL: update to version 6.3.1
joehw
parents: 47216
diff changeset
   172
        case Const.CONSTANT_Package:
8e0ae3830fca 8224157: BCEL: update to version 6.3.1
joehw
parents: 47216
diff changeset
   173
            return new ConstantPackage(dataInput);
8e0ae3830fca 8224157: BCEL: update to version 6.3.1
joehw
parents: 47216
diff changeset
   174
        default:
8e0ae3830fca 8224157: BCEL: update to version 6.3.1
joehw
parents: 47216
diff changeset
   175
            throw new ClassFormatException("Invalid byte tag in constant pool: " + b);
46174
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
   176
        }
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
   177
    }
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   178
46174
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
   179
    /**
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
   180
     * @return Comparison strategy object
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
   181
     */
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
   182
    public static BCELComparator getComparator() {
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
   183
        return bcelComparator;
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
   184
    }
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
   185
55496
8e0ae3830fca 8224157: BCEL: update to version 6.3.1
joehw
parents: 47216
diff changeset
   186
46174
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
   187
    /**
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
   188
     * @param comparator Comparison strategy object
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
   189
     */
55496
8e0ae3830fca 8224157: BCEL: update to version 6.3.1
joehw
parents: 47216
diff changeset
   190
    public static void setComparator( final BCELComparator comparator ) {
46174
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
   191
        bcelComparator = comparator;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   192
    }
46174
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
   193
55496
8e0ae3830fca 8224157: BCEL: update to version 6.3.1
joehw
parents: 47216
diff changeset
   194
46174
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
   195
    /**
55496
8e0ae3830fca 8224157: BCEL: update to version 6.3.1
joehw
parents: 47216
diff changeset
   196
     * Return value as defined by given BCELComparator strategy.
8e0ae3830fca 8224157: BCEL: update to version 6.3.1
joehw
parents: 47216
diff changeset
   197
     * By default two Constant objects are said to be equal when
8e0ae3830fca 8224157: BCEL: update to version 6.3.1
joehw
parents: 47216
diff changeset
   198
     * the result of toString() is equal.
46174
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
   199
     *
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
   200
     * @see java.lang.Object#equals(java.lang.Object)
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
   201
     */
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
   202
    @Override
55496
8e0ae3830fca 8224157: BCEL: update to version 6.3.1
joehw
parents: 47216
diff changeset
   203
    public boolean equals( final Object obj ) {
46174
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
   204
        return bcelComparator.equals(this, obj);
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
   205
    }
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
   206
55496
8e0ae3830fca 8224157: BCEL: update to version 6.3.1
joehw
parents: 47216
diff changeset
   207
46174
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
   208
    /**
55496
8e0ae3830fca 8224157: BCEL: update to version 6.3.1
joehw
parents: 47216
diff changeset
   209
     * Return value as defined by given BCELComparator strategy.
8e0ae3830fca 8224157: BCEL: update to version 6.3.1
joehw
parents: 47216
diff changeset
   210
     * By default return the hashcode of the result of toString().
46174
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
   211
     *
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
   212
     * @see java.lang.Object#hashCode()
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
   213
     */
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
   214
    @Override
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
   215
    public int hashCode() {
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
   216
        return bcelComparator.hashCode(this);
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
   217
    }
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   218
}