Esempio n. 1
0
  public Method lookupMethod(
      CtClass clazz,
      CtClass currentClass,
      MethodInfo current,
      String methodName,
      int[] argTypes,
      int[] argDims,
      String[] argClassNames)
      throws CompileError {
    Method maybe = null;
    // to enable the creation of a recursively called method
    if (current != null && clazz == currentClass)
      if (current.getName().equals(methodName)) {
        int res = compareSignature(current.getDescriptor(), argTypes, argDims, argClassNames);
        if (res != NO) {
          Method r = new Method(clazz, current, res);
          if (res == YES) return r;
          else maybe = r;
        }
      }

    Method m = lookupMethod(clazz, methodName, argTypes, argDims, argClassNames, maybe != null);
    if (m != null) return m;
    else return maybe;
  }
Esempio n. 2
0
  private Method lookupMethod(
      CtClass clazz,
      String methodName,
      int[] argTypes,
      int[] argDims,
      String[] argClassNames,
      boolean onlyExact)
      throws CompileError {
    Method maybe = null;
    ClassFile cf = clazz.getClassFile2();
    // If the class is an array type, the class file is null.
    // If so, search the super class java.lang.Object for clone() etc.
    if (cf != null) {
      List list = cf.getMethods();
      int n = list.size();
      for (int i = 0; i < n; ++i) {
        MethodInfo minfo = (MethodInfo) list.get(i);
        if (minfo.getName().equals(methodName)) {
          int res = compareSignature(minfo.getDescriptor(), argTypes, argDims, argClassNames);
          if (res != NO) {
            Method r = new Method(clazz, minfo, res);
            if (res == YES) return r;
            else if (maybe == null || maybe.notmatch > res) maybe = r;
          }
        }
      }
    }

    if (onlyExact) maybe = null;
    else onlyExact = maybe != null;

    int mod = clazz.getModifiers();
    boolean isIntf = Modifier.isInterface(mod);
    try {
      // skip searching java.lang.Object if clazz is an interface type.
      if (!isIntf) {
        CtClass pclazz = clazz.getSuperclass();
        if (pclazz != null) {
          Method r = lookupMethod(pclazz, methodName, argTypes, argDims, argClassNames, onlyExact);
          if (r != null) return r;
        }
      }
    } catch (NotFoundException e) {
    }

    if (isIntf || Modifier.isAbstract(mod))
      try {
        CtClass[] ifs = clazz.getInterfaces();
        int size = ifs.length;
        for (int i = 0; i < size; ++i) {
          Method r = lookupMethod(ifs[i], methodName, argTypes, argDims, argClassNames, onlyExact);
          if (r != null) return r;
        }

        if (isIntf) {
          // finally search java.lang.Object.
          CtClass pclazz = clazz.getSuperclass();
          if (pclazz != null) {
            Method r =
                lookupMethod(pclazz, methodName, argTypes, argDims, argClassNames, onlyExact);
            if (r != null) return r;
          }
        }
      } catch (NotFoundException e) {
      }

    return maybe;
  }