src/java.base/share/classes/jdk/internal/org/objectweb/asm/TypePath.java
author redestad
Thu, 13 Dec 2018 15:31:05 +0100
changeset 53018 8bf9268df0e2
parent 52515 746df0ae4fe1
permissions -rw-r--r--
8215281: Use String.isEmpty() when applicable in java.base Reviewed-by: dfuchs, alanb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
17420
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
     1
/*
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
     2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
     3
 *
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
     4
 * This code is free software; you can redistribute it and/or modify it
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
     5
 * under the terms of the GNU General Public License version 2 only, as
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
     6
 * published by the Free Software Foundation.  Oracle designates this
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
     7
 * particular file as subject to the "Classpath" exception as provided
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
     8
 * by Oracle in the LICENSE file that accompanied this code.
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
     9
 *
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
    10
 * This code is distributed in the hope that it will be useful, but WITHOUT
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
    11
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
    12
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
    13
 * version 2 for more details (a copy is included in the LICENSE file that
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
    14
 * accompanied this code).
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
    15
 *
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
    16
 * You should have received a copy of the GNU General Public License version
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
    17
 * 2 along with this work; if not, write to the Free Software Foundation,
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
    18
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
    19
 *
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
    20
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
    21
 * or visit www.oracle.com if you need additional information or have any
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
    22
 * questions.
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
    23
 */
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
    24
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
    25
/*
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
    26
 * This file is available under and governed by the GNU General Public
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
    27
 * License version 2 only, as published by the Free Software Foundation.
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
    28
 * However, the following notice accompanied the original version of this
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
    29
 * file:
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
    30
 *
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
    31
 * ASM: a very small and fast Java bytecode manipulation framework
52515
746df0ae4fe1 8213480: update internal ASM version to 7.0
vromero
parents: 47216
diff changeset
    32
 * Copyright (c) 2000-2011 INRIA, France Telecom
17420
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
    33
 * All rights reserved.
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
    34
 *
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
    35
 * Redistribution and use in source and binary forms, with or without
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
    36
 * modification, are permitted provided that the following conditions
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
    37
 * are met:
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
    38
 * 1. Redistributions of source code must retain the above copyright
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
    39
 *    notice, this list of conditions and the following disclaimer.
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
    40
 * 2. Redistributions in binary form must reproduce the above copyright
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
    41
 *    notice, this list of conditions and the following disclaimer in the
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
    42
 *    documentation and/or other materials provided with the distribution.
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
    43
 * 3. Neither the name of the copyright holders nor the names of its
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
    44
 *    contributors may be used to endorse or promote products derived from
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
    45
 *    this software without specific prior written permission.
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
    46
 *
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
    47
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
    48
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
    49
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
    50
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
    51
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
    52
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
    53
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
    54
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
    55
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
    56
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
    57
 * THE POSSIBILITY OF SUCH DAMAGE.
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
    58
 */
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
    59
package jdk.internal.org.objectweb.asm;
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
    60
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
    61
/**
52515
746df0ae4fe1 8213480: update internal ASM version to 7.0
vromero
parents: 47216
diff changeset
    62
 * The path to a type argument, wildcard bound, array element type, or static inner type within an
746df0ae4fe1 8213480: update internal ASM version to 7.0
vromero
parents: 47216
diff changeset
    63
 * enclosing type.
17420
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
    64
 *
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
    65
 * @author Eric Bruneton
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
    66
 */
52515
746df0ae4fe1 8213480: update internal ASM version to 7.0
vromero
parents: 47216
diff changeset
    67
