public Closure run() { // assume closures have only 1 constructor, of the form (Object, Reference*) Constructor constructor = closureClass.getConstructors()[0]; int paramCount = constructor.getParameterTypes().length; Object[] args = new Object[paramCount]; args[0] = delegate; for (int i = 1; i < paramCount; i++) { args[i] = new Reference(new BindPathSnooper()); } try { boolean acc = constructor.isAccessible(); constructor.setAccessible(true); Closure localCopy = (Closure) constructor.newInstance(args); if (!acc) { constructor.setAccessible(false); } localCopy.setResolveStrategy(Closure.DELEGATE_ONLY); for (Field f:closureClass.getDeclaredFields()) { acc = f.isAccessible(); f.setAccessible(true); if (f.getType() == Reference.class) { delegate.fields.put(f.getName(), (BindPathSnooper) ((Reference) f.get(localCopy)).get()); } if (!acc) { f.setAccessible(false); } } return localCopy; } catch (Exception e) { throw new RuntimeException("Error snooping closure", e); } } });
/** * This method is the workhorse of the builder. * * @param methodName the name of the method being invoked * @param name the name of the node * @param args the arguments passed into the node * @return the object from the factory */ private Object doInvokeMethod(String methodName, Object name, Object args) { Reference explicitResult = new Reference(); if (checkExplicitMethod(methodName, args, explicitResult)) { return explicitResult.get(); } else { try { return dispatchNodeCall(name, args); } catch(MissingMethodException mme) { if(mme.getMethod().equals(methodName) && methodMissingDelegate != null) { return methodMissingDelegate.call(methodName, args); } throw mme; } } }
private static void addGetterIfNeeded(DelegateDescription delegate, PropertyNode prop, String name, boolean allNames) { boolean isPrimBool = prop.getOriginType().equals(ClassHelper.boolean_TYPE); // do a little bit of pre-work since Groovy compiler hasn't added property accessors yet boolean willHaveGetAccessor = true; boolean willHaveIsAccessor = isPrimBool; String suffix = Verifier.capitalize(name); if (isPrimBool) { ClassNode cNode = prop.getDeclaringClass(); if (cNode.getGetterMethod("is" + suffix) != null && cNode.getGetterMethod("get" + suffix) == null) willHaveGetAccessor = false; if (cNode.getGetterMethod("get" + suffix) != null && cNode.getGetterMethod("is" + suffix) == null) willHaveIsAccessor = false; } Reference<Boolean> ownerWillHaveGetAccessor = new Reference<Boolean>(); Reference<Boolean> ownerWillHaveIsAccessor = new Reference<Boolean>(); extractAccessorInfo(delegate.owner, name, ownerWillHaveGetAccessor, ownerWillHaveIsAccessor); for (String prefix : new String[]{"get", "is"}) { String getterName = prefix + suffix; if ((prefix.equals("get") && willHaveGetAccessor && !ownerWillHaveGetAccessor.get() || prefix.equals("is") && willHaveIsAccessor && !ownerWillHaveIsAccessor.get()) && !shouldSkipPropertyMethod(name, getterName, delegate.excludes, delegate.includes, allNames)) { addGeneratedMethod(delegate.owner, getterName, ACC_PUBLIC, GenericsUtils.nonGeneric(prop.getType()), Parameter.EMPTY_ARRAY, null, returnS(propX(delegate.getOp, name))); } } }
Expression objectExpression = pexp.getObjectExpression(); ClassNode objectExpressionType = getType(objectExpression); final Reference<ClassNode> rType = new Reference<ClassNode>(objectExpressionType); ClassCodeVisitorSupport receiverMemoizer = new ClassCodeVisitorSupport() { @Override if (exists) { if (objectExpression.getNodeMetaData(StaticCompilationMetadataKeys.PROPERTY_OWNER)==null) { objectExpression.putNodeMetaData(StaticCompilationMetadataKeys.PROPERTY_OWNER, rType.get());
/** * This method is the workhorse of the builder. * * @param methodName the name of the method being invoked * @param name the name of the node * @param args the arguments passed into the node * @return the object from the factory */ private Object doInvokeMethod(String methodName, Object name, Object args) { Reference explicitResult = new Reference(); if (checkExplicitMethod(methodName, args, explicitResult)) { return explicitResult.get(); } else { return dispathNodeCall(name, args); } }
/** * This method is the workhorse of the builder. * * @param methodName the name of the method being invoked * @param name the name of the node * @param args the arguments passed into the node * @return the object from the factory */ private Object doInvokeMethod(String methodName, Object name, Object args) { Reference explicitResult = new Reference(); if (checkExplicitMethod(methodName, args, explicitResult)) { return explicitResult.get(); } else { return dispathNodeCall(name, args); } }
public Closure run() { // assume closures have only 1 constructor, of the form (Object, Reference*) Constructor constructor = closureClass.getConstructors()[0]; int paramCount = constructor.getParameterTypes().length; Object[] args = new Object[paramCount]; args[0] = delegate; for (int i = 1; i < paramCount; i++) { args[i] = new Reference(new BindPathSnooper()); } try { boolean acc = constructor.isAccessible(); constructor.setAccessible(true); Closure localCopy = (Closure) constructor.newInstance(args); if (!acc) { constructor.setAccessible(false); } localCopy.setResolveStrategy(Closure.DELEGATE_ONLY); for (Field f:closureClass.getDeclaredFields()) { acc = f.isAccessible(); f.setAccessible(true); if (f.getType() == Reference.class) { delegate.fields.put(f.getName(), (BindPathSnooper) ((Reference) f.get(localCopy)).get()); } if (!acc) { f.setAccessible(false); } } return localCopy; } catch (Exception e) { throw new RuntimeException("Error snooping closure", e); } } });
public Closure run() { // assume closures have only 1 constructor, of the form (Object, Reference*) Constructor constructor = closureClass.getConstructors()[0]; int paramCount = constructor.getParameterTypes().length; Object[] args = new Object[paramCount]; args[0] = delegate; for (int i = 1; i < paramCount; i++) { args[i] = new Reference(new BindPathSnooper()); } try { boolean acc = constructor.isAccessible(); constructor.setAccessible(true); Closure localCopy = (Closure) constructor.newInstance(args); if (!acc) { constructor.setAccessible(false); } localCopy.setResolveStrategy(Closure.DELEGATE_ONLY); for (Field f:closureClass.getDeclaredFields()) { acc = f.isAccessible(); f.setAccessible(true); if (f.getType() == Reference.class) { delegate.fields.put(f.getName(), (BindPathSnooper) ((Reference) f.get(localCopy)).get()); } if (!acc) { f.setAccessible(false); } } return localCopy; } catch (Exception e) { throw new RuntimeException("Error snooping closure", e); } } });
public Closure run() { // assume closures have only 1 constructor, of the form (Object, Reference*) Constructor constructor = closureClass.getConstructors()[0]; int paramCount = constructor.getParameterTypes().length; Object[] args = new Object[paramCount]; args[0] = delegate; for (int i = 1; i < paramCount; i++) { args[i] = new Reference(new BindPathSnooper()); } try { boolean acc = constructor.isAccessible(); constructor.setAccessible(true); Closure localCopy = (Closure) constructor.newInstance(args); if (!acc) { constructor.setAccessible(false); } localCopy.setResolveStrategy(Closure.DELEGATE_ONLY); for (Field f:closureClass.getDeclaredFields()) { acc = f.isAccessible(); f.setAccessible(true); if (f.getType() == Reference.class) { delegate.fields.put(f.getName(), (BindPathSnooper) ((Reference) f.get(localCopy)).get()); } if (!acc) { f.setAccessible(false); } } return localCopy; } catch (Exception e) { throw new RuntimeException("Error snooping closure", e); } } });
public Closure run() { // assume closures have only 1 constructor, of the form (Object, Reference*) Constructor constructor = closureClass.getConstructors()[0]; int paramCount = constructor.getParameterTypes().length; Object[] args = new Object[paramCount]; args[0] = delegate; for (int i = 1; i < paramCount; i++) { args[i] = new Reference(new BindPathSnooper()); } try { boolean acc = constructor.isAccessible(); constructor.setAccessible(true); Closure localCopy = (Closure) constructor.newInstance(args); if (!acc) { constructor.setAccessible(false); } localCopy.setResolveStrategy(Closure.DELEGATE_ONLY); for (Field f:closureClass.getDeclaredFields()) { acc = f.isAccessible(); f.setAccessible(true); if (f.getType() == Reference.class) { delegate.fields.put(f.getName(), (BindPathSnooper) ((Reference) f.get(localCopy)).get()); } if (!acc) { f.setAccessible(false); } } return localCopy; } catch (Exception e) { throw new RuntimeException("Error snooping closure", e); } } });
@Override public Closure run() { Constructor constructor = closureClass.getConstructors()[0]; int paramCount = constructor.getParameterTypes().length; Object[] args = new Object[paramCount]; args[0] = delegate; for (int i = 1; i < paramCount; i++) { args[i] = new Reference(new Snooper()); } try { boolean acc = constructor.isAccessible(); constructor.setAccessible(true); Closure localCopy = (Closure) constructor.newInstance(args); if (!acc) { constructor.setAccessible(false); } localCopy.setResolveStrategy(Closure.DELEGATE_ONLY); for (Field f:closureClass.getDeclaredFields()) { acc = f.isAccessible(); f.setAccessible(true); if (f.getType() == Reference.class) { delegate.getFields().put(f.getName(), (Snooper)((Reference) f.get(localCopy)).get()); } if (!acc) { f.setAccessible(false); } } return localCopy; } catch (Exception e) { throw new RuntimeException("Error snooping closure", e); } } });
/** * This method is the workhorse of the builder. * * @param methodName the name of the method being invoked * @param name the name of the node * @param args the arguments passed into the node * @return the object from the factory */ private Object doInvokeMethod(String methodName, Object name, Object args) { Reference explicitResult = new Reference(); if (checkExplicitMethod(methodName, args, explicitResult)) { return explicitResult.get(); } else { try { return dispathNodeCall(name, args); } catch(MissingMethodException mme) { if(mme.getMethod().equals(methodName) && methodMissingDelegate != null) { return methodMissingDelegate.call(new Object[]{methodName, args}); } throw mme; } } }