AnnotationDefaultAttribute.java

  1. /*
  2.  *  Licensed to the Apache Software Foundation (ASF) under one or more
  3.  *  contributor license agreements.  See the NOTICE file distributed with
  4.  *  this work for additional information regarding copyright ownership.
  5.  *  The ASF licenses this file to You under the Apache License, Version 2.0
  6.  *  (the "License"); you may not use this file except in compliance with
  7.  *  the License.  You may obtain a copy of the License at
  8.  *
  9.  *     http://www.apache.org/licenses/LICENSE-2.0
  10.  *
  11.  *  Unless required by applicable law or agreed to in writing, software
  12.  *  distributed under the License is distributed on an "AS IS" BASIS,
  13.  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.  *  See the License for the specific language governing permissions and
  15.  *  limitations under the License.
  16.  */
  17. package org.apache.commons.compress.harmony.unpack200.bytecode;

  18. import java.io.DataOutputStream;
  19. import java.io.IOException;
  20. import java.util.ArrayList;
  21. import java.util.List;

  22. /**
  23.  * AnnotationDefault class file attribute
  24.  */
  25. public class AnnotationDefaultAttribute extends AnnotationsAttribute {

  26.     private static CPUTF8 attributeName;

  27.     public static void setAttributeName(final CPUTF8 cpUTF8Value) {
  28.         attributeName = cpUTF8Value;
  29.     }

  30.     private final ElementValue elementValue;

  31.     /**
  32.      * Constructs a new instance.
  33.      *
  34.      * @param elementValue element value to track.
  35.      */
  36.     public AnnotationDefaultAttribute(final ElementValue elementValue) {
  37.         super(attributeName);
  38.         this.elementValue = elementValue;
  39.     }

  40.     @Override
  41.     public boolean equals(final Object obj) {
  42.         return this == obj;
  43.     }

  44.     @Override
  45.     protected int getLength() {
  46.         return elementValue.getLength();
  47.     }

  48.     @Override
  49.     protected ClassFileEntry[] getNestedClassFileEntries() {
  50.         final List<Object> nested = new ArrayList<>();
  51.         nested.add(attributeName);
  52.         nested.addAll(elementValue.getClassFileEntries());
  53.         final ClassFileEntry[] nestedEntries = new ClassFileEntry[nested.size()];
  54.         for (int i = 0; i < nestedEntries.length; i++) {
  55.             nestedEntries[i] = (ClassFileEntry) nested.get(i);
  56.         }
  57.         return nestedEntries;
  58.     }

  59.     @Override
  60.     protected void resolve(final ClassConstantPool pool) {
  61.         super.resolve(pool);
  62.         elementValue.resolve(pool);
  63.     }

  64.     @Override
  65.     public String toString() {
  66.         return "AnnotationDefault: " + elementValue;
  67.     }

  68.     @Override
  69.     protected void writeBody(final DataOutputStream dos) throws IOException {
  70.         elementValue.writeBody(dos);
  71.     }

  72. }