public final class TypePath {
17420
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
    68
52515
746df0ae4fe1 8213480: update internal ASM version to 7.0
vromero
parents: 47216
diff changeset
    69
    /** A type path step that steps into the element type of an array type. See {@link #getStep}. */
746df0ae4fe1 8213480: update internal ASM version to 7.0
vromero
parents: 47216
diff changeset
    70
    public static final int ARRAY_ELEMENT = 0;
17420
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
    71
52515
746df0ae4fe1 8213480: update internal ASM version to 7.0
vromero
parents: 47216
diff changeset
    72
    /** A type path step that steps into the nested type of a class type. See {@link #getStep}. */
746df0ae4fe1 8213480: update internal ASM version to 7.0
vromero
parents: 47216
diff changeset
    73
    public static final int INNER_TYPE = 1;
17420
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
    74
52515
746df0ae4fe1 8213480: update internal ASM version to 7.0
vromero
parents: 47216
diff changeset
    75
    /** A type path step that steps into the bound of a wildcard type. See {@link #getStep}. */
746df0ae4fe1 8213480: update internal ASM version to 7.0
vromero
parents: 47216
diff changeset
    76
    public static final int WILDCARD_BOUND = 2;
746df0ae4fe1 8213480: update internal ASM version to 7.0
vromero
parents: 47216
diff changeset
    77
746df0ae4fe1 8213480: update internal ASM version to 7.0
vromero
parents: 47216
diff changeset
    78
    /** A type path step that steps into a type argument of a generic type. See {@link #getStep}. */
746df0ae4fe1 8213480: update internal ASM version to 7.0
vromero
parents: 47216
diff changeset
    79
    public static final int TYPE_ARGUMENT = 3;
17420
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
    80
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
    81
    /**
52515
746df0ae4fe1 8213480: update internal ASM version to 7.0
vromero
parents: 47216
diff changeset
    82
      * The byte array where the 'type_path' structure - as defined in the Java Virtual Machine
746df0ae4fe1 8213480: update internal ASM version to 7.0
vromero
parents: 47216
diff changeset
    83
      * Specification (JVMS) - corresponding to this TypePath is stored. The first byte of the
746df0ae4fe1 8213480: update internal ASM version to 7.0
vromero
parents: 47216
diff changeset
    84
      * structure in this array is given by {@link #typePathOffset}.
746df0ae4fe1 8213480: update internal ASM version to 7.0
vromero
parents: 47216
diff changeset
    85
      *
746df0ae4fe1 8213480: update internal ASM version to 7.0
vromero
parents: 47216
diff changeset
    86
      * @see <a
746df0ae4fe1 8213480: update internal ASM version to 7.0
vromero
parents: 47216
diff changeset
    87
      *     href="https://docs.oracle.com/javase/specs/jvms/se9/html/jvms-4.html#jvms-4.7.20.2">JVMS
746df0ae4fe1 8213480: update internal ASM version to 7.0
vromero
parents: 47216
diff changeset
    88
      *     4.7.20.2</a>
746df0ae4fe1 8213480: update internal ASM version to 7.0
vromero
parents: 47216
diff changeset
    89
      */
746df0ae4fe1 8213480: update internal ASM version to 7.0
vromero
parents: 47216
diff changeset
    90
    private final byte[] typePathContainer;
17420
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
    91
52515
746df0ae4fe1 8213480: update internal ASM version to 7.0
vromero
parents: 47216
diff changeset
    92
    /** The offset of the first byte of the type_path JVMS structure in {@link #typePathContainer}. */
746df0ae4fe1 8213480: update internal ASM version to 7.0
vromero
parents: 47216
diff changeset
    93
    private final int typePathOffset;
17420
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
    94
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
    95
    /**
52515
746df0ae4fe1 8213480: update internal ASM version to 7.0
vromero
parents: 47216
diff changeset
    96
      * Constructs a new TypePath.
746df0ae4fe1 8213480: update internal ASM version to 7.0
vromero
parents: 47216
diff changeset
    97
      *
746df0ae4fe1 8213480: update internal ASM version to 7.0
vromero
parents: 47216
diff changeset
    98
      * @param typePathContainer a byte array containing a type_path JVMS structure.
746df0ae4fe1 8213480: update internal ASM version to 7.0
vromero
parents: 47216
diff changeset
    99
      * @param typePathOffset the offset of the first byte of the type_path structure in
746df0ae4fe1 8213480: update internal ASM version to 7.0
vromero
parents: 47216
diff changeset
   100
      *     typePathContainer.
746df0ae4fe1 8213480: update internal ASM version to 7.0
vromero
parents: 47216
diff changeset
   101
      */
746df0ae4fe1 8213480: update internal ASM version to 7.0
vromero
parents: 47216
diff changeset
   102
    TypePath(final byte[] typePathContainer, final int typePathOffset) {
746df0ae4fe1 8213480: update internal ASM version to 7.0
vromero
parents: 47216
diff changeset
   103
        this.typePathContainer = typePathContainer;
746df0ae4fe1 8213480: update internal ASM version to 7.0
vromero
parents: 47216
diff changeset
   104
        this.typePathOffset = typePathOffset;
17420
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   105
    }
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   106
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   107
    /**
52515
746df0ae4fe1 8213480: update internal ASM version to 7.0
vromero
parents: 47216
diff changeset
   108
      * Returns the length of this path, i.e. its number of steps.
746df0ae4fe1 8213480: update internal ASM version to 7.0
vromero
parents: 47216
diff changeset
   109
      *
746df0ae4fe1 8213480: update internal ASM version to 7.0
vromero
parents: 47216
diff changeset
   110
      * @return the length of this path.
746df0ae4fe1 8213480: update internal ASM version to 7.0
vromero
parents: 47216
diff changeset
   111
      */
17420
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   112
    public int getLength() {
52515
746df0ae4fe1 8213480: update internal ASM version to 7.0
vromero
parents: 47216
diff changeset
   113
        // path_length is stored in the first byte of a type_path.
746df0ae4fe1 8213480: update internal ASM version to 7.0
vromero
parents: 47216
diff changeset
   114
        return typePathContainer[typePathOffset];
17420
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   115
    }
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   116
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   117
    /**
52515
746df0ae4fe1 8213480: update internal ASM version to 7.0
vromero
parents: 47216
diff changeset
   118
      * Returns the value of the given step of this path.
746df0ae4fe1 8213480: update internal ASM version to 7.0
vromero
parents: 47216
diff changeset
   119
      *
746df0ae4fe1 8213480: update internal ASM version to 7.0
vromero
parents: 47216
diff changeset
   120
      * @param index an index between 0 and {@link #getLength()}, exclusive.
746df0ae4fe1 8213480: update internal ASM version to 7.0
vromero
parents: 47216
diff changeset
   121
      * @return one of {@link #ARRAY_ELEMENT}, {@link #INNER_TYPE}, {@link #WILDCARD_BOUND}, or {@link
746df0ae4fe1 8213480: update internal ASM version to 7.0
vromero
parents: 47216
diff changeset
   122
      *     #TYPE_ARGUMENT}.
746df0ae4fe1 8213480: update internal ASM version to 7.0
vromero
parents: 47216
diff changeset
   123
      */
746df0ae4fe1 8213480: update internal ASM version to 7.0
vromero
parents: 47216
diff changeset
   124
    public int getStep(final int index) {
746df0ae4fe1 8213480: update internal ASM version to 7.0
vromero
parents: 47216
diff changeset
   125
        // Returns the type_path_kind of the path element of the given index.
746df0ae4fe1 8213480: update internal ASM version to 7.0
vromero
parents: 47216
diff changeset
   126
        return typePathContainer[typePathOffset + 2 * index + 1];
17420
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   127
    }
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   128
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   129
    /**
52515
746df0ae4fe1 8213480: update internal ASM version to 7.0
vromero
parents: 47216
diff changeset
   130
      * Returns the index of the type argument that the given step is stepping into. This method should
746df0ae4fe1 8213480: update internal ASM version to 7.0
vromero
parents: 47216
diff changeset
   131
      * only be used for steps whose value is {@link #TYPE_ARGUMENT}.
746df0ae4fe1 8213480: update internal ASM version to 7.0
vromero
parents: 47216
diff changeset
   132
      *
746df0ae4fe1 8213480: update internal ASM version to 7.0
vromero
parents: 47216
diff changeset
   133
      * @param index an index between 0 and {@link #getLength()}, exclusive.
746df0ae4fe1 8213480: update internal ASM version to 7.0
vromero
parents: 47216
diff changeset
   134
      * @return the index of the type argument that the given step is stepping into.
746df0ae4fe1 8213480: update internal ASM version to 7.0
vromero
parents: 47216
diff changeset
   135
      */
746df0ae4fe1 8213480: update internal ASM version to 7.0
vromero
parents: 47216
diff changeset
   136
    public int getStepArgument(final int index) {
746df0ae4fe1 8213480: update internal ASM version to 7.0
vromero
parents: 47216
diff changeset
   137
        // Returns the type_argument_index of the path element of the given index.
746df0ae4fe1 8213480: update internal ASM version to 7.0
vromero
parents: 47216
diff changeset
   138
        return typePathContainer[typePathOffset + 2 * index + 2];
746df0ae4fe1 8213480: update internal ASM version to 7.0
vromero
parents: 47216
diff changeset
   139
    }
746df0ae4fe1 8213480: update internal ASM version to 7.0
vromero
parents: 47216
diff changeset
   140
746df0ae4fe1 8213480: update internal ASM version to 7.0
vromero
parents: 47216
diff changeset
   141
    /**
746df0ae4fe1 8213480: update internal ASM version to 7.0
vromero
parents: 47216
diff changeset
   142
      * Converts a type path in string form, in the format used by {@link #toString()}, into a TypePath
746df0ae4fe1 8213480: update internal ASM version to 7.0
vromero
parents: 47216
diff changeset
   143
      * object.
746df0ae4fe1 8213480: update internal ASM version to 7.0
vromero
parents: 47216
diff changeset
   144
      *
746df0ae4fe1 8213480: update internal ASM version to 7.0
vromero
parents: 47216
diff changeset
   145
      * @param typePath a type path in string form, in the format used by {@link #toString()}. May be
746df0ae4fe1 8213480: update internal ASM version to 7.0
vromero
parents: 47216
diff changeset
   146
      *     {@literal null} or empty.
746df0ae4fe1 8213480: update internal ASM version to 7.0
vromero
parents: 47216
diff changeset
   147
      * @return the corresponding TypePath object, or {@literal null} if the path is empty.
746df0ae4fe1 8213480: update internal ASM version to 7.0
vromero
parents: 47216
diff changeset
   148
      */
17420
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   149
    public static TypePath fromString(final String typePath) {
53018
8bf9268df0e2 8215281: Use String.isEmpty() when applicable in java.base
redestad
parents: 52515
diff changeset
   150
        if (typePath == null || typePath.isEmpty()) {
17420
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   151
            return null;
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   152
        }
52515
746df0ae4fe1 8213480: update internal ASM version to 7.0
vromero
parents: 47216
diff changeset
   153
        int typePathLength = typePath.length();
746df0ae4fe1 8213480: update internal ASM version to 7.0
vromero
parents: 47216
diff changeset
   154
        ByteVector output = new ByteVector(typePathLength);
746df0ae4fe1 8213480: update internal ASM version to 7.0
vromero
parents: 47216
diff changeset
   155
        output.putByte(0);
746df0ae4fe1 8213480: update internal ASM version to 7.0
vromero
parents: 47216
diff changeset
   156
        int typePathIndex = 0;
746df0ae4fe1 8213480: update internal ASM version to 7.0
vromero
parents: 47216
diff changeset
   157
        while (typePathIndex < typePathLength) {
746df0ae4fe1 8213480: update internal ASM version to 7.0
vromero
parents: 47216
diff changeset
   158
            char c = typePath.charAt(typePathIndex++);
17420
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   159
            if (c == '[') {
52515
746df0ae4fe1 8213480: update internal ASM version to 7.0
vromero
parents: 47216
diff changeset
   160
                output.put11(ARRAY_ELEMENT, 0);
17420
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   161
            } else if (c == '.') {
52515
746df0ae4fe1 8213480: update internal ASM version to 7.0
vromero
parents: 47216
diff changeset
   162
                output.put11(INNER_TYPE, 0);
17420
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   163
            } else if (c == '*') {
52515
746df0ae4fe1 8213480: update internal ASM version to 7.0
vromero
parents: 47216
diff changeset
   164
                output.put11(WILDCARD_BOUND, 0);
17420
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   165
            } else if (c >= '0' && c <= '9') {
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   166
                int typeArg = c - '0';
52515
746df0ae4fe1 8213480: update internal ASM version to 7.0
vromero
parents: 47216
diff changeset
   167
                while (typePathIndex < typePathLength) {
746df0ae4fe1 8213480: update internal ASM version to 7.0
vromero
parents: 47216
diff changeset
   168
                    c = typePath.charAt(typePathIndex++);
746df0ae4fe1 8213480: update internal ASM version to 7.0
vromero
parents: 47216
diff changeset
   169
                    if (c >= '0' && c <= '9') {
746df0ae4fe1 8213480: update internal ASM version to 7.0
vromero
parents: 47216
diff changeset
   170
                        typeArg = typeArg * 10 + c - '0';
746df0ae4fe1 8213480: update internal ASM version to 7.0
vromero
parents: 47216
diff changeset
   171
                    } else if (c == ';') {
746df0ae4fe1 8213480: update internal ASM version to 7.0
vromero
parents: 47216
diff changeset
   172
                        break;
746df0ae4fe1 8213480: update internal ASM version to 7.0
vromero
parents: 47216
diff changeset
   173
                    } else {
746df0ae4fe1 8213480: update internal ASM version to 7.0
vromero
parents: 47216
diff changeset
   174
                        throw new IllegalArgumentException();
746df0ae4fe1 8213480: update internal ASM version to 7.0
vromero
parents: 47216
diff changeset
   175
                    }
17420
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   176
                }
52515
746df0ae4fe1 8213480: update internal ASM version to 7.0
vromero
parents: 47216
diff changeset
   177
                output.put11(TYPE_ARGUMENT, typeArg);
746df0ae4fe1 8213480: update internal ASM version to 7.0
vromero
parents: 47216
diff changeset
   178
            } else {
746df0ae4fe1 8213480: update internal ASM version to 7.0
vromero
parents: 47216
diff changeset
   179
                throw new IllegalArgumentException();
17420
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   180
            }
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   181
        }
52515
746df0ae4fe1 8213480: update internal ASM version to 7.0
vromero
parents: 47216
diff changeset
   182
        output.data[0] = (byte) (output.length / 2);
746df0ae4fe1 8213480: update internal ASM version to 7.0
vromero
parents: 47216
diff changeset
   183
        return new TypePath(output.data, 0);
17420
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   184
    }
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   185
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   186
    /**
52515
746df0ae4fe1 8213480: update internal ASM version to 7.0
vromero
parents: 47216
diff changeset
   187
      * Returns a string representation of this type path. {@link #ARRAY_ELEMENT} steps are represented
746df0ae4fe1 8213480: update internal ASM version to 7.0
vromero
parents: 47216
diff changeset
   188
      * with '[', {@link #INNER_TYPE} steps with '.', {@link #WILDCARD_BOUND} steps with '*' and {@link
746df0ae4fe1 8213480: update internal ASM version to 7.0
vromero
parents: 47216
diff changeset
   189
      * #TYPE_ARGUMENT} steps with their type argument index in decimal form followed by ';'.
746df0ae4fe1 8213480: update internal ASM version to 7.0
vromero
parents: 47216
diff changeset
   190
      */
17420
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   191
    @Override
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   192
    public String toString() {
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   193
        int length = getLength();
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   194
        StringBuilder result = new StringBuilder(length * 2);
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   195
        for (int i = 0; i < length; ++i) {
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   196
            switch (getStep(i)) {
52515
746df0ae4fe1 8213480: update internal ASM version to 7.0
vromero
parents: 47216
diff changeset
   197
                case ARRAY_ELEMENT:
746df0ae4fe1 8213480: update internal ASM version to 7.0
vromero
parents: 47216
diff changeset
   198
                    result.append('[');
746df0ae4fe1 8213480: update internal ASM version to 7.0
vromero
parents: 47216
diff changeset
   199
                    break;
746df0ae4fe1 8213480: update internal ASM version to 7.0
vromero
parents: 47216
diff changeset
   200
                case INNER_TYPE:
746df0ae4fe1 8213480: update internal ASM version to 7.0
vromero
parents: 47216
diff changeset
   201
                    result.append('.');
746df0ae4fe1 8213480: update internal ASM version to 7.0
vromero
parents: 47216
diff changeset
   202
                    break;
746df0ae4fe1 8213480: update internal ASM version to 7.0
vromero
parents: 47216
diff changeset
   203
                case WILDCARD_BOUND:
746df0ae4fe1 8213480: update internal ASM version to 7.0
vromero
parents: 47216
diff changeset
   204
                    result.append('*');
746df0ae4fe1 8213480: update internal ASM version to 7.0
vromero
parents: 47216
diff changeset
   205
                    break;
746df0ae4fe1 8213480: update internal ASM version to 7.0
vromero
parents: 47216
diff changeset
   206
                case TYPE_ARGUMENT:
746df0ae4fe1 8213480: update internal ASM version to 7.0
vromero
parents: 47216
diff changeset
   207
                    result.append(getStepArgument(i)).append(';');
746df0ae4fe1 8213480: update internal ASM version to 7.0
vromero
parents: 47216
diff changeset
   208
                    break;
746df0ae4fe1 8213480: update internal ASM version to 7.0
vromero
parents: 47216
diff changeset
   209
                default:
746df0ae4fe1 8213480: update internal ASM version to 7.0
vromero
parents: 47216
diff changeset
   210
                    throw new AssertionError();
17420
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   211
            }
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   212
        }
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   213
        return result.toString();
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   214
    }
52515
746df0ae4fe1 8213480: update internal ASM version to 7.0
vromero
parents: 47216
diff changeset
   215
746df0ae4fe1 8213480: update internal ASM version to 7.0
vromero
parents: 47216
diff changeset
   216
    /**
746df0ae4fe1 8213480: update internal ASM version to 7.0
vromero
parents: 47216
diff changeset
   217
      * Puts the type_path JVMS structure corresponding to the given TypePath into the given
746df0ae4fe1 8213480: update internal ASM version to 7.0
vromero
parents: 47216
diff changeset
   218
      * ByteVector.
746df0ae4fe1 8213480: update internal ASM version to 7.0
vromero
parents: 47216
diff changeset
   219
      *
746df0ae4fe1 8213480: update internal ASM version to 7.0
vromero
parents: 47216
diff changeset
   220
      * @param typePath a TypePath instance, or {@literal null} for empty paths.
746df0ae4fe1 8213480: update internal ASM version to 7.0
vromero
parents: 47216
diff changeset
   221
      * @param output where the type path must be put.
746df0ae4fe1 8213480: update internal ASM version to 7.0
vromero
parents: 47216
diff changeset
   222
      */
746df0ae4fe1 8213480: update internal ASM version to 7.0
vromero
parents: 47216
diff changeset
   223
    static void put(final TypePath typePath, final ByteVector output) {
746df0ae4fe1 8213480: update internal ASM version to 7.0
vromero
parents: 47216
diff changeset
   224
        if (typePath == null) {
746df0ae4fe1 8213480: update internal ASM version to 7.0
vromero
parents: 47216
diff changeset
   225
            output.putByte(0);
746df0ae4fe1 8213480: update internal ASM version to 7.0
vromero
parents: 47216
diff changeset
   226
        } else {
746df0ae4fe1 8213480: update internal ASM version to 7.0
vromero
parents: 47216
diff changeset
   227
            int length = typePath.typePathContainer[typePath.typePathOffset] * 2 + 1;
746df0ae4fe1 8213480: update internal ASM version to 7.0
vromero
parents: 47216
diff changeset
   228
            output.putByteArray(typePath.typePathContainer, typePath.typePathOffset, length);
746df0ae4fe1 8213480: update internal ASM version to 7.0
vromero
parents: 47216
diff changeset
   229
        }
746df0ae4fe1 8213480: update internal ASM version to 7.0
vromero
parents: 47216
diff changeset
   230
    }
17420
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   231
}