KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > java > bridge > ConstructorsCollection


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.java.bridge;
21
22 // import java.beans.PropertyChangeEvent;
23
import java.util.*;
24
25 import javax.jmi.reflect.RefObject;
26 import org.netbeans.jmi.javamodel.Constructor;
27 import org.netbeans.jmi.javamodel.Parameter;
28 import org.netbeans.jmi.javamodel.TypeReference;
29
30 import org.openide.src.*;
31
32 class ConstructorsCollection extends ObjectsCollection {
33
34     static final ConstructorElement[] EMPTY = new ConstructorElement[0];
35
36     public ConstructorsCollection(FeaturesCollection members) {
37         super (members);
38     }
39
40     public RefObject createFeature(RefObject parent, Element elem) {
41         Constructor res = members.createConstructor ((ConstructorElement) elem);
42         // res.setDeclaringClass ((JavaClass) parent);
43
return res;
44     }
45     
46     public Element [] getEmptyArray () {
47         return EMPTY;
48     }
49     
50     public String JavaDoc getPropertyName () {
51         return ElementProperties.PROP_CONSTRUCTORS;
52     }
53     
54     public boolean isOfType (RefObject feature) {
55         return feature instanceof Constructor;
56     }
57     
58     public Element createElement (RefObject constr) {
59         return (ConstructorElement) members.model.createConstructor (members.getParentClass (), (Constructor)constr).getElement ();
60     }
61     
62     public ConstructorElement getConstructor(Type[] argtypes) {
63         members.repository.beginTrans(false);
64         try {
65             if (isValid()) {
66                 if (argtypes == null)
67                     argtypes = NO_TYPES;
68                 List args = members.typesToDescriptors (argtypes);
69                 Constructor constr = members.javaClass.getConstructor (args, false);
70                 return constr == null ? null : (ConstructorElement)cachedElement (constr);
71             } else {
72                 return null;
73             }
74         } finally {
75             members.repository.endTrans();
76         }
77     }
78     
79     public ConstructorElement [] getConstructors() {
80         return (ConstructorElement []) getElements ();
81     }
82     
83     // [PENDING] this code nearly duplicates MethodsCollection.matches () ...
84
public boolean matches (Element elem, RefObject f) {
85         Constructor method = (Constructor) f;
86         ConstructorElement methodElem = (ConstructorElement) elem;
87         
88         // check parameters
89
List params = method.getParameters();
90         MethodParameter [] params2 = methodElem.getParameters ();
91         if (params.size () != params2.length)
92             return false;
93         Iterator iter = params.iterator ();
94         for (int x = 0; x < params2.length; x++) {
95             TypeReference typeRef = ((Parameter) iter.next ()).getTypeName ();
96             Type type2 = params2 [x].getType ();
97             if (typeRef == null) {
98                 if (type2 != null)
99                     return false;
100             } else if (!members.parentImpl.typeReferenceToType (typeRef).equals (type2))
101                 return false;
102         }
103         
104         return true;
105     }
106     
107     public int getPositionalValue () {
108         return ObjectsCollection.POS_VAL_CONSTRUCTOR;
109     }
110     
111 }
112
Popular Tags