KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > beehive > controls > runtime > generator > AptMethodSet


1 package org.apache.beehive.controls.runtime.generator;
2 /*
3  * Copyright 2004 The Apache Software Foundation.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  * $Header:$
18  */

19
20 import java.util.ArrayList JavaDoc;
21 import java.util.HashMap JavaDoc;
22 import java.util.Collection JavaDoc;
23
24 import com.sun.mirror.declaration.ClassDeclaration;
25 import com.sun.mirror.declaration.MethodDeclaration;
26 import com.sun.mirror.declaration.ParameterDeclaration;
27 import com.sun.mirror.type.ClassType;
28 import com.sun.mirror.type.PrimitiveType;
29 import com.sun.mirror.type.ReferenceType;
30 import com.sun.mirror.type.TypeMirror;
31
32 import org.apache.beehive.controls.api.packaging.FeatureInfo;
33
34
35 /**
36  * The AptMethodSet method represents a collection of AptMethod objects. It contains special
37  * support for method overloading, to ensure that overloaded method objects contained within
38  * the set will each have a unique index value.
39  *
40  * @see org.apache.beehive.controls.runtime.generator.AptMethod#setIndex
41  */

42 public class AptMethodSet<T extends AptMethod>
43 {
44     /**
45      * Adds a new method to the list. Also detects overloaded methods and ensures that they
46      * will receive a unique index value.
47      */

48     public void add(T method)
49     {
50         // Add to the list of managed methods
51
_methods.add(method);
52
53         // Ensure that all added methods have a unique index
54
Object JavaDoc nameValue = _nameMap.get(method.getName());
55         if (nameValue == null)
56         {
57             // first method with this name, considered unique (for now)
58
_nameMap.put(method.getName(), method);
59         }
60         else
61         {
62             int nextIndex;
63             if (nameValue instanceof AptMethod)
64             {
65                 // 2nd method with this name, add index to original and start indexing
66
((AptMethod)nameValue).setIndex(0);
67                 nextIndex = 1;
68             }
69             else
70             {
71                 // 3rd (or later) method with this name, continue indexing
72
nextIndex = ((Integer JavaDoc)nameValue).intValue();
73             }
74
75             method.setIndex(nextIndex++);
76             _nameMap.put(method.getName(), nextIndex);
77         }
78     }
79
80     public Collection JavaDoc<T> getMethods()
81     {
82         return _methods;
83     }
84
85     public int size()
86     {
87         return _methods.size();
88     }
89         
90     HashMap JavaDoc _nameMap = new HashMap JavaDoc(); // method name -> a single (unique) AptMethod or next index
91
ArrayList JavaDoc<T> _methods = new ArrayList JavaDoc<T>();
92 }
93
Popular Tags