1 2 29 package com.puppycrawl.tools.checkstyle.checks.usage.transmogrify; 30 31 import java.util.Iterator ; 32 import java.util.SortedSet ; 33 import java.util.TreeSet ; 34 35 36 37 38 48 49 public abstract class Definition implements IDefinition, Comparable { 50 private String _name = null; 51 private Scope _parentScope = null; 52 private SymTabAST _node = null; 53 private SortedSet _references; 54 55 private Occurrence _occurrence = null; 56 57 public Definition(String name, Scope parentScope, SymTabAST node) { 58 _name = name; 59 _parentScope = parentScope; 60 _node = node; 61 _references = new TreeSet (); 62 63 if ( node != null ) { 64 _occurrence = new Occurrence( _node.getFile(), 65 ASTUtil.getLine( _node ), 66 ASTUtil.getColumn( _node )); 67 } 68 } 69 70 public boolean isSourced() { 71 return true; 72 } 73 74 79 80 public String getName() { 81 return _name; 82 } 83 84 89 public SymTabAST getTreeNode() { 90 return _node; 91 } 92 93 98 public void addReference( Reference reference ) { 99 _references.add( reference ); 100 } 101 102 107 public Iterator getReferences() { 108 return _references.iterator(); 109 } 110 111 public int getNumReferences() { 112 return _references.size(); 113 } 114 115 120 public Scope getParentScope() { 121 return _parentScope; 122 } 123 124 131 public String getQualifiedName() { 132 String nameToUse = _name; 133 String result; 134 135 if (_name == null) { 136 nameToUse = "~NO NAME~"; 137 } 138 139 if (getParentScope() != null && 140 !(getParentScope() instanceof BaseScope)) { 141 result = getParentScope().getQualifiedName() + "." + nameToUse; 142 } 143 else { 144 result = nameToUse; 145 } 146 return result; 147 } 148 149 154 public Occurrence getOccurrence() { 155 return _occurrence; 156 } 157 158 163 public ClassDef getEnclosingClass() { 164 ClassDef result = null; 165 166 if ( getParentScope() != null ) { 167 result = getParentScope().getEnclosingClass(); 168 } 169 170 return result; 171 } 172 173 public IPackage getEnclosingPackage() { 174 IPackage result = null; 175 if (getParentScope() != null) { 176 result = getParentScope().getEnclosingPackage(); 177 } 178 179 return result; 180 } 181 182 188 public String toString() { 189 return getClass().getName() + "[" + getQualifiedName() + "]"; 190 } 191 192 public int compareTo(Object o) { 193 int result = 0; 194 195 if (!(o instanceof Definition)) { 196 throw new ClassCastException (o.getClass().getName()); 197 } 198 result = getQualifiedName().compareTo(((Definition)o).getQualifiedName()); 199 200 return result; 201 } 202 203 } 204 | Popular Tags |