Exemplo n.º 1
0
 // example usage (please do not use directly, use instead the spoon.Launcher
 // API to create the factory)
 public static void main(String[] args) throws Exception {
   Launcher main = new Launcher();
   JDTBasedSpoonCompiler comp = new JDTBasedSpoonCompiler(main.createFactory());
   comp.createBatchCompiler().printUsage();
   SpoonFile file =
       new FileSystemFile(new File("./src/main/java/spoon/support/compiler/JDTCompiler.java"));
   comp.addInputSource(file);
   try {
     comp.build();
     final Set<CtType<?>> types =
         comp.getFactory().Package().get("spoon.support.compiler").getTypes();
     for (CtType<?> type : types) {
       main.getEnvironment().debugMessage(type.toString());
     }
   } catch (Exception e) {
     throw new RuntimeException(e);
   }
 }
Exemplo n.º 2
0
  @Test
  public void superInvocationWithEnclosingInstance() throws Exception {

    /**
     * To extend a nested class an enclosing instance must be provided to call the super
     * constructor.
     */
    String sourcePath = "./src/test/resources/spoon/test/prettyprinter/NestedSuperCall.java";
    List<SpoonResource> files = SpoonResourceHelper.resources(sourcePath);
    assertEquals(1, files.size());

    SpoonCompiler comp = new Launcher().createCompiler();
    comp.addInputSources(files);
    comp.build();

    Factory factory = comp.getFactory();
    CtType<?> theClass = factory.Type().get("spoon.test.prettyprinter.NestedSuperCall");

    assertTrue(theClass.toString().contains("nc.super(\"a\")"));
  }