jaxp/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/classfile/ParameterAnnotationEntry.java
author joehw
Sun, 13 Aug 2017 21:10:40 -0700
changeset 46174 5611d2529b49
permissions -rw-r--r--
8163121: BCEL: update to the latest 6.0 release Reviewed-by: dfuchs, lancea
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
46174
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
     1
/*
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
     2
 * reserved comment block
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
     3
 * DO NOT REMOVE OR ALTER!
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
     4
 */
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
     5
/*
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
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:
diff changeset
     7
 * contributor license agreements.  See the NOTICE file distributed with
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
     8
 * this work for additional information regarding copyright ownership.
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
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:
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:
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:
diff changeset
    12
 *
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    13
 *      http://www.apache.org/licenses/LICENSE-2.0
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    14
 *
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
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:
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:
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:
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:
diff changeset
    19
 * limitations under the License.
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    20
 */
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    21
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    22
package com.sun.org.apache.bcel.internal.classfile;
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    23
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    24
import java.io.DataInput;
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    25
import java.io.DataOutputStream;
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    26
import java.io.IOException;
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    27
import java.util.ArrayList;
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    28
import java.util.Collections;
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    29
import java.util.List;
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    30
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    31
/**
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    32
 * represents one parameter annotation in the parameter annotation table
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    33
 *
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    34
 * @version $Id: ParameterAnnotationEntry
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    35
 * @since 6.0
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    36
 */
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    37
public class ParameterAnnotationEntry implements Node {
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    38
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    39
    private final AnnotationEntry[] annotation_table;
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    40
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    41
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    42
    /**
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    43
     * Construct object from input stream.
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    44
     *
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    45
     * @param input Input stream
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    46
     * @throws IOException
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    47
     */
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    48
    ParameterAnnotationEntry(final DataInput input, final ConstantPool constant_pool) throws IOException {
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    49
        final int annotation_table_length = input.readUnsignedShort();
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    50
        annotation_table = new AnnotationEntry[annotation_table_length];
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    51
        for (int i = 0; i < annotation_table_length; i++) {
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    52
            // TODO isRuntimeVisible
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    53
            annotation_table[i] = AnnotationEntry.read(input, constant_pool, false);
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    54
        }
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    55
    }
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    56
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    57
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    58
    /**
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    59
     * Called by objects that are traversing the nodes of the tree implicitely
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    60
     * 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:
diff changeset
    61
     * fields, attributes, etc. spawns a tree of objects.
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    62
     *
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    63
     * @param v Visitor object
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    64
     */
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    65
    @Override
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    66
    public void accept( final Visitor v ) {
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    67
        v.visitParameterAnnotationEntry(this);
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    68
    }
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    69
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    70
    /**
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    71
     * returns the array of annotation entries in this annotation
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    72
     */
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    73
    public AnnotationEntry[] getAnnotationEntries() {
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    74
        return annotation_table;
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    75
    }
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    76
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    77
    public void dump(final DataOutputStream dos) throws IOException {
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    78
        dos.writeShort(annotation_table.length);
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    79
        for (final AnnotationEntry entry : annotation_table) {
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    80
            entry.dump(dos);
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    81
        }
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    82
    }
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    83
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    84
  public static ParameterAnnotationEntry[] createParameterAnnotationEntries(final Attribute[] attrs) {
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    85
      // Find attributes that contain parameter annotation data
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    86
      final List<ParameterAnnotationEntry> accumulatedAnnotations = new ArrayList<>(attrs.length);
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    87
      for (final Attribute attribute : attrs) {
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    88
          if (attribute instanceof ParameterAnnotations) {
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    89
              final ParameterAnnotations runtimeAnnotations = (ParameterAnnotations)attribute;
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    90
              Collections.addAll(accumulatedAnnotations, runtimeAnnotations.getParameterAnnotationEntries());
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    91
          }
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    92
      }
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    93
      return accumulatedAnnotations.toArray(new ParameterAnnotationEntry[accumulatedAnnotations.size()]);
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    94
  }
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents:
diff changeset
    95
}