001: /*
002: * Javassist, a Java-bytecode translator toolkit.
003: * Copyright (C) 2004 Bill Burke. All Rights Reserved.
004: *
005: * The contents of this file are subject to the Mozilla Public License Version
006: * 1.1 (the "License"); you may not use this file except in compliance with
007: * the License. Alternatively, the contents of this file may be used under
008: * the terms of the GNU Lesser General Public License Version 2.1 or later.
009: *
010: * Software distributed under the License is distributed on an "AS IS" basis,
011: * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
012: * for the specific language governing rights and limitations under the
013: * License.
014: */
015:
016: package javassist.bytecode.annotation;
017:
018: import javassist.ClassPool;
019: import javassist.bytecode.ConstPool;
020: import java.io.IOException;
021: import java.lang.reflect.Method;
022:
023: /**
024: * Char constant value.
025: *
026: * @author <a href="mailto:bill@jboss.org">Bill Burke</a>
027: * @author Shigeru Chiba
028: */
029: public class CharMemberValue extends MemberValue {
030: int valueIndex;
031:
032: /**
033: * Constructs a char constant value. The initial value is specified
034: * by the constant pool entry at the given index.
035: *
036: * @param index the index of a CONSTANT_Integer_info structure.
037: */
038: public CharMemberValue(int index, ConstPool cp) {
039: super ('C', cp);
040: this .valueIndex = index;
041: }
042:
043: /**
044: * Constructs a char constant value.
045: *
046: * @param c the initial value.
047: */
048: public CharMemberValue(char c, ConstPool cp) {
049: super ('C', cp);
050: setValue(c);
051: }
052:
053: /**
054: * Constructs a char constant value. The initial value is '\0'.
055: */
056: public CharMemberValue(ConstPool cp) {
057: super ('C', cp);
058: setValue('\0');
059: }
060:
061: Object getValue(ClassLoader cl, ClassPool cp, Method m) {
062: return new Character(getValue());
063: }
064:
065: Class getType(ClassLoader cl) {
066: return char.class;
067: }
068:
069: /**
070: * Obtains the value of the member.
071: */
072: public char getValue() {
073: return (char) cp.getIntegerInfo(valueIndex);
074: }
075:
076: /**
077: * Sets the value of the member.
078: */
079: public void setValue(char newValue) {
080: valueIndex = cp.addIntegerInfo(newValue);
081: }
082:
083: /**
084: * Obtains the string representation of this object.
085: */
086: public String toString() {
087: return Character.toString(getValue());
088: }
089:
090: /**
091: * Writes the value.
092: */
093: public void write(AnnotationsWriter writer) throws IOException {
094: writer.constValueIndex(getValue());
095: }
096:
097: /**
098: * Accepts a visitor.
099: */
100: public void accept(MemberValueVisitor visitor) {
101: visitor.visitCharMemberValue(this);
102: }
103: }
|