示例#1
0
  private static String getTypeMetadata(Class<?> clazz) {
    StringBuilder sb = new StringBuilder();

    if (clazz.isInterface()) {
      sb.append("I ");
    } else {
      sb.append("C ");
    }

    if (Modifier.isStatic(clazz.getModifiers())) {
      sb.append("S\n");
    } else {
      sb.append("I\n");
    }

    Class<?> baseClass = clazz.getSuperclass();
    sb.append("B " + ((baseClass != null) ? baseClass.getName() : "").replace('.', '/') + "\n");

    Method[] methods = clazz.getDeclaredMethods();
    Arrays.sort(methods, methodComparator);

    for (Method m : methods) {
      int modifiers = m.getModifiers();
      if (!Modifier.isStatic(modifiers)
          && (Modifier.isPublic(modifiers) || Modifier.isProtected(modifiers))) {
        sb.append("M ");
        sb.append(m.getName());
        Class<?>[] params = m.getParameterTypes();
        String sig = MethodResolver.getMethodSignature(m.getReturnType(), params);
        sb.append(" ");
        sb.append(sig);
        int paramCount = params.length;
        sb.append(" ");
        sb.append(paramCount);
        sb.append("\n");
      }
    }

    Field[] fields = clazz.getDeclaredFields();
    for (Field f : fields) {
      int modifiers = f.getModifiers();
      if (!Modifier.isStatic(modifiers)
          && (Modifier.isPublic(modifiers) || Modifier.isProtected(modifiers))) {
        sb.append("F ");
        sb.append(f.getName());
        sb.append(" ");
        String sig = MethodResolver.getTypeSignature(f.getType());
        sb.append(sig);
        sb.append(" 0\n");
      }
    }

    String ret = sb.toString();

    return ret;
  }
  /** Compiles MethodExpressions */
  @Override
  public void visit(MethodExpression method) {
    if (method == null) {
      throw new ArgumentException(METHOD + E_IS_NULL);
    }

    LogicalExpression[] parameters = new LogicalExpression[method.getParameters().length];
    for (int i = 0; i < parameters.length; i++) {
      parameters[i] = evaluate(method.getParameters()[i]);
    }

    MethodArgs args = new MethodArgs(method.getName());
    args.setParameters(parameters);

    resolveMethod(args);

    // If an external implementation was found get the result back
    if (args.getResult() != null) {
      result.setResult((LogicalExpression) args.getResult());
      return;
    }

    defaultMethodResolver.resolve(args);
    result.setResult((LogicalExpression) args.getResult());
  }
示例#3
0
  private static int cacheConstructor(Class<?> clazz, Object[] args)
      throws ClassNotFoundException, IOException {
    Constructor<?> ctor = MethodResolver.resolveConstructor(clazz, args);

    // TODO: Lubo: Not thread safe already.
    // TODO: Lubo: Does not check for existing items
    int ctorId = ctorCache.size();

    ctorCache.add(ctor);

    return ctorId;
  }
示例#4
0
  public static String resolveMethodOverload(String className, String methodName, Object[] args)
      throws Exception {
    if (IsLogEnabled)
      Log.d(
          DEFAULT_LOG_TAG,
          "resolveMethodOverload: Resolving method " + methodName + " on class " + className);
    String res = MethodResolver.resolveMethodOverload(classCache, className, methodName, args);
    if (IsLogEnabled) Log.d(DEFAULT_LOG_TAG, "resolveMethodOverload: method found :" + res);
    if (res == null) {
      throw new Exception("Failed resolving method " + methodName + " on class " + className);
    }

    return res;
  }
示例#5
0
  private static Object createInstance(Object[] args, int objectId, int constructorId)
      throws InstantiationException, IllegalAccessException, ClassNotFoundException,
          NoSuchMethodException, IllegalArgumentException, InvocationTargetException, IOException {
    Constructor<?> ctor = ctorCache.get(constructorId);
    boolean success = MethodResolver.convertConstructorArgs(ctor, args);

    if (!success) {
      StringBuilder builder = new StringBuilder();
      builder.append(constructorId + "(");
      for (Object arg : args) {
        if (arg != null) {
          builder.append(arg.toString() + ", ");
        } else {
          builder.append("null, ");
        }
      }
      builder.append(")");

      throw new InstantiationException(
          "MethodResolver didn't resolve any constructor with the specified arguments "
              + builder.toString());
    }

    Object instance;
    try {
      Platform.currentObjectId = objectId;
      instance = ctor.newInstance(args);

      makeInstanceStrong(instance, objectId);
    } finally {
      Platform.currentObjectId = -1;
    }

    adjustAmountOfExternalAllocatedMemory();

    return instance;
  }
 private void resolveMethod(MethodArgs args) {
   if (methodResolver != null) {
     methodResolver.resolve(args);
   }
 }