/**
  * Tests whether the ClassNode implements the specified method name
  *
  * @param classNode The ClassNode
  * @param methodName The method name
  * @param argTypes
  * @return True if it implements the method
  */
 private static boolean implementsMethod(
     ClassNode classNode, String methodName, Class[] argTypes) {
   List methods = classNode.getMethods();
   for (Iterator i = methods.iterator(); i.hasNext(); ) {
     MethodNode mn = (MethodNode) i.next();
     final boolean isZeroArg = (argTypes == null || argTypes.length == 0);
     boolean methodMatch = mn.getName().equals(methodName) && isZeroArg;
     if (methodMatch) return true;
     // TODO Implement further parameter analysis
   }
   return false;
 }
Пример #2
0
  public MethodNode tryFindPossibleMethod(String name, Expression arguments) {
    int count = 0;

    if (arguments instanceof TupleExpression) {
      TupleExpression tuple = (TupleExpression) arguments;
      // TODO this won't strictly be true when using list expansion in argument calls
      count = tuple.getExpressions().size();
    } else return null;

    MethodNode res = null;
    ClassNode node = this;
    TupleExpression args = (TupleExpression) arguments;
    do {
      for (MethodNode method : node.getMethods(name)) {
        if (method.getParameters().length == count) {
          boolean match = true;
          for (int i = 0; i != count; ++i)
            if (!args.getType().isDerivedFrom(method.getParameters()[i].getType())) {
              match = false;
              break;
            }

          if (match) {
            if (res == null) res = method;
            else {
              if (res.getParameters().length != count) return null;
              if (node.equals(this)) return null;

              match = true;
              for (int i = 0; i != count; ++i)
                if (!res.getParameters()[i].getType().equals(method.getParameters()[i].getType())) {
                  match = false;
                  break;
                }
              if (!match) return null;
            }
          }
        }
      }
      node = node.getSuperClass();
    } while (node != null);

    return res;
  }
Пример #3
0
  private static void showDocument(Document doc) {
    StringBuffer content = new StringBuffer();
    Node node = doc.getChildNodes().item(0);
    ApplicationNode appNode = new ApplicationNode(node);

    content.append("Application \n");

    List<ClassNode> classes = appNode.getClasses();

    for (int i = 0; i < classes.size(); i++) {
      ClassNode classNode = classes.get(i);
      content.append(SPACE + "Class: " + classNode.getName() + " \n");

      List<MethodNode> methods = classNode.getMethods();

      for (int j = 0; j < methods.size(); j++) {
        MethodNode methodNode = methods.get(j);
        content.append(SPACE + SPACE + "Method: " + methodNode.getName() + " \n");
      }
    }

    System.out.println(content.toString());
  }
 private boolean anyMethodSkip(final ClassNode node) {
   for (MethodNode methodNode : node.getMethods()) {
     if (isSkipMode(methodNode)) return true;
   }
   return false;
 }