KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > puppycrawl > tools > checkstyle > checks > usage > transmogrify > ReferenceCounter


1
2 // Transmogrify License
3
//
4
// Copyright (c) 2001, ThoughtWorks, Inc.
5
// All rights reserved.
6
// Redistribution and use in source and binary forms, with or without
7
// modification, are permitted provided that the following conditions
8
// are met:
9
// - Redistributions of source code must retain the above copyright notice,
10
// this list of conditions and the following disclaimer.
11
// - Redistributions in binary form must reproduce the above copyright
12
// notice, this list of conditions and the following disclaimer in the
13
// documentation and/or other materials provided with the distribution.
14
// Neither the name of the ThoughtWorks, Inc. nor the names of its
15
// contributors may be used to endorse or promote products derived from this
16
// software without specific prior written permission.
17
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19
// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
21
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
24
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
26
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
27
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28

29 package com.puppycrawl.tools.checkstyle.checks.usage.transmogrify;
30
31 import java.util.ArrayList JavaDoc;
32 import java.util.List JavaDoc;
33 import java.util.ListIterator JavaDoc;
34
35 import com.puppycrawl.tools.checkstyle.api.TokenTypes;
36
37 /**
38  * This class is for counting the reference
39  */

40 public class ReferenceCounter extends ReferenceTool {
41   private List JavaDoc _references = new ArrayList JavaDoc();
42   private List JavaDoc _resolvedReferences = new ArrayList JavaDoc();
43   private List JavaDoc _unresolvedReferences = new ArrayList JavaDoc();
44
45   public ReferenceCounter(SymbolTable table) {
46     super(table.getTree());
47     countReferences();
48   }
49
50   /**
51    * Return the number of references
52    */

53   public int numberOfReferences() {
54     return _references.size();
55   }
56
57   /**
58    * Return the number of resolved references
59    */

60   public int numberOfResolvedReferences() {
61     return _resolvedReferences.size();
62   }
63
64   public int numberOfUnresolvedReferences() {
65     return _unresolvedReferences.size();
66   }
67
68   public ListIterator JavaDoc getUnresolvedReferences() {
69     return _unresolvedReferences.listIterator();
70   }
71
72   private void countReferences() {
73     handleNode( _tree );
74   }
75
76   protected void handleNode( SymTabAST node ) {
77     if (node.getType() == TokenTypes.IDENT && node.isMeaningful()) {
78       _references.add( node );
79       if (node.getDefinition() != null && !(node.getDefinition() instanceof UnknownClass)) {
80             _resolvedReferences.add( node );
81       }
82       else {
83             _unresolvedReferences.add( node );
84       }
85     }
86     walkChildren( node );
87   }
88 }
89
Popular Tags