public static String prettyMethodSignature(ClassSymbol origin, MethodSymbol m) {
    StringBuilder sb = new StringBuilder();
    if (m.isConstructor()) {
      Name name = m.owner.enclClass().getSimpleName();
      if (name.isEmpty()) {
        // use the superclass name of anonymous classes
        name = m.owner.enclClass().getSuperclass().asElement().getSimpleName();
      }
      sb.append(name);
    } else {
      if (!m.owner.equals(origin)) {
        sb.append(m.owner.getSimpleName()).append('.');
      }
      sb.append(m.getSimpleName());
    }
    sb.append(
        m.getParameters().stream()
            .map(v -> v.type.accept(PRETTY_TYPE_VISITOR, null))
            .collect(joining(", ", "(", ")")));
    return sb.toString();
  }
@Test
  public void prettyMethodSignature() throws Exception {
    FileSystem fileSystem = Jimfs.newFileSystem(Configuration.unix());
    Path source = fileSystem.getPath("Test.java");
    Files.write(
        source,
        ImmutableList.of(
            "class Test {", //
            "  void f() {",
            "    new Test();",
            "    new Test() {};",
            "  }",
            "}"),
        UTF_8);
    JavacFileManager fileManager = new JavacFileManager(new Context(), false, UTF_8);
    List<String> signatures = new ArrayList<>();
    JavacTask task =
        JavacTool.create()
            .getTask(
                /* out= */ null,
                fileManager,
                /* diagnosticListener= */ null,
                /* options= */ ImmutableList.of(),
                /* classes= */ ImmutableList.of(),
                fileManager.getJavaFileObjects(source));
    task.addTaskListener(
        new TaskListener() {
          @Override
          public void finished(TaskEvent e) {
            if (e.getKind() != Kind.ANALYZE) {
              return;
            }
            new TreePathScanner<Void, Void>() {
              @Override
              public Void visitNewClass(NewClassTree node, Void unused) {
                signatures.add(
                    Signatures.prettyMethodSignature(
                        (ClassSymbol) e.getTypeElement(), ASTHelpers.getSymbol(node)));
                return super.visitNewClass(node, null);
              }
            }.scan(e.getCompilationUnit(), null);
          }
        });
    assertThat(task.call()).isTrue();
    assertThat(signatures).containsExactly("Test()", "Test()");
  }