/* * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Sun designates this * particular file as subject to the "Classpath" exception as provided * by Sun in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, * CA 95054 USA or visit www.sun.com if you need additional information or * have any questions. */ package com.sun.tools.classfile; import java.io.IOException; import java.lang.reflect.Constructor; import java.util.HashMap; import java.util.Map; /** *
This is NOT part of any API supported by Sun Microsystems. If
* you write code that depends on this, you do so at your own risk.
* This code and its internal interfaces are subject to change or
* deletion without notice.
*/
public abstract class Attribute {
public static final String AnnotationDefault = "AnnotationDefault";
public static final String CharacterRangeTable = "CharacterRangeTable";
public static final String Code = "Code";
public static final String ConstantValue = "ConstantValue";
public static final String CompilationID = "CompilationID";
public static final String Deprecated = "Deprecated";
public static final String EnclosingMethod = "EnclosingMethod";
public static final String Exceptions = "Exceptions";
public static final String InnerClasses = "InnerClasses";
public static final String LineNumberTable = "LineNumberTable";
public static final String LocalVariableTable = "LocalVariableTable";
public static final String LocalVariableTypeTable = "LocalVariableTypeTable";
public static final String RuntimeVisibleAnnotations = "RuntimeVisibleAnnotations";
public static final String RuntimeInvisibleAnnotations = "RuntimeInvisibleAnnotations";
public static final String RuntimeVisibleParameterAnnotations = "RuntimeVisibleParameterAnnotations";
public static final String RuntimeInvisibleParameterAnnotations = "RuntimeInvisibleParameterAnnotations";
public static final String Signature = "Signature";
public static final String SourceDebugExtension = "SourceDebugExtension";
public static final String SourceFile = "SourceFile";
public static final String SourceID = "SourceID";
public static final String StackMap = "StackMap";
public static final String StackMapTable = "StackMapTable";
public static final String Synthetic = "Synthetic";
// JSR 277/294
public static final String Module = "Module";
public static final String ModuleExportTable = "ModuleExportTable";
public static final String ModuleMemberTable = "ModuleMemberTable";
public static class Factory {
public Factory() {
// defer init of standardAttributeClasses until after options set up
}
public void setCompat(boolean compat) {
this.compat = compat;
}
public void setJSR277(boolean jsr277) {
this.jsr277 = jsr277;
}
public Attribute createAttribute(ClassReader cr, int name_index, byte[] data)
throws IOException {
if (standardAttributes == null)
init();
ConstantPool cp = cr.getConstantPool();
try {
String name = cp.getUTF8Value(name_index);
Class extends Attribute> attrClass = standardAttributes.get(name);
if (attrClass != null) {
try {
Class>[] constrArgTypes = {ClassReader.class, int.class, int.class};
Constructor extends Attribute> constr = attrClass.getDeclaredConstructor(constrArgTypes);
return constr.newInstance(new Object[] { cr, name_index, data.length });
} catch (Throwable t) {
// fall through and use DefaultAttribute
// t.printStackTrace();
}
}
} catch (ConstantPoolException e) {
// fall through and use DefaultAttribute
}
return new DefaultAttribute(cr, name_index, data);
}
protected void init() {
standardAttributes = new HashMap