@Override
 protected ClassNode createClosureClass(final ClosureExpression expression, final int mods) {
   ClassNode closureClass = super.createClosureClass(expression, mods);
   List<MethodNode> methods = closureClass.getDeclaredMethods("call");
   List<MethodNode> doCall = closureClass.getMethods("doCall");
   if (doCall.size() != 1) {
     throw new GroovyBugError(
         "Expected to find one (1) doCall method on generated closure, but found "
             + doCall.size());
   }
   MethodNode doCallMethod = doCall.get(0);
   if (methods.isEmpty() && doCallMethod.getParameters().length == 1) {
     createDirectCallMethod(closureClass, doCallMethod);
   }
   MethodTargetCompletionVisitor visitor = new MethodTargetCompletionVisitor(doCallMethod);
   Object dynamic = expression.getNodeMetaData(StaticTypesMarker.DYNAMIC_RESOLUTION);
   if (dynamic != null) {
     doCallMethod.putNodeMetaData(StaticTypesMarker.DYNAMIC_RESOLUTION, dynamic);
   }
   for (MethodNode method : methods) {
     visitor.visitMethod(method);
   }
   closureClass.putNodeMetaData(StaticCompilationMetadataKeys.STATIC_COMPILE_NODE, Boolean.TRUE);
   return closureClass;
 }
示例#2
0
 /**
  * This methods creates a list of all methods with this name of the current class and of all super
  * classes
  *
  * @return the methods list
  * @see #getDeclaredMethods(String)
  */
 public List<MethodNode> getMethods(String name) {
   List<MethodNode> answer = new ArrayList<MethodNode>();
   ClassNode node = this;
   while (node != null) {
     answer.addAll(node.getDeclaredMethods(name));
     node = node.getSuperClass();
   }
   return answer;
 }
 public static boolean hasDeclaredMethod(ClassNode cNode, String name, int argsCount) {
   List<MethodNode> ms = cNode.getDeclaredMethods(name);
   for (MethodNode m : ms) {
     Parameter[] paras = m.getParameters();
     if (paras != null && paras.length == argsCount) {
       return true;
     }
   }
   return false;
 }
示例#4
0
 public static void removeMethod(ClassNode declaringClass, MethodNode methodNode) {
   declaringClass.getMethods().remove(methodNode);
   declaringClass.getDeclaredMethods(methodNode.getName()).clear();
 }