コード例 #1
0
 @Override
 public int hashCode() {
   int result = owner != null ? owner.hashCode() : 0;
   result = 31 * result + (methodName != null ? methodName.hashCode() : 0);
   result = 31 * result + (arguments != null ? arguments.hashCode() : 0);
   return result;
 }
コード例 #2
0
  @Override
  public Type type(Context ctx) {
    List<Class<?>> argumentClasses = new ArrayList<>();
    List<Type> argumentTypes = new ArrayList<>();
    for (Expression argument : arguments) {
      argumentTypes.add(argument.type(ctx));
      if (argument.type(ctx).equals(getType(Object[].class))) {
        argumentClasses.add(Object[].class);
      } else {
        argumentClasses.add(getJavaType(ctx.getClassLoader(), argument.type(ctx)));
      }
    }
    Type returnType;
    try {
      if (ctx.getThisType().equals(owner.type(ctx))) {
        for (org.objectweb.asm.commons.Method method : ctx.getMethods().keySet()) {
          if (method.getName().equals(methodName)) {
            if (method.getArgumentTypes().length == arguments.size()) {
              Type[] methodTypes = method.getArgumentTypes();
              boolean isSame = true;
              for (int i = 0; i < arguments.size(); i++) {
                if (!methodTypes[i].equals(argumentTypes.get(i))) {
                  isSame = false;
                  break;
                }
              }
              if (isSame) return method.getReturnType();
            }
          }
        }
        throw new NoSuchMethodException();
      } else {
        Class<?> ownerJavaType = getJavaType(ctx.getClassLoader(), owner.type(ctx));
        Method method =
            ownerJavaType.getMethod(methodName, argumentClasses.toArray(new Class<?>[] {}));
        Class<?> returnClass = method.getReturnType();
        returnType = getType(returnClass);
      }

    } catch (NoSuchMethodException e) {
      throw new RuntimeException(
          format(
              "No method %s.%s(%s). %s",
              owner.type(ctx).getClassName(),
              methodName,
              (!argumentClasses.isEmpty() ? argsToString(argumentClasses) : ""),
              exceptionInGeneratedClass(ctx)));
    }

    return returnType;
  }
コード例 #3
0
  @Override
  public boolean equals(Object o) {
    if (this == o) return true;
    if (o == null || getClass() != o.getClass()) return false;

    ExpressionCall that = (ExpressionCall) o;

    if (arguments != null ? !arguments.equals(that.arguments) : that.arguments != null)
      return false;
    if (methodName != null ? !methodName.equals(that.methodName) : that.methodName != null)
      return false;
    if (owner != null ? !owner.equals(that.owner) : that.owner != null) return false;

    return true;
  }
コード例 #4
0
  @Override
  public Type load(Context ctx) {
    GeneratorAdapter g = ctx.getGeneratorAdapter();

    owner.load(ctx);

    List<Class<?>> argumentClasses = new ArrayList<>();
    List<Type> argumentTypes = new ArrayList<>();
    for (Expression argument : arguments) {
      argument.load(ctx);
      argumentTypes.add(argument.type(ctx));
      argumentClasses.add(getJavaType(ctx.getClassLoader(), argument.type(ctx)));
    }

    Type returnType;
    try {
      if (ctx.getThisType().equals(owner.type(ctx))) {
        org.objectweb.asm.commons.Method method = null;
        for (org.objectweb.asm.commons.Method m : ctx.getMethods().keySet()) {
          if (m.getName().equals(methodName)) {
            if (m.getArgumentTypes().length == arguments.size()) {
              Type[] methodTypes = m.getArgumentTypes();
              boolean isSame = true;
              for (int i = 0; i < arguments.size(); i++) {
                if (!methodTypes[i].equals(argumentTypes.get(i))) {
                  isSame = false;
                  break;
                }
              }
              if (isSame) {
                method = m;
                break;
              }
            }
          }
        }
        if (method == null) throw new NoSuchMethodException();
        g.invokeVirtual(owner.type(ctx), method);
        return method.getReturnType();
      }
      Class<?> ownerJavaType = getJavaType(ctx.getClassLoader(), owner.type(ctx));
      Method method =
          ownerJavaType.getMethod(methodName, argumentClasses.toArray(new Class<?>[] {}));
      Class<?> returnClass = method.getReturnType();
      returnType = getType(returnClass);

      invokeVirtualOrInterface(
          g,
          ownerJavaType,
          new org.objectweb.asm.commons.Method(
              methodName, returnType, argumentTypes.toArray(new Type[] {})));

    } catch (NoSuchMethodException e) {
      throw new RuntimeException(
          format(
              "No method %s.%s(%s). %s",
              owner.type(ctx).getClassName(),
              methodName,
              (!argumentClasses.isEmpty() ? argsToString(argumentClasses) : ""),
              exceptionInGeneratedClass(ctx)));
    }
    return returnType;
  }