01: //Tested with BCEL-5.1
02: //http://jakarta.apache.org/builds/jakarta-bcel/release/v5.1/
03:
04: package com.puppycrawl.tools.checkstyle.bcel.classfile;
05:
06: import java.util.HashSet;
07: import java.util.Set;
08:
09: import org.apache.bcel.classfile.Field;
10:
11: import com.puppycrawl.tools.checkstyle.bcel.generic.FieldReference;
12: import com.puppycrawl.tools.checkstyle.bcel.generic.PUTFIELDReference;
13: import com.puppycrawl.tools.checkstyle.bcel.generic.PUTSTATICReference;
14:
15: /**
16: * Contains the definition of a Field and its references.
17: * @author Rick Giles
18: */
19: public class FieldDefinition extends FieldOrMethodDefinition {
20: /** the GET references for the Field */
21: private final Set mGetReferences = new HashSet();
22:
23: /** the PUT references for the FSield */
24: private final Set mPutReferences = new HashSet();
25:
26: /**
27: * Creates a <code>FieldDefinition</code> for a Field.
28: * @param aField the Field.
29: */
30: public FieldDefinition(Field aField) {
31: super (aField);
32: }
33:
34: /**
35: * Returns the Field for this definition.
36: * @return the Field for this definition.
37: */
38: public Field getField() {
39: return (Field) getFieldOrMethod();
40: }
41:
42: /**
43: * Determines the number of read, or GET, references to the Field.
44: * @return the number of read references to the Field.
45: */
46: public int getReadReferenceCount() {
47: return mGetReferences.size();
48: }
49:
50: /**
51: * Determines the number of write, or PUT, references to the Field.
52: * @return the number of write references to the Field.
53: */
54: public int getWriteReferenceCount() {
55: return mPutReferences.size();
56: }
57:
58: /**
59: * Determines the total number of references to the Field.
60: * @return the number of references to the Field.
61: */
62: public int getReferenceCount() {
63: return getReadReferenceCount() + getWriteReferenceCount();
64: }
65:
66: /**
67: * Adds a reference to the Field.
68: * @param aFieldRef the reference.
69: */
70: public void addReference(FieldReference aFieldRef) {
71: // TODO Polymorphize
72: if ((aFieldRef instanceof PUTFIELDReference)
73: || (aFieldRef instanceof PUTSTATICReference)) {
74: mPutReferences.add(aFieldRef);
75: } else {
76: mGetReferences.add(aFieldRef);
77: }
78: }
79: }
|