001: /***
002: * ASM: a very small and fast Java bytecode manipulation framework
003: * Copyright (c) 2000-2005 INRIA, France Telecom
004: * All rights reserved.
005: *
006: * Redistribution and use in source and binary forms, with or without
007: * modification, are permitted provided that the following conditions
008: * are met:
009: * 1. Redistributions of source code must retain the above copyright
010: * notice, this list of conditions and the following disclaimer.
011: * 2. Redistributions in binary form must reproduce the above copyright
012: * notice, this list of conditions and the following disclaimer in the
013: * documentation and/or other materials provided with the distribution.
014: * 3. Neither the name of the copyright holders nor the names of its
015: * contributors may be used to endorse or promote products derived from
016: * this software without specific prior written permission.
017: *
018: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
019: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
020: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
021: * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
022: * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
023: * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
024: * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
025: * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
026: * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
027: * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
028: * THE POSSIBILITY OF SUCH DAMAGE.
029: */package org.objectweb.asm.tree;
030:
031: import org.objectweb.asm.Attribute;
032: import org.objectweb.asm.ClassVisitor;
033: import org.objectweb.asm.FieldVisitor;
034:
035: /**
036: * A node that represents a field.
037: *
038: * @author Eric Bruneton
039: */
040: public class FieldNode extends MemberNode implements FieldVisitor {
041:
042: /**
043: * The field's access flags (see {@link org.objectweb.asm.Opcodes}). This
044: * field also indicates if the field is synthetic and/or deprecated.
045: */
046: public int access;
047:
048: /**
049: * The field's name.
050: */
051: public String name;
052:
053: /**
054: * The field's descriptor (see {@link org.objectweb.asm.Type}).
055: */
056: public String desc;
057:
058: /**
059: * The field's signature. May be <tt>null</tt>.
060: */
061: public String signature;
062:
063: /**
064: * The field's initial value. This field, which may be <tt>null</tt> if
065: * the field does not have an initial value, must be an {@link Integer}, a
066: * {@link Float}, a {@link Long}, a {@link Double} or a {@link String}.
067: */
068: public Object value;
069:
070: /**
071: * Constructs a new {@link FieldNode}.
072: *
073: * @param access the field's access flags (see
074: * {@link org.objectweb.asm.Opcodes}). This parameter also indicates
075: * if the field is synthetic and/or deprecated.
076: * @param name the field's name.
077: * @param desc the field's descriptor (see
078: * {@link org.objectweb.asm.Type Type}).
079: * @param signature the field's signature.
080: * @param value the field's initial value. This parameter, which may be
081: * <tt>null</tt> if the field does not have an initial value, must
082: * be an {@link Integer}, a {@link Float}, a {@link Long}, a
083: * {@link Double} or a {@link String}.
084: */
085: public FieldNode(final int access, final String name,
086: final String desc, final String signature,
087: final Object value) {
088: this .access = access;
089: this .name = name;
090: this .desc = desc;
091: this .signature = signature;
092: this .value = value;
093: }
094:
095: /**
096: * Makes the given class visitor visit this field.
097: *
098: * @param cv a class visitor.
099: */
100: public void accept(final ClassVisitor cv) {
101: FieldVisitor fv = cv.visitField(access, name, desc, signature,
102: value);
103: int i, n;
104: n = visibleAnnotations == null ? 0 : visibleAnnotations.size();
105: for (i = 0; i < n; ++i) {
106: AnnotationNode an = (AnnotationNode) visibleAnnotations
107: .get(i);
108: an.accept(fv.visitAnnotation(an.desc, true));
109: }
110: n = invisibleAnnotations == null ? 0 : invisibleAnnotations
111: .size();
112: for (i = 0; i < n; ++i) {
113: AnnotationNode an = (AnnotationNode) invisibleAnnotations
114: .get(i);
115: an.accept(fv.visitAnnotation(an.desc, false));
116: }
117: n = attrs == null ? 0 : attrs.size();
118: for (i = 0; i < n; ++i) {
119: fv.visitAttribute((Attribute) attrs.get(i));
120: }
121: fv.visitEnd();
122: }
123: }
|