KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > oracle > toplink > libraries > asm > attrs > SignatureAttribute


1 /**
2  * ASM: a very small and fast Java bytecode manipulation framework
3  * Copyright (c) 2000,2002,2003 INRIA, France Telecom
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in the
13  * documentation and/or other materials provided with the distribution.
14  * 3. Neither the name of the copyright holders nor the names of its
15  * contributors may be used to endorse or promote products derived from
16  * this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
22  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
28  * THE POSSIBILITY OF SUCH DAMAGE.
29  */

30
31 package oracle.toplink.libraries.asm.attrs;
32
33 import oracle.toplink.libraries.asm.Attribute;
34 import oracle.toplink.libraries.asm.ByteVector;
35 import oracle.toplink.libraries.asm.ClassReader;
36 import oracle.toplink.libraries.asm.ClassWriter;
37 import oracle.toplink.libraries.asm.Label;
38
39 /**
40  * The Signature Attribute introduced in JSR-14 (Adding Generics to the
41  * Java Programming Language) and also defined in the Java Virtual Machine
42  * Specification, 3rd edition draft. This atribute is used for classes,
43  * fields and methods.
44  * <p>
45  * Classfiles need to carry generic type information in a backwards
46  * compatible way. This is accomplished by introducing a new "Signature"
47  * attribute for classes, methods and fields. The structure of this
48  * attribute is as follows:
49  * <pre>
50  * "Signature" (u4 attr-length, u2 signature-index)
51  * </pre>
52  * When used as an attribute of a method or field, a signature gives the
53  * full (possibly generic) type of that method or field.
54  * When used as a class attribute, a signature indicates the type
55  * parameters of the class, followed by its supertype, followed by
56  * all its interfaces.
57  * <p>
58  * The type syntax in signatures is extended to parameterized types and
59  * type variables. There is also a new signature syntax for formal type
60  * parameters. The syntax extensions for signature strings are as follows:
61  * <pre>
62  * MethodOrFieldSignature ::= TypeSignature
63  * ClassSignature ::= ParameterPartOpt super_TypeSignature interface_TypeSignatures
64  * TypeSignatures ::= TypeSignatures TypeSignature
65  * |
66  * TypeSignature ::= ...
67  * | ClassTypeSignature
68  * | MethodTypeSignature
69  * | TypeVariableSignature
70  * ClassTypeSignature ::= 'L' Ident TypeArgumentsOpt ';'
71  * | ClassTypeSignature '.' Ident ';' TypeArgumentsOpt
72  * MethodTypeSignature ::= TypeArgumentsOpt '(' TypeSignatures ')'
73  * TypeSignature ThrowsSignatureListOpt
74  * ThrowsSignatureList ::= ThrowsSignature ThrowsSignatureList
75  * | ThrowsSignature
76  * ThrowsSignature ::= '^' TypeSignature
77  * TypeVariableSignature ::= 'T' Ident ';'
78  * TypeArguments ::= '<' TypeSignature TypeSignatures '>'
79  * ParameterPart ::= '<' ParameterSignature ParameterSignatures '>'
80  * ParameterSignatures ::= ParameterSignatures ParameterSignature
81  * |
82  * ParameterSignature ::= Ident ':' bound_TypeSignature
83  * </pre>
84  *
85  * @see <a HREF="http://www.jcp.org/en/jsr/detail?id=14">JSR 14 : Add Generic
86  * Types To The JavaTM Programming Language</a>
87  *
88  * @author Eugene Kuleshov
89  */

90
91 public class SignatureAttribute extends Attribute {
92
93   public String JavaDoc signature;
94
95   public SignatureAttribute () {
96     super("Signature");
97   }
98
99   public SignatureAttribute (String JavaDoc signature) {
100     this();
101     this.signature = signature;
102   }
103
104   protected Attribute read (ClassReader cr, int off,
105                             int len, char[] buf, int codeOff, Label[] labels) {
106     return new SignatureAttribute(cr.readUTF8(off, buf));
107   }
108
109   protected ByteVector write (ClassWriter cw, byte[] code,
110                               int len, int maxStack, int maxLocals) {
111     return new ByteVector().putShort(cw.newUTF8(signature));
112   }
113
114   public String JavaDoc toString () {
115     return signature;
116   }
117 }
118
Popular Tags