1 19 20 package org.netbeans.modules.java.bridge; 21 22 import java.util.*; 24 25 import org.openide.src.*; 26 27 import javax.jmi.reflect.RefObject; 28 29 import org.netbeans.jmi.javamodel.Method; 30 import org.netbeans.jmi.javamodel.Parameter; 31 import org.netbeans.jmi.javamodel.TypeReference; 32 33 class MethodsCollection extends ObjectsCollection { 34 35 static final MethodElement[] EMPTY = new MethodElement[0]; 36 37 public MethodsCollection(FeaturesCollection members) { 38 super (members); 39 } 40 41 public RefObject createFeature(RefObject parent, Element elem) { 42 Method res = members.createMethod ((MethodElement) elem); 43 return res; 45 } 46 47 public Element [] getEmptyArray () { 48 return EMPTY; 49 } 50 51 public String getPropertyName () { 52 return ElementProperties.PROP_METHODS; 53 } 54 55 public boolean isOfType (RefObject feature) { 56 return feature instanceof Method; 57 } 58 59 public Element createElement (RefObject method) { 60 return (MethodElement) members.model.createMethod (members.getParentClass (), (Method)method).getElement (); 61 } 62 63 public MethodElement getMethod(Identifier name, Type[] argtypes) { 64 members.repository.beginTrans(false); 65 try { 66 if (isValid()) { 67 String methodName = name.getName(); 68 if (argtypes == null) 69 argtypes = ObjectsCollection.NO_TYPES; 70 List args = members.typesToDescriptors (argtypes); 71 Method method = members.javaClass.getMethod (methodName, args, false); 72 return method == null ? null : (MethodElement)cachedElement (method); 73 } else { 74 return null; 75 } 76 } finally { 77 members.repository.endTrans(); 78 } 79 } 80 81 public MethodElement [] getMethods() { 82 return (MethodElement []) getElements (); 83 } 84 85 public boolean matches (Element elem, RefObject f) { 86 Method method = (Method) f; 87 MethodElement methodElem = (MethodElement) elem; 88 89 if (!methodElem.getName ().getName ().equals (method.getName ())) 91 return false; 92 93 Type returnType2 = methodElem.getReturn (); 95 TypeReference returnType = method.getTypeName(); 96 if (returnType == null) { 97 if (returnType2 != null) 98 return false; 99 } else if (!members.parentImpl.typeReferenceToType (returnType).equals (returnType2)) 100 return false; 101 102 List params = method.getParameters(); 104 MethodParameter [] params2 = methodElem.getParameters (); 105 if (params.size () != params2.length) 106 return false; 107 Iterator iter = params.iterator (); 108 for (int x = 0; x < params2.length; x++) { 109 TypeReference typeRef = ((Parameter) iter.next ()).getTypeName (); 110 Type type2 = params2 [x].getType (); 111 if (typeRef == null) { 112 if (type2 != null) 113 return false; 114 } else if (!members.parentImpl.typeReferenceToType (typeRef).equals (type2)) 115 return false; 116 } 117 118 return true; 119 } 120 121 public int getPositionalValue () { 122 return ObjectsCollection.POS_VAL_METHOD; 123 } 124 } 125 | Popular Tags |