aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/javassist/bytecode/FieldInfo.java
diff options
context:
space:
mode:
authorchiba <chiba@30ef5769-5b8d-40dd-aea6-55b5d6557bb3>2004-08-30 17:10:34 +0000
committerchiba <chiba@30ef5769-5b8d-40dd-aea6-55b5d6557bb3>2004-08-30 17:10:34 +0000
commitf39d058e65fb1a8b53a965f3ef20b38337ccfd76 (patch)
tree593db80f17e810672b344e47e77099375e6658e1 /src/main/javassist/bytecode/FieldInfo.java
parentbe3a1d153f56e20dde215368b2f7cb5f98ea9370 (diff)
downloadjavassist-f39d058e65fb1a8b53a965f3ef20b38337ccfd76.tar.gz
javassist-f39d058e65fb1a8b53a965f3ef20b38337ccfd76.zip
implemented CtField#getConstantValue().
git-svn-id: http://anonsvn.jboss.org/repos/javassist/trunk@128 30ef5769-5b8d-40dd-aea6-55b5d6557bb3
Diffstat (limited to 'src/main/javassist/bytecode/FieldInfo.java')
-rw-r--r--src/main/javassist/bytecode/FieldInfo.java28
1 files changed, 27 insertions, 1 deletions
diff --git a/src/main/javassist/bytecode/FieldInfo.java b/src/main/javassist/bytecode/FieldInfo.java
index 54ae1ba6..ff45f1ba 100644
--- a/src/main/javassist/bytecode/FieldInfo.java
+++ b/src/main/javassist/bytecode/FieldInfo.java
@@ -60,7 +60,15 @@ public final class FieldInfo {
}
void prune(ConstPool cp) {
- attribute = null;
+ int index = getConstantValue();
+ if (index == 0)
+ attribute = null;
+ else {
+ index = constPool.copy(index, cp, null);
+ attribute = new LinkedList();
+ attribute.add(new ConstantAttribute(cp, index));
+ }
+
name = cp.addUtf8Info(getName());
descriptor = cp.addUtf8Info(getDescriptor());
constPool = cp;
@@ -126,6 +134,24 @@ public final class FieldInfo {
}
/**
+ * Finds a ConstantValue attribute and returns the index into
+ * the <code>constant_pool</code> table.
+ *
+ * @return 0 if a ConstantValue attribute is not found.
+ */
+ public int getConstantValue() {
+ if ((accessFlags & AccessFlag.STATIC) == 0)
+ return 0;
+
+ ConstantAttribute attr
+ = (ConstantAttribute)getAttribute(ConstantAttribute.tag);
+ if (attr == null)
+ return 0;
+ else
+ return attr.getConstantValue();
+ }
+
+ /**
* Returns all the attributes.
* A new element can be added to the returned list
* and an existing element can be removed from the list.