View Javadoc

1   /*
2    * Copyright (c) 2001-2003 The XDoclet team
3    * All rights reserved.
4    */
5   package xjavadoc;
6   
7   import java.util.Iterator;
8   import java.util.StringTokenizer;
9   
10  /***
11   * This is a flyweight implementation of XParameter
12   *
13   * @author    Ara Abrahamian (ara_e_w@yahoo.com)
14   * @author    Aslak Hellesøy
15   * @created   9. mars 2003
16   * @version   $Revision: 1.18 $
17   */
18  public final class ParameterImpl extends AbstractType implements XParameter
19  {
20  	public static int  instanceCount = 0;
21  
22  	/***
23  	 * XMember we're currently reresenting.
24  	 */
25  	private AbstractExecutableMember _containingExecutableMember;
26  
27  	/***
28  	 * Index of the parameter we're currently representing.
29  	 */
30  	private int        _parameterIndex;
31  
32  	private String     _description;
33  
34  	public ParameterImpl()
35  	{
36  		instanceCount++;
37  	}
38  
39  	public final String getName()
40  	{
41  		return _containingExecutableMember.getParameterName( _parameterIndex );
42  	}
43  
44  	/***
45  	 * Returns the class describing the type of this parameter.
46  	 *
47  	 * @return
48  	 */
49  	public final XClass getType()
50  	{
51  		String type = _containingExecutableMember.getParameterType( _parameterIndex );
52  		AbstractClass containingClass = _containingExecutableMember.getContainingAbstractClass();
53  
54  		XClass result = containingClass.qualify( type );
55  
56  		return result;
57  	}
58  
59  	public final int getDimension()
60  	{
61  		return _containingExecutableMember.getParameterDimension( _parameterIndex );
62  	}
63  
64  	public XTag getParamTag()
65  	{
66  		for( Iterator paramTags = _containingExecutableMember.getDoc().getTags( "param", true ).iterator(); paramTags.hasNext();  )
67  		{
68  			XTag paramTag = ( XTag ) paramTags.next();
69  			StringTokenizer st = new StringTokenizer( paramTag.getValue() );
70  
71  			if( st.hasMoreTokens() )
72  			{
73  				if( st.nextToken().equals( getName() ) )
74  				{
75  					// We found the @param tag.
76  
77  					// Set the description so it's readily available if someone asks for it.
78  					_description = paramTag.getValue().substring( getName().length() ).trim();
79  					return paramTag;
80  				}
81  			}
82  		}
83  		// Didn't find any param tags.
84  		_description = null;
85  		return null;
86  	}
87  
88  	public String getDescription()
89  	{
90  		XTag paramTag = getParamTag();
91  
92  		if( paramTag != null )
93  		{
94  			return _description;
95  		}
96  		else
97  		{
98  			return null;
99  		}
100 	}
101 
102 	public String getDimensionAsString()
103 	{
104 		return Util.appendDimensionAsString( getDimension(), new StringBuffer() ).toString();
105 	}
106 
107 	public final String toString()
108 	{
109 		StringBuffer sb = new StringBuffer( getType().getQualifiedName() );
110 
111 		Util.appendDimensionAsString( getDimension(), sb ).append( " " ).append( getName() );
112 		return sb.toString();
113 	}
114 
115 	/***
116 	 * Sets the extrinsic flyweight state.
117 	 *
118 	 * @param containingExecutableMember  The containing member
119 	 * @param parameterIndex
120 	 */
121 	final void setState( AbstractExecutableMember containingExecutableMember, int parameterIndex )
122 	{
123 		_containingExecutableMember = containingExecutableMember;
124 		_parameterIndex = parameterIndex;
125 	}
126 }