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 ModuleResolution attribute. This attribute is specific to the OpenJDK and may change in the 39 * future. 40 * 41 * @author Remi Forax 42 */ 43 public final class ModuleResolutionAttribute extends Attribute { 44 /** 45 * The resolution state of a module meaning that the module is not available from the class-path 46 * by default. 47 */ 48 public static final int RESOLUTION_DO_NOT_RESOLVE_BY_DEFAULT = 1; 49 50 /** The resolution state of a module meaning the module is marked as deprecated. */ 51 public static final int RESOLUTION_WARN_DEPRECATED = 2; 52 53 /** 54 * The resolution state of a module meaning the module is marked as deprecated and will be removed 55 * in a future release. 56 */ 57 public static final int RESOLUTION_WARN_DEPRECATED_FOR_REMOVAL = 4; 58 59 /** 60 * The resolution state of a module meaning the module is not yet standardized, so in incubating 61 * mode. 62 */ 63 public static final int RESOLUTION_WARN_INCUBATING = 8; 64 65 /** 66 * The resolution state of the module. Must be one of {@link #RESOLUTION_WARN_DEPRECATED}, {@link 67 * #RESOLUTION_WARN_DEPRECATED_FOR_REMOVAL}, and {@link #RESOLUTION_WARN_INCUBATING}. 68 */ 69 public int resolution; 70 71 /** 72 * Constructs a new {@link ModuleResolutionAttribute}. 73 * 74 * @param resolution the resolution state of the module. Must be one of {@link 75 * #RESOLUTION_WARN_DEPRECATED}, {@link #RESOLUTION_WARN_DEPRECATED_FOR_REMOVAL}, and {@link 76 * #RESOLUTION_WARN_INCUBATING}. 77 */ ModuleResolutionAttribute(final int resolution)78 public ModuleResolutionAttribute(final int resolution) { 79 super("ModuleResolution"); 80 this.resolution = resolution; 81 } 82 83 /** 84 * Constructs an empty {@link ModuleResolutionAttribute}. This object can be passed as a prototype 85 * to the {@link ClassReader#accept(org.objectweb.asm.ClassVisitor, Attribute[], int)} method. 86 */ ModuleResolutionAttribute()87 public ModuleResolutionAttribute() { 88 this(0); 89 } 90 91 @Override read( final ClassReader classReader, final int offset, final int length, final char[] charBuffer, final int codeOffset, final Label[] labels)92 protected Attribute read( 93 final ClassReader classReader, 94 final int offset, 95 final int length, 96 final char[] charBuffer, 97 final int codeOffset, 98 final Label[] labels) { 99 return new ModuleResolutionAttribute(classReader.readUnsignedShort(offset)); 100 } 101 102 @Override write( final ClassWriter classWriter, final byte[] code, final int codeLength, final int maxStack, final int maxLocals)103 protected ByteVector write( 104 final ClassWriter classWriter, 105 final byte[] code, 106 final int codeLength, 107 final int maxStack, 108 final int maxLocals) { 109 ByteVector byteVector = new ByteVector(); 110 byteVector.putShort(resolution); 111 return byteVector; 112 } 113 } 114