jaxp/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/classfile/ArrayElementValue.java
changeset 46174 5611d2529b49
equal deleted inserted replaced
46173:5546b5710844 46174:5611d2529b49
       
     1 /*
       
     2  * reserved comment block
       
     3  * DO NOT REMOVE OR ALTER!
       
     4  */
       
     5 /*
       
     6  * Licensed to the Apache Software Foundation (ASF) under one or more
       
     7  * contributor license agreements.  See the NOTICE file distributed with
       
     8  * this work for additional information regarding copyright ownership.
       
     9  * The ASF licenses this file to You under the Apache License, Version 2.0
       
    10  * (the "License"); you may not use this file except in compliance with
       
    11  * the License.  You may obtain a copy of the License at
       
    12  *
       
    13  *      http://www.apache.org/licenses/LICENSE-2.0
       
    14  *
       
    15  * Unless required by applicable law or agreed to in writing, software
       
    16  * distributed under the License is distributed on an "AS IS" BASIS,
       
    17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
       
    18  * See the License for the specific language governing permissions and
       
    19  * limitations under the License.
       
    20  */
       
    21 
       
    22 package com.sun.org.apache.bcel.internal.classfile;
       
    23 
       
    24 import java.io.DataOutputStream;
       
    25 import java.io.IOException;
       
    26 
       
    27 /**
       
    28  * @since 6.0
       
    29  */
       
    30 public class ArrayElementValue extends ElementValue
       
    31 {
       
    32     // For array types, this is the array
       
    33     private final ElementValue[] evalues;
       
    34 
       
    35     @Override
       
    36     public String toString()
       
    37     {
       
    38         final StringBuilder sb = new StringBuilder();
       
    39         sb.append("{");
       
    40         for (int i = 0; i < evalues.length; i++)
       
    41         {
       
    42             sb.append(evalues[i]);
       
    43             if ((i + 1) < evalues.length) {
       
    44                 sb.append(",");
       
    45             }
       
    46         }
       
    47         sb.append("}");
       
    48         return sb.toString();
       
    49     }
       
    50 
       
    51     public ArrayElementValue(final int type, final ElementValue[] datums, final ConstantPool cpool)
       
    52     {
       
    53         super(type, cpool);
       
    54         if (type != ARRAY) {
       
    55             throw new RuntimeException(
       
    56                     "Only element values of type array can be built with this ctor - type specified: " + type);
       
    57         }
       
    58         this.evalues = datums;
       
    59     }
       
    60 
       
    61     @Override
       
    62     public void dump(final DataOutputStream dos) throws IOException
       
    63     {
       
    64         dos.writeByte(super.getType()); // u1 type of value (ARRAY == '[')
       
    65         dos.writeShort(evalues.length);
       
    66         for (final ElementValue evalue : evalues) {
       
    67             evalue.dump(dos);
       
    68         }
       
    69     }
       
    70 
       
    71     @Override
       
    72     public String stringifyValue()
       
    73     {
       
    74         final StringBuilder sb = new StringBuilder();
       
    75         sb.append("[");
       
    76         for (int i = 0; i < evalues.length; i++)
       
    77         {
       
    78             sb.append(evalues[i].stringifyValue());
       
    79             if ((i + 1) < evalues.length) {
       
    80                 sb.append(",");
       
    81             }
       
    82         }
       
    83         sb.append("]");
       
    84         return sb.toString();
       
    85     }
       
    86 
       
    87     public ElementValue[] getElementValuesArray()
       
    88     {
       
    89         return evalues;
       
    90     }
       
    91 
       
    92     public int getElementValuesArraySize()
       
    93     {
       
    94         return evalues.length;
       
    95     }
       
    96 }