1 // ASM: a very small and fast Java bytecode manipulation framework 2 // Copyright (c) 2000-2011 INRIA, France Telecom 3 // All rights reserved. 4 // 5 // Redistribution and use in source and binary forms, with or without 6 // modification, are permitted provided that the following conditions 7 // are met: 8 // 1. Redistributions of source code must retain the above copyright 9 // notice, this list of conditions and the following disclaimer. 10 // 2. Redistributions in binary form must reproduce the above copyright 11 // notice, this list of conditions and the following disclaimer in the 12 // documentation and/or other materials provided with the distribution. 13 // 3. Neither the name of the copyright holders nor the names of its 14 // contributors may be used to endorse or promote products derived from 15 // this software without specific prior written permission. 16 // 17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 21 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 27 // THE POSSIBILITY OF SUCH DAMAGE. 28 29 package org.objectweb.asm.commons; 30 31 import org.objectweb.asm.Attribute; 32 import org.objectweb.asm.ByteVector; 33 import org.objectweb.asm.ClassReader; 34 import org.objectweb.asm.ClassWriter; 35 import org.objectweb.asm.Label; 36 37 /** 38 * A ModuleTarget attribute. This attribute is specific to the OpenJDK and may change in the future. 39 * 40 * @author Remi Forax 41 */ 42 public final class ModuleTargetAttribute extends Attribute { 43 44 /** The name of the platform on which the module can run. */ 45 public String platform; 46 47 /** 48 * Constructs a new {@link ModuleTargetAttribute}. 49 * 50 * @param platform the name of the platform on which the module can run. 51 */ ModuleTargetAttribute(final String platform)52 public ModuleTargetAttribute(final String platform) { 53 super("ModuleTarget"); 54 this.platform = platform; 55 } 56 57 /** 58 * Constructs an empty {@link ModuleTargetAttribute}. This object can be passed as a prototype to 59 * the {@link ClassReader#accept(org.objectweb.asm.ClassVisitor, Attribute[], int)} method. 60 */ ModuleTargetAttribute()61 public ModuleTargetAttribute() { 62 this(null); 63 } 64 65 @Override read( final ClassReader classReader, final int offset, final int length, final char[] charBuffer, final int codeOffset, final Label[] labels)66 protected Attribute read( 67 final ClassReader classReader, 68 final int offset, 69 final int length, 70 final char[] charBuffer, 71 final int codeOffset, 72 final Label[] labels) { 73 return new ModuleTargetAttribute(classReader.readUTF8(offset, charBuffer)); 74 } 75 76 @Override write( final ClassWriter classWriter, final byte[] code, final int codeLength, final int maxStack, final int maxLocals)77 protected ByteVector write( 78 final ClassWriter classWriter, 79 final byte[] code, 80 final int codeLength, 81 final int maxStack, 82 final int maxLocals) { 83 ByteVector byteVector = new ByteVector(); 84 byteVector.putShort(platform == null ? 0 : classWriter.newUTF8(platform)); 85 return byteVector; 86 } 87 } 88