1 19 20 package org.netbeans.modules.java.bridge; 21 22 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 return res; 44 } 45 46 public Element [] getEmptyArray () { 47 return EMPTY; 48 } 49 50 public String 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 public boolean matches (Element elem, RefObject f) { 85 Constructor method = (Constructor) f; 86 ConstructorElement methodElem = (ConstructorElement) elem; 87 88 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 |