Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/puppycrawl/tools/checkstyle/bcel/classfile/FieldDefinition.java


1   //Tested with BCEL-5.1
2   //http://jakarta.apache.org/builds/jakarta-bcel/release/v5.1/
3   
4   package com.puppycrawl.tools.checkstyle.bcel.classfile;
5   
6   import java.util.HashSet;
7   import java.util.Set;
8   
9   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
20      extends FieldOrMethodDefinition
21  {
22      /** the GET references for the Field */
23      private final Set mGetReferences = new HashSet();
24  
25      /** the PUT references for the FSield */
26      private final Set mPutReferences = new HashSet();
27  
28      /**
29       * Creates a <code>FieldDefinition</code> for a Field.
30       * @param aField the Field.
31       */
32      public FieldDefinition(Field aField)
33      {
34          super(aField);
35      }
36  
37      /**
38       * Returns the Field for this definition.
39       * @return the Field for this definition.
40       */
41      public Field getField()
42      {
43          return (Field) getFieldOrMethod();
44      }
45  
46      /**
47       * Determines the number of read, or GET, references to the Field.
48       * @return the number of read references to the Field.
49       */
50      public int getReadReferenceCount()
51      {
52          return mGetReferences.size();
53      }
54  
55      /**
56       * Determines the number of write, or PUT, references to the Field.
57       * @return the number of write references to the Field.
58       */
59      public int getWriteReferenceCount()
60      {
61          return mPutReferences.size();
62      }
63  
64      /**
65       * Determines the total number of references to the Field.
66       * @return the number of references to the Field.
67       */
68      public int getReferenceCount()
69      {
70          return getReadReferenceCount() + getWriteReferenceCount();
71      }
72  
73      /**
74       * Adds a reference to the Field.
75       * @param aFieldRef the reference.
76       */
77      public void addReference(FieldReference aFieldRef)
78      {
79          // TODO Polymorphize
80          if ((aFieldRef instanceof PUTFIELDReference)
81              || (aFieldRef instanceof PUTSTATICReference))
82          {
83              mPutReferences.add(aFieldRef);
84          }
85          else {
86              mGetReferences.add(aFieldRef);
87          }
88      }
89  }