001// ASM: a very small and fast Java bytecode manipulation framework
002// Copyright (c) 2000-2011 INRIA, France Telecom
003// All rights reserved.
004//
005// Redistribution and use in source and binary forms, with or without
006// modification, are permitted provided that the following conditions
007// are met:
008// 1. Redistributions of source code must retain the above copyright
009//    notice, this list of conditions and the following disclaimer.
010// 2. Redistributions in binary form must reproduce the above copyright
011//    notice, this list of conditions and the following disclaimer in the
012//    documentation and/or other materials provided with the distribution.
013// 3. Neither the name of the copyright holders nor the names of its
014//    contributors may be used to endorse or promote products derived from
015//    this software without specific prior written permission.
016//
017// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
018// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
019// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
020// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
021// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
022// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
023// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
024// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
025// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
026// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
027// THE POSSIBILITY OF SUCH DAMAGE.
028
029package io.ebean.enhance.asm.commons;
030
031import io.ebean.enhance.asm.*;
032
033/**
034 * A ModuleTarget attribute. This attribute is specific to the OpenJDK and may change in the future.
035 *
036 * @author Remi Forax
037 */
038public final class ModuleTargetAttribute extends Attribute {
039
040  /** The name of the platform on which the module can run. */
041  public String platform;
042
043  /**
044   * Constructs a new {@link ModuleTargetAttribute}.
045   *
046   * @param platform the name of the platform on which the module can run.
047   */
048  public ModuleTargetAttribute(final String platform) {
049    super("ModuleTarget");
050    this.platform = platform;
051  }
052
053  /**
054   * Constructs an empty {@link ModuleTargetAttribute}. This object can be passed as a prototype to
055   * the {@link ClassReader#accept(ClassVisitor, Attribute[], int)} method.
056   */
057  public ModuleTargetAttribute() {
058    this(null);
059  }
060
061  @Override
062  protected Attribute read(
063      final ClassReader classReader,
064      final int offset,
065      final int length,
066      final char[] charBuffer,
067      final int codeOffset,
068      final Label[] labels) {
069    return new ModuleTargetAttribute(classReader.readUTF8(offset, charBuffer));
070  }
071
072  @Override
073  protected ByteVector write(
074      final ClassWriter classWriter,
075      final byte[] code,
076      final int codeLength,
077      final int maxStack,
078      final int maxLocals) {
079    ByteVector byteVector = new ByteVector();
080    byteVector.putShort(platform == null ? 0 : classWriter.newUTF8(platform));
081    return byteVector;
082  }
083}