public DynMethod getDynMethod(String name) throws DynMethodException { if (this.methodsMap == null) { consolide(); } MethodAndIndex mindex = (MethodAndIndex) methodsMap.get(name); return mindex == null ? null : mindex.getDynMethod(); }
public void consolide() { // Use classes and decalredFieldsMap to update all. // Updates superClasses array this.superClasses = (DefaultDynClass[]) buildSuperDynClassSet().toArray(new DefaultDynClass[] {}); // Updates declaredFields array this.declaredFields = (DynField[]) this.declaredFieldsMap.values().toArray(new DynField[] {}); // Updates declaredMethods array this.declaredMethods = (DynMethod[]) this.declaredMethodsMap.values().toArray(new DynMethod[] {}); // Updates fieldsMap this.fieldsMap = new LinkedHashMap(); int index = 0; for (int i = 0; i < this.declaredFields.length; i++) { this.fieldsMap.put( this.declaredFields[i].getName().toLowerCase(), new FieldAndIndex(this.declaredFields[i], index++)); } for (int i = 0; i < this.superClasses.length; i++) { Iterator it = this.superClasses[i].declaredFieldsMap.values().iterator(); while (it.hasNext()) { DynField field = (DynField) it.next(); if (!this.fieldsMap.containsKey(field.getName().toLowerCase())) { this.fieldsMap.put(field.getName().toLowerCase(), new FieldAndIndex(field, index++)); } } } // Updates methodsMap this.methodsMap = new LinkedHashMap(); index = 0; for (int i = 0; i < this.declaredMethods.length; i++) { this.methodsMap.put( this.declaredMethods[i].getName(), new MethodAndIndex(this.declaredMethods[i], index++)); } for (int i = 0; i < this.superClasses.length; i++) { Iterator it = this.superClasses[i].declaredMethodsMap.values().iterator(); while (it.hasNext()) { DynMethod method = (DynMethod) it.next(); if (!this.methodsMap.containsKey(method.getName())) { this.methodsMap.put(method.getName(), new MethodAndIndex(method, index++)); } } } // Updates fields array this.fields = new DynField[this.fieldsMap.size()]; int i = 0; Iterator it = this.fieldsMap.values().iterator(); while (it.hasNext()) { FieldAndIndex findex = (FieldAndIndex) it.next(); DynField field = findex.getDynField(); fields[i++] = field; } // Updates methods array this.methods = new DynMethod[this.methodsMap.size()]; i = 0; it = this.methodsMap.values().iterator(); while (it.hasNext()) { MethodAndIndex mindex = (MethodAndIndex) it.next(); DynMethod method = mindex.getDynMethod(); methods[i++] = method; } // Updates superClassesMap this.superClassesMap = new HashMap(); for (i = 0; i < this.superClasses.length; i++) { this.superClassesMap.put(this.superClasses[i].getFullName(), this.superClasses[i]); } }