src/java.xml/share/classes/com/sun/org/apache/bcel/internal/classfile/LocalVariableTypeTable.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:
15346
3f6fd93fec9a 8003147: port fix for BCEL bug 39695
dbuck
parents:
diff changeset
     1
/*
3f6fd93fec9a 8003147: port fix for BCEL bug 39695
dbuck
parents:
diff changeset
     2
 * reserved comment block
3f6fd93fec9a 8003147: port fix for BCEL bug 39695
dbuck
parents:
diff changeset
     3
 * DO NOT REMOVE OR ALTER!
3f6fd93fec9a 8003147: port fix for BCEL bug 39695
dbuck
parents:
diff changeset
     4
 */
46174
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 25868
diff changeset
     5
/*
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 25868
diff changeset
     6
 * Licensed to the Apache Software Foundation (ASF) under one or more
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 25868
diff changeset
     7
 * contributor license agreements.  See the NOTICE file distributed with
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 25868
diff changeset
     8
 * this work for additional information regarding copyright ownership.
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 25868
diff changeset
     9
 * The ASF licenses this file to You under the Apache License, Version 2.0
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 25868
diff changeset
    10
 * (the "License"); you may not use this file except in compliance with
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 25868
diff changeset
    11
 * the License.  You may obtain a copy of the License at
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 25868
diff changeset
    12
 *
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 25868
diff changeset
    13
 *      http://www.apache.org/licenses/LICENSE-2.0
15346
3f6fd93fec9a 8003147: port fix for BCEL bug 39695
dbuck
parents:
diff changeset
    14
 *
46174
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 25868
diff changeset
    15
 * Unless required by applicable law or agreed to in writing, software
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 25868
diff changeset
    16
 * distributed under the License is distributed on an "AS IS" BASIS,
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 25868
diff changeset
    17
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 25868
diff changeset
    18
 * See the License for the specific language governing permissions and
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 25868
diff changeset
    19
 * limitations under the License.
15346
3f6fd93fec9a 8003147: port fix for BCEL bug 39695
dbuck
parents:
diff changeset
    20
 */
46174
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 25868
diff changeset
    21
package com.sun.org.apache.bcel.internal.classfile;
15346
3f6fd93fec9a 8003147: port fix for BCEL bug 39695
dbuck
parents:
diff changeset
    22
46174
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 25868
diff changeset
    23
import java.io.DataInput;
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 25868
diff changeset
    24
import java.io.DataOutputStream;
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 25868
diff changeset
    25
import java.io.IOException;
55496
8e0ae3830fca 8224157: BCEL: update to version 6.3.1
joehw
parents: 47216
diff changeset
    26
46174
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 25868
diff changeset
    27
import com.sun.org.apache.bcel.internal.Const;
15346
3f6fd93fec9a 8003147: port fix for BCEL bug 39695
dbuck
parents:
diff changeset
    28
3f6fd93fec9a 8003147: port fix for BCEL bug 39695
dbuck
parents:
diff changeset
    29
// The new table is used when generic types are about...
55496
8e0ae3830fca 8224157: BCEL: update to version 6.3.1
joehw
parents: 47216
diff changeset
    30
15346
3f6fd93fec9a 8003147: port fix for BCEL bug 39695
dbuck
parents:
diff changeset
    31
//LocalVariableTable_attribute {
46174
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 25868
diff changeset
    32
//       u2 attribute_name_index;
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 25868
diff changeset
    33
//       u4 attribute_length;
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 25868
diff changeset
    34
//       u2 local_variable_table_length;
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 25868
diff changeset
    35
//       {  u2 start_pc;
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 25868
diff changeset
    36
//          u2 length;
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 25868
diff changeset
    37
//          u2 name_index;
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 25868
diff changeset
    38
//          u2 descriptor_index;
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 25868
diff changeset
    39
//          u2 index;
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 25868
diff changeset
    40
//       } local_variable_table[local_variable_table_length];
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 25868
diff changeset
    41
//     }
55496
8e0ae3830fca 8224157: BCEL: update to version 6.3.1
joehw
parents: 47216
diff changeset
    42
15346
3f6fd93fec9a 8003147: port fix for BCEL bug 39695
dbuck
parents:
diff changeset
    43
//LocalVariableTypeTable_attribute {
3f6fd93fec9a 8003147: port fix for BCEL bug 39695
dbuck
parents:
diff changeset
    44
//    u2 attribute_name_index;
3f6fd93fec9a 8003147: port fix for BCEL bug 39695
dbuck
parents:
diff changeset
    45
//    u4 attribute_length;
3f6fd93fec9a 8003147: port fix for BCEL bug 39695
dbuck
parents:
diff changeset
    46
//    u2 local_variable_type_table_length;
3f6fd93fec9a 8003147: port fix for BCEL bug 39695
dbuck
parents:
diff changeset
    47
