public void registerSubclassInstanceMethod(MetaMethod metaMethod) { modified = true; final String name = metaMethod.getName(); Object methodOrList = expandoSubclassMethods.get(name); if (methodOrList == null) { expandoSubclassMethods.put(name, metaMethod); } else { if (methodOrList instanceof MetaMethod) { FastArray arr = new FastArray(2); arr.add(methodOrList); arr.add(metaMethod); expandoSubclassMethods.put(name, arr); } else { ((FastArray) methodOrList).add(metaMethod); } } }
private void createMetaMethodFromClass(Map<CachedClass, List<MetaMethod>> map, Class aClass) { try { MetaMethod method = (MetaMethod) aClass.newInstance(); final CachedClass declClass = method.getDeclaringClass(); List<MetaMethod> arr = map.get(declClass); if (arr == null) { arr = new ArrayList<MetaMethod>(4); map.put(declClass, arr); } arr.add(method); instanceMethods.add(method); } catch (InstantiationException | IllegalAccessException e) { /* ignore */ } }
private static void filterMatchingMethodForCategory(FastArray list, MetaMethod method) { int len = list.size(); if (len==0) { list.add(method); return; } Object data[] = list.getArray(); for (int j = 0; j != len; ++j) { MetaMethod aMethod = (MetaMethod) data[j]; Boolean match = getMatchKindForCategory(aMethod, method); // true == replace if (match==Boolean.TRUE) { list.set(j, method); return; // null == ignore (we have a better method already) } else if (match==null) { return; } } // the casese true and null for a match are through, the // remaining case is false and that means adding the method // to our list list.add(method); }
public synchronized void initialize() { if (!isInitialized()) { CachedMethod[] methodArray = theCachedClass.getMethods(); synchronized (theCachedClass) { for (final CachedMethod cachedMethod : methodArray) { if (!cachedMethod.getName().equals(CLOSURE_DO_CALL_METHOD)) continue; closureMethods.add(cachedMethod); } } assignMethodChooser(); initialized = true; } }
if (answer instanceof MetaMethod) { arr = new FastArray(); arr.add(answer);
public void onModule(final ExtensionModule module) { if (moduleRegistry.hasModule(module.getName())) { ExtensionModule loadedModule = moduleRegistry.getModule(module.getName()); if (loadedModule.getVersion().equals(module.getVersion())) { // already registered return; } else { throw new GroovyRuntimeException("Conflicting module versions. Module [" + module.getName() + " is loaded in version " + loadedModule.getVersion() + " and you are trying to load version " + module.getVersion()); } } moduleRegistry.addModule(module); // register MetaMethods List<MetaMethod> metaMethods = module.getMetaMethods(); for (MetaMethod metaMethod : metaMethods) { CachedClass cachedClass = metaMethod.getDeclaringClass(); List<MetaMethod> methods = map.get(cachedClass); if (methods == null) { methods = new ArrayList<MetaMethod>(4); map.put(cachedClass, methods); } methods.add(metaMethod); if (metaMethod.isStatic()) { staticMethods.add(metaMethod); } else { instanceMethods.add(metaMethod); } } } }
public void registerSubclassInstanceMethod(MetaMethod metaMethod) { modified = true; final String name = metaMethod.getName(); Object methodOrList = expandoSubclassMethods.get(name); if (methodOrList == null) { expandoSubclassMethods.put(name, metaMethod); } else { if (methodOrList instanceof MetaMethod) { FastArray arr = new FastArray(2); arr.add(methodOrList); arr.add(metaMethod); expandoSubclassMethods.put(name, arr); } else { ((FastArray) methodOrList).add(metaMethod); } } }
public void registerSubclassInstanceMethod(MetaMethod metaMethod) { modified = true; final String name = metaMethod.getName(); Object methodOrList = expandoSubclassMethods.get(name); if (methodOrList == null) { expandoSubclassMethods.put(name, metaMethod); } else { if (methodOrList instanceof MetaMethod) { FastArray arr = new FastArray(2); arr.add(methodOrList); arr.add(metaMethod); expandoSubclassMethods.put(name, arr); } else { ((FastArray)methodOrList).add(metaMethod); } } }
private void createMetaMethodFromClass(Map<CachedClass, List<MetaMethod>> map, Class aClass) { try { MetaMethod method = (MetaMethod) aClass.newInstance(); final CachedClass declClass = method.getDeclaringClass(); List<MetaMethod> arr = map.get(declClass); if (arr == null) { arr = new ArrayList<MetaMethod>(4); map.put(declClass, arr); } arr.add(method); instanceMethods.add(method); } catch (InstantiationException e) { /* ignore */ } catch (IllegalAccessException e) { /* ignore */ } }
private void createMetaMethodFromClass(Map map, Class aClass) { try { MetaMethod method = (MetaMethod) aClass.newInstance(); final CachedClass declClass = method.getDeclaringClass(); ArrayList arr = (ArrayList) map.get(declClass); if (arr == null) { arr = new ArrayList(4); map.put(declClass,arr); } arr.add(method); instanceMethods.add(method); } catch (InstantiationException e) { } catch (IllegalAccessException e) { } }
private void createMetaMethodFromClass(Map map, Class aClass) { try { MetaMethod method = (MetaMethod) aClass.newInstance(); final CachedClass declClass = method.getDeclaringClass(); ArrayList arr = (ArrayList) map.get(declClass); if (arr == null) { arr = new ArrayList(4); map.put(declClass,arr); } arr.add(method); instanceMethods.add(method); } catch (InstantiationException e) { } catch (IllegalAccessException e) { } }
public void registerSubclassInstanceMethod(MetaMethod metaMethod) { modified = true; final String name = metaMethod.getName(); Object methodOrList = expandoSubclassMethods.get(name); if (methodOrList == null) { expandoSubclassMethods.put(name, metaMethod); } else { if (methodOrList instanceof MetaMethod) { FastArray arr = new FastArray(2); arr.add(methodOrList); arr.add(metaMethod); expandoSubclassMethods.put(name, arr); } else { ((FastArray)methodOrList).add(metaMethod); } } }
private void filterMatchingMethodForCategory(FastArray list, MetaMethod method) { int len = list.size(); if (len==0) { list.add(method); return; } Object data[] = list.getArray(); for (int j = 0; j != len; ++j) { MetaMethod aMethod = (MetaMethod) data[j]; Boolean match = getMatchKindForCategory(aMethod, method); // true == replace if (match==Boolean.TRUE) { list.set(j, method); return; // null == ignore (we have a better method already) } else if (match==null) { return; } } // the casese true and null for a match are through, the // remaining case is false and that means adding the method // to our list list.add(method); }
private void filterMatchingMethodForCategory(FastArray list, MetaMethod method) { int len = list.size(); if (len==0) { list.add(method); return; } Object data[] = list.getArray(); for (int j = 0; j != len; ++j) { MetaMethod aMethod = (MetaMethod) data[j]; Boolean match = getMatchKindForCategory(aMethod, method); // true == replace if (match==Boolean.TRUE) { list.set(j, method); return; // null == ignore (we have a better method already) } else if (match==null) { return; } } // the casese true and null for a match are through, the // remaining case is false and that means adding the method // to our list list.add(method); }
public synchronized void initialize() { if (!isInitialized()) { CachedMethod[] methodArray = theCachedClass.getMethods(); synchronized (theCachedClass) { for (final CachedMethod cachedMethod : methodArray) { if (!cachedMethod.getName().equals(CLOSURE_DO_CALL_METHOD)) continue; closureMethods.add(cachedMethod); } } assignMethodChooser(); initialized = true; } }
public static void addExtensionMethods(ExtensionModule module) { MetaClassRegistry metaClassRegistry = GroovySystem.getMetaClassRegistry(); ((MetaClassRegistryImpl) metaClassRegistry).getModuleRegistry().addModule(module); Map<CachedClass, List<MetaMethod>> classMap = new HashMap<>(); for (MetaMethod metaMethod : module.getMetaMethods()){ if (classMap.containsKey(metaMethod.getDeclaringClass())){ classMap.get(metaMethod.getDeclaringClass()).add(metaMethod); } else { List<MetaMethod> methodList = new ArrayList<>(); methodList.add(metaMethod); classMap.put(metaMethod.getDeclaringClass(), methodList); } if (metaMethod.isStatic()){ ((MetaClassRegistryImpl)metaClassRegistry).getStaticMethods().add(metaMethod); } else { ((MetaClassRegistryImpl)metaClassRegistry).getInstanceMethods().add(metaMethod); } LOG.debug("registered method: {}", metaMethod); } for (Map.Entry<CachedClass, List<MetaMethod>> cachedClassEntry : classMap.entrySet()) { cachedClassEntry.getKey().addNewMopMethods(cachedClassEntry.getValue()); } }
public synchronized void initialize() { if (!isInitialized()) { CachedMethod[] methodArray = theCachedClass.getMethods(); synchronized (theCachedClass) { for (int i = 0; i < methodArray.length; i++) { final CachedMethod cachedMethod = methodArray[i]; if (!cachedMethod.getName().equals(CLOSURE_DO_CALL_METHOD)) continue; MetaMethod method = cachedMethod; closureMethods.add(method); } } assignMethodChooser(); initialized = true; } }
public synchronized void initialize() { if (!isInitialized()) { CachedMethod[] methodArray = theCachedClass.getMethods(); synchronized (theCachedClass) { for (int i = 0; i < methodArray.length; i++) { final CachedMethod cachedMethod = methodArray[i]; if (!cachedMethod.getName().equals(CLOSURE_DO_CALL_METHOD)) continue; MetaMethod method = cachedMethod; closureMethods.add(method); } } assignMethodChooser(); initialized = true; } }