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 com.tc.asm.tree;
030:
031: import com.tc.asm.Attribute;
032: import com.tc.asm.ClassVisitor;
033: import com.tc.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 com.tc.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 com.tc.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 com.tc.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 com.tc.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: if (fv == null) {
104: return;
105: }
106: int i, n;
107: n = visibleAnnotations == null ? 0 : visibleAnnotations.size();
108: for (i = 0; i < n; ++i) {
109: AnnotationNode an = (AnnotationNode) visibleAnnotations
110: .get(i);
111: an.accept(fv.visitAnnotation(an.desc, true));
112: }
113: n = invisibleAnnotations == null ? 0 : invisibleAnnotations
114: .size();
115: for (i = 0; i < n; ++i) {
116: AnnotationNode an = (AnnotationNode) invisibleAnnotations
117: .get(i);
118: an.accept(fv.visitAnnotation(an.desc, false));
119: }
120: n = attrs == null ? 0 : attrs.size();
121: for (i = 0; i < n; ++i) {
122: fv.visitAttribute((Attribute) attrs.get(i));
123: }
124: fv.visitEnd();
125: }
126: }
|