//    {
3f6fd93fec9a 8003147: port fix for BCEL bug 39695
dbuck
parents:
diff changeset
    48
//      u2 start_pc;
3f6fd93fec9a 8003147: port fix for BCEL bug 39695
dbuck
parents:
diff changeset
    49
//      u2 length;
3f6fd93fec9a 8003147: port fix for BCEL bug 39695
dbuck
parents:
diff changeset
    50
//      u2 name_index;
3f6fd93fec9a 8003147: port fix for BCEL bug 39695
dbuck
parents:
diff changeset
    51
//      u2 signature_index;
3f6fd93fec9a 8003147: port fix for BCEL bug 39695
dbuck
parents:
diff changeset
    52
//      u2 index;
3f6fd93fec9a 8003147: port fix for BCEL bug 39695
dbuck
parents:
diff changeset
    53
//    } local_variable_type_table[local_variable_type_table_length];
3f6fd93fec9a 8003147: port fix for BCEL bug 39695
dbuck
parents:
diff changeset
    54
//  }
3f6fd93fec9a 8003147: port fix for BCEL bug 39695
dbuck
parents:
diff changeset
    55
// J5TODO: Needs some testing !
55496
8e0ae3830fca 8224157: BCEL: update to version 6.3.1
joehw
parents: 47216
diff changeset
    56
46174
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 25868
diff changeset
    57
/**
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 25868
diff changeset
    58
 * @since 6.0
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 25868
diff changeset
    59
 */
15346
3f6fd93fec9a 8003147: port fix for BCEL bug 39695
dbuck
parents:
diff changeset
    60
