jdk/src/java.base/share/classes/jdk/internal/org/objectweb/asm/TypePath.java
author martin
Tue, 15 Sep 2015 21:56:04 -0700
changeset 32649 2ee9017c7597
parent 27195 b33768211561
child 36635 f0147be2f50f
permissions -rw-r--r--
8136583: Core libraries should use blessed modifier order Summary: Run blessed-modifier-order script (see bug) Reviewed-by: psandoz, chegar, alanb, plevart
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
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
    32
 * Copyright (c) 2000-2013 INRIA, France Telecom
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
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
    60
package jdk.internal.org.objectweb.asm;
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
    61
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
    62
/**
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
    63
 * The path to a type argument, wildcard bound, array element type, or static
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
    64
 * inner type within an enclosing type.
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
    65
 *
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
    66
 * @author Eric Bruneton
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
    67
 */
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
    68
public class TypePath {
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
    69
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
    70
    /**
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
    71
     * A type path step that steps into the element type of an array type. See
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
    72
     * {@link #getStep getStep}.
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
    73
     */
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 27195
diff changeset
    74
    public static final int ARRAY_ELEMENT = 0;
17420
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
    75
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
    76
    /**
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
    77
     * A type path step that steps into the nested type of a class type. See
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
    78
     * {@link #getStep getStep}.
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
    79
     */
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 27195
diff changeset
    80
    public static final int INNER_TYPE = 1;
17420
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
    81
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
    82
    /**
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
    83
     * A type path step that steps into the bound of a wildcard type. See
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
    84
     * {@link #getStep getStep}.
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
    85
     */
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 27195
diff changeset
    86
    public static final int WILDCARD_BOUND = 2;
17420
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
    87
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
    88
    /**
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
    89
     * A type path step that steps into a type argument of a generic type. See
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
    90
     * {@link #getStep getStep}.
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
    91
     */
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 27195
diff changeset
    92
    public static final int TYPE_ARGUMENT = 3;
17420
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
    93
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
     * The byte array where the path is stored, in Java class file format.
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
    96
     */
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
    97
    byte[] b;
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
    98
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
    99
    /**
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   100
     * The offset of the first byte of the type path in 'b'.
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   101
     */
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   102
    int offset;
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   103
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   104
    /**
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   105
     * Creates a new type path.
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
     * @param b
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   108
     *            the byte array containing the type path in Java class file
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   109
     *            format.
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   110
     * @param offset
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   111
     *            the offset of the first byte of the type path in 'b'.
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   112
     */
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   113
    TypePath(byte[] b, int offset) {
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   114
        this.b = b;
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   115
        this.offset = offset;
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
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   118
    /**
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   119
     * Returns the length of this path.
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   120
     *
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   121
     * @return the length of this path.
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   122
     */
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   123
    public int getLength() {
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   124
        return b[offset];
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   125
    }
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   126
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
     * Returns the value of the given step of this path.
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   129
     *
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   130
     * @param index
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   131
     *            an index between 0 and {@link #getLength()}, exclusive.
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   132
     * @return {@link #ARRAY_ELEMENT ARRAY_ELEMENT}, {@link #INNER_TYPE
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   133
     *         INNER_TYPE}, {@link #WILDCARD_BOUND WILDCARD_BOUND}, or
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   134
     *         {@link #TYPE_ARGUMENT TYPE_ARGUMENT}.
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   135
     */
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   136
    public int getStep(int index) {
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   137
        return b[offset + 2 * index + 1];
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   138
    }
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   139
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   140
    /**
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   141
     * Returns the index of the type argument that the given step is stepping
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   142
     * into. This method should only be used for steps whose value is
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   143
     * {@link #TYPE_ARGUMENT TYPE_ARGUMENT}.
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   144
     *
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   145
     * @param index
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   146
     *            an index between 0 and {@link #getLength()}, exclusive.
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   147
     * @return the index of the type argument that the given step is stepping
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   148
     *         into.
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   149
     */
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   150
    public int getStepArgument(int index) {
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   151
        return b[offset + 2 * index + 2];
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   152
    }
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   153
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   154
    /**
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   155
     * Converts a type path in string form, in the format used by
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   156
     * {@link #toString()}, into a TypePath object.
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   157
     *
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   158
     * @param typePath
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   159
     *            a type path in string form, in the format used by
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   160
     *            {@link #toString()}. May be null or empty.
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   161
     * @return the corresponding TypePath object, or null if the path is empty.
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   162
     */
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   163
    public static TypePath fromString(final String typePath) {
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   164
        if (typePath == null || typePath.length() == 0) {
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   165
            return null;
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   166
        }
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   167
        int n = typePath.length();
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   168
        ByteVector out = new ByteVector(n);
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   169
        out.putByte(0);
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   170
        for (int i = 0; i < n;) {
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   171
            char c = typePath.charAt(i++);
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   172
            if (c == '[') {
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   173
                out.put11(ARRAY_ELEMENT, 0);
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   174
            } else if (c == '.') {
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   175
                out.put11(INNER_TYPE, 0);
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   176
            } else if (c == '*') {
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   177
                out.put11(WILDCARD_BOUND, 0);
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   178
            } else if (c >= '0' && c <= '9') {
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   179
                int typeArg = c - '0';
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   180
                while (i < n && (c = typePath.charAt(i)) >= '0' && c <= '9') {
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   181
                    typeArg = typeArg * 10 + c - '0';
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   182
                    i += 1;
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   183
                }
27195
b33768211561 8061830: [asm] refresh internal ASM version v5.0.3
ksrini
parents: 25859
diff changeset
   184
                if (i < n && typePath.charAt(i) == ';') {
b33768211561 8061830: [asm] refresh internal ASM version v5.0.3
ksrini
parents: 25859
diff changeset
   185
                    i += 1;
b33768211561 8061830: [asm] refresh internal ASM version v5.0.3
ksrini
parents: 25859
diff changeset
   186
                }
17420
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   187
                out.put11(TYPE_ARGUMENT, typeArg);
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   188
            }
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   189
        }
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   190
        out.data[0] = (byte) (out.length / 2);
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   191
        return new TypePath(out.data, 0);
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   192
    }
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   193
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   194
    /**
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   195
     * Returns a string representation of this type path. {@link #ARRAY_ELEMENT
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   196
     * ARRAY_ELEMENT} steps are represented with '[', {@link #INNER_TYPE
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   197
     * INNER_TYPE} steps with '.', {@link #WILDCARD_BOUND WILDCARD_BOUND} steps
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   198
     * with '*' and {@link #TYPE_ARGUMENT TYPE_ARGUMENT} steps with their type
27195
b33768211561 8061830: [asm] refresh internal ASM version v5.0.3
ksrini
parents: 25859
diff changeset
   199
     * argument index in decimal form followed by ';'.
17420
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   200
     */
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   201
    @Override
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   202
    public String toString() {
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   203
        int length = getLength();
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   204
        StringBuilder result = new StringBuilder(length * 2);
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   205
        for (int i = 0; i < length; ++i) {
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   206
            switch (getStep(i)) {
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   207
            case ARRAY_ELEMENT:
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   208
                result.append('[');
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   209
                break;
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   210
            case INNER_TYPE:
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   211
                result.append('.');
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   212
                break;
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   213
            case WILDCARD_BOUND:
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   214
                result.append('*');
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   215
                break;
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   216
            case TYPE_ARGUMENT:
27195
b33768211561 8061830: [asm] refresh internal ASM version v5.0.3
ksrini
parents: 25859
diff changeset
   217
                result.append(getStepArgument(i)).append(';');
17420
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   218
                break;
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   219
            default:
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   220
                result.append('_');
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   221
            }
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   222
        }
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   223
        return result.toString();
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   224
    }
6163a8236046 8013225: Refresh jdk's private ASM to the latest.
ksrini
parents:
diff changeset
   225
}