/**
   * Returns a class which has a static method with the same name as 'method', whose body creates an
   * new instance of 'specimen', casts it to 'iface' (including the type parameters) and invokes
   * 'method' upon it via an invokeinterface instruction with 'args' as function call parameters.
   */
  private Class invokeInterfaceHarness(
      Class specimen, Extends iface, AbstractMethod method, String... args) {
    Interface istub =
        new Interface(
            iface.getType().getName(),
            iface.getType().getAccessFlags(),
            iface.getType().getParameters(),
            null,
            Arrays.asList((Method) method));
    Class cstub = new Class(specimen.getName());

    String params = toJoinedString(args, ", ");

    ConcreteMethod sm =
        new ConcreteMethod(
            "int",
            SourceModel.stdMethodName,
            String.format(
                "return ((%s)(new %s())).%s(%s);",
                iface.toString(), specimen.getName(), method.getName(), params),
            new AccessFlag("public"),
            new AccessFlag("static"));
    sm.suppressWarnings();

    Class ii = new Class("II_" + specimen.getName() + "_" + iface.getType().getName(), sm);
    ii.addCompilationDependency(istub);
    ii.addCompilationDependency(cstub);
    ii.addCompilationDependency(method);
    return ii;
  }
Example #2
0
  /**
   * Compiles a hierarchy, starting at 'type' and return a mapping of the name to the location where
   * the classfile for that type resides.
   */
  private Map<String, File> compileHierarchy(Type type) {
    HashMap<String, File> outputDirs = new HashMap<>();

    File outDir = compileOne(type);
    outputDirs.put(type.getName(), outDir);

    Class superClass = type.getSuperclass();
    if (superClass != null) {
      for (Map.Entry<String, File> each : compileHierarchy(superClass).entrySet()) {
        outputDirs.put(each.getKey(), each.getValue());
      }
    }
    for (Extends ext : type.getSupertypes()) {
      Type iface = ext.getType();
      for (Map.Entry<String, File> each : compileHierarchy(iface).entrySet()) {
        outputDirs.put(each.getKey(), each.getValue());
      }
    }

    return outputDirs;
  }
Example #3
0
 public static void main(String[] args) {
   Extends ex = new Extends();
   ex.getC();
 }