public class LocalVariableTypeTable extends Attribute {
3f6fd93fec9a 8003147: port fix for BCEL bug 39695
dbuck
parents:
diff changeset
    61
46174
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 25868
diff changeset
    62
    private LocalVariable[] local_variable_type_table;        // variables
15346
3f6fd93fec9a 8003147: port fix for BCEL bug 39695
dbuck
parents:
diff changeset
    63
46174
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 25868
diff changeset
    64
    public LocalVariableTypeTable(final LocalVariableTypeTable c) {
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 25868
diff changeset
    65
        this(c.getNameIndex(), c.getLength(), c.getLocalVariableTypeTable(), c.getConstantPool());
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 25868
diff changeset
    66
    }
15346
3f6fd93fec9a 8003147: port fix for BCEL bug 39695
dbuck
parents:
diff changeset
    67
55496
8e0ae3830fca 8224157: BCEL: update to version 6.3.1
joehw
parents: 47216
diff changeset
    68
    public LocalVariableTypeTable(final int name_index, final int length, final LocalVariable[] local_variable_table, final ConstantPool constant_pool) {
46174
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 25868
diff changeset
    69
        super(Const.ATTR_LOCAL_VARIABLE_TYPE_TABLE, name_index, length, constant_pool);
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 25868
diff changeset
    70
        this.local_variable_type_table = local_variable_table;
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 25868
diff changeset
    71
    }
15346
3f6fd93fec9a 8003147: port fix for BCEL bug 39695
dbuck
parents:
diff changeset
    72
55496
8e0ae3830fca 8224157: BCEL: update to version 6.3.1
joehw
parents: 47216
diff changeset
    73
    LocalVariableTypeTable(final int nameIdx, final int len, final DataInput input, final ConstantPool cpool) throws IOException {
46174
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 25868
diff changeset
    74
        this(nameIdx, len, (LocalVariable[]) null, cpool);
15346
3f6fd93fec9a 8003147: port fix for BCEL bug 39695
dbuck
parents:
diff changeset
    75
46174
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 25868
diff changeset
    76
        final int local_variable_type_table_length = input.readUnsignedShort();
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 25868
diff changeset
    77
        local_variable_type_table = new LocalVariable[local_variable_type_table_length];
15346
3f6fd93fec9a 8003147: port fix for BCEL bug 39695
dbuck
parents:
diff changeset
    78
46174
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 25868
diff changeset
    79
        for (int i = 0; i < local_variable_type_table_length; i++) {
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 25868
diff changeset
    80
            local_variable_type_table[i] = new LocalVariable(input, cpool);
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 25868
diff changeset
    81
        }
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 25868
diff changeset
    82
    }
15346
3f6fd93fec9a 8003147: port fix for BCEL bug 39695
dbuck
parents:
diff changeset
    83
46174
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 25868
diff changeset
    84
    @Override
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 25868
diff changeset
    85
    public void accept(final Visitor v) {
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 25868
diff changeset
    86
        v.visitLocalVariableTypeTable(this);
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 25868
diff changeset
    87
    }
15346
3f6fd93fec9a 8003147: port fix for BCEL bug 39695
dbuck
parents:
diff changeset
    88
46174
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 25868
diff changeset
    89
    @Override
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 25868
diff changeset
    90
    public final void dump(final DataOutputStream file) throws IOException {
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 25868
diff changeset
    91
        super.dump(file);
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 25868
diff changeset
    92
        file.writeShort(local_variable_type_table.length);
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 25868
diff changeset
    93
        for (final LocalVariable variable : local_variable_type_table) {
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 25868
diff changeset
    94
            variable.dump(file);
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 25868
diff changeset
    95
        }
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 25868
diff changeset
    96
    }
15346
3f6fd93fec9a 8003147: port fix for BCEL bug 39695
dbuck
parents:
diff changeset
    97
46174
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 25868
diff changeset
    98
    public final LocalVariable[] getLocalVariableTypeTable() {
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 25868
diff changeset
    99
        return local_variable_type_table;
15346
3f6fd93fec9a 8003147: port fix for BCEL bug 39695
dbuck
parents:
diff changeset
   100
    }
3f6fd93fec9a 8003147: port fix for BCEL bug 39695
dbuck
parents:
diff changeset
   101
46174
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 25868
diff changeset
   102
    public final LocalVariable getLocalVariable(final int index) {
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 25868
diff changeset
   103
        for (final LocalVariable variable : local_variable_type_table) {
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 25868
diff changeset
   104
            if (variable.getIndex() == index) {
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 25868
diff changeset
   105
                return variable;
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 25868
diff changeset
   106
            }
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 25868
diff changeset
   107
        }
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 25868
diff changeset
   108
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 25868
diff changeset
   109
        return null;
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 25868
diff changeset
   110
    }
15346
3f6fd93fec9a 8003147: port fix for BCEL bug 39695
dbuck
parents:
diff changeset
   111
46174
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 25868
diff changeset
   112
    public final void setLocalVariableTable(final LocalVariable[] local_variable_table) {
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 25868
diff changeset
   113
        this.local_variable_type_table = local_variable_table;
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 25868
diff changeset
   114
    }
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 25868
diff changeset
   115
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 25868
diff changeset
   116
    /**
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 25868
diff changeset
   117
     * @return String representation.
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 25868
diff changeset
   118
     */
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 25868
diff changeset
   119
    @Override
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 25868
diff changeset
   120
    public final String toString() {
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 25868
diff changeset
   121
        final StringBuilder buf = new StringBuilder();
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 25868
diff changeset
   122
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 25868
diff changeset
   123
        for (int i = 0; i < local_variable_type_table.length; i++) {
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 25868
diff changeset
   124
            buf.append(local_variable_type_table[i].toStringShared(true));
15346
3f6fd93fec9a 8003147: port fix for BCEL bug 39695
dbuck
parents:
diff changeset
   125
46174
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 25868
diff changeset
   126
            if (i < local_variable_type_table.length - 1) {
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 25868
diff changeset
   127
                buf.append('\n');
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 25868
diff changeset
   128
            }
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 25868
diff changeset
   129
        }
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 25868
diff changeset
   130
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 25868
diff changeset
   131
        return buf.toString();
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 25868
diff changeset
   132
    }
15346
3f6fd93fec9a 8003147: port fix for BCEL bug 39695
dbuck
parents:
diff changeset
   133
46174
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 25868
diff changeset
   134
    /**
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 25868
diff changeset
   135
     * @return deep copy of this attribute
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 25868
diff changeset
   136
     */
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 25868
diff changeset
   137
    @Override
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 25868
diff changeset
   138
    public Attribute copy(final ConstantPool constant_pool) {
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 25868
diff changeset
   139
        final LocalVariableTypeTable c = (LocalVariableTypeTable) clone();
15346
3f6fd93fec9a 8003147: port fix for BCEL bug 39695
dbuck
parents:
diff changeset
   140
46174
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 25868
diff changeset
   141
        c.local_variable_type_table = new LocalVariable[local_variable_type_table.length];
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 25868
diff changeset
   142
        for (int i = 0; i < local_variable_type_table.length; i++) {
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 25868
diff changeset
   143
            c.local_variable_type_table[i] = local_variable_type_table[i].copy();
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 25868
diff changeset
   144
        }
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 25868
diff changeset
   145
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 25868
diff changeset
   146
        c.setConstantPool(constant_pool);
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 25868
diff changeset
   147
        return c;
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 25868
diff changeset
   148
    }
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 25868
diff changeset
   149
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 25868
diff changeset
   150
    public final int getTableLength() {
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 25868
diff changeset
   151
        return local_variable_type_table == null ? 0 : local_variable_type_table.length;
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 25868
diff changeset
   152
    }
15346
3f6fd93fec9a 8003147: port fix for BCEL bug 39695
dbuck
parents:
diff changeset
   153
}