Exemple #1
0
  @Test
  public void testPrintNotAllSourcesWithFilter() throws Exception {
    final File target = new File("./target/print-not-all/default");
    final SpoonAPI launcher = new Launcher();
    launcher.getEnvironment().setNoClasspath(true);
    launcher.addInputResource("./src/main/java");
    launcher.setSourceOutputDirectory(target);
    launcher.setOutputFilter(
        new AbstractFilter<CtType<?>>(CtType.class) {
          @Override
          public boolean matches(CtType<?> element) {
            return "spoon.Launcher".equals(element.getQualifiedName())
                || "spoon.template.AbstractTemplate".equals(element.getQualifiedName());
          }
        });
    launcher.run();

    List<File> list = new ArrayList<>(FileUtils.listFiles(target, new String[] {"java"}, true));
    final List<String> filesName =
        list.stream().map(File::getName).sorted().collect(Collectors.<String>toList());

    assertEquals(2, filesName.size());
    assertEquals("AbstractTemplate.java", filesName.get(0));
    assertEquals("Launcher.java", filesName.get(1));
  }
Exemple #2
0
  @Test
  public void testPrintNotAllSourcesWithNames() throws Exception {
    final File target = new File("./target/print-not-all/array");
    final SpoonAPI launcher = new Launcher();
    launcher.getEnvironment().setNoClasspath(true);
    launcher.addInputResource("./src/main/java");
    launcher.setSourceOutputDirectory(target);
    launcher.setOutputFilter("spoon.Launcher", "spoon.template.AbstractTemplate");
    launcher.run();

    List<File> list = new ArrayList<>(FileUtils.listFiles(target, new String[] {"java"}, true));
    final List<String> filesName =
        list.stream().map(File::getName).sorted().collect(Collectors.<String>toList());

    assertEquals(2, filesName.size());
    assertEquals("AbstractTemplate.java", filesName.get(0));
    assertEquals("Launcher.java", filesName.get(1));
  }