Skip to content

Commit

Permalink
feat(java_common): add function to render signature as plaintext (#5400)
Browse files Browse the repository at this point in the history
  • Loading branch information
wcalandro committed Oct 21, 2022
1 parent 50e7e23 commit a70ccc0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
14 changes: 14 additions & 0 deletions kythe/java/com/google/devtools/kythe/doc/MarkedSourceRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,20 @@ public static SafeHtml renderSignature(
0);
}

/**
* Render {@code signature} a full signature as plaintext.
*
* @param signature the {@link MarkedSource} to render.
*/
public static String renderSignatureText(MarkedSource signature) {
return new RenderSimpleIdentifierState(null)
.renderText(
signature,
Sets.immutableEnumSet(
MarkedSource.Kind.IDENTIFIER, MarkedSource.Kind.TYPE, MarkedSource.Kind.PARAMETER),
0);
}

/**
* Extract and render a plaintext initializer from {@code signature}.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ public void testRenderingSignatures() throws IOException {
.isEqualTo(
"<span>void H(<a href=\"a\">String </a>message, <a href=\"b\">Throwable"
+ " </a>cause)</span>");
assertThat(MarkedSourceRenderer.renderSignatureText(markedSource))
.isEqualTo("void H(String message, Throwable cause)");
}

public void testRenderingLists() throws IOException {
Expand Down

0 comments on commit a70ccc0

Please sign in to comment.